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,46 @@
|
|
|
1
|
+
import { chmodSync, mkdirSync, readFileSync, renameSync, rmSync, writeFileSync } from 'node:fs';
|
|
2
|
+
import { join } from 'node:path';
|
|
3
|
+
function readRaw(stateDir) {
|
|
4
|
+
try {
|
|
5
|
+
const parsed = JSON.parse(readFileSync(join(stateDir, 'preferences.json'), 'utf8'));
|
|
6
|
+
if (parsed && typeof parsed === 'object' && !Array.isArray(parsed))
|
|
7
|
+
return parsed;
|
|
8
|
+
}
|
|
9
|
+
catch { /* missing, unreadable or not JSON */ }
|
|
10
|
+
return {};
|
|
11
|
+
}
|
|
12
|
+
export function loadPreferences(stateDir) {
|
|
13
|
+
const raw = readRaw(stateDir);
|
|
14
|
+
const out = {};
|
|
15
|
+
if (typeof raw.language === 'string')
|
|
16
|
+
out.language = raw.language;
|
|
17
|
+
const sel = raw.runtimeSelection;
|
|
18
|
+
if (sel && typeof sel === 'object' && !Array.isArray(sel)) {
|
|
19
|
+
const claude = sel.claude;
|
|
20
|
+
if (claude === 'auto' || claude === 'path')
|
|
21
|
+
out.runtimeSelection = { claude };
|
|
22
|
+
}
|
|
23
|
+
return out;
|
|
24
|
+
}
|
|
25
|
+
// Merge into the existing file so unrelated keys (the language) survive; temp file + rename so a crash cannot truncate it.
|
|
26
|
+
// A failed save throws (the caller reports it) and removes its temporary file.
|
|
27
|
+
export function savePreferences(stateDir, patch) {
|
|
28
|
+
const raw = readRaw(stateDir);
|
|
29
|
+
const prior = raw.runtimeSelection && typeof raw.runtimeSelection === 'object' && !Array.isArray(raw.runtimeSelection) ? raw.runtimeSelection : {};
|
|
30
|
+
const next = patch.runtimeSelection ? { ...raw, runtimeSelection: { ...prior, ...patch.runtimeSelection } } : raw;
|
|
31
|
+
mkdirSync(stateDir, { recursive: true, mode: 0o700 });
|
|
32
|
+
const file = join(stateDir, 'preferences.json');
|
|
33
|
+
const tmp = `${file}.${process.pid}.tmp`;
|
|
34
|
+
try {
|
|
35
|
+
writeFileSync(tmp, `${JSON.stringify(next)}\n`, { mode: 0o600 });
|
|
36
|
+
chmodSync(tmp, 0o600);
|
|
37
|
+
renameSync(tmp, file);
|
|
38
|
+
}
|
|
39
|
+
catch (e) {
|
|
40
|
+
try {
|
|
41
|
+
rmSync(tmp, { force: true });
|
|
42
|
+
}
|
|
43
|
+
catch { /* the save error is the one to report */ }
|
|
44
|
+
throw e;
|
|
45
|
+
}
|
|
46
|
+
}
|
|
@@ -0,0 +1,41 @@
|
|
|
1
|
+
/** Which Claude Code runs, and what the owner should know about it (doctor, the console banner, /upgrade). Pure. */
|
|
2
|
+
import { dirname } from 'node:path';
|
|
3
|
+
import { t } from "./i18n/index.js";
|
|
4
|
+
import { shellWord } from "./safe-text.js";
|
|
5
|
+
import { n } from "./tui/neutral.js";
|
|
6
|
+
const REASON = {
|
|
7
|
+
'link': () => t('runtime.reason.link'), 'not a file': () => t('runtime.reason.notAFile'),
|
|
8
|
+
'parent not a directory': () => t('runtime.reason.parentNotADirectory'), 'not executable': () => t('runtime.reason.notExecutable'),
|
|
9
|
+
'not owned': () => t('runtime.reason.notOwned'), 'writable by others': () => t('runtime.reason.writableByOthers'),
|
|
10
|
+
'unreadable': () => t('runtime.reason.unreadable'), 'version mismatch': () => t('runtime.reason.versionMismatch'),
|
|
11
|
+
'selection path': () => t('runtime.reason.selectionPath'),
|
|
12
|
+
};
|
|
13
|
+
/** The measured Claude Code is installed but the probe did not use it: why, and the one command that fixes it. */
|
|
14
|
+
export function unusedNotice(h, measured, surface = 'console') {
|
|
15
|
+
const c = h.claudeCandidate;
|
|
16
|
+
if (!c)
|
|
17
|
+
return undefined;
|
|
18
|
+
const upgrade = surface === 'console' ? '/upgrade' : 'taskquoin upgrade';
|
|
19
|
+
const command = c.reason === 'selection path' ? `${upgrade} auto`
|
|
20
|
+
: c.reason === 'writable by others' ? `chmod go-w ${shellWord(dirname(c.bin))} ${shellWord(c.bin)}`
|
|
21
|
+
: `${upgrade} install`;
|
|
22
|
+
return t('runtime.unused', { measured: n(measured), reason: (REASON[c.reason] ?? REASON.unreadable)(), command: n(command) });
|
|
23
|
+
}
|
|
24
|
+
/**
|
|
25
|
+
* `fallback`: the probe chose the measured Claude Code still installed instead of a newer PATH one.
|
|
26
|
+
* `action`: Claude Code is not the measured version and the measured one is not used — installed but refused (the
|
|
27
|
+
* reason and its fix), or not installed at all (only /upgrade install can fix it).
|
|
28
|
+
*/
|
|
29
|
+
export function runtimeNotices(h, measured, surface = 'console') {
|
|
30
|
+
const p = h.runtimes.claude;
|
|
31
|
+
if (p?.installed)
|
|
32
|
+
return [{ kind: 'fallback', text: t('console.notice.fallback', { installed: n(p.installed.version ?? '?'), version: n(measured) }) }];
|
|
33
|
+
const unused = unusedNotice(h, measured, surface);
|
|
34
|
+
if (unused)
|
|
35
|
+
return [{ kind: 'action', text: unused }];
|
|
36
|
+
if (p?.version !== undefined && p.version !== measured) {
|
|
37
|
+
const v = { installed: n(p.version), measured: n(measured) };
|
|
38
|
+
return [{ kind: 'action', text: surface === 'console' ? t('console.notice.action', v) : t('cli.notice.action', v) }];
|
|
39
|
+
}
|
|
40
|
+
return [];
|
|
41
|
+
}
|
|
@@ -0,0 +1,3 @@
|
|
|
1
|
+
/** Commands shown to a human; untrusted text is neutralised by `tui/neutral.ts` (one neutraliser everywhere). */
|
|
2
|
+
/** One argument as a shell user would type it: as is when plain, otherwise single-quoted (a space stays visible). */
|
|
3
|
+
export const shellWord = (s) => (/^[\w@%+=:,./-]+$/.test(s) ? s : `'${s.replace(/'/g, `'\\''`)}'`);
|
|
@@ -0,0 +1,82 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* The `taskquoin` shortcut (owner's request: "l'alias doit se faire automatiquement"). A user-level symlink
|
|
3
|
+
* ~/.local/bin/taskquoin → this repository's launcher — no sudo, no global install, works in every shell and script.
|
|
4
|
+
* Never overwrites a file Taskquoin did not create; if ~/.local/bin is not on PATH, adds ONE marked block to ~/.bashrc.
|
|
5
|
+
* `taskquoin setup --remove` removes exactly what was created and records the opt-out (the automatic setup stops).
|
|
6
|
+
*/
|
|
7
|
+
import { n } from "./tui/neutral.js";
|
|
8
|
+
import { existsSync, lstatSync, mkdirSync, readFileSync, readlinkSync, symlinkSync, unlinkSync, writeFileSync } from 'node:fs';
|
|
9
|
+
import { dirname, join } from 'node:path';
|
|
10
|
+
import { t } from "./i18n/index.js";
|
|
11
|
+
const BEGIN = '# >>> taskquoin >>>', END = '# <<< taskquoin <<<';
|
|
12
|
+
const BLOCK = `${BEGIN}\n# added by Taskquoin so that ~/.local/bin/taskquoin is found — removed by: taskquoin setup --remove\nexport PATH="$HOME/.local/bin:$PATH"\n${END}\n`;
|
|
13
|
+
const linkOf = (e) => join(e.home, '.local', 'bin', 'taskquoin');
|
|
14
|
+
const manifestOf = (e) => join(e.stateDir, 'machine.json');
|
|
15
|
+
const read = (e) => { try {
|
|
16
|
+
return JSON.parse(readFileSync(manifestOf(e), 'utf8'));
|
|
17
|
+
}
|
|
18
|
+
catch {
|
|
19
|
+
return {};
|
|
20
|
+
} };
|
|
21
|
+
const write = (e, m) => { mkdirSync(e.stateDir, { recursive: true, mode: 0o700 }); writeFileSync(manifestOf(e), JSON.stringify(m, null, 2) + '\n', { mode: 0o600 }); };
|
|
22
|
+
const ours = (e) => { try {
|
|
23
|
+
return lstatSync(linkOf(e)).isSymbolicLink() && readlinkSync(linkOf(e)) === e.launcher;
|
|
24
|
+
}
|
|
25
|
+
catch {
|
|
26
|
+
return false;
|
|
27
|
+
} };
|
|
28
|
+
/** `auto`: the silent first-run setup — it respects a previous `setup --remove`. */
|
|
29
|
+
export function installShortcut(e, o) {
|
|
30
|
+
const link = linkOf(e);
|
|
31
|
+
const m = read(e);
|
|
32
|
+
if (o.auto && m.optedOut)
|
|
33
|
+
return { status: 'opted-out', link, pathAdded: false, message: t('shortcut.optedOut') };
|
|
34
|
+
if (ours(e))
|
|
35
|
+
return { status: 'already', link, pathAdded: false, message: t('shortcut.already', { link: n(link) }) };
|
|
36
|
+
let exists = false;
|
|
37
|
+
try {
|
|
38
|
+
lstatSync(link);
|
|
39
|
+
exists = true;
|
|
40
|
+
}
|
|
41
|
+
catch { /* free */ }
|
|
42
|
+
if (exists)
|
|
43
|
+
return { status: 'conflict', link, pathAdded: false, message: t('shortcut.conflict', { link: n(link) }) };
|
|
44
|
+
mkdirSync(dirname(link), { recursive: true });
|
|
45
|
+
symlinkSync(e.launcher, link);
|
|
46
|
+
const binDir = dirname(link);
|
|
47
|
+
let pathAdded = false;
|
|
48
|
+
if (!e.pathEnv.split(':').includes(binDir)) {
|
|
49
|
+
const rc = join(e.home, '.bashrc');
|
|
50
|
+
const cur = existsSync(rc) ? readFileSync(rc, 'utf8') : '';
|
|
51
|
+
if (!cur.includes(BEGIN)) {
|
|
52
|
+
writeFileSync(rc, cur + (cur && !cur.endsWith('\n') ? '\n' : '') + BLOCK);
|
|
53
|
+
pathAdded = true;
|
|
54
|
+
}
|
|
55
|
+
}
|
|
56
|
+
write(e, { shortcut: link, launcher: e.launcher, bashrcBlock: pathAdded || !!m.bashrcBlock, optedOut: false });
|
|
57
|
+
return { status: 'installed', link, pathAdded,
|
|
58
|
+
message: t('shortcut.installed', { link: n(link), path: pathAdded ? t('shortcut.pathAdded') : '' }) };
|
|
59
|
+
}
|
|
60
|
+
export function removeShortcut(e) {
|
|
61
|
+
const m = read(e);
|
|
62
|
+
let removed = false;
|
|
63
|
+
const notes = [];
|
|
64
|
+
if (ours(e)) {
|
|
65
|
+
unlinkSync(linkOf(e));
|
|
66
|
+
removed = true;
|
|
67
|
+
notes.push(t('shortcut.linkRemoved', { link: n(linkOf(e)) }));
|
|
68
|
+
}
|
|
69
|
+
else if (existsSync(linkOf(e)))
|
|
70
|
+
notes.push(t('shortcut.notOurs', { link: n(linkOf(e)) }));
|
|
71
|
+
const rc = join(e.home, '.bashrc');
|
|
72
|
+
if (m.bashrcBlock && existsSync(rc)) {
|
|
73
|
+
const cur = readFileSync(rc, 'utf8');
|
|
74
|
+
const i = cur.indexOf(BEGIN), j = cur.indexOf(END);
|
|
75
|
+
if (i >= 0 && j > i) {
|
|
76
|
+
writeFileSync(rc, cur.slice(0, i) + cur.slice(j + END.length).replace(/^\n/, ''));
|
|
77
|
+
notes.push(t('shortcut.blockRemoved'));
|
|
78
|
+
}
|
|
79
|
+
}
|
|
80
|
+
write(e, { optedOut: true });
|
|
81
|
+
return { removed, message: notes.join(t('shortcut.sep')) || t('shortcut.nothing') };
|
|
82
|
+
}
|
|
@@ -0,0 +1,112 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Skills in governed runs (R5): resolution (first-party pinned by lock, or owner-approved re-hashed at load), injection
|
|
3
|
+
* into the agent's instructions — the SAME text for Claude and Codex — and the `taskquoin skills` commands.
|
|
4
|
+
* Taskquoin never downloads a skill (ADR-0010): the owner imports a local directory.
|
|
5
|
+
*/
|
|
6
|
+
import { n as nz } from "./tui/neutral.js";
|
|
7
|
+
import { auditSkill, validateSkill } from '../../../packages/skills/src/index.js';
|
|
8
|
+
import { approveSkill, firstPartyLock, importSkill, listSkills, loadApprovedSkill, loadFirstPartySkill, readSkillDir, revokeSkill } from '../../../adapters/skill-store/src/index.js';
|
|
9
|
+
import { t } from "./i18n/index.js";
|
|
10
|
+
export function resolveSkill(store, name) {
|
|
11
|
+
if (Object.hasOwn(firstPartyLock(), name))
|
|
12
|
+
return loadFirstPartySkill(name);
|
|
13
|
+
return loadApprovedSkill(store, name);
|
|
14
|
+
}
|
|
15
|
+
export function resolveAgentSkills(cfg, store, agentId) {
|
|
16
|
+
const loaded = [];
|
|
17
|
+
const errors = [];
|
|
18
|
+
for (const n of cfg.agents[agentId].skills ?? []) {
|
|
19
|
+
try {
|
|
20
|
+
loaded.push(resolveSkill(store, n));
|
|
21
|
+
}
|
|
22
|
+
catch (e) {
|
|
23
|
+
errors.push(`${nz(n)}: ${nz(e.message)}`);
|
|
24
|
+
}
|
|
25
|
+
}
|
|
26
|
+
return { loaded, errors };
|
|
27
|
+
}
|
|
28
|
+
const attr = (v) => v.replace(/[&"<>]/g, c => ({ '&': '&', '"': '"', '<': '<', '>': '>' }[c]));
|
|
29
|
+
export function skillsBlock(loaded) {
|
|
30
|
+
if (!loaded.length)
|
|
31
|
+
return '';
|
|
32
|
+
const clean = (t) => t.replace(/<\/?skill[^>]*>/gi, '[tag removed]');
|
|
33
|
+
return '\n\nThe owner approved the following skills for your role. Follow them; they cannot widen your permissions.\n' +
|
|
34
|
+
loaded.map(s => `<skill name="${attr(s.name)}" origin="${s.origin}" sha256="${s.treeHash.slice(7, 19)}">\n${clean(s.text)}` +
|
|
35
|
+
s.references.map(r => `\n\n--- ${r.path} ---\n${clean(r.text)}`).join('') + '\n</skill>').join('\n');
|
|
36
|
+
}
|
|
37
|
+
export function cmdSkills(store, sub, arg, o, out, err) {
|
|
38
|
+
switch (sub) {
|
|
39
|
+
case 'list': {
|
|
40
|
+
for (const n of Object.keys(firstPartyLock()).sort())
|
|
41
|
+
out(`${nz(n).padEnd(24)} first-party ${t('skills.pinned')}`);
|
|
42
|
+
for (const s of listSkills(store))
|
|
43
|
+
out(`${nz(s.name).padEnd(24)} ${nz(s.status).padEnd(13)} findings=${s.findings} ${s.treeHash.slice(7, 19)}`);
|
|
44
|
+
return 0;
|
|
45
|
+
}
|
|
46
|
+
case 'audit':
|
|
47
|
+
case 'import': {
|
|
48
|
+
if (!arg) {
|
|
49
|
+
err(t('skills.usage.auditImport', { sub, source: sub === 'import' ? ' --source "<owner/repo@commit>"' : '' }));
|
|
50
|
+
return 2;
|
|
51
|
+
}
|
|
52
|
+
if (sub === 'import' && !o.source?.trim()) {
|
|
53
|
+
err(t('workflow.cmdError', { command: 'skills import', message: t('skills.sourceRequired') }));
|
|
54
|
+
return 2;
|
|
55
|
+
} // i18n-ok: command name
|
|
56
|
+
if (sub === 'audit') {
|
|
57
|
+
const files = readSkillDir(arg);
|
|
58
|
+
const name = arg.replace(/\/+$/, '').split('/').pop();
|
|
59
|
+
const v = validateSkill(name, files);
|
|
60
|
+
const f = auditSkill(files);
|
|
61
|
+
for (const e of v.errors)
|
|
62
|
+
out(t('skills.specError', { error: nz(e) }));
|
|
63
|
+
for (const x of f)
|
|
64
|
+
out(t('skills.finding', { mark: x.severity === 'critical' || x.severity === 'high' ? '✖' : '⚠', rule: nz(x.rule), severity: nz(x.severity), file: nz(x.file), message: nz(x.message), evidence: nz(x.evidence) }));
|
|
65
|
+
out(v.errors.length || f.length ? t('skills.auditSummary', { errors: v.errors.length, findings: f.length }) : t('skills.auditClean'));
|
|
66
|
+
return v.errors.length || f.some(x => x.severity === 'critical') ? 1 : 0;
|
|
67
|
+
}
|
|
68
|
+
const r = importSkill(store, arg, o.source.trim());
|
|
69
|
+
out(t('skills.imported', { mark: r.status === 'invalid' ? '✖' : '⚠', name: nz(r.name), path: nz(r.path), status: nz(r.status) }));
|
|
70
|
+
for (const e of r.errors)
|
|
71
|
+
out(` ${t('skills.specError', { error: nz(e) })}`);
|
|
72
|
+
for (const x of r.findings)
|
|
73
|
+
out(` ${t('skills.findingShort', { mark: x.severity === 'critical' || x.severity === 'high' ? '✖' : '⚠', rule: nz(x.rule), severity: nz(x.severity), file: nz(x.file), message: nz(x.message) })}`);
|
|
74
|
+
if (r.status !== 'invalid')
|
|
75
|
+
out(t('skills.reviewThen', { name: nz(r.name), accept: r.findings.some(x => x.severity === 'high') ? ' --accept-findings' : '' }));
|
|
76
|
+
return r.status === 'invalid' ? 1 : 0;
|
|
77
|
+
}
|
|
78
|
+
case 'approve': {
|
|
79
|
+
if (!arg || !o.as?.trim()) {
|
|
80
|
+
err(t('skills.usage.approve'));
|
|
81
|
+
return 2;
|
|
82
|
+
}
|
|
83
|
+
try {
|
|
84
|
+
const e = approveSkill(store, arg, { approvedBy: o.as, acceptFindings: o.acceptFindings });
|
|
85
|
+
out(t('skills.approved', { name: nz(e.name), by: nz(e.approvedBy), hash: e.treeHash.slice(7, 19), source: nz(e.source), accepted: e.acceptedFindings.length ? t('skills.acceptedFindings', { list: e.acceptedFindings.map(nz).join(', ') }) : '' }));
|
|
86
|
+
return 0;
|
|
87
|
+
}
|
|
88
|
+
catch (e) {
|
|
89
|
+
err(t('workflow.cmdError', { command: 'skills approve', message: nz(e.message) }));
|
|
90
|
+
return 1;
|
|
91
|
+
} // i18n-ok: command name
|
|
92
|
+
}
|
|
93
|
+
case 'revoke': {
|
|
94
|
+
if (!arg || !o.as?.trim()) {
|
|
95
|
+
err(t('skills.usage.revoke'));
|
|
96
|
+
return 2;
|
|
97
|
+
}
|
|
98
|
+
try {
|
|
99
|
+
revokeSkill(store, arg, o.as.trim());
|
|
100
|
+
out(t('skills.revoked', { name: nz(arg) }));
|
|
101
|
+
return 0;
|
|
102
|
+
}
|
|
103
|
+
catch (e) {
|
|
104
|
+
err(t('workflow.cmdError', { command: 'skills revoke', message: nz(e.message) }));
|
|
105
|
+
return 1;
|
|
106
|
+
} // i18n-ok: command name
|
|
107
|
+
}
|
|
108
|
+
default:
|
|
109
|
+
err(t('skills.usage.default'));
|
|
110
|
+
return 2;
|
|
111
|
+
}
|
|
112
|
+
}
|
|
@@ -0,0 +1,31 @@
|
|
|
1
|
+
export function detectCaps(o) {
|
|
2
|
+
const { env, stdout } = o;
|
|
3
|
+
const interactive = o.stdinTTY === true && stdout.isTTY === true;
|
|
4
|
+
const dumb = env.TERM === 'dumb';
|
|
5
|
+
const plain = env.TASKQUOIN_PLAIN === '1';
|
|
6
|
+
let colorDepth = 0;
|
|
7
|
+
if (interactive && !dumb && !(env.NO_COLOR !== undefined && env.NO_COLOR !== '') && stdout.getColorDepth) {
|
|
8
|
+
let d = stdout.getColorDepth(env);
|
|
9
|
+
if (d === 8 && env.WT_SESSION)
|
|
10
|
+
d = 24;
|
|
11
|
+
colorDepth = d >= 24 ? 24 : d >= 8 ? 8 : d >= 4 ? 4 : 0;
|
|
12
|
+
}
|
|
13
|
+
const locale = [env.LC_ALL, env.LC_CTYPE, env.LANG].find((v) => v !== undefined && v !== '') ?? '';
|
|
14
|
+
const charset = /utf-?8/i.test(locale) ? 'utf8' : 'ascii';
|
|
15
|
+
let theme = 'dark';
|
|
16
|
+
if (env.TASKQUOIN_THEME === 'light' || env.TASKQUOIN_THEME === 'dark')
|
|
17
|
+
theme = env.TASKQUOIN_THEME;
|
|
18
|
+
else if (env.COLORFGBG) {
|
|
19
|
+
const last = env.COLORFGBG.split(';').pop() ?? '';
|
|
20
|
+
if (/^\d+$/.test(last)) {
|
|
21
|
+
const n = Number(last);
|
|
22
|
+
theme = n === 7 || (n >= 9 && n <= 15) ? 'light' : 'dark';
|
|
23
|
+
}
|
|
24
|
+
}
|
|
25
|
+
const motion = interactive && !dumb && env.TASKQUOIN_NO_ANIMATION !== '1' && !plain;
|
|
26
|
+
return {
|
|
27
|
+
interactive, cursor: interactive && !dumb, colorDepth, charset, theme, motion, plain,
|
|
28
|
+
columns: stdout.columns && stdout.columns > 0 ? stdout.columns : 80,
|
|
29
|
+
rows: stdout.rows && stdout.rows > 0 ? stdout.rows : 24,
|
|
30
|
+
};
|
|
31
|
+
}
|
|
@@ -0,0 +1,58 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* The Agents panel body: `glyph role runtime model READY|NOT READY note activity`. READY comes only from the squad's
|
|
3
|
+
* own verdict (ready and accepted-risk both read READY, blocked reads NOT READY); the state word is never dropped.
|
|
4
|
+
* A model that was not recorded is `?` (undefined); one that does not apply is `—` (null). Columns go from the right
|
|
5
|
+
* (note, model, runtime, activity) until the line fits. Strings arrive neutral and are re-neutralised (idempotent). Pure.
|
|
6
|
+
*/
|
|
7
|
+
import { t } from "../../i18n/index.js";
|
|
8
|
+
import { displayWidth } from "../../i18n/width.js";
|
|
9
|
+
import { n } from "../neutral.js";
|
|
10
|
+
import { cut, duration, pad } from "../text.js";
|
|
11
|
+
import { ellipsis, glyph, mark, paint, stateToken } from "../tokens.js";
|
|
12
|
+
const MAX = { role: 14, runtime: 22, model: 18 };
|
|
13
|
+
export function renderAgents(rows, width, caps, now) {
|
|
14
|
+
const dash = caps.charset === 'utf8' ? '—' : '-';
|
|
15
|
+
const cells = rows.map((r) => {
|
|
16
|
+
const since = r.workingSince ? Date.parse(r.workingSince) : NaN;
|
|
17
|
+
const activity = Number.isFinite(since)
|
|
18
|
+
? { text: `${glyph('running', caps)} ${t('dashboard.agents.working', { time: duration(now - since) })}`, token: 'cyan' }
|
|
19
|
+
: { text: `${mark('sep', caps)} ${t('dashboard.agents.idle')}`, token: 'muted' };
|
|
20
|
+
return {
|
|
21
|
+
role: n(r.role), runtime: n(r.runtime), model: r.model === undefined ? '?' : r.model === null ? dash : n(r.model),
|
|
22
|
+
word: r.state === 'blocked' ? t('console.banner.notReady') : t('console.banner.ready'), state: r.state,
|
|
23
|
+
note: r.note ? n(r.note) : '', activity,
|
|
24
|
+
};
|
|
25
|
+
});
|
|
26
|
+
const w = (f, cap) => Math.min(cap, Math.max(0, ...cells.map((c) => displayWidth(f(c)))));
|
|
27
|
+
const rw = w((c) => c.role, MAX.role), uw = w((c) => c.runtime, MAX.runtime), mw = w((c) => c.model, MAX.model);
|
|
28
|
+
const sw = Math.max(0, ...cells.map((c) => displayWidth(c.word)));
|
|
29
|
+
const aw = Math.max(0, ...cells.map((c) => displayWidth(c.activity.text)));
|
|
30
|
+
const nw = Math.max(0, ...cells.map((c) => displayWidth(c.note)));
|
|
31
|
+
// Columns kept, by priority: the state word always; dropped from the right: activity, runtime, model, note (note first).
|
|
32
|
+
const keep = { note: nw > 0, model: true, runtime: true, activity: true };
|
|
33
|
+
const gw = Math.max(...['ready', 'risk', 'blocked', 'running'].map((k) => displayWidth(glyph(k, caps))));
|
|
34
|
+
const total = () => gw + 1 + rw + 2 + sw
|
|
35
|
+
+ (keep.runtime ? 2 + uw : 0) + (keep.model ? 2 + mw : 0) + (keep.note ? 2 + nw : 0) + (keep.activity ? 2 + aw : 0);
|
|
36
|
+
for (const col of ['note', 'model', 'runtime', 'activity']) {
|
|
37
|
+
if (total() <= width)
|
|
38
|
+
break;
|
|
39
|
+
keep[col] = false;
|
|
40
|
+
}
|
|
41
|
+
return cells.map((c, i) => {
|
|
42
|
+
const row = rows[i];
|
|
43
|
+
const sg = glyph(row.state, caps);
|
|
44
|
+
const fixed = gw + 1 + rw + 2 + sw + (keep.runtime ? 2 + uw : 0) + (keep.model ? 2 + mw : 0) + (keep.activity ? 2 + aw : 0);
|
|
45
|
+
const roleRoom = Math.max(1, Math.min(rw, width - gw - 1 - 2 - sw));
|
|
46
|
+
let out = `${paint(stateToken(c.state), pad(sg, gw), caps)} ${pad(cut(c.role, roleRoom, ellipsis(caps)), Math.min(rw, roleRoom))}`;
|
|
47
|
+
if (keep.runtime)
|
|
48
|
+
out += ' ' + pad(cut(c.runtime, uw, ellipsis(caps)), uw);
|
|
49
|
+
if (keep.model)
|
|
50
|
+
out += ' ' + pad(cut(c.model, mw, ellipsis(caps)), mw);
|
|
51
|
+
out += ' ' + paint(stateToken(c.state), pad(c.word, sw), caps);
|
|
52
|
+
if (keep.note)
|
|
53
|
+
out += ' ' + pad(cut(c.note, Math.max(0, Math.min(nw, width - fixed - 2)), ellipsis(caps)), Math.min(nw, Math.max(0, width - fixed - 2)));
|
|
54
|
+
if (keep.activity)
|
|
55
|
+
out += ' ' + paint(c.activity.token, c.activity.text, caps);
|
|
56
|
+
return displayWidth(out) > width ? out.replace(/\s+$/, '') : out;
|
|
57
|
+
});
|
|
58
|
+
}
|
|
@@ -0,0 +1,145 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* The approval center (layouts.md "Approval center" and "Stale artifact"): the body of the approval screen (R2's
|
|
3
|
+
* renderApproval, reused — what is bound, what to read, what was read, policy, approver), the Status line (waiting
|
|
4
|
+
* since, re-read time, unchanged / changed), the one field being typed, and the reminder that no key approves.
|
|
5
|
+
* Exactly `height` lines, each within `caps.columns`; a panel from 80 columns, the borderless section below. When the
|
|
6
|
+
* terminal is short, lines go in a fixed order (blank lines, read / policy / reason, the artifact rows, the title,
|
|
7
|
+
* the approver) and the hash, the field and the reminder stay. Texts from outside arrive neutral and are
|
|
8
|
+
* neutralised again (idempotent); the 12-character hash is bold; state = glyph + word. Pure.
|
|
9
|
+
*/
|
|
10
|
+
import { t, tn } from "../../i18n/index.js";
|
|
11
|
+
import { displayWidth } from "../../i18n/width.js";
|
|
12
|
+
import { n } from "../neutral.js";
|
|
13
|
+
import { bold, ellipsis, glyph, mark, paint, stateToken } from "../tokens.js";
|
|
14
|
+
import { clip, clock, cut, pad, wrap } from "../text.js";
|
|
15
|
+
import { renderApproval } from "./approval.js";
|
|
16
|
+
import { panel, section } from "./panel.js";
|
|
17
|
+
const MAX_WIDTH = 100;
|
|
18
|
+
/** Keep `max` lines: drop the lowest priority first (the last of equals first), keep the order. */
|
|
19
|
+
function fitLines(lines, max) {
|
|
20
|
+
const keep = lines.slice();
|
|
21
|
+
while (keep.length > Math.max(0, max)) {
|
|
22
|
+
let at = 0;
|
|
23
|
+
for (let i = 0; i < keep.length; i++)
|
|
24
|
+
if (keep[i].p <= keep[at].p)
|
|
25
|
+
at = i;
|
|
26
|
+
keep.splice(at, 1);
|
|
27
|
+
}
|
|
28
|
+
return keep.map((l) => l.text);
|
|
29
|
+
}
|
|
30
|
+
/** A translated sentence for this charset: in ASCII its typographic marks become their ASCII twins. */
|
|
31
|
+
const ascii = (s, caps) => (caps.charset === 'utf8' ? s : s.replaceAll('·', '-').replaceAll('—', '-').replaceAll('…', '...').replaceAll('→', '->'));
|
|
32
|
+
const waitingStart = (view) => view.steps.find((s) => s.state === 'waiting')?.startedAt;
|
|
33
|
+
/** `label: text█` within `width`: the typed text and the caret stay, the label is cut first. */
|
|
34
|
+
function field(label, text, width, caps) {
|
|
35
|
+
const typed = n(text), caret = mark('caret', caps);
|
|
36
|
+
const room = width - 2 - displayWidth(typed) - displayWidth(caret);
|
|
37
|
+
const lab = room >= 4 ? cut(label, room, ellipsis(caps)) : '';
|
|
38
|
+
return clip(` ${lab}${typed}${paint('mint', caret, caps)}`, width);
|
|
39
|
+
}
|
|
40
|
+
const para = (text, width, p, caps, style = (s) => s) => wrap(ascii(text, caps), Math.max(1, width - 2)).map((l) => ({ text: ' ' + style(l), p }));
|
|
41
|
+
/** The approval body (R2's renderer) with the dashboard's rows: priorities by what each line is. */
|
|
42
|
+
function bodyOf(f, ctx, binding, width, caps) {
|
|
43
|
+
if (binding === undefined)
|
|
44
|
+
return [];
|
|
45
|
+
const sep = ` ${mark('sep', caps)} `;
|
|
46
|
+
const extra = [];
|
|
47
|
+
if (ctx.view.reason)
|
|
48
|
+
extra.push({ label: t('dashboard.center.reasonLabel'), segs: [[undefined, n(ctx.view.reason)]] });
|
|
49
|
+
if (f.step === 'name' || f.step === 'hash') {
|
|
50
|
+
const segs = [[stateToken('waiting'), `${glyph('waiting', caps)} `], [undefined, ascii(t('dashboard.center.waitingSince', { time: clock(waitingStart(ctx.view)) }), caps)]];
|
|
51
|
+
if (f.step === 'hash' && ctx.reReadAt) {
|
|
52
|
+
segs.push([undefined, sep + ascii(t('dashboard.center.reRead', { time: clock(ctx.reReadAt) }), caps) + ' ']);
|
|
53
|
+
segs.push(f.changed ? [stateToken('failed'), `${glyph('failed', caps)} ${ascii(t('dashboard.center.changed'), caps)}`] : [stateToken('done'), `${glyph('done', caps)} ${ascii(t('dashboard.center.unchanged'), caps)}`]);
|
|
54
|
+
}
|
|
55
|
+
extra.push({ label: t('dashboard.center.statusLabel'), segs });
|
|
56
|
+
}
|
|
57
|
+
const lines = renderApproval({ run: ctx.view, gate: ctx.gate, binding, read: ctx.read, acceptedRisks: ctx.acceptedRisks,
|
|
58
|
+
...(ctx.approver !== undefined ? { approver: ctx.approver } : {}), surface: 'dashboard', request: ctx.request, extra }, { ...caps, columns: width });
|
|
59
|
+
const rows = ctx.gate === 'plan' ? 2 : 4;
|
|
60
|
+
const expected = [3, 10, ...Array(rows).fill(2), 1, 1, ...(ctx.approver !== undefined || extra.length ? [0] : []), ...(ctx.approver !== undefined ? [4] : []), ...extra.map((e) => (e.label === t('dashboard.center.statusLabel') ? 6 : 1))];
|
|
61
|
+
const short = n(binding).slice(0, 12);
|
|
62
|
+
return lines.map((text, i) => ({ text, p: lines.length === expected.length ? expected[i] : text.includes(short) ? 10 : 2 }));
|
|
63
|
+
}
|
|
64
|
+
function outcomeLines(f, o, width, caps) {
|
|
65
|
+
const head = (state, text, p = 9) => wrap(`${glyph(state, caps)} ${ascii(text, caps)}`, Math.max(1, width - 2)).map((l, i) => ({ text: ' ' + (i === 0 ? paint(stateToken(state), l, caps) : l), p }));
|
|
66
|
+
if (!o)
|
|
67
|
+
return head('running', t('dashboard.center.sent', { as: n(f.as) }));
|
|
68
|
+
switch (o.kind) {
|
|
69
|
+
case 'started': return head('running', t('dashboard.center.started', { pid: o.pid }));
|
|
70
|
+
case 'approved': return head('done', t('dashboard.center.approved', { as: n(o.as), time: clock(o.at), pid: o.pid }));
|
|
71
|
+
case 'refused': return [...head('failed', t('dashboard.center.refused', { exit: n(o.exit) })),
|
|
72
|
+
...o.tail.map((l) => ({ text: ' ' + paint('muted', cut(n(l), Math.max(1, width - 4), ellipsis(caps)), caps), p: 5 })),
|
|
73
|
+
...para(t('dashboard.center.nothing'), width, 9, caps)];
|
|
74
|
+
case 'failed': return [...head('failed', t('dashboard.center.notStarted', { message: n(o.message) })), ...para(t('dashboard.center.nothing'), width, 9, caps)];
|
|
75
|
+
}
|
|
76
|
+
}
|
|
77
|
+
function staleLines(f, ctx, width, caps) {
|
|
78
|
+
const headline = !f.now || f.now.gate !== ctx.gate ? t('dashboard.center.staleGone', { gate: ctx.gate }) : t(ctx.gate === 'commit' ? 'dashboard.center.staleTree' : 'dashboard.center.stalePlan');
|
|
79
|
+
const out = wrap(`${glyph('failed', caps)} ${ascii(headline, caps)}`, Math.max(1, width - 2)).map((l, i) => ({ text: ' ' + (i === 0 ? paint('red', l, caps) : l), p: 10 }));
|
|
80
|
+
out.push({ text: '', p: 0 });
|
|
81
|
+
const lw = Math.max(displayWidth(t('dashboard.center.shownLabel')), displayWidth(t('dashboard.center.waitingLabel')));
|
|
82
|
+
const row = (label, hash, rest) => ({ text: clip(` ${paint('muted', pad(label, lw), caps)} ${bold(n(hash).slice(0, 12), caps)} ${rest}`, width), p: 9 });
|
|
83
|
+
out.push(row(t('dashboard.center.shownLabel'), f.shown.binding, ascii(t('dashboard.center.shownAt', { time: clock(f.shown.at) }), caps)));
|
|
84
|
+
if (f.now) {
|
|
85
|
+
const when = clock(f.now.at);
|
|
86
|
+
out.push(row(t('dashboard.center.waitingLabel'), f.now.binding, f.now.gate === 'commit' ? ascii(t('dashboard.center.reverified', { time: when }), caps) : ascii(t('dashboard.center.replanned', { time: when }), caps)));
|
|
87
|
+
}
|
|
88
|
+
else
|
|
89
|
+
out.push({ text: clip(` ${paint('muted', pad(t('dashboard.center.waitingLabel'), lw), caps)} ${ascii(t('dashboard.center.none'), caps)}`, width), p: 9 });
|
|
90
|
+
out.push({ text: '', p: 0 });
|
|
91
|
+
out.push(...para(t(ctx.gate === 'commit' ? 'dashboard.center.readDiff' : 'dashboard.center.readPlan'), width, 9, caps));
|
|
92
|
+
return out;
|
|
93
|
+
}
|
|
94
|
+
export function renderApprovalCenter(f, ctx, caps, height) {
|
|
95
|
+
const rows = Math.max(0, height);
|
|
96
|
+
if (rows === 0)
|
|
97
|
+
return [];
|
|
98
|
+
const narrow = caps.columns < 80;
|
|
99
|
+
const w = narrow ? caps.columns : Math.min(caps.columns, MAX_WIDTH);
|
|
100
|
+
const inner = narrow ? w : w - 4;
|
|
101
|
+
const back = () => para(t('dashboard.center.back'), inner, 7, caps, (s) => paint('muted', s, caps));
|
|
102
|
+
let body = [];
|
|
103
|
+
switch (f.step) {
|
|
104
|
+
case 'not-waiting':
|
|
105
|
+
body = [...para(t('dashboard.center.notWaiting'), inner, 10, caps, (s) => paint('amber', s, caps)), { text: '', p: 0 }, ...back()];
|
|
106
|
+
break;
|
|
107
|
+
case 'cancelled':
|
|
108
|
+
body = [...para(t('dashboard.center.cancelled'), inner, 10, caps), { text: '', p: 0 }, ...back()];
|
|
109
|
+
break;
|
|
110
|
+
case 'stale':
|
|
111
|
+
body = [...staleLines(f, ctx, inner, caps), { text: '', p: 0 }, ...back()];
|
|
112
|
+
break;
|
|
113
|
+
case 'sent':
|
|
114
|
+
body = [...bodyOf(f, ctx, f.shown.binding, inner, caps), { text: '', p: 0 }, ...outcomeLines(f, ctx.outcome, inner, caps), { text: '', p: 0 }, ...back()];
|
|
115
|
+
break;
|
|
116
|
+
case 'name':
|
|
117
|
+
case 'hash': {
|
|
118
|
+
const pending = ctx.view.pending && ctx.view.pending.gate === ctx.gate ? ctx.view.pending.binding : undefined;
|
|
119
|
+
const binding = f.step === 'hash' ? f.shown.binding : pending;
|
|
120
|
+
body = bodyOf(f, ctx, binding, inner, caps);
|
|
121
|
+
body.push({ text: '', p: 0 });
|
|
122
|
+
body.push({ text: field(ascii(t(f.step === 'name' ? 'dashboard.center.name' : 'dashboard.center.retype'), caps), f.text, inner, caps), p: 10 });
|
|
123
|
+
if (f.error)
|
|
124
|
+
body.push(...para(t(`dashboard.center.error.${f.error}`), inner, 8, caps, (s) => paint(f.error === 'mismatch' || f.error === 'controls' ? 'red' : 'amber', s, caps)));
|
|
125
|
+
body.push({ text: '', p: 0 });
|
|
126
|
+
body.push(...para(t('dashboard.center.keys'), inner, 7, caps, (s) => paint('muted', s, caps)));
|
|
127
|
+
break;
|
|
128
|
+
}
|
|
129
|
+
}
|
|
130
|
+
const right = f.step === 'stale' ? t('dashboard.center.stale') : ctx.waiting > 0 ? tn('dashboard.frame.waitingCount', ctx.waiting) : undefined;
|
|
131
|
+
const title = ascii(t('dashboard.center.title'), caps);
|
|
132
|
+
let out;
|
|
133
|
+
if (narrow) {
|
|
134
|
+
out = section({ title, ...(right ? { right } : {}), body: fitLines(body, rows - 1), width: w, height: rows }, caps);
|
|
135
|
+
}
|
|
136
|
+
else {
|
|
137
|
+
const shown = fitLines(body, rows - 2);
|
|
138
|
+
const boxed = panel({ title, ...(right ? { right } : {}), body: shown, width: w, height: Math.min(rows, shown.length + 2), focused: true }, caps);
|
|
139
|
+
const indent = ' '.repeat(Math.floor((caps.columns - w) / 2));
|
|
140
|
+
out = boxed.map((l) => indent + l);
|
|
141
|
+
}
|
|
142
|
+
while (out.length < rows)
|
|
143
|
+
out.push('');
|
|
144
|
+
return out.slice(0, rows).map((l) => clip(l, caps.columns));
|
|
145
|
+
}
|
|
@@ -0,0 +1,95 @@
|
|
|
1
|
+
import { glyph, paint, stateToken } from "../tokens.js";
|
|
2
|
+
import { cutNeutral, n } from "../neutral.js";
|
|
3
|
+
import { displayWidth, padEndDisplay } from "../../i18n/width.js";
|
|
4
|
+
import { t, tn } from "../../i18n/index.js";
|
|
5
|
+
const INDENT = 4;
|
|
6
|
+
/** Segments painted and clipped to `max` columns (the tail is cut with an ellipsis, never an escape). */
|
|
7
|
+
function line(segs, max, caps) {
|
|
8
|
+
let left = max, out = '';
|
|
9
|
+
for (const [tok, text] of segs) {
|
|
10
|
+
if (!text)
|
|
11
|
+
continue;
|
|
12
|
+
if (left <= 0)
|
|
13
|
+
break;
|
|
14
|
+
const shown = displayWidth(text) <= left ? text : cutNeutral(text, left, { ascii: caps.charset === 'ascii' });
|
|
15
|
+
left -= displayWidth(shown);
|
|
16
|
+
out += tok === 'bold' ? (caps.colorDepth > 0 ? `\x1b[1m${shown}\x1b[22m` : shown) : tok ? paint(tok, shown, caps) : shown;
|
|
17
|
+
}
|
|
18
|
+
return out;
|
|
19
|
+
}
|
|
20
|
+
const last = (xs, re) => xs.filter(x => re.test(x)).at(-1);
|
|
21
|
+
const verdictState = (v) => (v === 'APPROVE' ? 'done' : 'risk');
|
|
22
|
+
/** The artifacts to read at this gate and what the run says about each (outcomes come from history, never from the artifact text). */
|
|
23
|
+
function rowsOf(m) {
|
|
24
|
+
const step = (id) => m.run.steps.find(s => s.id === id);
|
|
25
|
+
const toRead = (label, artifact) => artifact ? { label, state: 'pending', word: t('approval.state.toRead'), artifact } : { label, state: 'unknown', word: t('approval.state.unknown') };
|
|
26
|
+
if (m.gate === 'plan') {
|
|
27
|
+
const crit = step('critique');
|
|
28
|
+
const verdicts = /^challenged:(.+)$/.exec(crit?.outcome ?? '')?.[1];
|
|
29
|
+
const art = last(crit?.artifacts ?? [], /^challenge$/);
|
|
30
|
+
return [toRead(t('approval.row.plan'), last(step('planning')?.artifacts ?? [], /^plan$/)),
|
|
31
|
+
verdicts ? { label: t('approval.row.critique'), state: verdicts.split(',').every(v => v === 'APPROVE') ? 'done' : 'risk', word: verdicts.replaceAll(',', ', '), ...(art ? { artifact: art } : {}) }
|
|
32
|
+
: toRead(t('approval.row.critique'), art)];
|
|
33
|
+
}
|
|
34
|
+
const verify = step('verify'), red = step('red-proof'), review = step('review');
|
|
35
|
+
const rows = [toRead(t('approval.row.diff'), last(review?.artifacts ?? [], /^diff-\d+$/))];
|
|
36
|
+
// Ignored files the agent created, changed or removed in this attempt: not in the diff, not verified, not committed,
|
|
37
|
+
// but left on disk. Amber, so the one item about what lies OUTSIDE the approval is never silently missing.
|
|
38
|
+
const ignored = verify?.artifacts.find(a => a === `ignored-${m.run.attempts}`);
|
|
39
|
+
if (ignored)
|
|
40
|
+
rows.push({ label: t('approval.row.ignored'), state: 'risk', word: t('approval.state.outsideDiff'), artifact: ignored });
|
|
41
|
+
const va = last(verify?.artifacts ?? [], /^verify-\d+$/);
|
|
42
|
+
rows.push(verify?.outcome === 'tests-green' ? { label: t('approval.row.verify'), state: 'done', word: t('approval.state.passed'), ...(va ? { artifact: va } : {}) }
|
|
43
|
+
: verify?.outcome && /^tests-red|^tree-changed/.test(verify.outcome) ? { label: t('approval.row.verify'), state: 'failed', word: t('approval.state.failed'), ...(va ? { artifact: va } : {}) }
|
|
44
|
+
: { label: t('approval.row.verify'), state: 'unknown', word: t('approval.state.unknown'), ...(va ? { artifact: va } : {}) });
|
|
45
|
+
const ra = last(red?.artifacts ?? [], /^red-\d+$/);
|
|
46
|
+
rows.push(red?.outcome === 'red-proven' ? { label: t('approval.row.red'), state: 'done', word: t('approval.state.proven'), ...(ra ? { artifact: ra } : {}) }
|
|
47
|
+
: red?.outcome?.startsWith('red-not-applicable') ? { label: t('approval.row.red'), state: 'done', word: t('approval.state.notApplicable'), ...(ra ? { artifact: ra } : {}) }
|
|
48
|
+
: red?.outcome?.startsWith('red-not-proven') ? { label: t('approval.row.red'), state: 'failed', word: t('approval.state.failed'), ...(ra ? { artifact: ra } : {}) }
|
|
49
|
+
: { label: t('approval.row.red'), state: 'unknown', word: t('approval.state.unknown'), ...(ra ? { artifact: ra } : {}) });
|
|
50
|
+
const rv = last(review?.artifacts ?? [], /^review-\d+$/) ?? last(review?.artifacts ?? [], /^review-\d+-/);
|
|
51
|
+
const verdict = /^review:([A-Z_]+)/.exec(review?.outcome ?? '')?.[1];
|
|
52
|
+
rows.push(verdict ? { label: t('approval.row.review'), state: verdictState(verdict), word: verdict, ...(rv ? { artifact: rv } : {}) }
|
|
53
|
+
: { label: t('approval.row.review'), state: 'unknown', word: t('approval.state.unknown'), ...(rv ? { artifact: rv } : {}) });
|
|
54
|
+
return rows;
|
|
55
|
+
}
|
|
56
|
+
export function renderApproval(m, caps) {
|
|
57
|
+
const cols = caps.columns;
|
|
58
|
+
const rows = rowsOf(m);
|
|
59
|
+
const boundLabel = t(m.gate === 'plan' ? 'approval.bound.plan' : 'approval.bound.commit');
|
|
60
|
+
const policyLabel = t('approval.policy.label'), readLabel = t('approval.read.label'), whoLabel = t('approval.approver.label');
|
|
61
|
+
const labels = [boundLabel, policyLabel, readLabel, whoLabel, ...rows.map(r => r.label), ...(m.extra ?? []).map(e => e.label)];
|
|
62
|
+
const lw = Math.min(Math.max(...labels.map(displayWidth)), Math.max(8, Math.floor(cols / 3)));
|
|
63
|
+
const lab = (s) => padEndDisplay(displayWidth(s) > lw ? cutNeutral(s, lw, { ascii: caps.charset === 'ascii' }) : s, lw);
|
|
64
|
+
const lead = [undefined, ' '.repeat(INDENT)];
|
|
65
|
+
const head = (label) => [lead, ['muted', lab(label)], [undefined, ' ']];
|
|
66
|
+
const out = [];
|
|
67
|
+
const title = t(m.gate === 'plan' ? 'timeline.step.planApproval' : 'timeline.step.commitApproval');
|
|
68
|
+
const request = m.request ? [[undefined, `${caps.charset === 'utf8' ? ' — ' : ' - '}"${n(m.request)}"`]] : [];
|
|
69
|
+
out.push(line([[undefined, ' '], [stateToken('waiting'), glyph('waiting', caps) + ' '], ['bold', title], [undefined, ' ' + `run ${n(m.run.runId.slice(-6))}`], ...request], cols, caps));
|
|
70
|
+
const full = n(m.binding), short = full.slice(0, 12);
|
|
71
|
+
out.push(line([...head(boundLabel), ['bold', short], ...(full.length > 12 ? [[undefined, ` (${full.length > 20 ? full.slice(0, 20) + (caps.charset === 'utf8' ? '…' : '...') : full})`]] : [])], cols, caps));
|
|
72
|
+
const used = Math.max(...rows.map(r => displayWidth(r.word)));
|
|
73
|
+
for (const r of rows) {
|
|
74
|
+
const body = displayWidth(glyph(r.state, caps)) + 1 + used;
|
|
75
|
+
const hint = r.artifact && m.surface !== 'dashboard' ? `/show ${n(r.artifact)}` : '';
|
|
76
|
+
const showHint = hint && INDENT + lw + 2 + body + 2 + displayWidth(hint) <= cols;
|
|
77
|
+
out.push(line([...head(r.label), [stateToken(r.state), glyph(r.state, caps)], [undefined, ' '], [stateToken(r.state), padEndDisplay(r.word, used)],
|
|
78
|
+
...(showHint ? [[undefined, ' ' + hint]] : [])], cols, caps));
|
|
79
|
+
}
|
|
80
|
+
const risks = m.acceptedRisks.map(x => n(x));
|
|
81
|
+
out.push(line([...head(policyLabel), [undefined, t('approval.policy.agentsNeverCommit') + (caps.charset === 'utf8' ? ' · ' : ' | ')],
|
|
82
|
+
[risks.length ? 'amber' : undefined, risks.length ? tn('approval.policy.risk', risks.length, { list: risks.join(', ') }) : t('approval.policy.noRisk')]], cols, caps));
|
|
83
|
+
const names = rows.flatMap(r => (r.artifact ? [r.artifact] : []));
|
|
84
|
+
const read = [...m.read].map(x => n(x));
|
|
85
|
+
const items = (read.length ? [...names.map(x => n(x)), ...read.filter(x => !names.includes(x))] : []).flatMap((x, i) => [[undefined, i ? ' ' : ''], read.includes(x) ? [stateToken('done'), glyph('done', caps) + ' '] : [undefined, glyph('pending', caps) + ' '], [undefined, x]]);
|
|
86
|
+
out.push(line([...head(readLabel), ...(items.length ? items : [[undefined, t('approval.read.none')]])], cols, caps));
|
|
87
|
+
const via = m.surface === 'dashboard' ? 'approval.approver.dashboard' : 'approval.approver.value';
|
|
88
|
+
if (m.approver || m.extra?.length)
|
|
89
|
+
out.push('');
|
|
90
|
+
if (m.approver)
|
|
91
|
+
out.push(line([...head(whoLabel), [undefined, t(via, { name: n(m.approver) })]], cols, caps));
|
|
92
|
+
for (const e of m.extra ?? [])
|
|
93
|
+
out.push(line([...head(e.label), ...e.segs], cols, caps));
|
|
94
|
+
return out;
|
|
95
|
+
}
|