taskquoin 0.0.0-stage → 2026.12.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +62 -0
- package/LICENSE +55 -0
- package/README.md +227 -2
- package/SECURITY.md +26 -0
- package/adapters/git/src/git.js +250 -0
- package/adapters/git/src/index.js +1 -0
- package/adapters/hooks-claude/src/canonical.js +45 -0
- package/adapters/hooks-claude/src/index.js +2 -0
- package/adapters/hooks-claude/src/main.js +58 -0
- package/adapters/hooks-claude/src/payload.js +40 -0
- package/adapters/host-probe/src/index.js +2 -0
- package/adapters/host-probe/src/ollama.js +18 -0
- package/adapters/host-probe/src/probe.js +107 -0
- package/adapters/local-tool/src/fingerprint.js +56 -0
- package/adapters/local-tool/src/index.js +4 -0
- package/adapters/local-tool/src/local-tool.js +22 -0
- package/adapters/local-tool/src/sandboxed.js +105 -0
- package/adapters/local-tool/src/scan.js +52 -0
- package/adapters/memory-claude-mem/src/claude-mem.js +115 -0
- package/adapters/memory-claude-mem/src/index.js +1 -0
- package/adapters/process-runner/src/index.js +1 -0
- package/adapters/process-runner/src/runner.js +123 -0
- package/adapters/runtime-api/src/capabilities.json +116 -0
- package/adapters/runtime-api/src/executor.js +131 -0
- package/adapters/runtime-api/src/index.js +1 -0
- package/adapters/runtime-claude/src/capabilities.json +375 -0
- package/adapters/runtime-claude/src/command.js +34 -0
- package/adapters/runtime-claude/src/executor.js +162 -0
- package/adapters/runtime-claude/src/index.js +4 -0
- package/adapters/runtime-claude/src/permissions.js +76 -0
- package/adapters/runtime-claude/src/stream.js +60 -0
- package/adapters/runtime-codex/src/capabilities.json +192 -0
- package/adapters/runtime-codex/src/command.js +36 -0
- package/adapters/runtime-codex/src/executor.js +83 -0
- package/adapters/runtime-codex/src/index.js +4 -0
- package/adapters/runtime-codex/src/scratch.js +32 -0
- package/adapters/runtime-codex/src/stream.js +39 -0
- package/adapters/runtime-opencode/src/capabilities.json +149 -0
- package/adapters/runtime-opencode/src/config.js +33 -0
- package/adapters/runtime-opencode/src/credentials.js +130 -0
- package/adapters/runtime-opencode/src/executor.js +127 -0
- package/adapters/runtime-opencode/src/facts.js +43 -0
- package/adapters/runtime-opencode/src/hosts.js +16 -0
- package/adapters/runtime-opencode/src/hosts.json +3 -0
- package/adapters/runtime-opencode/src/index.js +6 -0
- package/adapters/runtime-opencode/src/mounts.js +58 -0
- package/adapters/runtime-opencode/src/stream.js +63 -0
- package/adapters/skill-store/src/index.js +1 -0
- package/adapters/skill-store/src/skill-store.js +162 -0
- package/adapters/store-fs/src/index.js +2 -0
- package/adapters/store-fs/src/store.js +201 -0
- package/adapters/store-fs/src/trusted-dir.js +37 -0
- package/apps/cli/src/console.js +432 -0
- package/apps/cli/src/dashboard-approve.js +259 -0
- package/apps/cli/src/dashboard-data.js +424 -0
- package/apps/cli/src/dashboard.js +500 -0
- package/apps/cli/src/history.js +35 -0
- package/apps/cli/src/home.js +18 -0
- package/apps/cli/src/i18n/en.js +527 -0
- package/apps/cli/src/i18n/index.js +90 -0
- package/apps/cli/src/i18n/languages.js +25 -0
- package/apps/cli/src/i18n/locales/ar.json +526 -0
- package/apps/cli/src/i18n/locales/de.json +505 -0
- package/apps/cli/src/i18n/locales/es.json +505 -0
- package/apps/cli/src/i18n/locales/fa.json +505 -0
- package/apps/cli/src/i18n/locales/fr.json +505 -0
- package/apps/cli/src/i18n/locales/he.json +505 -0
- package/apps/cli/src/i18n/locales/hi.json +505 -0
- package/apps/cli/src/i18n/locales/id.json +491 -0
- package/apps/cli/src/i18n/locales/it.json +505 -0
- package/apps/cli/src/i18n/locales/ja.json +491 -0
- package/apps/cli/src/i18n/locales/ko.json +491 -0
- package/apps/cli/src/i18n/locales/nl.json +505 -0
- package/apps/cli/src/i18n/locales/pl.json +512 -0
- package/apps/cli/src/i18n/locales/pt-BR.json +505 -0
- package/apps/cli/src/i18n/locales/ru.json +512 -0
- package/apps/cli/src/i18n/locales/th.json +491 -0
- package/apps/cli/src/i18n/locales/tr.json +505 -0
- package/apps/cli/src/i18n/locales/uk.json +512 -0
- package/apps/cli/src/i18n/locales/vi.json +491 -0
- package/apps/cli/src/i18n/locales/zh-CN.json +491 -0
- package/apps/cli/src/i18n/locales/zh-TW.json +491 -0
- package/apps/cli/src/i18n/width.js +40 -0
- package/apps/cli/src/layout.js +18 -0
- package/apps/cli/src/main.js +830 -0
- package/apps/cli/src/preferences.js +46 -0
- package/apps/cli/src/runtime-notices.js +41 -0
- package/apps/cli/src/safe-text.js +3 -0
- package/apps/cli/src/shortcut.js +82 -0
- package/apps/cli/src/skills-cli.js +112 -0
- package/apps/cli/src/tui/caps.js +31 -0
- package/apps/cli/src/tui/components/agent-list.js +58 -0
- package/apps/cli/src/tui/components/approval-center.js +145 -0
- package/apps/cli/src/tui/components/approval.js +95 -0
- package/apps/cli/src/tui/components/dashboard-frame.js +293 -0
- package/apps/cli/src/tui/components/diff-viewer.js +549 -0
- package/apps/cli/src/tui/components/event-viewer.js +46 -0
- package/apps/cli/src/tui/components/help-panel.js +59 -0
- package/apps/cli/src/tui/components/home.js +185 -0
- package/apps/cli/src/tui/components/logo.js +67 -0
- package/apps/cli/src/tui/components/panel.js +70 -0
- package/apps/cli/src/tui/components/status-bar.js +96 -0
- package/apps/cli/src/tui/components/timeline.js +120 -0
- package/apps/cli/src/tui/keys.js +139 -0
- package/apps/cli/src/tui/neutral.js +68 -0
- package/apps/cli/src/tui/screen.js +111 -0
- package/apps/cli/src/tui/text.js +165 -0
- package/apps/cli/src/tui/tokens.js +89 -0
- package/apps/cli/src/tui/view.js +64 -0
- package/apps/cli/src/upgrade-check.js +86 -0
- package/apps/cli/src/upgrade-cli.js +168 -0
- package/apps/cli/src/workflow-cli.js +674 -0
- package/package.json +29 -4
- package/packages/application/src/index.js +8 -0
- package/packages/application/src/lib/digest.js +7 -0
- package/packages/application/src/ports/memory.js +1 -0
- package/packages/application/src/ports/runtime-executor.js +1 -0
- package/packages/application/src/projection/run-view.js +194 -0
- package/packages/application/src/projection/squad-view.js +33 -0
- package/packages/application/src/use-cases/prepare-run.js +68 -0
- package/packages/application/src/workflow/feature-governed.js +420 -0
- package/packages/application/src/workflow/gate-signals.js +40 -0
- package/packages/application/src/workflow/prompts.js +81 -0
- package/packages/config/src/config.js +372 -0
- package/packages/config/src/index.js +1 -0
- package/packages/domain/src/capabilities.js +13 -0
- package/packages/domain/src/capability-matrix.js +63 -0
- package/packages/domain/src/enforcement.js +95 -0
- package/packages/domain/src/index.js +4 -0
- package/packages/domain/src/policy.js +32 -0
- package/packages/rules/src/glob.js +47 -0
- package/packages/rules/src/index.js +5 -0
- package/packages/rules/src/inherit.js +19 -0
- package/packages/rules/src/lists.js +41 -0
- package/packages/rules/src/rules.js +79 -0
- package/packages/rules/src/shell.js +83 -0
- package/packages/skills/src/index.js +1 -0
- package/packages/skills/src/skills.js +108 -0
- package/skills/code-review/SKILL.md +51 -0
- package/skills/egm-design/LICENSE +202 -0
- package/skills/egm-design/SKILL.md +68 -0
- package/skills/egm-design/references/feature-spec-standard.md +39 -0
- package/skills/egm-implementation-readiness/LICENSE +202 -0
- package/skills/egm-implementation-readiness/SKILL.md +67 -0
- package/skills/egm-implementation-readiness/references/implementation-readiness-standard.md +37 -0
- package/skills/first-party.lock.json +10 -0
- package/skills/planning-contract/SKILL.md +51 -0
- package/skills/ponytail/LICENSE +21 -0
- package/skills/ponytail/SKILL.md +56 -0
- package/skills/security-review/SKILL.md +58 -0
- package/skills/tdd/SKILL.md +52 -0
- package/skills/unslop/LICENSE +396 -0
- package/skills/unslop/SKILL.md +239 -0
- package/skills/unslop/references/cjk.md +34 -0
- package/skills/unslop/references/effects.md +113 -0
- package/skills/unslop/references/refs.md +17 -0
- package/skills/unslop/references/rtl.md +111 -0
- package/skills/unslop/references/signs.md +122 -0
- package/skills/unslop/references/tokens.md +139 -0
- package/skills/unslop/references/visuals.md +84 -0
|
@@ -0,0 +1,201 @@
|
|
|
1
|
+
import { createHash } from 'node:crypto';
|
|
2
|
+
import { appendFileSync, chmodSync, closeSync, constants, existsSync, fstatSync, openSync, readSync, readdirSync, readFileSync, realpathSync, renameSync, writeFileSync } from 'node:fs';
|
|
3
|
+
import { homedir } from 'node:os';
|
|
4
|
+
import { join } from 'node:path';
|
|
5
|
+
import { checkTrustedDir, ensureTrustedDir } from "./trusted-dir.js";
|
|
6
|
+
/** `$XDG_STATE_HOME/taskquoin` (default `~/.local/state/taskquoin`). */
|
|
7
|
+
export function stateBase() {
|
|
8
|
+
return join(process.env.XDG_STATE_HOME || join(homedir(), '.local', 'state'), 'taskquoin');
|
|
9
|
+
}
|
|
10
|
+
/** Control store for one repository, keyed by its physical path; always outside the repository (ADR-0005). */
|
|
11
|
+
export function repoStore(repoRoot, base = stateBase()) {
|
|
12
|
+
const realRepo = realpathSync(repoRoot);
|
|
13
|
+
const id = createHash('sha256').update(realRepo).digest('hex').slice(0, 16);
|
|
14
|
+
const root = ensureTrustedDir(join(ensureTrustedDir(join(ensureTrustedDir(base, realRepo), 'repos'), realRepo), id), realRepo);
|
|
15
|
+
const sub = (n) => ensureTrustedDir(join(root, n), realRepo);
|
|
16
|
+
return { root, runs: sub('runs'), artifacts: sub('artifacts'), policies: sub('policies'), approvals: sub('approvals') };
|
|
17
|
+
}
|
|
18
|
+
/**
|
|
19
|
+
* Read-only twin of `repoStore()`: same paths, creates nothing. `undefined` when the repo store does not exist;
|
|
20
|
+
* throws when a directory on the way fails the trusted-dir checks. Sub-directories that do not exist yet are still
|
|
21
|
+
* returned as paths (readers treat a missing file as empty).
|
|
22
|
+
*/
|
|
23
|
+
export function openRepoStoreReadOnly(repoRoot, base = stateBase()) {
|
|
24
|
+
const realRepo = realpathSync(repoRoot);
|
|
25
|
+
const id = createHash('sha256').update(realRepo).digest('hex').slice(0, 16);
|
|
26
|
+
const b = checkTrustedDir(base, realRepo);
|
|
27
|
+
if (!b)
|
|
28
|
+
return undefined;
|
|
29
|
+
const repos = checkTrustedDir(join(b, 'repos'), realRepo);
|
|
30
|
+
if (!repos)
|
|
31
|
+
return undefined;
|
|
32
|
+
const root = checkTrustedDir(join(repos, id), realRepo);
|
|
33
|
+
if (!root)
|
|
34
|
+
return undefined;
|
|
35
|
+
const sub = (n) => checkTrustedDir(join(root, n), realRepo) ?? join(root, n);
|
|
36
|
+
return { root, runs: sub('runs'), artifacts: sub('artifacts'), policies: sub('policies'), approvals: sub('approvals') };
|
|
37
|
+
}
|
|
38
|
+
const READ_FLAGS = constants.O_RDONLY | (constants.O_NOFOLLOW ?? 0) | (constants.O_NONBLOCK ?? 0);
|
|
39
|
+
/**
|
|
40
|
+
* A regular file, read through ONE descriptor: opened without following a symlink (`<file> is a symlink; refusing`)
|
|
41
|
+
* and without blocking (a FIFO or a device opens at once), then `fstat` must say a regular file (else `ENOTREG`), and
|
|
42
|
+
* only that descriptor is read — never the path again. `maxBytes`: a larger file is refused unread (`EFBIG`, with its
|
|
43
|
+
* `size`). `tailBytes`: only its last bytes (`cut` when that is not the whole file). A missing file throws ENOENT.
|
|
44
|
+
*/
|
|
45
|
+
export function readRegularFile(file, o = {}) {
|
|
46
|
+
let fd;
|
|
47
|
+
try {
|
|
48
|
+
fd = openSync(file, READ_FLAGS);
|
|
49
|
+
}
|
|
50
|
+
catch (e) {
|
|
51
|
+
if (e.code === 'ELOOP')
|
|
52
|
+
throw Object.assign(new Error(`${file} is a symlink; refusing`), { code: 'ELOOP' });
|
|
53
|
+
throw e;
|
|
54
|
+
}
|
|
55
|
+
try {
|
|
56
|
+
const st = fstatSync(fd);
|
|
57
|
+
if (!st.isFile())
|
|
58
|
+
throw Object.assign(new Error(`${file} is not a regular file; refusing`), { code: 'ENOTREG' });
|
|
59
|
+
const size = st.size;
|
|
60
|
+
if (o.maxBytes !== undefined && size > o.maxBytes)
|
|
61
|
+
throw Object.assign(new Error(`${file} is ${size} bytes, over ${o.maxBytes}`), { code: 'EFBIG', size });
|
|
62
|
+
const len = o.tailBytes === undefined ? size : Math.min(size, Math.max(1, o.tailBytes));
|
|
63
|
+
const buf = Buffer.alloc(len);
|
|
64
|
+
let got = 0;
|
|
65
|
+
while (got < len) {
|
|
66
|
+
const k = readSync(fd, buf, got, len - got, size - len + got);
|
|
67
|
+
if (k === 0)
|
|
68
|
+
break;
|
|
69
|
+
got += k;
|
|
70
|
+
}
|
|
71
|
+
return { bytes: buf.subarray(0, got), size, cut: size > len };
|
|
72
|
+
}
|
|
73
|
+
finally {
|
|
74
|
+
closeSync(fd);
|
|
75
|
+
}
|
|
76
|
+
}
|
|
77
|
+
/**
|
|
78
|
+
* Tolerant reader of runs/<runId>/events.jsonl (appended without lock or fsync: the last line may be partial).
|
|
79
|
+
* Keeps the last `max` (default 1000) well-formed object lines; blank lines are ignored; malformed lines, non-object
|
|
80
|
+
* lines and an unterminated last line that does not parse are counted in `skipped`. A missing file is empty.
|
|
81
|
+
* Only the last `tailBytes` (default 4 MiB) are read; when that starts mid-file the cut first line is dropped, not counted.
|
|
82
|
+
* `cut` is true when older events exist that are not returned (the tail did not reach the file's start, or more than `max` lines).
|
|
83
|
+
*/
|
|
84
|
+
export function readEvents(store, runId, o = {}) {
|
|
85
|
+
if (!RUN_ID_RE.test(runId) || runId.includes('..'))
|
|
86
|
+
throw new Error(`invalid run id ${JSON.stringify(runId)}`);
|
|
87
|
+
const file = join(store.runs, runId, 'events.jsonl');
|
|
88
|
+
let text;
|
|
89
|
+
let cut = false;
|
|
90
|
+
try {
|
|
91
|
+
const r = readRegularFile(file, { tailBytes: o.tailBytes ?? EVENTS_TAIL_BYTES }); // a link, a FIFO or a device is refused
|
|
92
|
+
text = r.bytes.toString('utf8');
|
|
93
|
+
cut = r.cut;
|
|
94
|
+
}
|
|
95
|
+
catch (e) {
|
|
96
|
+
if (e.code === 'ENOENT')
|
|
97
|
+
return { events: [], skipped: 0, cut: false };
|
|
98
|
+
throw e;
|
|
99
|
+
}
|
|
100
|
+
if (cut) {
|
|
101
|
+
const nl = text.indexOf('\n');
|
|
102
|
+
text = nl < 0 ? '' : text.slice(nl + 1);
|
|
103
|
+
}
|
|
104
|
+
const max = Math.max(0, o.max ?? 1000);
|
|
105
|
+
const events = [];
|
|
106
|
+
let skipped = 0;
|
|
107
|
+
for (const ln of text.split('\n')) {
|
|
108
|
+
if (ln.trim() === '')
|
|
109
|
+
continue;
|
|
110
|
+
try {
|
|
111
|
+
const v = JSON.parse(ln);
|
|
112
|
+
if (typeof v === 'object' && v !== null && !Array.isArray(v))
|
|
113
|
+
events.push(v);
|
|
114
|
+
else
|
|
115
|
+
skipped++;
|
|
116
|
+
}
|
|
117
|
+
catch {
|
|
118
|
+
skipped++;
|
|
119
|
+
}
|
|
120
|
+
}
|
|
121
|
+
return { events: max >= events.length ? events : events.slice(events.length - max), skipped, cut: cut || events.length > max };
|
|
122
|
+
}
|
|
123
|
+
const EVENTS_TAIL_BYTES = 4 * 1024 * 1024;
|
|
124
|
+
const SHA_RE = /^[0-9a-f]{64}$/;
|
|
125
|
+
/** Write-once, content-addressed, read-only. Re-putting identical bytes is a no-op. */
|
|
126
|
+
export function putArtifact(store, bytes, meta) {
|
|
127
|
+
const sha256 = createHash('sha256').update(bytes).digest('hex');
|
|
128
|
+
const path = join(store.artifacts, sha256);
|
|
129
|
+
if (!existsSync(path)) {
|
|
130
|
+
writeFileSync(path, bytes, { flag: 'wx', mode: 0o400 });
|
|
131
|
+
writeFileSync(`${path}.meta.json`, JSON.stringify({ ...meta, size: bytes.length, createdAt: new Date().toISOString() }), { flag: 'wx', mode: 0o400 });
|
|
132
|
+
}
|
|
133
|
+
return { sha256, path, size: bytes.length, ...meta };
|
|
134
|
+
}
|
|
135
|
+
/**
|
|
136
|
+
* Read and verify. Throws on a malformed id, a hash mismatch (tampering), or a file that is not regular (a symlink, a
|
|
137
|
+
* FIFO, a device: see readRegularFile); `maxBytes`: a larger artifact is refused unread (`EFBIG`, with its `size`).
|
|
138
|
+
*/
|
|
139
|
+
export function getArtifact(store, sha256, o = {}) {
|
|
140
|
+
if (!SHA_RE.test(sha256))
|
|
141
|
+
throw new Error(`invalid artifact id ${JSON.stringify(sha256)}`);
|
|
142
|
+
const { bytes } = readRegularFile(join(store.artifacts, sha256), o.maxBytes !== undefined ? { maxBytes: o.maxBytes } : {});
|
|
143
|
+
const actual = createHash('sha256').update(bytes).digest('hex');
|
|
144
|
+
if (actual !== sha256)
|
|
145
|
+
throw new Error(`artifact ${sha256} hash mismatch (got ${actual})`);
|
|
146
|
+
return bytes;
|
|
147
|
+
}
|
|
148
|
+
/** Fields that may carry prompts, model output or file content — never persisted by default (architecture §12). */
|
|
149
|
+
const FREE_TEXT = new Set(['prompt', 'task', 'output', 'content', 'stdin', 'stdout', 'stderr', 'terminalMessage', 'resultText', 'message', 'input']);
|
|
150
|
+
const RUN_ID_RE = /^[A-Za-z0-9._-]{1,64}$/;
|
|
151
|
+
/** Append one metadata-only event (scalars only, free-text keys dropped) to runs/<runId>/events.jsonl. */
|
|
152
|
+
export function appendEvent(store, runId, event) {
|
|
153
|
+
if (!RUN_ID_RE.test(runId) || runId.includes('..'))
|
|
154
|
+
throw new Error(`invalid run id ${JSON.stringify(runId)}`);
|
|
155
|
+
const dir = ensureTrustedDir(join(store.runs, runId));
|
|
156
|
+
const clean = { ts: new Date().toISOString() };
|
|
157
|
+
for (const [k, v] of Object.entries(event)) {
|
|
158
|
+
if (FREE_TEXT.has(k))
|
|
159
|
+
continue;
|
|
160
|
+
if (v === null || ['string', 'number', 'boolean'].includes(typeof v))
|
|
161
|
+
clean[k] = typeof v === 'string' ? v.slice(0, 256) : v;
|
|
162
|
+
}
|
|
163
|
+
const file = join(dir, 'events.jsonl');
|
|
164
|
+
appendFileSync(file, JSON.stringify(clean) + '\n', { mode: 0o600 });
|
|
165
|
+
chmodSync(file, 0o600);
|
|
166
|
+
return file;
|
|
167
|
+
}
|
|
168
|
+
export function loadRiskAcceptances(store) {
|
|
169
|
+
const f = join(store.approvals, 'risk-acceptances.json');
|
|
170
|
+
if (!existsSync(f))
|
|
171
|
+
return [];
|
|
172
|
+
const raw = JSON.parse(readFileSync(f, 'utf8'));
|
|
173
|
+
if (!Array.isArray(raw))
|
|
174
|
+
throw new Error(`${f}: expected a list`);
|
|
175
|
+
return raw.filter((e) => typeof e === 'object' && e !== null
|
|
176
|
+
&& ['agent', 'capability', 'reason', 'expires', 'approvedBy', 'runtimeVersion', 'failureDigest', 'createdAt'].every(k => typeof e[k] === 'string'));
|
|
177
|
+
}
|
|
178
|
+
/** One acceptance per (agent, capability): a new one replaces the old one. */
|
|
179
|
+
export function saveRiskAcceptance(store, a) {
|
|
180
|
+
const f = join(store.approvals, 'risk-acceptances.json');
|
|
181
|
+
const all = loadRiskAcceptances(store).filter(e => !(e.agent === a.agent && e.capability === a.capability));
|
|
182
|
+
writeFileSync(f, JSON.stringify([...all, a], null, 2), { mode: 0o600 });
|
|
183
|
+
}
|
|
184
|
+
/** Atomic JSON write (tmp + rename), 0600, under runs/<runId>/. */
|
|
185
|
+
export function saveRunState(store, runId, state) {
|
|
186
|
+
if (!RUN_ID_RE.test(runId) || runId.includes('..'))
|
|
187
|
+
throw new Error(`invalid run id ${JSON.stringify(runId)}`);
|
|
188
|
+
const dir = ensureTrustedDir(join(store.runs, runId));
|
|
189
|
+
const tmp = join(dir, `.state.${process.pid}.tmp`);
|
|
190
|
+
writeFileSync(tmp, JSON.stringify(state, null, 2), { mode: 0o600 });
|
|
191
|
+
renameSync(tmp, join(dir, 'state.json'));
|
|
192
|
+
}
|
|
193
|
+
export function loadRunState(store, runId) {
|
|
194
|
+
if (!RUN_ID_RE.test(runId) || runId.includes('..'))
|
|
195
|
+
throw new Error(`invalid run id ${JSON.stringify(runId)}`);
|
|
196
|
+
const f = join(store.runs, runId, 'state.json');
|
|
197
|
+
return existsSync(f) ? JSON.parse(readFileSync(f, 'utf8')) : undefined;
|
|
198
|
+
}
|
|
199
|
+
export function listRuns(store) {
|
|
200
|
+
return readdirSync(store.runs, { withFileTypes: true }).filter(d => d.isDirectory() && existsSync(join(store.runs, d.name, 'state.json'))).map(d => d.name).sort();
|
|
201
|
+
}
|
|
@@ -0,0 +1,37 @@
|
|
|
1
|
+
import { lstatSync, mkdirSync, realpathSync } from 'node:fs';
|
|
2
|
+
import { sep } from 'node:path';
|
|
3
|
+
const inside = (child, parent) => child === parent || child.startsWith(parent + sep);
|
|
4
|
+
/**
|
|
5
|
+
* Create (0700) or validate a directory Taskquoin trusts for control state or scratch: not a symlink, a directory,
|
|
6
|
+
* owned by the current user, not group/world-writable, not inside `workspace` (ADR-0005, Codex R1.1 P1).
|
|
7
|
+
* Returns its physical path.
|
|
8
|
+
*/
|
|
9
|
+
export function ensureTrustedDir(dir, workspace) {
|
|
10
|
+
mkdirSync(dir, { recursive: true, mode: 0o700 });
|
|
11
|
+
return checkTrustedDir(dir, workspace);
|
|
12
|
+
}
|
|
13
|
+
/**
|
|
14
|
+
* The check-only variant of `ensureTrustedDir`: never creates anything. Returns the physical path, `undefined` when
|
|
15
|
+
* `dir` does not exist, and throws on the same conditions as `ensureTrustedDir`.
|
|
16
|
+
*/
|
|
17
|
+
export function checkTrustedDir(dir, workspace) {
|
|
18
|
+
let st;
|
|
19
|
+
try {
|
|
20
|
+
st = lstatSync(dir);
|
|
21
|
+
}
|
|
22
|
+
catch (e) {
|
|
23
|
+
if (e.code === 'ENOENT')
|
|
24
|
+
return undefined;
|
|
25
|
+
throw e;
|
|
26
|
+
}
|
|
27
|
+
if (st.isSymbolicLink() || !st.isDirectory())
|
|
28
|
+
throw new Error(`${dir} is a symlink or not a directory; refusing`);
|
|
29
|
+
if ((st.mode & 0o022) !== 0)
|
|
30
|
+
throw new Error(`${dir} is group/world-writable; refusing`);
|
|
31
|
+
if (typeof process.getuid === 'function' && st.uid !== process.getuid())
|
|
32
|
+
throw new Error(`${dir} is not owned by the current user; refusing`);
|
|
33
|
+
const real = realpathSync(dir);
|
|
34
|
+
if (workspace && inside(real, realpathSync(workspace)))
|
|
35
|
+
throw new Error(`${dir} is inside the workspace; refusing`);
|
|
36
|
+
return real;
|
|
37
|
+
}
|
|
@@ -0,0 +1,432 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* `taskquoin console` — an interactive shell over the existing commands (no new workflow logic).
|
|
3
|
+
* Human-only by design: plain text never starts anything (only `/` commands act), and `/approve` approves ONLY when the
|
|
4
|
+
* human retypes the pending hash. It is never installed as slash commands INSIDE Claude Code or Codex, where a model
|
|
5
|
+
* could type them. The real boundary stays the control store: agents cannot write it, so they cannot approve at all.
|
|
6
|
+
*/
|
|
7
|
+
import { projectSquad } from '../../../packages/application/src/index.js';
|
|
8
|
+
import { n as nz } from "./tui/neutral.js";
|
|
9
|
+
import { shownSquad } from "./tui/view.js";
|
|
10
|
+
import { t, tn } from "./i18n/index.js";
|
|
11
|
+
import { paint } from "./tui/tokens.js";
|
|
12
|
+
import { renderHome } from "./tui/components/home.js";
|
|
13
|
+
import { renderApproval } from "./tui/components/approval.js";
|
|
14
|
+
import { alignColumns, displayWidth } from "./i18n/width.js";
|
|
15
|
+
/** Where the approval screen is drawn when the caller gives no terminal facts: no colour, UTF-8, 80 columns. */
|
|
16
|
+
const PLAIN = { interactive: false, cursor: false, colorDepth: 0, charset: 'utf8', theme: 'dark', motion: false, plain: false, columns: 80, rows: 24 };
|
|
17
|
+
/**
|
|
18
|
+
* Lines from readline for `ask`. In a terminal, lines typed BEFORE a prompt (type-ahead during a long /run) are
|
|
19
|
+
* discarded with a notice: an approval must be answered after it is shown (Codex console review HIGH 3). Piped input
|
|
20
|
+
* (scripts, tests) has no one watching and is kept, like `taskquoin approve --expect` in a script.
|
|
21
|
+
*/
|
|
22
|
+
export function lineReader(src, write, o) {
|
|
23
|
+
const queue = [];
|
|
24
|
+
let waiting;
|
|
25
|
+
let closed = false;
|
|
26
|
+
src.on('line', (l) => { if (waiting) {
|
|
27
|
+
const w = waiting;
|
|
28
|
+
waiting = undefined;
|
|
29
|
+
w(l);
|
|
30
|
+
}
|
|
31
|
+
else
|
|
32
|
+
queue.push(l); });
|
|
33
|
+
src.on('close', () => { closed = true; if (waiting) {
|
|
34
|
+
const w = waiting;
|
|
35
|
+
waiting = undefined;
|
|
36
|
+
w(undefined);
|
|
37
|
+
} });
|
|
38
|
+
return {
|
|
39
|
+
ask(question) {
|
|
40
|
+
if (o.discardTypeAhead && queue.length) {
|
|
41
|
+
write(tn('console.typeAhead', queue.length) + '\n');
|
|
42
|
+
queue.length = 0;
|
|
43
|
+
}
|
|
44
|
+
(o.showPrompt ?? write)(question);
|
|
45
|
+
if (queue.length)
|
|
46
|
+
return Promise.resolve(queue.shift());
|
|
47
|
+
if (closed)
|
|
48
|
+
return Promise.resolve(undefined);
|
|
49
|
+
return new Promise((res) => { waiting = res; });
|
|
50
|
+
},
|
|
51
|
+
};
|
|
52
|
+
}
|
|
53
|
+
/**
|
|
54
|
+
* While another program owns the terminal (the /upgrade installer, stdio inherited): the console's readline is paused
|
|
55
|
+
* and raw mode is off, so Ctrl+C reaches that program as a signal — in raw mode it was a keypress the installer never
|
|
56
|
+
* saw. The console ignores that SIGINT itself (it would end the session); both are restored afterwards, even on failure.
|
|
57
|
+
*/
|
|
58
|
+
export async function withTerminalReleased(o, f) {
|
|
59
|
+
const tty = !!o.stdin.isTTY && typeof o.stdin.setRawMode === 'function';
|
|
60
|
+
const wasRaw = !!o.stdin.isRaw;
|
|
61
|
+
const ignore = () => { };
|
|
62
|
+
o.rl.pause();
|
|
63
|
+
if (tty)
|
|
64
|
+
o.stdin.setRawMode(false);
|
|
65
|
+
o.signals.on('SIGINT', ignore);
|
|
66
|
+
try {
|
|
67
|
+
return await f();
|
|
68
|
+
}
|
|
69
|
+
finally {
|
|
70
|
+
o.signals.off('SIGINT', ignore);
|
|
71
|
+
if (tty)
|
|
72
|
+
o.stdin.setRawMode(wasRaw);
|
|
73
|
+
o.rl.resume();
|
|
74
|
+
}
|
|
75
|
+
}
|
|
76
|
+
const CATEGORIES = ['run', 'review', 'diagnose', 'console'];
|
|
77
|
+
/** Single source for /help, Tab completion and the "/" menu: [command, arguments key, description key, category] (names are not translated). */
|
|
78
|
+
const COMMAND_TABLE = [
|
|
79
|
+
['/run', 'console.doc.run.args', 'console.doc.run', 'run'],
|
|
80
|
+
['/runs', '', 'console.doc.runs', 'run'],
|
|
81
|
+
['/use', '', 'console.doc.use', 'run'],
|
|
82
|
+
['/status', '', 'console.doc.status', 'run'],
|
|
83
|
+
['/resume', '', 'console.doc.resume', 'run'],
|
|
84
|
+
['/show', 'console.doc.show.args', 'console.doc.show', 'review'],
|
|
85
|
+
['/approve', '', 'console.doc.approve', 'review'],
|
|
86
|
+
['/dashboard', '', 'console.doc.dashboard', 'review'],
|
|
87
|
+
['/agents', '', 'console.doc.agents', 'diagnose'],
|
|
88
|
+
['/doctor', '', 'console.doc.doctor', 'diagnose'],
|
|
89
|
+
['/skills', '', 'console.doc.skills', 'diagnose'],
|
|
90
|
+
['/upgrade', 'console.doc.upgrade.args', 'console.doc.upgrade', 'diagnose'],
|
|
91
|
+
['/help', '', 'console.doc.help', 'console'],
|
|
92
|
+
['/quit', '', 'console.doc.quit', 'console'],
|
|
93
|
+
];
|
|
94
|
+
const BARE_ARGS = { '/use': '<run>', '/approve': '<plan|commit>' };
|
|
95
|
+
/** [command, arguments, description] in the current language. Computed at call time: nothing translated at module load. */
|
|
96
|
+
export function commandDocs() {
|
|
97
|
+
return COMMAND_TABLE.map(([c, a, d]) => [c, a ? t(a) : (BARE_ARGS[c] ?? ''), t(d)]);
|
|
98
|
+
}
|
|
99
|
+
const usage = (c, a) => (a ? `${c} ${a}` : c);
|
|
100
|
+
const docLines = () => alignColumns(commandDocs().map(([c, a, d]) => [usage(c, a), d]));
|
|
101
|
+
export function consoleHelp() {
|
|
102
|
+
return t('console.help.title') + '\n' + docLines().map(l => ` ${l}`).join('\n') + '\n' + t('console.help.footer');
|
|
103
|
+
}
|
|
104
|
+
/** `s` cut to at most `cols` display columns, ending with an ellipsis when something was cut. */
|
|
105
|
+
function fitWidth(s, cols) {
|
|
106
|
+
if (displayWidth(s) <= cols)
|
|
107
|
+
return s;
|
|
108
|
+
let out = '';
|
|
109
|
+
for (const ch of s) {
|
|
110
|
+
if (displayWidth(out + ch) > cols - 1)
|
|
111
|
+
break;
|
|
112
|
+
out += ch;
|
|
113
|
+
}
|
|
114
|
+
return out + '…';
|
|
115
|
+
}
|
|
116
|
+
/**
|
|
117
|
+
* The "/" menu for what is typed so far: matching commands grouped under their category title, each with its
|
|
118
|
+
* description, while no argument is typed. Every line fits `columns` (the description is cut first).
|
|
119
|
+
*/
|
|
120
|
+
export function slashMenu(line, columns = 80) {
|
|
121
|
+
if (!line.startsWith('/') || line.includes(' '))
|
|
122
|
+
return [];
|
|
123
|
+
const rows = docLines();
|
|
124
|
+
const lines = [];
|
|
125
|
+
for (const cat of CATEGORIES) {
|
|
126
|
+
const idx = COMMAND_TABLE.map((e, i) => (e[3] === cat && e[0].startsWith(line) ? i : -1)).filter(i => i >= 0);
|
|
127
|
+
if (!idx.length)
|
|
128
|
+
continue;
|
|
129
|
+
lines.push(fitWidth(t(`console.cat.${cat}`), columns), ...idx.map(i => fitWidth(' ' + rows[i], columns)));
|
|
130
|
+
}
|
|
131
|
+
return lines;
|
|
132
|
+
}
|
|
133
|
+
/**
|
|
134
|
+
* Terminal escapes that draw `items` under the input line and put the cursor back (relative moves: correct even when
|
|
135
|
+
* the screen scrolls); always clears what was drawn before, so an empty list just erases the menu. Only where the
|
|
136
|
+
* cursor may move (`consoleSurface(caps).menu`); the items are muted through the caps, so no colour without colour.
|
|
137
|
+
*/
|
|
138
|
+
export function drawSlashMenu(o) {
|
|
139
|
+
const dim = (t) => paint('muted', t, o.caps);
|
|
140
|
+
let s = `\x1b[${o.promptWidth + displayWidth(o.line) + 1}G\x1b[J`;
|
|
141
|
+
if (o.items.length)
|
|
142
|
+
s += '\n' + o.items.map(dim).join('\n') + `\x1b[${o.items.length}A`;
|
|
143
|
+
return s + `\x1b[${o.promptWidth + displayWidth(o.line.slice(0, o.cursor)) + 1}G`;
|
|
144
|
+
}
|
|
145
|
+
/**
|
|
146
|
+
* What the console draws besides its lines, decided from the caps alone (AC-2, ADR-0019): the live "/" menu moves the
|
|
147
|
+
* cursor, so it needs a terminal that allows it (both ends a TTY, not `TERM=dumb`) and not plain mode; an error line is
|
|
148
|
+
* red only when the caps have colour (never with `NO_COLOR`, `TERM=dumb` or a pipe) and stderr is a terminal too.
|
|
149
|
+
*/
|
|
150
|
+
export function consoleSurface(caps, stderrTTY) {
|
|
151
|
+
return { menu: caps.cursor && !caps.plain, error: (s) => (stderrTTY ? paint('red', s, caps) : s) };
|
|
152
|
+
}
|
|
153
|
+
/** Edit distance (Levenshtein). */
|
|
154
|
+
function distance(a, b) {
|
|
155
|
+
let prev = Array.from({ length: b.length + 1 }, (_, j) => j);
|
|
156
|
+
for (let i = 1; i <= a.length; i++) {
|
|
157
|
+
const cur = [i];
|
|
158
|
+
for (let j = 1; j <= b.length; j++)
|
|
159
|
+
cur[j] = Math.min(prev[j] + 1, cur[j - 1] + 1, prev[j - 1] + (a[i - 1] === b[j - 1] ? 0 : 1));
|
|
160
|
+
prev = cur;
|
|
161
|
+
}
|
|
162
|
+
return prev[b.length];
|
|
163
|
+
}
|
|
164
|
+
/** The known command closest to `name` (with or without the leading `/`), if within 2 edits. */
|
|
165
|
+
export function suggestCommand(name) {
|
|
166
|
+
const bare = name.replace(/^\//, '').toLowerCase();
|
|
167
|
+
let best;
|
|
168
|
+
let bestD = 3;
|
|
169
|
+
for (const [c] of COMMAND_TABLE) {
|
|
170
|
+
const d = distance(bare, c.slice(1));
|
|
171
|
+
if (d < bestD) {
|
|
172
|
+
best = c;
|
|
173
|
+
bestD = d;
|
|
174
|
+
}
|
|
175
|
+
}
|
|
176
|
+
return best;
|
|
177
|
+
}
|
|
178
|
+
/** "unknown command /x — did you mean /y?" (the typed name is neutralised: it came from outside). */
|
|
179
|
+
function unknownCommand(name) {
|
|
180
|
+
const s = suggestCommand(name);
|
|
181
|
+
return s ? t('console.unknownCommandDid', { name: nz(name), suggestion: s }) : t('console.unknownCommand', { name: nz(name) });
|
|
182
|
+
}
|
|
183
|
+
/** `taskquoin [ab12cd ◆ commit] › `: the current run and, with ◆, the approval it waits for (glyph + word). Plain text: its width is its display width. */
|
|
184
|
+
export const promptFor = (current, waiting) => current ? `taskquoin [${nz(current.slice(-6))}${waiting ? ` ◆ ${waiting}` : ''}] › ` : 'taskquoin › ';
|
|
185
|
+
export const CONSOLE_COMMANDS = COMMAND_TABLE.map(([c]) => c);
|
|
186
|
+
/**
|
|
187
|
+
* readline completer: `/ap` → `/approve `; then contextual: `/use <run>`, `/show <artifact>` (current run),
|
|
188
|
+
* `/approve <gate>` (only the gate really pending), `/help <command>`. Free text gets no completion.
|
|
189
|
+
*/
|
|
190
|
+
export function completeCommand(line, ctx = { runs: [], artifacts: [] }) {
|
|
191
|
+
if (!line.startsWith('/'))
|
|
192
|
+
return [[], line];
|
|
193
|
+
const sp = line.indexOf(' ');
|
|
194
|
+
if (sp < 0)
|
|
195
|
+
return [CONSOLE_COMMANDS.filter(c => c.startsWith(line)).map(c => c + ' '), line];
|
|
196
|
+
const cmd = line.slice(0, sp);
|
|
197
|
+
const rest = line.slice(sp + 1);
|
|
198
|
+
if (rest.includes(' '))
|
|
199
|
+
return [[], line];
|
|
200
|
+
const pool = cmd === '/use' ? ctx.runs : cmd === '/show' ? ctx.artifacts : cmd === '/approve' ? (ctx.pendingGate ? [ctx.pendingGate] : [])
|
|
201
|
+
: cmd === '/help' ? CONSOLE_COMMANDS.map(c => c.slice(1)) : [];
|
|
202
|
+
return [pool.filter(v => v.startsWith(rest)), rest];
|
|
203
|
+
}
|
|
204
|
+
/**
|
|
205
|
+
* The squad as it really is: every agent with its gate verdict (a judge's provider shown), then Taskquoin's own
|
|
206
|
+
* sandboxed Verify as the tester. A refusal shows its short reason (the text before " — ").
|
|
207
|
+
* The projection is raw and shared with doctor (isReady); shownSquad says it in the user's language and neutralises
|
|
208
|
+
* what came from config, gates or skill files — never a translated message.
|
|
209
|
+
*/
|
|
210
|
+
export function squadOf(agents, gateOf, testerReady) {
|
|
211
|
+
return shownSquad(projectSquad(agents, gateOf, testerReady)).view;
|
|
212
|
+
}
|
|
213
|
+
/** The V2 home screen as one string (the lines of `renderHome`). */
|
|
214
|
+
export function renderBanner(model, caps) {
|
|
215
|
+
return renderHome(model, caps).join('\n');
|
|
216
|
+
}
|
|
217
|
+
/**
|
|
218
|
+
* Reveals the logo rows left to right, in place, in at most 0.9 s (cursor hidden, always shown again). `rows` are the
|
|
219
|
+
* finished lines: every frame keeps each escape and shows only the first columns' characters, so the last frame IS the
|
|
220
|
+
* static logo and a frame never leaves a colour open.
|
|
221
|
+
*/
|
|
222
|
+
const ESCAPE = /(\x1b\[[0-9;]*[A-Za-z])/;
|
|
223
|
+
export function logoFrames(rows, steps = 16) {
|
|
224
|
+
const width = Math.max(...rows.map(displayWidth));
|
|
225
|
+
const reveal = (row, shown) => {
|
|
226
|
+
let seen = 0;
|
|
227
|
+
return row.split(ESCAPE).map((part) => {
|
|
228
|
+
if (ESCAPE.test(part))
|
|
229
|
+
return part;
|
|
230
|
+
return [...part].map((ch) => (seen++ < shown ? ch : ' ')).join('');
|
|
231
|
+
}).join('');
|
|
232
|
+
};
|
|
233
|
+
const frames = [];
|
|
234
|
+
for (let k = 1; k <= steps; k++)
|
|
235
|
+
frames.push(rows.map((r) => reveal(r, Math.round((width * k) / steps))).join('\n'));
|
|
236
|
+
return frames;
|
|
237
|
+
}
|
|
238
|
+
export async function animateLogo(write, sleep, rows) {
|
|
239
|
+
const frames = logoFrames(rows);
|
|
240
|
+
const height = rows.length;
|
|
241
|
+
write('\x1b[?25l');
|
|
242
|
+
try {
|
|
243
|
+
for (let i = 0; i < frames.length; i++) {
|
|
244
|
+
write((i ? `\x1b[${height - 1}A\r` : '') + frames[i]);
|
|
245
|
+
await sleep(i < frames.length - 1 ? 45 : 0);
|
|
246
|
+
}
|
|
247
|
+
write('\n');
|
|
248
|
+
}
|
|
249
|
+
finally {
|
|
250
|
+
write('\x1b[?25h');
|
|
251
|
+
}
|
|
252
|
+
}
|
|
253
|
+
export async function runConsole(io, cmd, banner, caps = PLAIN) {
|
|
254
|
+
let current;
|
|
255
|
+
const read = new Map(); // artifacts the human showed with /show, per run, this session
|
|
256
|
+
let approver;
|
|
257
|
+
let failed = false; // exit code of the session: 1 if any command or approval failed (scripts must see it)
|
|
258
|
+
const setCurrent = (r) => { current = r; io.setCurrent?.(r); };
|
|
259
|
+
const fail = (msg) => { failed = true; io.err(msg); };
|
|
260
|
+
const track = (code) => { if (code !== 0)
|
|
261
|
+
failed = true; };
|
|
262
|
+
if (banner)
|
|
263
|
+
io.out(banner);
|
|
264
|
+
io.out(t('console.welcome'));
|
|
265
|
+
for (;;) {
|
|
266
|
+
const line = await io.ask(promptFor(current, current ? cmd.pending(current)?.gate : undefined));
|
|
267
|
+
if (line === undefined)
|
|
268
|
+
return failed ? 1 : 0;
|
|
269
|
+
const text = line.trim();
|
|
270
|
+
if (!text)
|
|
271
|
+
continue;
|
|
272
|
+
if (!text.startsWith('/')) {
|
|
273
|
+
io.out(t('console.noCommand'));
|
|
274
|
+
continue;
|
|
275
|
+
}
|
|
276
|
+
const [name, ...rest] = text.slice(1).split(/\s+/);
|
|
277
|
+
const arg = text.slice(1 + name.length).trim();
|
|
278
|
+
const needRun = () => { if (!current)
|
|
279
|
+
fail(t('console.noRun')); return current; };
|
|
280
|
+
switch (name) {
|
|
281
|
+
case 'quit':
|
|
282
|
+
case 'exit': return failed ? 1 : 0;
|
|
283
|
+
case 'help': {
|
|
284
|
+
if (!arg) {
|
|
285
|
+
io.out(consoleHelp());
|
|
286
|
+
break;
|
|
287
|
+
}
|
|
288
|
+
const row = commandDocs().find(([c]) => c === '/' + arg.replace(/^\//, ''));
|
|
289
|
+
if (!row) {
|
|
290
|
+
fail(unknownCommand(arg.replace(/^\//, '')));
|
|
291
|
+
break;
|
|
292
|
+
}
|
|
293
|
+
io.out(usage(row[0], row[1]));
|
|
294
|
+
io.out(' ' + row[2]);
|
|
295
|
+
break;
|
|
296
|
+
}
|
|
297
|
+
case 'run': {
|
|
298
|
+
if (!arg) {
|
|
299
|
+
fail(t('console.usage.run'));
|
|
300
|
+
break;
|
|
301
|
+
}
|
|
302
|
+
setCurrent(undefined); // never fall back silently to the previously selected run (Codex console review HIGH 2)
|
|
303
|
+
const r = await cmd.run(arg);
|
|
304
|
+
track(r.code);
|
|
305
|
+
if (r.runId) {
|
|
306
|
+
setCurrent(r.runId);
|
|
307
|
+
io.out(t('console.currentRun', { run: r.runId }));
|
|
308
|
+
}
|
|
309
|
+
else
|
|
310
|
+
io.out(t('console.noCurrentRun'));
|
|
311
|
+
break;
|
|
312
|
+
}
|
|
313
|
+
case 'runs':
|
|
314
|
+
track(await cmd.status());
|
|
315
|
+
break;
|
|
316
|
+
case 'use': {
|
|
317
|
+
if (!cmd.runs().includes(arg)) {
|
|
318
|
+
fail(t('console.unknownRun', { run: arg ? nz(arg) : t('console.empty') }));
|
|
319
|
+
break;
|
|
320
|
+
}
|
|
321
|
+
setCurrent(arg);
|
|
322
|
+
io.out(t('console.currentRun', { run: nz(arg) }));
|
|
323
|
+
break;
|
|
324
|
+
}
|
|
325
|
+
case 'status': {
|
|
326
|
+
const r = needRun();
|
|
327
|
+
if (r)
|
|
328
|
+
track(await cmd.status(r));
|
|
329
|
+
break;
|
|
330
|
+
}
|
|
331
|
+
case 'show': {
|
|
332
|
+
const r = needRun();
|
|
333
|
+
if (!r)
|
|
334
|
+
break;
|
|
335
|
+
const code = await cmd.show(r, rest[0]);
|
|
336
|
+
track(code);
|
|
337
|
+
if (code === 0 && rest[0])
|
|
338
|
+
read.set(r, (read.get(r) ?? new Set()).add(rest[0])); // only what was really shown
|
|
339
|
+
break;
|
|
340
|
+
}
|
|
341
|
+
case 'resume': {
|
|
342
|
+
const r = needRun();
|
|
343
|
+
if (r)
|
|
344
|
+
track(await cmd.resume(r));
|
|
345
|
+
break;
|
|
346
|
+
}
|
|
347
|
+
case 'dashboard':
|
|
348
|
+
await cmd.dashboard(current);
|
|
349
|
+
break; // the screen's own refusal is not a failed command
|
|
350
|
+
case 'agents':
|
|
351
|
+
track(await cmd.agents());
|
|
352
|
+
break;
|
|
353
|
+
case 'doctor':
|
|
354
|
+
track(await cmd.doctor());
|
|
355
|
+
break;
|
|
356
|
+
case 'skills':
|
|
357
|
+
track(await cmd.skills());
|
|
358
|
+
break;
|
|
359
|
+
case 'upgrade':
|
|
360
|
+
track(await cmd.upgrade(arg, io.ask));
|
|
361
|
+
break;
|
|
362
|
+
case 'approve': {
|
|
363
|
+
const r = needRun();
|
|
364
|
+
if (!r)
|
|
365
|
+
break;
|
|
366
|
+
const gate = rest[0];
|
|
367
|
+
if (gate !== 'plan' && gate !== 'commit') {
|
|
368
|
+
fail(t('console.usage.approve'));
|
|
369
|
+
break;
|
|
370
|
+
}
|
|
371
|
+
if (!cmd.pending(r) || cmd.pending(r).gate !== gate) {
|
|
372
|
+
const p = cmd.pending(r);
|
|
373
|
+
fail(p ? t('console.notWaitingWaits', { run: r, gate, waits: p.gate }) : t('console.notWaiting', { run: r, gate }));
|
|
374
|
+
break;
|
|
375
|
+
}
|
|
376
|
+
// The name FIRST, so the last thing typed before approving is the hash; a `/…` line is never a name (HIGH 1).
|
|
377
|
+
let cancelled = false;
|
|
378
|
+
while (!approver) {
|
|
379
|
+
const n = (await io.ask(t('console.askName')))?.trim();
|
|
380
|
+
if (n === undefined)
|
|
381
|
+
return failed ? 1 : 0;
|
|
382
|
+
if (n.startsWith('/')) {
|
|
383
|
+
cancelled = true;
|
|
384
|
+
break;
|
|
385
|
+
}
|
|
386
|
+
if (n)
|
|
387
|
+
approver = n;
|
|
388
|
+
}
|
|
389
|
+
if (cancelled) {
|
|
390
|
+
fail(t('console.cancelledCommand'));
|
|
391
|
+
break;
|
|
392
|
+
}
|
|
393
|
+
const p = cmd.pending(r); // re-read right before showing it: what is shown is what can be approved
|
|
394
|
+
if (!p || p.gate !== gate) {
|
|
395
|
+
fail(t('console.notWaitingAnymore', { run: r, gate }));
|
|
396
|
+
break;
|
|
397
|
+
}
|
|
398
|
+
const shown = cmd.approval(r);
|
|
399
|
+
if (!shown) {
|
|
400
|
+
fail(t('console.notWaitingAnymore', { run: r, gate }));
|
|
401
|
+
break;
|
|
402
|
+
}
|
|
403
|
+
// The screen shows the binding recorded in the run (the plan's hash, the reviewed tree). The working tree, the
|
|
404
|
+
// branch and the hash are checked by `approve` itself, as for `taskquoin approve`: no console-only logic (ADR-0015 §1).
|
|
405
|
+
const short = p.binding.slice(0, 12);
|
|
406
|
+
io.out(renderApproval({ run: shown.run, gate, binding: p.binding, read: read.get(r) ?? new Set(), acceptedRisks: shown.acceptedRisks, approver }, caps).join('\n'));
|
|
407
|
+
const typed = (await io.ask(t('console.retype', { hash: short })))?.trim();
|
|
408
|
+
if (!typed) {
|
|
409
|
+
io.out(t('console.cancelled'));
|
|
410
|
+
break;
|
|
411
|
+
}
|
|
412
|
+
if (typed !== short) {
|
|
413
|
+
fail(t('console.hashMismatch'));
|
|
414
|
+
break;
|
|
415
|
+
}
|
|
416
|
+
// What was shown is what is approved: the pending binding is read again after the last keystroke (AC-6).
|
|
417
|
+
const now = cmd.pending(r);
|
|
418
|
+
if (!now || now.gate !== gate) {
|
|
419
|
+
fail(t('console.notWaitingAnymore', { run: r, gate }));
|
|
420
|
+
break;
|
|
421
|
+
}
|
|
422
|
+
if (now.binding !== p.binding) {
|
|
423
|
+
fail(t(gate === 'commit' ? 'console.treeChanged' : 'console.planChanged'));
|
|
424
|
+
break;
|
|
425
|
+
}
|
|
426
|
+
track(await cmd.approve(r, gate, typed, `${approver} (via taskquoin console)`));
|
|
427
|
+
break;
|
|
428
|
+
}
|
|
429
|
+
default: fail(unknownCommand(name));
|
|
430
|
+
}
|
|
431
|
+
}
|
|
432
|
+
}
|