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,830 @@
|
|
|
1
|
+
#!/usr/bin/env node
|
|
2
|
+
/**
|
|
3
|
+
* taskquoin — composition root (architecture §3). Commands: init, doctor, check <agent> [--json], uninstall [--purge-state].
|
|
4
|
+
* Exit codes: 0 ok · 1 refused / failed check · 2 usage error.
|
|
5
|
+
*/
|
|
6
|
+
import { createHash } from 'node:crypto';
|
|
7
|
+
import { accessSync, constants, existsSync, lstatSync, readFileSync, realpathSync, rmSync, statSync, writeFileSync } from 'node:fs';
|
|
8
|
+
import { spawn, spawnSync } from 'node:child_process';
|
|
9
|
+
import { homedir, tmpdir } from 'node:os';
|
|
10
|
+
import { dirname, join } from 'node:path';
|
|
11
|
+
import { parseArgs } from 'node:util';
|
|
12
|
+
import { validateCapabilityMatrix } from '../../../packages/domain/src/index.js';
|
|
13
|
+
import { API_RUNTIME_VERSION } from '../../../adapters/runtime-api/src/index.js';
|
|
14
|
+
import { failureDigest, isReady, isRealDate, pendingApproval, prepareRun, projectRun } from '../../../packages/application/src/index.js';
|
|
15
|
+
import { defaultConfig, keyEnvName, KNOWN_KEY_VARS, MAX_CONFIG_BYTES, parseConfig, providerOf, renderConfig, workflowOf } from '../../../packages/config/src/index.js';
|
|
16
|
+
import { findOnPath, probeHost, probeOllama } from '../../../adapters/host-probe/src/index.js';
|
|
17
|
+
import { connectedProviders, connectEnv, LOCAL_PROVIDERS, LOGIN_ARGS, MEASURED_CONNECTIONS, measuredHosts, OPENCODE_VERSION, userOpenCodeDirs, userOpenCodePaths } from '../../../adapters/runtime-opencode/src/index.js';
|
|
18
|
+
import { ensureTrustedDir, listRuns, loadRiskAcceptances, loadRunState, openRepoStoreReadOnly, readEvents, repoStore, saveRiskAcceptance, stateBase } from '../../../adapters/store-fs/src/index.js';
|
|
19
|
+
import { codexSandboxFor } from '../../../adapters/runtime-codex/src/index.js';
|
|
20
|
+
import { ClaudeMemMemory } from '../../../adapters/memory-claude-mem/src/index.js';
|
|
21
|
+
import { GitWorkspace } from '../../../adapters/git/src/index.js';
|
|
22
|
+
import { cmdApprove, cmdResume, cmdRun, requestFrom, cmdShow, cmdStatus, configDigest } from "./workflow-cli.js";
|
|
23
|
+
import { jsonOut, n as nz, nLog } from "./tui/neutral.js";
|
|
24
|
+
import { animateLogo, completeCommand, consoleSurface, drawSlashMenu, lineReader, runConsole, slashMenu, squadOf, withTerminalReleased } from "./console.js";
|
|
25
|
+
import { sandboxedToolAvailable } from '../../../adapters/local-tool/src/index.js';
|
|
26
|
+
import { installShortcut, removeShortcut } from "./shortcut.js";
|
|
27
|
+
import { runtimeNotices } from "./runtime-notices.js";
|
|
28
|
+
import { layoutOf } from "./layout.js";
|
|
29
|
+
import { detectCaps } from "./tui/caps.js";
|
|
30
|
+
import { nodeTty } from "./tui/screen.js";
|
|
31
|
+
import { runDashboard } from "./dashboard.js";
|
|
32
|
+
import { fileURLToPath } from 'node:url';
|
|
33
|
+
import { homeMode, LOGO_ROWS, renderHome } from "./tui/components/home.js";
|
|
34
|
+
import { shownRun } from "./tui/view.js";
|
|
35
|
+
import { timelineLine } from "./tui/components/timeline.js";
|
|
36
|
+
import { en, english, ENGLISH_ONLY, loadPreferences, resolveLanguage, setLanguage, t, translate } from "./i18n/index.js";
|
|
37
|
+
import { alignColumns } from "./i18n/width.js";
|
|
38
|
+
import { createInterface } from 'node:readline';
|
|
39
|
+
import { appendHistory, loadHistory, scrubReadlineHistory } from "./history.js";
|
|
40
|
+
import { displayWidth } from "./i18n/width.js";
|
|
41
|
+
import { cmdSkills, resolveAgentSkills } from "./skills-cli.js";
|
|
42
|
+
import { cmdUpgrade } from "./upgrade-cli.js";
|
|
43
|
+
import { fetchLatest } from "./upgrade-check.js";
|
|
44
|
+
import { absoluteHome } from "./home.js";
|
|
45
|
+
import { savePreferences } from "./preferences.js";
|
|
46
|
+
const CONFIG = 'taskquoin.yaml';
|
|
47
|
+
const out = (s = '') => process.stdout.write(s + '\n');
|
|
48
|
+
const err = (s) => process.stderr.write(s + '\n');
|
|
49
|
+
const sha = (s) => createHash('sha256').update(s).digest('hex');
|
|
50
|
+
const LAYOUT = layoutOf(import.meta.url);
|
|
51
|
+
const HOOK_ENTRY = LAYOUT.hookEntry;
|
|
52
|
+
function loadMatrix(rt) {
|
|
53
|
+
return validateCapabilityMatrix(JSON.parse(readFileSync(new URL(`../../../adapters/runtime-${rt}/src/capabilities.json`, import.meta.url), 'utf8')));
|
|
54
|
+
}
|
|
55
|
+
function detectStack(root) {
|
|
56
|
+
const has = (f) => existsSync(join(root, f));
|
|
57
|
+
if (has('package.json'))
|
|
58
|
+
return 'node';
|
|
59
|
+
if (has('composer.json'))
|
|
60
|
+
return 'php';
|
|
61
|
+
if (has('pyproject.toml') || has('requirements.txt') || has('setup.py'))
|
|
62
|
+
return 'python';
|
|
63
|
+
if (has('go.mod'))
|
|
64
|
+
return 'go';
|
|
65
|
+
if (has('pom.xml'))
|
|
66
|
+
return 'java-maven';
|
|
67
|
+
if (has('build.gradle') || has('build.gradle.kts'))
|
|
68
|
+
return 'java-gradle';
|
|
69
|
+
return 'unknown';
|
|
70
|
+
}
|
|
71
|
+
async function host() {
|
|
72
|
+
// No absolute home: '' (the probe then never looks for the measured file, and nothing resolves against the cwd).
|
|
73
|
+
return probeHost({ cwd: process.cwd(), PATH: process.env.PATH ?? '', HOME: absoluteHome() ?? '',
|
|
74
|
+
claude: { measured: loadMatrix('claude').runtimeVersion, selection: loadPreferences(stateBase()).runtimeSelection?.claude ?? 'auto' } });
|
|
75
|
+
}
|
|
76
|
+
function requireRepo(h) {
|
|
77
|
+
if (!h.gitRoot) {
|
|
78
|
+
err(t('cli.notGit'));
|
|
79
|
+
process.exit(1);
|
|
80
|
+
}
|
|
81
|
+
return h.gitRoot;
|
|
82
|
+
}
|
|
83
|
+
function loadConfig(root) {
|
|
84
|
+
const p = join(root, CONFIG);
|
|
85
|
+
if (!existsSync(p)) {
|
|
86
|
+
err(t('cli.configMissing', { config: CONFIG }));
|
|
87
|
+
process.exit(1);
|
|
88
|
+
}
|
|
89
|
+
if (statSync(p).size > MAX_CONFIG_BYTES) {
|
|
90
|
+
err(t('cli.configTooLarge', { config: CONFIG }));
|
|
91
|
+
process.exit(1);
|
|
92
|
+
}
|
|
93
|
+
try {
|
|
94
|
+
return parseConfig(readFileSync(p, 'utf8'));
|
|
95
|
+
}
|
|
96
|
+
catch (e) {
|
|
97
|
+
err(`taskquoin: ${nz(e.message)}`);
|
|
98
|
+
process.exit(1);
|
|
99
|
+
} // i18n-ok: the message comes from the config parser (domain text)
|
|
100
|
+
}
|
|
101
|
+
function gate(cfg, h, agentId, store = repoStore(h.gitRoot)) {
|
|
102
|
+
const a = cfg.agents[agentId];
|
|
103
|
+
if (a.runtime === 'api') {
|
|
104
|
+
// A text-only judge: certified by construction (no tool path); runnable only when its provider key is present.
|
|
105
|
+
const g = prepareRun({ agentId, agent: a, mandatory: cfg.policy.mandatory, exceptions: [], matrix: loadMatrix('api'), facts: { runtimeVersion: API_RUNTIME_VERSION, satisfied: ['landing-gate'] }, now: new Date() });
|
|
106
|
+
const name = keyEnvName(cfg.providers[a.provider]);
|
|
107
|
+
if (name && !process.env[name]?.trim())
|
|
108
|
+
return { ...g, ok: false, ticket: undefined, runtimeFound: true,
|
|
109
|
+
failures: [...g.failures, { capability: 'net.egress', class: 'UNSUPPORTED', message: english('cli.apiKeyMissing', { name }) }] };
|
|
110
|
+
return { ...g, runtimeFound: true };
|
|
111
|
+
}
|
|
112
|
+
const matrix = loadMatrix(a.runtime);
|
|
113
|
+
const probe = h.runtimes[a.runtime];
|
|
114
|
+
const facts = {
|
|
115
|
+
runtimeVersion: probe?.version ?? 'not-installed',
|
|
116
|
+
// landing-gate: the only execution path is the Taskquoin workflow, which enforces it.
|
|
117
|
+
satisfied: [...(a.runtime === 'claude' && h.bashSandbox ? ['bash-sandbox'] : []), ...(a.runtime === 'opencode' && h.fileSandbox ? ['file-sandbox'] : []), 'landing-gate'],
|
|
118
|
+
...(a.runtime === 'codex' ? { sandbox: codexSandboxFor(a.capabilities) } : {}),
|
|
119
|
+
};
|
|
120
|
+
const exceptions = loadRiskAcceptances(store);
|
|
121
|
+
const g = { ...prepareRun({ agentId, agent: a, mandatory: cfg.policy.mandatory, exceptions, matrix, facts, now: new Date() }), runtimeFound: !!probe };
|
|
122
|
+
if (a.runtime === 'opencode') {
|
|
123
|
+
// Taskquoin's own OpenCode connection (spec §5.2) must hold the model's provider — checked without reading any secret.
|
|
124
|
+
const provider = providerOf(a.model);
|
|
125
|
+
const conn = connectedProviders(userOpenCodePaths()).find(p => p.id === provider);
|
|
126
|
+
const refuse = (message) => ({ ...g, ok: false, ticket: undefined, failures: [...g.failures, { capability: 'net.egress', class: 'UNSUPPORTED', message }] });
|
|
127
|
+
if (!conn)
|
|
128
|
+
return refuse(english('cli.opencode.notConnected', { provider }));
|
|
129
|
+
// Only measured provider/sign-in pairs are certified: their hosts are known (spec §5.4, final review C1).
|
|
130
|
+
if (!measuredHosts(provider, conn.type))
|
|
131
|
+
return refuse(english('cli.opencode.unmeasured', { provider, type: conn.type, version: OPENCODE_VERSION, measured: MEASURED_CONNECTIONS.join(', ') }));
|
|
132
|
+
}
|
|
133
|
+
return g;
|
|
134
|
+
}
|
|
135
|
+
async function cmdInit() {
|
|
136
|
+
const h = await host();
|
|
137
|
+
const root = requireRepo(h);
|
|
138
|
+
const p = join(root, CONFIG);
|
|
139
|
+
if (existsSync(p)) {
|
|
140
|
+
err(t('cli.init.exists', { config: CONFIG }));
|
|
141
|
+
return 1;
|
|
142
|
+
}
|
|
143
|
+
const stack = detectStack(root);
|
|
144
|
+
const tools = { claude: !!h.runtimes.claude, codex: !!h.runtimes.codex, opencode: !!h.runtimes.opencode };
|
|
145
|
+
const cfg0 = defaultConfig(stack, tools);
|
|
146
|
+
// Detection is LOCAL only: which key variables exist (their values are never read into the file), and a local Ollama.
|
|
147
|
+
const detected = { env: KNOWN_KEY_VARS.filter(n => !!process.env[n]), ollamaModels: (await probeOllama()) ?? [] };
|
|
148
|
+
const text = renderConfig(cfg0, detected);
|
|
149
|
+
// Transactional (Codex R3): validate the store and record ownership BEFORE creating the file; roll back on failure.
|
|
150
|
+
const store = repoStore(root);
|
|
151
|
+
const mf = join(store.root, 'manifest.json');
|
|
152
|
+
writeFileSync(mf, JSON.stringify({ version: 1, createdAt: new Date().toISOString(), files: [{ path: CONFIG, sha256: sha(text) }] }, null, 2), { mode: 0o600 });
|
|
153
|
+
try {
|
|
154
|
+
writeFileSync(p, text, { flag: 'wx' });
|
|
155
|
+
}
|
|
156
|
+
catch (e) {
|
|
157
|
+
rmSync(mf, { force: true });
|
|
158
|
+
throw e;
|
|
159
|
+
}
|
|
160
|
+
out(t('cli.init.created', { config: CONFIG, stack, agents: Object.entries(cfg0.agents).map(([id, a]) => `${nz(id)} (${a.runtime})`).join(', ') }));
|
|
161
|
+
out(t('cli.init.store', { path: nz(store.root) }));
|
|
162
|
+
if (detected.env.length || detected.ollamaModels.length)
|
|
163
|
+
out(t('cli.init.detected', { list: [...detected.env, ...(detected.ollamaModels.length ? [t('cli.init.ollama', { models: detected.ollamaModels.map(nz).join(', ') })] : [])].join(', '), config: CONFIG }));
|
|
164
|
+
if (!tools.claude && tools.opencode) {
|
|
165
|
+
const ps = connectedProviders(userOpenCodePaths()).map(p => p.id);
|
|
166
|
+
out(t('cli.init.opencodeOnly', { config: CONFIG, providers: ps.length ? ps.map(nz).join(', ') : t('cli.init.noProvider') }));
|
|
167
|
+
}
|
|
168
|
+
else if (!tools.claude)
|
|
169
|
+
out(t('cli.init.needImplementer'));
|
|
170
|
+
else if (!tools.codex)
|
|
171
|
+
out(t('cli.init.claudeOnly'));
|
|
172
|
+
// OpenCode has no commands (the parser refuses shell.run for it): Taskquoin runs the tests with verify.command alone.
|
|
173
|
+
if (stack === 'unknown')
|
|
174
|
+
out(cfg0.agents.implementer?.runtime === 'opencode' ? t('cli.init.unknownStackOpencode', { config: CONFIG }) : t('cli.init.unknownStack', { config: CONFIG }));
|
|
175
|
+
out(t('cli.init.next'));
|
|
176
|
+
return 0;
|
|
177
|
+
}
|
|
178
|
+
function printGate(id, cfg, g) {
|
|
179
|
+
out(t('cli.gate.agent', { id: nz(id), runtime: cfg.agents[id].runtime }) + (g.runtimeFound ? '' : t('cli.gate.notInstalled')));
|
|
180
|
+
const a = cfg.agents[id];
|
|
181
|
+
if (a.runtime === 'api') {
|
|
182
|
+
const p = cfg.providers[a.provider];
|
|
183
|
+
const name = keyEnvName(p);
|
|
184
|
+
out(t('cli.gate.provider', { id: nz(a.provider), url: nz(p.url), model: nz(p.model), key: name ? t('cli.gate.key', { name: nz(name), state: process.env[name]?.trim() ? t('cli.gate.present') : t('cli.gate.absent') }) : t('cli.gate.noKey') }));
|
|
185
|
+
}
|
|
186
|
+
const shown = new Set();
|
|
187
|
+
for (const r of g.resolved) {
|
|
188
|
+
const f = g.failures.find(x => x.capability === r.capability);
|
|
189
|
+
const a = g.acceptedRisks.find(x => x.capability === r.capability);
|
|
190
|
+
if (r.certified)
|
|
191
|
+
out(` ✔ ${r.capability} ${r.class} — ${nz(r.mechanism)}`);
|
|
192
|
+
else if (a)
|
|
193
|
+
out(t('cli.gate.acceptedRisk', { capability: r.capability, by: nz(a.approvedBy), until: nz(a.expires), reason: nz(a.reason), message: nz(a.message) }));
|
|
194
|
+
else {
|
|
195
|
+
out(` ✖ ${r.capability} — ${nz(f?.message ?? r.mechanism)}`);
|
|
196
|
+
if (f)
|
|
197
|
+
shown.add(f);
|
|
198
|
+
}
|
|
199
|
+
}
|
|
200
|
+
// Failures added outside the capability matrix (a missing api key, an unconnected OpenCode provider) are shown too.
|
|
201
|
+
for (const f of g.failures)
|
|
202
|
+
if (!shown.has(f))
|
|
203
|
+
out(` ✖ ${nz(f.message)}`);
|
|
204
|
+
}
|
|
205
|
+
async function cmdDoctor() {
|
|
206
|
+
const h = await host();
|
|
207
|
+
const root = requireRepo(h);
|
|
208
|
+
const cfg = loadConfig(root);
|
|
209
|
+
out(t('cli.doctor.title', { root: nz(root) }));
|
|
210
|
+
for (const rt of ['claude', 'codex', 'opencode']) {
|
|
211
|
+
const p = h.runtimes[rt];
|
|
212
|
+
const m = loadMatrix(rt);
|
|
213
|
+
if (p?.installed) {
|
|
214
|
+
out(t('cli.doctor.runtimeFallback', { rt, installed: nz(p.installed.version ?? '?'), version: nz(p.version ?? '?'), bin: nz(p.bin) }));
|
|
215
|
+
continue;
|
|
216
|
+
}
|
|
217
|
+
out(p ? t('cli.doctor.runtime', { rt, version: nz(p.version ?? '?'), bin: nz(p.bin), mark: p.version === m.runtimeVersion ? '✔' : t('cli.doctor.matrix', { version: m.runtimeVersion }) }) : t('cli.doctor.runtimeMissing', { rt }));
|
|
218
|
+
}
|
|
219
|
+
// Claude Code not measured and the measured one not used: why, and the `taskquoin upgrade` command that fixes it.
|
|
220
|
+
for (const n of runtimeNotices(h, loadMatrix('claude').runtimeVersion, 'cli'))
|
|
221
|
+
if (n.kind === 'action')
|
|
222
|
+
out(n.text);
|
|
223
|
+
out(t('cli.doctor.bash', { state: h.bashSandbox ? '✔' : t('cli.doctor.bashMissing') }));
|
|
224
|
+
out(t('cli.doctor.file', { state: h.fileSandbox ? '✔' : t('cli.doctor.fileMissing') }));
|
|
225
|
+
out(t('cli.doctor.isolation', { state: h.localIsolation ? '✔' : t('cli.doctor.isolationMissing') }));
|
|
226
|
+
out(t('cli.doctor.hook', { state: existsSync(HOOK_ENTRY) ? '✔' : t('cli.doctor.hookMissing'), path: HOOK_ENTRY }));
|
|
227
|
+
const conns = Object.entries(cfg.connectors);
|
|
228
|
+
// Where this project's code goes (multi-LLM A): every agent that receives it, grouped by destination.
|
|
229
|
+
const used = [...new Set(['planner', 'implementer', ...workflowOf(cfg).challengers, ...workflowOf(cfg).reviewers])].filter(id => cfg.agents[id]);
|
|
230
|
+
const dest = new Map();
|
|
231
|
+
for (const id of used) {
|
|
232
|
+
const a = cfg.agents[id];
|
|
233
|
+
let where;
|
|
234
|
+
let local = false;
|
|
235
|
+
if (a.runtime === 'claude')
|
|
236
|
+
where = 'Anthropic (Claude Code)';
|
|
237
|
+
else if (a.runtime === 'codex')
|
|
238
|
+
where = 'OpenAI (Codex)';
|
|
239
|
+
else if (a.runtime === 'opencode') {
|
|
240
|
+
const provider = providerOf(a.model);
|
|
241
|
+
const type = connectedProviders(userOpenCodePaths()).find(p => p.id === provider)?.type;
|
|
242
|
+
const hosts = measuredHosts(provider, type)?.code ?? [];
|
|
243
|
+
local = LOCAL_PROVIDERS.includes(provider);
|
|
244
|
+
where = `${nz(provider)} via OpenCode (${nz(a.model)})${local ? '' : hosts.length ? t('cli.where.hosts', { hosts: hosts.join(', ') }) : t('cli.where.unmeasured')}`;
|
|
245
|
+
}
|
|
246
|
+
else {
|
|
247
|
+
const p = cfg.providers[a.provider];
|
|
248
|
+
const u = new URL(p.url);
|
|
249
|
+
where = `${nz(u.host)} (${nz(p.model)})`;
|
|
250
|
+
local = ['localhost', '127.0.0.1', '[::1]'].includes(u.hostname);
|
|
251
|
+
}
|
|
252
|
+
dest.set(where, { ids: [...(dest.get(where)?.ids ?? []), id], local });
|
|
253
|
+
}
|
|
254
|
+
for (const id of workflowOf(cfg).reviewers) {
|
|
255
|
+
const rt = cfg.agents[id]?.runtime;
|
|
256
|
+
if (rt && rt !== 'api' && rt === cfg.agents.implementer?.runtime)
|
|
257
|
+
out(t('cli.doctor.sameModel', { id: nz(id), rt, config: CONFIG }));
|
|
258
|
+
}
|
|
259
|
+
out(t('cli.doctor.codeGoesTo'));
|
|
260
|
+
for (const [where, d] of dest)
|
|
261
|
+
out(` ${where} — ${d.ids.map(nz).join(', ')}${d.local ? ` (${t('cli.where.stays')})` : ''}`);
|
|
262
|
+
out(t('cli.doctor.connectors', { list: conns.length ? conns.map(([id, c]) => t('cli.doctor.connector', { id: nz(id), host: nz(c.host), scope: nz(c.scope), read: c.read.length, write: c.write.length })).join('; ') : t('cli.doctor.none') }));
|
|
263
|
+
if (cfg.memory.claudeMem.enabled) {
|
|
264
|
+
const mem = new ClaudeMemMemory();
|
|
265
|
+
const lo = await mem.localOnlyCheck();
|
|
266
|
+
out(t('cli.doctor.memory', { state: !lo.ok ? t('cli.doctor.memRefused', { reason: nz(lo.reason ?? '') }) : (await mem.available()) ? t('cli.doctor.memOk') : t('cli.doctor.memNoWorker') }));
|
|
267
|
+
}
|
|
268
|
+
else
|
|
269
|
+
out(t('cli.doctor.memory', { state: t('cli.doctor.memOff') }));
|
|
270
|
+
out();
|
|
271
|
+
let refused = 0;
|
|
272
|
+
for (const id of Object.keys(cfg.agents)) {
|
|
273
|
+
const g = gate(cfg, h, id);
|
|
274
|
+
printGate(id, cfg, g);
|
|
275
|
+
const sk = resolveAgentSkills(cfg, repoStore(root), id);
|
|
276
|
+
if ((cfg.agents[id].skills ?? []).length)
|
|
277
|
+
out(t('cli.doctor.skills', { list: [...sk.loaded.map(x => `✔ ${nz(x.name)} (${nz(x.origin)}, ${x.treeHash.slice(7, 19)})`), ...sk.errors.map(e => `✖ ${nz(e)}`)].join(' · ') }));
|
|
278
|
+
if (!isReady({ ...g, skillErrors: sk.errors }))
|
|
279
|
+
refused++;
|
|
280
|
+
out();
|
|
281
|
+
}
|
|
282
|
+
const n = Object.keys(cfg.agents).length;
|
|
283
|
+
out(refused ? t('cli.doctor.verdictSome', { ok: n - refused, total: n }) : t('cli.doctor.verdictAll', { total: n }));
|
|
284
|
+
return refused ? 1 : 0;
|
|
285
|
+
}
|
|
286
|
+
async function cmdCheck(agentId, json) {
|
|
287
|
+
const h = await host();
|
|
288
|
+
const root = requireRepo(h);
|
|
289
|
+
const cfg = loadConfig(root);
|
|
290
|
+
if (!agentId || !cfg.agents[agentId]) {
|
|
291
|
+
err(t('cli.check.usage', { agents: Object.keys(cfg.agents).join(', ') }));
|
|
292
|
+
return 2;
|
|
293
|
+
}
|
|
294
|
+
const g = gate(cfg, h, agentId);
|
|
295
|
+
const ok = g.ok && g.runtimeFound;
|
|
296
|
+
if (json)
|
|
297
|
+
out(jsonOut({ agent: agentId, ok, runtimeFound: g.runtimeFound, failures: g.failures, acceptedRisks: g.acceptedRisks, resolved: g.resolved, warnings: g.warnings }));
|
|
298
|
+
else
|
|
299
|
+
printGate(agentId, cfg, g);
|
|
300
|
+
return ok ? 0 : 1;
|
|
301
|
+
}
|
|
302
|
+
/** Record an owner risk acceptance for the CURRENT failure of (agent, capability), in the control store. */
|
|
303
|
+
async function cmdAcceptRisk(agentId, capability, o) {
|
|
304
|
+
const h = await host();
|
|
305
|
+
const root = requireRepo(h);
|
|
306
|
+
const cfg = loadConfig(root);
|
|
307
|
+
if (!agentId || !Object.hasOwn(cfg.agents, agentId) || !capability) {
|
|
308
|
+
err(t('cli.accept.usage'));
|
|
309
|
+
return 2;
|
|
310
|
+
}
|
|
311
|
+
if (!o.reason?.trim() || !o.as?.trim() || !o.expires || !isRealDate(o.expires)) {
|
|
312
|
+
err(t('cli.accept.required'));
|
|
313
|
+
return 2;
|
|
314
|
+
}
|
|
315
|
+
if (o.expires < new Date().toISOString().slice(0, 10)) {
|
|
316
|
+
err(t('cli.accept.past'));
|
|
317
|
+
return 2;
|
|
318
|
+
}
|
|
319
|
+
if (cfg.agents[agentId].runtime === 'api') {
|
|
320
|
+
err(t('cli.accept.apiJudge', { agent: agentId }));
|
|
321
|
+
return 1;
|
|
322
|
+
}
|
|
323
|
+
const g = gate(cfg, h, agentId);
|
|
324
|
+
const f = g.failures.find(x => x.capability === capability);
|
|
325
|
+
if (!f) {
|
|
326
|
+
err(t('cli.accept.notFailing', { capability: nz(capability), agent: nz(agentId) }));
|
|
327
|
+
return 1;
|
|
328
|
+
}
|
|
329
|
+
const probe = h.runtimes[cfg.agents[agentId].runtime]; // api judges returned above
|
|
330
|
+
saveRiskAcceptance(repoStore(root), { agent: agentId, capability, reason: o.reason.trim(), expires: o.expires, approvedBy: o.as.trim(),
|
|
331
|
+
runtimeVersion: probe?.version ?? 'not-installed', failureDigest: failureDigest(f.message), createdAt: new Date().toISOString() });
|
|
332
|
+
out(t('cli.accept.done', { by: nz(o.as.trim()), until: nz(o.expires), agent: nz(agentId), capability: nz(capability) }));
|
|
333
|
+
out(` ${nz(f.message)}`);
|
|
334
|
+
out(t('cli.accept.stops'));
|
|
335
|
+
return 0;
|
|
336
|
+
}
|
|
337
|
+
/** `connect opencode` (spec §5.2): OpenCode's own sign-in, on Taskquoin's OpenCode directory; secrets are never printed. */
|
|
338
|
+
function cmdConnect(target, remove) {
|
|
339
|
+
if (target !== 'opencode') {
|
|
340
|
+
err(t('cli.connect.usage'));
|
|
341
|
+
return 2;
|
|
342
|
+
}
|
|
343
|
+
const dir = join(stateBase(), 'opencode');
|
|
344
|
+
if (remove) {
|
|
345
|
+
rmSync(dir, { recursive: true, force: true });
|
|
346
|
+
out(t('cli.connect.removed', { dir: nz(dir) }));
|
|
347
|
+
return 0;
|
|
348
|
+
}
|
|
349
|
+
const bin = findOnPath('opencode', process.env.PATH ?? '');
|
|
350
|
+
if (!bin) {
|
|
351
|
+
err(t('cli.connect.notInstalled'));
|
|
352
|
+
return 1;
|
|
353
|
+
}
|
|
354
|
+
const d = userOpenCodeDirs();
|
|
355
|
+
out(t('cli.connect.intro', { dir: nz(dirname(d.config)) }));
|
|
356
|
+
const r = spawnSync(bin, [...LOGIN_ARGS], { stdio: 'inherit', cwd: tmpdir(),
|
|
357
|
+
env: { PATH: process.env.PATH ?? '', HOME: process.env.HOME ?? homedir(), LANG: process.env.LANG ?? 'C.UTF-8', ...connectEnv(d) } });
|
|
358
|
+
const ps = connectedProviders(d);
|
|
359
|
+
if (r.status !== 0)
|
|
360
|
+
err(t('cli.connect.failed'));
|
|
361
|
+
if (!ps.length) {
|
|
362
|
+
err(t('cli.connect.none'));
|
|
363
|
+
return 1;
|
|
364
|
+
}
|
|
365
|
+
out(t('cli.connect.connected', { list: ps.map(p => `${nz(p.id)} (${nz(p.type)})`).join(', ') }));
|
|
366
|
+
return r.status === 0 ? 0 : 1;
|
|
367
|
+
}
|
|
368
|
+
async function cmdUninstall(purge) {
|
|
369
|
+
const h = await host();
|
|
370
|
+
const root = requireRepo(h);
|
|
371
|
+
const store = repoStore(root);
|
|
372
|
+
const mf = join(store.root, 'manifest.json');
|
|
373
|
+
if (!existsSync(mf)) {
|
|
374
|
+
if (!purge) {
|
|
375
|
+
err(t('cli.uninstall.noManifest'));
|
|
376
|
+
return 1;
|
|
377
|
+
}
|
|
378
|
+
// A previous uninstall already removed the manifest: the purge still has to remove the store.
|
|
379
|
+
if (!store.root.startsWith(stateBase() + '/')) {
|
|
380
|
+
err(t('cli.uninstall.refusePurge', { path: nz(store.root), base: nz(stateBase()) }));
|
|
381
|
+
return 1;
|
|
382
|
+
}
|
|
383
|
+
rmSync(store.root, { recursive: true, force: true });
|
|
384
|
+
out(t('cli.uninstall.purged', { path: nz(store.root) }));
|
|
385
|
+
return 0;
|
|
386
|
+
}
|
|
387
|
+
// Validate before touching anything (Codex R3): known schema, only files Taskquoin can create, contained, no symlinks.
|
|
388
|
+
const OWNED = new Set([CONFIG]);
|
|
389
|
+
let manifest;
|
|
390
|
+
try {
|
|
391
|
+
manifest = JSON.parse(readFileSync(mf, 'utf8'));
|
|
392
|
+
if (!Array.isArray(manifest.files))
|
|
393
|
+
throw new Error(t('cli.uninstall.notList'));
|
|
394
|
+
for (const f of manifest.files) {
|
|
395
|
+
if (typeof f?.path !== 'string' || typeof f.sha256 !== 'string' || !/^[0-9a-f]{64}$/.test(f.sha256))
|
|
396
|
+
throw new Error(t('cli.uninstall.malformed'));
|
|
397
|
+
if (!OWNED.has(f.path))
|
|
398
|
+
throw new Error(t('cli.uninstall.notOwned', { path: nz(f.path) })); // the parameter, neutralised here
|
|
399
|
+
}
|
|
400
|
+
// A whole message (translated, or the JSON parser's quoting the file): the log profile, as for any thrown error.
|
|
401
|
+
}
|
|
402
|
+
catch (e) {
|
|
403
|
+
err(t('cli.uninstall.invalid', { reason: nLog(e.message) }));
|
|
404
|
+
return 1;
|
|
405
|
+
}
|
|
406
|
+
let kept = 0;
|
|
407
|
+
for (const f of manifest.files) {
|
|
408
|
+
const p = join(root, f.path);
|
|
409
|
+
if (!existsSync(p)) {
|
|
410
|
+
out(t('cli.uninstall.absent', { path: nz(f.path) }));
|
|
411
|
+
continue;
|
|
412
|
+
}
|
|
413
|
+
if (lstatSync(p).isSymbolicLink() || realpathSync(p) !== join(realpathSync(root), f.path)) {
|
|
414
|
+
kept++;
|
|
415
|
+
out(t('cli.uninstall.keptLink', { path: nz(f.path) }));
|
|
416
|
+
continue;
|
|
417
|
+
}
|
|
418
|
+
if (sha(readFileSync(p)) === f.sha256) {
|
|
419
|
+
rmSync(p);
|
|
420
|
+
out(t('cli.uninstall.removed', { path: nz(f.path) }));
|
|
421
|
+
}
|
|
422
|
+
else {
|
|
423
|
+
kept++;
|
|
424
|
+
out(t('cli.uninstall.keptModified', { path: nz(f.path) }));
|
|
425
|
+
}
|
|
426
|
+
}
|
|
427
|
+
if (purge) {
|
|
428
|
+
if (!store.root.startsWith(stateBase() + '/')) {
|
|
429
|
+
err(t('cli.uninstall.refusePurge', { path: nz(store.root), base: nz(stateBase()) }));
|
|
430
|
+
return 1;
|
|
431
|
+
}
|
|
432
|
+
rmSync(store.root, { recursive: true, force: true });
|
|
433
|
+
out(t('cli.uninstall.purged', { path: nz(store.root) }));
|
|
434
|
+
}
|
|
435
|
+
else {
|
|
436
|
+
if (!kept)
|
|
437
|
+
rmSync(mf); // keep the manifest while a recorded file remains, so a later uninstall still knows it
|
|
438
|
+
out(t('cli.uninstall.storeKept', { path: nz(store.root) }));
|
|
439
|
+
}
|
|
440
|
+
return kept ? 1 : 0;
|
|
441
|
+
}
|
|
442
|
+
/** Short commands are aligned in one column by display width; the long ones keep their description on the next line. */
|
|
443
|
+
export function help() {
|
|
444
|
+
const col = [
|
|
445
|
+
[' init', t('cli.help.init')], [' doctor', t('cli.help.doctor')], [' check <agent> [--json]', t('cli.help.check')], [' version', t('cli.help.version')],
|
|
446
|
+
[' upgrade [auto|path|install] [--offline]', t('cli.help.upgrade')], [' console', t('cli.help.console')], [' run "<request>"', t('cli.help.run')], [' status [<run>] [--json]', t('cli.help.status')],
|
|
447
|
+
[' dashboard [<run>]', t('cli.help.dashboard')], [' show <run>', t('cli.help.showList')], [' show <run> <artifact>', t('cli.help.showOne')], [' resume <run>', t('cli.help.resume')],
|
|
448
|
+
[' skills list', t('cli.help.skillsList')], [' skills audit <dir>', t('cli.help.skillsAudit')],
|
|
449
|
+
[' connect opencode [--remove]', t('cli.help.connect')], [' setup [--remove]', t('cli.help.setup2')], [' uninstall [--purge-state]', t('cli.help.uninstall')],
|
|
450
|
+
];
|
|
451
|
+
const L = alignColumns(col);
|
|
452
|
+
const at = (cmd) => L[col.findIndex(([c]) => c === ` ${cmd}`)];
|
|
453
|
+
const wrap = ' '.repeat(L[0].length - col[0][1].length);
|
|
454
|
+
return [
|
|
455
|
+
t('cli.help.title'), '',
|
|
456
|
+
t('cli.help.setup'), at('init'), at('doctor'), at('upgrade [auto|path|install] [--offline]'), at('check <agent> [--json]'),
|
|
457
|
+
' accept-risk <agent> <capability> --reason "<why>" --expires YYYY-MM-DD --as <name>', wrap + t('cli.help.acceptRisk'), at('version'),
|
|
458
|
+
t('cli.help.workflow'), at('console'), at('run "<request>"'), at('status [<run>] [--json]'), at('dashboard [<run>]'), at('show <run>'), at('show <run> <artifact>'),
|
|
459
|
+
' approve <run> <plan|commit> --expect <hash> --as <name>', wrap + t('cli.help.approve'), at('resume <run>'),
|
|
460
|
+
t('cli.help.skills'), at('skills list'), at('skills audit <dir>'),
|
|
461
|
+
` skills import <dir> --source "<owner/repo@commit>" ${t('cli.help.skillsImport')}`,
|
|
462
|
+
` skills approve <name> --as <name> [--accept-findings] ${t('cli.help.skillsApprove')}`,
|
|
463
|
+
' skills revoke <name> --as <name>',
|
|
464
|
+
t('cli.help.shortcut'), at('connect opencode [--remove]'), at('setup [--remove]'),
|
|
465
|
+
t('cli.help.removal'), at('uninstall [--purge-state]'), '',
|
|
466
|
+
t('cli.help.exit'),
|
|
467
|
+
].join('\n');
|
|
468
|
+
}
|
|
469
|
+
async function ctx() {
|
|
470
|
+
const h = await host();
|
|
471
|
+
const root = requireRepo(h);
|
|
472
|
+
const cfg = loadConfig(root);
|
|
473
|
+
if (!h.git)
|
|
474
|
+
throw new Error(t('cli.gitMissing'));
|
|
475
|
+
const store = repoStore(root);
|
|
476
|
+
const c = { cfg, h, root, store, gate: (id) => gate(cfg, c.h, id), hookEntry: HOOK_ENTRY, out, err,
|
|
477
|
+
caps: detectCaps({ stdinTTY: !!process.stdin.isTTY, stdout: process.stdout, env: process.env }) };
|
|
478
|
+
return { c, git: new GitWorkspace({ gitBin: h.git, cwd: root, env: { PATH: process.env.PATH ?? '', HOME: process.env.HOME ?? homedir() }, scratchDir: ensureTrustedDir(join(store.root, 'scratch')) }) };
|
|
479
|
+
}
|
|
480
|
+
/** One line from stdin (a terminal or a pipe, like the console's lineReader, ADR-0015); closed input → undefined (cancel). */
|
|
481
|
+
function askStdin(question) {
|
|
482
|
+
process.stdout.write(question);
|
|
483
|
+
return new Promise((res) => {
|
|
484
|
+
const rl = createInterface({ input: process.stdin, terminal: false });
|
|
485
|
+
let got = false;
|
|
486
|
+
rl.once('line', (l) => { got = true; res(l); rl.close(); });
|
|
487
|
+
rl.once('close', () => { if (!got)
|
|
488
|
+
res(undefined); });
|
|
489
|
+
});
|
|
490
|
+
}
|
|
491
|
+
/** Starts `bin` with the user's environment and terminal; never throws: a binary that cannot start is exit code 127. */
|
|
492
|
+
function runInherit(bin, args, cwd) {
|
|
493
|
+
return new Promise((res) => {
|
|
494
|
+
let child;
|
|
495
|
+
try {
|
|
496
|
+
child = spawn(bin, args, { cwd, stdio: 'inherit', env: process.env });
|
|
497
|
+
}
|
|
498
|
+
catch (e) {
|
|
499
|
+
err(t('upgrade.runFailed', { bin: nz(bin), reason: nz(e.message) }));
|
|
500
|
+
res(127);
|
|
501
|
+
return;
|
|
502
|
+
}
|
|
503
|
+
child.once('error', (e) => { err(t('upgrade.runFailed', { bin: nz(bin), reason: nz(e.message) })); res(127); });
|
|
504
|
+
child.once('close', (code) => res(code ?? 1));
|
|
505
|
+
});
|
|
506
|
+
}
|
|
507
|
+
/** `taskquoin upgrade` and `/upgrade`: the registry is read only here, never when `offline`. */
|
|
508
|
+
async function cmdUpgradeWith(arg, o) {
|
|
509
|
+
const measured = { claude: loadMatrix('claude').runtimeVersion, codex: loadMatrix('codex').runtimeVersion, opencode: loadMatrix('opencode').runtimeVersion };
|
|
510
|
+
const e = {
|
|
511
|
+
h: o.h, measured, selection: loadPreferences(stateBase()).runtimeSelection?.claude ?? 'auto', packaged: LAYOUT.packaged, version: LAYOUT.version,
|
|
512
|
+
offline: o.offline, home: absoluteHome(), surface: o.surface, out, err, ask: o.ask,
|
|
513
|
+
save: (sel) => savePreferences(stateBase(), { runtimeSelection: { ...loadPreferences(stateBase()).runtimeSelection, claude: sel } }),
|
|
514
|
+
reprobe: () => host(), latest: () => fetchLatest(), run: o.run ?? runInherit,
|
|
515
|
+
};
|
|
516
|
+
const code = await cmdUpgrade(arg || undefined, e);
|
|
517
|
+
return { code, h: e.h };
|
|
518
|
+
}
|
|
519
|
+
const isOffline = (flag) => !!flag || process.env.TASKQUOIN_OFFLINE === '1';
|
|
520
|
+
/** `taskquoin console`: the same commands behind `/…` lines; approvals need the hash retyped (see console.ts). */
|
|
521
|
+
async function cmdConsole(offline) {
|
|
522
|
+
const { c, git } = await ctx();
|
|
523
|
+
const tty = !!process.stdin.isTTY;
|
|
524
|
+
let currentRun;
|
|
525
|
+
let cmdsRef;
|
|
526
|
+
const completer = (line) => {
|
|
527
|
+
const r = currentRun;
|
|
528
|
+
const p = r ? cmdsRef?.pending(r) : undefined;
|
|
529
|
+
return completeCommand(line, { runs: cmdsRef?.runs() ?? [], artifacts: r ? cmdsRef?.artifacts?.(r) ?? [] : [], ...(p ? { pendingGate: p.gate } : {}) });
|
|
530
|
+
};
|
|
531
|
+
// A run in the console reports its progress as it goes: one line per event, before the gate report.
|
|
532
|
+
c.onEvent = (e) => { const line = timelineLine(e, c.caps); if (line !== undefined)
|
|
533
|
+
out(line); };
|
|
534
|
+
const rl = createInterface({ input: process.stdin, output: process.stdout, terminal: tty, ...(tty ? { completer, history: loadHistory(c.store).reverse(), historySize: 500 } : {}) });
|
|
535
|
+
// The menu and the colours of the error lines follow the caps (AC-2): nothing drawn with TERM=dumb, in a pipe or plain mode.
|
|
536
|
+
const surface = consoleSurface(c.caps, !!process.stderr.isTTY);
|
|
537
|
+
rl.on('SIGINT', () => out('\n' + t('cli.console.sigint')));
|
|
538
|
+
// History keeps `/` commands only: readline's in-memory copy drops names and hashes, the file never gets them.
|
|
539
|
+
if (tty)
|
|
540
|
+
rl.on('line', (l) => { scrubReadlineHistory(rl, l); appendHistory(c.store, l); });
|
|
541
|
+
// readline owns the prompt (redrawn correctly); the "/" menu is drawn only while a prompt waits for input.
|
|
542
|
+
const reader = lineReader(rl, (s) => process.stdout.write(s), { discardTypeAhead: tty, showPrompt: (q) => { rl.setPrompt(q); rl.prompt(); } });
|
|
543
|
+
let prompting = false;
|
|
544
|
+
let menuShown = false;
|
|
545
|
+
const io = {
|
|
546
|
+
ask: async (q) => { prompting = true; try {
|
|
547
|
+
return await reader.ask(q);
|
|
548
|
+
}
|
|
549
|
+
finally {
|
|
550
|
+
prompting = false;
|
|
551
|
+
} },
|
|
552
|
+
setCurrent: (r) => { currentRun = r; },
|
|
553
|
+
out, err: (s) => err(surface.error(s)),
|
|
554
|
+
};
|
|
555
|
+
if (surface.menu) {
|
|
556
|
+
process.stdin.on('keypress', (_ch, key) => {
|
|
557
|
+
if (key?.name === 'return' || key?.name === 'enter')
|
|
558
|
+
return;
|
|
559
|
+
setImmediate(() => {
|
|
560
|
+
if (!prompting)
|
|
561
|
+
return;
|
|
562
|
+
const items = slashMenu(rl.line, process.stdout.columns || 80);
|
|
563
|
+
if (!items.length && !menuShown)
|
|
564
|
+
return;
|
|
565
|
+
process.stdout.write(drawSlashMenu({ promptWidth: displayWidth(rl.getPrompt()), line: rl.line, cursor: rl.cursor, items, caps: c.caps }));
|
|
566
|
+
menuShown = items.length > 0;
|
|
567
|
+
});
|
|
568
|
+
});
|
|
569
|
+
rl.on('line', () => { if (menuShown) {
|
|
570
|
+
process.stdout.write('\x1b[J');
|
|
571
|
+
menuShown = false;
|
|
572
|
+
} });
|
|
573
|
+
}
|
|
574
|
+
// The console loaded taskquoin.yaml once: if it changes (or disappears) while the console is open, commands are
|
|
575
|
+
// refused instead of running with a stale config (or a helper exiting the whole console).
|
|
576
|
+
const startDigest = configDigest(c.root);
|
|
577
|
+
const guard = async (f) => {
|
|
578
|
+
let now;
|
|
579
|
+
try {
|
|
580
|
+
now = configDigest(c.root);
|
|
581
|
+
}
|
|
582
|
+
catch { /* missing */ }
|
|
583
|
+
if (now !== startDigest) {
|
|
584
|
+
err(t('cli.console.configChanged'));
|
|
585
|
+
return 1;
|
|
586
|
+
}
|
|
587
|
+
return f();
|
|
588
|
+
};
|
|
589
|
+
const cmds = {
|
|
590
|
+
run: async (r) => { let runId; const code = await guard(() => cmdRun(c, git, r, (id) => { runId = id; })); return { code, ...(runId ? { runId } : {}) }; },
|
|
591
|
+
status: (r) => guard(() => cmdStatus(c, r)), show: (r, a) => guard(() => cmdShow(c, r, a)),
|
|
592
|
+
approve: (r, g, e, as) => guard(() => cmdApprove(c, git, r, g, e, as)), resume: (r) => guard(() => cmdResume(c, git, r)),
|
|
593
|
+
dashboard: (r) => guard(() => withTerminalReleased({ rl, stdin: process.stdin, signals: process }, () => runInherit(process.execPath, [SELF, 'dashboard', ...(r ? [r] : [])], c.root))),
|
|
594
|
+
doctor: () => guard(() => cmdDoctor()), skills: () => guard(() => cmdSkills(c.store, 'list', undefined, {}, out, err)),
|
|
595
|
+
agents: () => guard(() => {
|
|
596
|
+
for (const [id, a] of Object.entries(c.cfg.agents))
|
|
597
|
+
out(`${nz(id).padEnd(12)} ${a.runtime.padEnd(7)} ${Object.keys(a.capabilities).join(', ')}${a.skills?.length ? t('cli.console.agentSkills', { list: a.skills.map(nz).join(', ') }) : ''}`);
|
|
598
|
+
return 0;
|
|
599
|
+
}),
|
|
600
|
+
pending: (r) => { const s = loadRunState(c.store, r); const p = s && pendingApproval(s); return p ? { gate: p.node === 'approve-plan' ? 'plan' : 'commit', binding: p.binding } : undefined; },
|
|
601
|
+
runs: () => listRuns(c.store),
|
|
602
|
+
approval: (r) => {
|
|
603
|
+
const s = loadRunState(c.store, r);
|
|
604
|
+
if (!s)
|
|
605
|
+
return undefined;
|
|
606
|
+
let events = [];
|
|
607
|
+
try {
|
|
608
|
+
events = readEvents(c.store, r).events;
|
|
609
|
+
}
|
|
610
|
+
catch { /* no log yet: the view shows what the state holds */ }
|
|
611
|
+
const today = new Date().toISOString().slice(0, 10);
|
|
612
|
+
return { run: shownRun(projectRun(s, events)).view, acceptedRisks: loadRiskAcceptances(c.store).filter(x => x.expires >= today).map(x => x.capability) };
|
|
613
|
+
},
|
|
614
|
+
artifacts: (r) => Object.keys(loadRunState(c.store, r)?.artifacts ?? {}).sort(),
|
|
615
|
+
// The installer gets the terminal (Ctrl+C stops it); --offline given to `taskquoin console` holds for /upgrade.
|
|
616
|
+
upgrade: async (a, ask) => {
|
|
617
|
+
const r = await cmdUpgradeWith(a, { h: c.h, offline, ask, surface: 'console',
|
|
618
|
+
run: (bin, args, cwd) => withTerminalReleased({ rl, stdin: process.stdin, signals: process }, () => runInherit(bin, args, cwd)) });
|
|
619
|
+
c.h = await host();
|
|
620
|
+
return r.code;
|
|
621
|
+
},
|
|
622
|
+
};
|
|
623
|
+
cmdsRef = cmds;
|
|
624
|
+
// The squad as it really is: each agent's gate verdict, and Taskquoin's own sandboxed Verify as the tester.
|
|
625
|
+
// Computed while the logo animation plays (terminal with colours only; TASKQUOIN_NO_ANIMATION=1 turns it off).
|
|
626
|
+
const caps = c.caps;
|
|
627
|
+
const sandbox = await sandboxedToolAvailable();
|
|
628
|
+
const squad = squadOf(c.cfg.agents, (id) => ({ ...gate(c.cfg, c.h, id), skillErrors: resolveAgentSkills(c.cfg, repoStore(c.root), id).errors }), sandbox);
|
|
629
|
+
const model = await homeModel(c, git, squad, sandbox);
|
|
630
|
+
const lines = renderHome(model, caps);
|
|
631
|
+
// The logo is revealed while the screen is built (a terminal with colours, Full or Compact; TASKQUOIN_NO_ANIMATION=1 turns it off).
|
|
632
|
+
const animate = caps.motion && caps.colorDepth > 0 && homeMode(caps) !== 'minimal';
|
|
633
|
+
if (animate)
|
|
634
|
+
await animateLogo((s) => process.stdout.write(s), (ms) => new Promise(r => setTimeout(r, ms)), lines.slice(0, LOGO_ROWS));
|
|
635
|
+
try {
|
|
636
|
+
return await runConsole(io, cmds, (animate ? lines.slice(LOGO_ROWS) : lines).join('\n'), caps);
|
|
637
|
+
}
|
|
638
|
+
finally {
|
|
639
|
+
rl.close();
|
|
640
|
+
}
|
|
641
|
+
}
|
|
642
|
+
/** This file, for the console's `/dashboard` child process and the dashboard's `taskquoin approve` process. */
|
|
643
|
+
export const SELF = fileURLToPath(import.meta.url);
|
|
644
|
+
/**
|
|
645
|
+
* `taskquoin dashboard [<run>]`: a live, read-only screen over the control store. Order: repository, config, the store
|
|
646
|
+
* opened read-only, the run, THEN the terminal refusal (no probe for a message), then the squad as the banner shows it.
|
|
647
|
+
*/
|
|
648
|
+
async function cmdDashboard(runId) {
|
|
649
|
+
const h = await host();
|
|
650
|
+
const root = requireRepo(h);
|
|
651
|
+
const cfg = loadConfig(root);
|
|
652
|
+
let store;
|
|
653
|
+
try {
|
|
654
|
+
store = openRepoStoreReadOnly(root);
|
|
655
|
+
}
|
|
656
|
+
catch {
|
|
657
|
+
store = undefined;
|
|
658
|
+
}
|
|
659
|
+
if (!store) {
|
|
660
|
+
err(t('dashboard.noStore'));
|
|
661
|
+
return 1;
|
|
662
|
+
}
|
|
663
|
+
if (runId !== undefined) {
|
|
664
|
+
let known = false;
|
|
665
|
+
try {
|
|
666
|
+
known = !!loadRunState(store, runId);
|
|
667
|
+
}
|
|
668
|
+
catch {
|
|
669
|
+
known = false;
|
|
670
|
+
}
|
|
671
|
+
if (!known) {
|
|
672
|
+
err(t('workflow.unknownRun', { run: nz(runId) }));
|
|
673
|
+
return 1;
|
|
674
|
+
}
|
|
675
|
+
}
|
|
676
|
+
const capsOf = (size) => detectCaps({ stdinTTY: !!process.stdin.isTTY,
|
|
677
|
+
stdout: { isTTY: process.stdout.isTTY, columns: size?.columns ?? process.stdout.columns, rows: size?.rows ?? process.stdout.rows, getColorDepth: (e) => process.stdout.getColorDepth?.(e) ?? 1 }, env: process.env });
|
|
678
|
+
const c0 = capsOf();
|
|
679
|
+
if (!c0.interactive || c0.plain || process.env.TERM === 'dumb') {
|
|
680
|
+
err(t('dashboard.needsTerminal'));
|
|
681
|
+
return 1;
|
|
682
|
+
}
|
|
683
|
+
const sandbox = await sandboxedToolAvailable();
|
|
684
|
+
const ro = store;
|
|
685
|
+
const squad = squadOf(cfg.agents, (id) => ({ ...gate(cfg, h, id, ro), skillErrors: resolveAgentSkills(cfg, ro, id).errors }), sandbox);
|
|
686
|
+
const home = process.env.HOME ?? homedir();
|
|
687
|
+
const git = (...a) => { try {
|
|
688
|
+
const r = spawnSync(h.git, ['--no-optional-locks', ...a], { cwd: root, encoding: 'utf8', env: { PATH: process.env.PATH ?? '', HOME: home } });
|
|
689
|
+
return r.status === 0 ? r.stdout : undefined;
|
|
690
|
+
}
|
|
691
|
+
catch {
|
|
692
|
+
return undefined;
|
|
693
|
+
} };
|
|
694
|
+
const branch = h.git ? git('branch', '--show-current')?.trim() : undefined;
|
|
695
|
+
const porcelain = h.git ? git('status', '--porcelain') : undefined;
|
|
696
|
+
const today = new Date().toISOString().slice(0, 10);
|
|
697
|
+
const fixed = { version: LAYOUT.version, repo: nz(root === home ? '~' : root.startsWith(home + '/') ? '~' + root.slice(home.length) : root),
|
|
698
|
+
...(branch ? { branch: nz(branch) } : {}), ...(porcelain === undefined ? {} : { clean: porcelain.trim() === '' }),
|
|
699
|
+
acceptedRisks: loadRiskAcceptances(store).filter(r => r.expires >= today).map(r => nz(r.capability)), squad,
|
|
700
|
+
runtimeVersions: Object.fromEntries(Object.entries(h.runtimes).flatMap(([k, v]) => (v?.version ? [[k, nz(v.version)]] : []))), checkedAt: new Date().toISOString() };
|
|
701
|
+
// approving hands the typed hash to `taskquoin approve` (this file) in its own process; runDashboard says, once the
|
|
702
|
+
// terminal is back, which such process still runs and where its output is
|
|
703
|
+
return runDashboard({ tty: nodeTty(process.stdin, process.stdout), signals: process, caps: (size) => capsOf(size), store, fixed, ...(runId !== undefined ? { runId } : {}),
|
|
704
|
+
approve: { node: process.execPath, entry: SELF, cwd: root, env: process.env }, err });
|
|
705
|
+
}
|
|
706
|
+
/** What the home screen shows about this repository, read once at start-up. Nothing here is a verdict: READY comes from the gates. */
|
|
707
|
+
async function homeModel(c, git, squad, bubblewrap) {
|
|
708
|
+
const home = process.env.HOME ?? homedir();
|
|
709
|
+
const repo = c.root === home ? '~' : c.root.startsWith(home + '/') ? '~' + c.root.slice(home.length) : c.root;
|
|
710
|
+
let branch;
|
|
711
|
+
let clean;
|
|
712
|
+
try {
|
|
713
|
+
branch = await git.currentBranch();
|
|
714
|
+
clean = await git.isClean();
|
|
715
|
+
}
|
|
716
|
+
catch { /* a detached or broken tree: shown without */ }
|
|
717
|
+
const today = new Date().toISOString().slice(0, 10);
|
|
718
|
+
const acceptedRisks = loadRiskAcceptances(c.store).filter(r => r.expires >= today).map(r => ({ capability: r.capability, expires: r.expires }));
|
|
719
|
+
const socat = (process.env.PATH ?? '').split(':').some(d => { try {
|
|
720
|
+
accessSync(join(d || '.', 'socat'), constants.X_OK);
|
|
721
|
+
return true;
|
|
722
|
+
}
|
|
723
|
+
catch {
|
|
724
|
+
return false;
|
|
725
|
+
} });
|
|
726
|
+
return { version: LAYOUT.version, repo, ...(branch ? { branch } : {}), ...(clean === undefined ? {} : { clean }),
|
|
727
|
+
sandbox: { bubblewrap, socat, verify: bubblewrap }, policy: { digest: configDigest(c.root).replace(/^sha256:/, ''), acceptedRisks },
|
|
728
|
+
squad, notices: runtimeNotices(c.h, loadMatrix('claude').runtimeVersion) };
|
|
729
|
+
}
|
|
730
|
+
/** Source checkouts only: an npm install has no launcher to link — npm already put `taskquoin` on the PATH. */
|
|
731
|
+
const shortcutEnv = (launcher) => ({ home: process.env.HOME ?? homedir(), launcher: realpathSync(launcher), pathEnv: process.env.PATH ?? '', stateDir: stateBase() });
|
|
732
|
+
async function main() {
|
|
733
|
+
setLanguage(resolveLanguage(process.env, loadPreferences(stateBase())));
|
|
734
|
+
let parsed;
|
|
735
|
+
try {
|
|
736
|
+
parsed = parseArgs({ allowPositionals: true, options: { json: { type: 'boolean' }, 'purge-state': { type: 'boolean' },
|
|
737
|
+
reason: { type: 'string' }, expires: { type: 'string' }, as: { type: 'string' }, help: { type: 'boolean', short: 'h' },
|
|
738
|
+
source: { type: 'string' }, 'accept-findings': { type: 'boolean' }, expect: { type: 'string' }, remove: { type: 'boolean' }, offline: { type: 'boolean' } } });
|
|
739
|
+
}
|
|
740
|
+
catch (e) {
|
|
741
|
+
err(`taskquoin: ${nz(e.message)}\n${help()}`);
|
|
742
|
+
return 2;
|
|
743
|
+
} // i18n-ok: node's parseArgs message (usage errors exit 2, Codex R4)
|
|
744
|
+
const { positionals, values } = parsed;
|
|
745
|
+
if (values.help) {
|
|
746
|
+
out(help());
|
|
747
|
+
return 0;
|
|
748
|
+
}
|
|
749
|
+
// First launch in a terminal: put `taskquoin` on the PATH by itself (owner's request), unless removed or disabled.
|
|
750
|
+
if (LAYOUT.launcher && process.stdin.isTTY && process.stdout.isTTY && !process.env.TASKQUOIN_NO_SETUP && positionals[0] !== 'setup') {
|
|
751
|
+
try {
|
|
752
|
+
const r = installShortcut(shortcutEnv(LAYOUT.launcher), { auto: true });
|
|
753
|
+
if (r.status === 'installed')
|
|
754
|
+
err(`✔ ${r.message}`);
|
|
755
|
+
}
|
|
756
|
+
catch { /* never blocks a command */ }
|
|
757
|
+
}
|
|
758
|
+
// Like `claude` or `codex`: `taskquoin` alone opens the console in a terminal (scripts still get the help).
|
|
759
|
+
if (!positionals.length) {
|
|
760
|
+
if (process.stdin.isTTY && process.stdout.isTTY)
|
|
761
|
+
return cmdConsole(isOffline(values.offline));
|
|
762
|
+
out(help());
|
|
763
|
+
return 0;
|
|
764
|
+
}
|
|
765
|
+
const [cmd, arg, arg2] = positionals;
|
|
766
|
+
switch (cmd) {
|
|
767
|
+
case 'help':
|
|
768
|
+
out(help());
|
|
769
|
+
return 0;
|
|
770
|
+
case 'version':
|
|
771
|
+
out(`taskquoin ${LAYOUT.version}`);
|
|
772
|
+
return 0;
|
|
773
|
+
case 'init': return cmdInit();
|
|
774
|
+
case 'doctor': return cmdDoctor();
|
|
775
|
+
case 'upgrade': return (await cmdUpgradeWith(arg, { h: await host(), offline: isOffline(values.offline), ask: askStdin, surface: 'cli' })).code;
|
|
776
|
+
case 'check': return cmdCheck(arg, !!values.json);
|
|
777
|
+
case 'console': return cmdConsole(isOffline(values.offline));
|
|
778
|
+
case 'connect': return cmdConnect(arg, !!values.remove);
|
|
779
|
+
case 'setup': {
|
|
780
|
+
if (!LAYOUT.launcher) {
|
|
781
|
+
out(t('cli.setup.npm'));
|
|
782
|
+
return 0;
|
|
783
|
+
}
|
|
784
|
+
if (values.remove) {
|
|
785
|
+
const r = removeShortcut(shortcutEnv(LAYOUT.launcher));
|
|
786
|
+
out(r.message);
|
|
787
|
+
return 0;
|
|
788
|
+
}
|
|
789
|
+
const r = installShortcut(shortcutEnv(LAYOUT.launcher), { auto: false });
|
|
790
|
+
(r.status === 'conflict' ? err : out)(r.message);
|
|
791
|
+
return r.status === 'conflict' ? 1 : 0;
|
|
792
|
+
}
|
|
793
|
+
case 'run': {
|
|
794
|
+
const { c, git } = await ctx();
|
|
795
|
+
return cmdRun(c, git, requestFrom(positionals));
|
|
796
|
+
}
|
|
797
|
+
case 'approve': {
|
|
798
|
+
const { c, git } = await ctx();
|
|
799
|
+
return cmdApprove(c, git, arg, arg2, values.expect, values.as);
|
|
800
|
+
}
|
|
801
|
+
case 'resume': {
|
|
802
|
+
const { c, git } = await ctx();
|
|
803
|
+
return cmdResume(c, git, arg);
|
|
804
|
+
}
|
|
805
|
+
case 'dashboard': return cmdDashboard(arg);
|
|
806
|
+
case 'status': {
|
|
807
|
+
const { c } = await ctx();
|
|
808
|
+
return cmdStatus(c, arg, !!values.json);
|
|
809
|
+
}
|
|
810
|
+
case 'show': {
|
|
811
|
+
const { c } = await ctx();
|
|
812
|
+
return cmdShow(c, arg, arg2);
|
|
813
|
+
}
|
|
814
|
+
case 'skills': {
|
|
815
|
+
const h = await host();
|
|
816
|
+
const root = requireRepo(h);
|
|
817
|
+
return cmdSkills(repoStore(root), arg, arg2, { source: values.source, as: values.as, acceptFindings: !!values['accept-findings'] }, out, err);
|
|
818
|
+
}
|
|
819
|
+
case 'accept-risk': return cmdAcceptRisk(arg, arg2, { reason: values.reason, expires: values.expires, as: values.as });
|
|
820
|
+
case 'uninstall': return cmdUninstall(!!values['purge-state']);
|
|
821
|
+
default:
|
|
822
|
+
err(t('cli.usage'));
|
|
823
|
+
return 2;
|
|
824
|
+
}
|
|
825
|
+
}
|
|
826
|
+
/** Exit only once stdout/stderr have drained: process.exit() drops whatever a pipe has not taken yet (pilot 2: `show … | grep` lost the tail). */
|
|
827
|
+
const exitAfterFlush = (code) => { process.exitCode = code; process.stdout.write('', () => process.stderr.write('', () => process.exit(code))); };
|
|
828
|
+
// A whole message from outside (any thrown error): the log profile, like cmdApprove / cmdResume, so a translated
|
|
829
|
+
// message keeps its ZWNJ/ZWJ while controls and bidi are still marked.
|
|
830
|
+
main().then(exitAfterFlush, e => { err(`taskquoin: ${nLog(e.message)}`); exitAfterFlush(1); }); // i18n-ok: the message comes from the thrown error
|