restores Helder in all its glory

This commit is contained in:
2026-09-28 11:34:49 +02:00
parent c2b38b853c
commit 1d29d0952d
280 changed files with 29205 additions and 7 deletions
@@ -0,0 +1,57 @@
import Foundation
/// A pointer at code the agent understands: `path`, `path:42` or `path:42-58`.
public struct AgentReference: Sendable, Equatable, CustomStringConvertible {
public var path: String
/// First line, 1-based; nil for a whole-file (or folder) reference.
public var startLine: Int?
/// Last line; equal to `startLine` for a single line.
public var endLine: Int?
public init(path: String, startLine: Int? = nil, endLine: Int? = nil) {
self.path = path
self.startLine = startLine
self.endLine = endLine ?? startLine
}
/// A reference to a line range.
public init(path: String, lines: ClosedRange<Int>) {
self.init(path: path, startLine: lines.lowerBound, endLine: lines.upperBound)
}
public var description: String {
guard let start = startLine else { return path }
guard let end = endLine, end != start else { return "\(path):\(start)" }
return "\(path):\(start)-\(end)"
}
}
public enum PassOn {
/// The exact text a "Pass on …" action inserts into the agent.
///
/// With code: `note ref` then the code in a fenced block. Without: `note => ref`,
/// or just `ref` when the note is empty.
public static func compose(note: String, reference: String, code: String? = nil) -> String {
let n = note.trimmingCharacters(in: .whitespacesAndNewlines)
if let code {
let head = (n.isEmpty ? "" : n + " ") + reference
return head + "\n```\n" + code + "\n```"
}
return n.isEmpty ? reference : "\(n) => \(reference)"
}
}
public enum BracketedPaste {
public static let start = "\u{1b}[200~"
public static let end = "\u{1b}[201~"
/// Wraps text so the CLI treats it as pasted and does not submit it.
///
/// ESC and the 8-bit CSI are stripped from the payload: a file or note holding `ESC[201~`
/// would otherwise end the paste early and let the rest run as typed input.
public static func wrap(_ text: String, composerHasText: Bool) -> String {
var payload = String.UnicodeScalarView()
payload.append(contentsOf: text.unicodeScalars.lazy.filter { $0 != "\u{1b}" && $0 != "\u{9b}" })
return start + (composerHasText ? "\n" : "") + String(payload) + end
}
}
@@ -0,0 +1,45 @@
import Foundation
public enum TerminalKind: String, Sendable, Equatable, CaseIterable {
/// The top pane: a shell that runs the `claude` CLI.
case agent
/// The bottom pane: a plain login shell.
case shell
}
/// Executable, arguments and environment for one terminal pane.
public struct TerminalLaunch: Sendable, Equatable {
public var executable: String
public var arguments: [String]
public var environment: [String: String]
public var workingDirectory: String
public init(executable: String, arguments: [String], environment: [String: String], workingDirectory: String) {
self.executable = executable
self.arguments = arguments
self.environment = environment
self.workingDirectory = workingDirectory
}
/// The launch for a pane. The agent runs as `$SHELL -i -c <command>`: `-i` still sources the rc
/// files (nvm etc.) but leaves no prompt line or echoed command behind.
public static func make(kind: TerminalKind, config: HelderConfig, projectRoot: String?, environment base: [String: String]) -> TerminalLaunch {
let shell = config.terminal.shell ?? base["SHELL"] ?? "/bin/zsh"
let args = kind == .agent && config.ai.autoLaunch ? ["-i", "-c", config.ai.command] : []
let cwd = projectRoot ?? base["HOME"] ?? "/"
return TerminalLaunch(executable: shell, arguments: args, environment: environment(from: base), workingDirectory: cwd)
}
/// The child environment. A GUI launch inherits no locale and no COLORTERM, which turns
/// multibyte output into mojibake and shifts the CLI's 24-bit colours; npm's prefix
/// variables make nvm refuse to load.
public static func environment(from base: [String: String]) -> [String: String] {
var env = base
env["npm_config_prefix"] = nil
env["npm_config_globalconfig"] = nil
if env["LC_ALL"] == nil && env["LC_CTYPE"] == nil && env["LANG"] == nil { env["LANG"] = "en_US.UTF-8" }
if env["COLORTERM"] == nil { env["COLORTERM"] = "truecolor" }
env["TERM"] = "xterm-256color"
return env
}
}