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.
Files changed (160) hide show
  1. package/CHANGELOG.md +62 -0
  2. package/LICENSE +55 -0
  3. package/README.md +227 -2
  4. package/SECURITY.md +26 -0
  5. package/adapters/git/src/git.js +250 -0
  6. package/adapters/git/src/index.js +1 -0
  7. package/adapters/hooks-claude/src/canonical.js +45 -0
  8. package/adapters/hooks-claude/src/index.js +2 -0
  9. package/adapters/hooks-claude/src/main.js +58 -0
  10. package/adapters/hooks-claude/src/payload.js +40 -0
  11. package/adapters/host-probe/src/index.js +2 -0
  12. package/adapters/host-probe/src/ollama.js +18 -0
  13. package/adapters/host-probe/src/probe.js +107 -0
  14. package/adapters/local-tool/src/fingerprint.js +56 -0
  15. package/adapters/local-tool/src/index.js +4 -0
  16. package/adapters/local-tool/src/local-tool.js +22 -0
  17. package/adapters/local-tool/src/sandboxed.js +105 -0
  18. package/adapters/local-tool/src/scan.js +52 -0
  19. package/adapters/memory-claude-mem/src/claude-mem.js +115 -0
  20. package/adapters/memory-claude-mem/src/index.js +1 -0
  21. package/adapters/process-runner/src/index.js +1 -0
  22. package/adapters/process-runner/src/runner.js +123 -0
  23. package/adapters/runtime-api/src/capabilities.json +116 -0
  24. package/adapters/runtime-api/src/executor.js +131 -0
  25. package/adapters/runtime-api/src/index.js +1 -0
  26. package/adapters/runtime-claude/src/capabilities.json +375 -0
  27. package/adapters/runtime-claude/src/command.js +34 -0
  28. package/adapters/runtime-claude/src/executor.js +162 -0
  29. package/adapters/runtime-claude/src/index.js +4 -0
  30. package/adapters/runtime-claude/src/permissions.js +76 -0
  31. package/adapters/runtime-claude/src/stream.js +60 -0
  32. package/adapters/runtime-codex/src/capabilities.json +192 -0
  33. package/adapters/runtime-codex/src/command.js +36 -0
  34. package/adapters/runtime-codex/src/executor.js +83 -0
  35. package/adapters/runtime-codex/src/index.js +4 -0
  36. package/adapters/runtime-codex/src/scratch.js +32 -0
  37. package/adapters/runtime-codex/src/stream.js +39 -0
  38. package/adapters/runtime-opencode/src/capabilities.json +149 -0
  39. package/adapters/runtime-opencode/src/config.js +33 -0
  40. package/adapters/runtime-opencode/src/credentials.js +130 -0
  41. package/adapters/runtime-opencode/src/executor.js +127 -0
  42. package/adapters/runtime-opencode/src/facts.js +43 -0
  43. package/adapters/runtime-opencode/src/hosts.js +16 -0
  44. package/adapters/runtime-opencode/src/hosts.json +3 -0
  45. package/adapters/runtime-opencode/src/index.js +6 -0
  46. package/adapters/runtime-opencode/src/mounts.js +58 -0
  47. package/adapters/runtime-opencode/src/stream.js +63 -0
  48. package/adapters/skill-store/src/index.js +1 -0
  49. package/adapters/skill-store/src/skill-store.js +162 -0
  50. package/adapters/store-fs/src/index.js +2 -0
  51. package/adapters/store-fs/src/store.js +201 -0
  52. package/adapters/store-fs/src/trusted-dir.js +37 -0
  53. package/apps/cli/src/console.js +432 -0
  54. package/apps/cli/src/dashboard-approve.js +259 -0
  55. package/apps/cli/src/dashboard-data.js +424 -0
  56. package/apps/cli/src/dashboard.js +500 -0
  57. package/apps/cli/src/history.js +35 -0
  58. package/apps/cli/src/home.js +18 -0
  59. package/apps/cli/src/i18n/en.js +527 -0
  60. package/apps/cli/src/i18n/index.js +90 -0
  61. package/apps/cli/src/i18n/languages.js +25 -0
  62. package/apps/cli/src/i18n/locales/ar.json +526 -0
  63. package/apps/cli/src/i18n/locales/de.json +505 -0
  64. package/apps/cli/src/i18n/locales/es.json +505 -0
  65. package/apps/cli/src/i18n/locales/fa.json +505 -0
  66. package/apps/cli/src/i18n/locales/fr.json +505 -0
  67. package/apps/cli/src/i18n/locales/he.json +505 -0
  68. package/apps/cli/src/i18n/locales/hi.json +505 -0
  69. package/apps/cli/src/i18n/locales/id.json +491 -0
  70. package/apps/cli/src/i18n/locales/it.json +505 -0
  71. package/apps/cli/src/i18n/locales/ja.json +491 -0
  72. package/apps/cli/src/i18n/locales/ko.json +491 -0
  73. package/apps/cli/src/i18n/locales/nl.json +505 -0
  74. package/apps/cli/src/i18n/locales/pl.json +512 -0
  75. package/apps/cli/src/i18n/locales/pt-BR.json +505 -0
  76. package/apps/cli/src/i18n/locales/ru.json +512 -0
  77. package/apps/cli/src/i18n/locales/th.json +491 -0
  78. package/apps/cli/src/i18n/locales/tr.json +505 -0
  79. package/apps/cli/src/i18n/locales/uk.json +512 -0
  80. package/apps/cli/src/i18n/locales/vi.json +491 -0
  81. package/apps/cli/src/i18n/locales/zh-CN.json +491 -0
  82. package/apps/cli/src/i18n/locales/zh-TW.json +491 -0
  83. package/apps/cli/src/i18n/width.js +40 -0
  84. package/apps/cli/src/layout.js +18 -0
  85. package/apps/cli/src/main.js +830 -0
  86. package/apps/cli/src/preferences.js +46 -0
  87. package/apps/cli/src/runtime-notices.js +41 -0
  88. package/apps/cli/src/safe-text.js +3 -0
  89. package/apps/cli/src/shortcut.js +82 -0
  90. package/apps/cli/src/skills-cli.js +112 -0
  91. package/apps/cli/src/tui/caps.js +31 -0
  92. package/apps/cli/src/tui/components/agent-list.js +58 -0
  93. package/apps/cli/src/tui/components/approval-center.js +145 -0
  94. package/apps/cli/src/tui/components/approval.js +95 -0
  95. package/apps/cli/src/tui/components/dashboard-frame.js +293 -0
  96. package/apps/cli/src/tui/components/diff-viewer.js +549 -0
  97. package/apps/cli/src/tui/components/event-viewer.js +46 -0
  98. package/apps/cli/src/tui/components/help-panel.js +59 -0
  99. package/apps/cli/src/tui/components/home.js +185 -0
  100. package/apps/cli/src/tui/components/logo.js +67 -0
  101. package/apps/cli/src/tui/components/panel.js +70 -0
  102. package/apps/cli/src/tui/components/status-bar.js +96 -0
  103. package/apps/cli/src/tui/components/timeline.js +120 -0
  104. package/apps/cli/src/tui/keys.js +139 -0
  105. package/apps/cli/src/tui/neutral.js +68 -0
  106. package/apps/cli/src/tui/screen.js +111 -0
  107. package/apps/cli/src/tui/text.js +165 -0
  108. package/apps/cli/src/tui/tokens.js +89 -0
  109. package/apps/cli/src/tui/view.js +64 -0
  110. package/apps/cli/src/upgrade-check.js +86 -0
  111. package/apps/cli/src/upgrade-cli.js +168 -0
  112. package/apps/cli/src/workflow-cli.js +674 -0
  113. package/package.json +29 -4
  114. package/packages/application/src/index.js +8 -0
  115. package/packages/application/src/lib/digest.js +7 -0
  116. package/packages/application/src/ports/memory.js +1 -0
  117. package/packages/application/src/ports/runtime-executor.js +1 -0
  118. package/packages/application/src/projection/run-view.js +194 -0
  119. package/packages/application/src/projection/squad-view.js +33 -0
  120. package/packages/application/src/use-cases/prepare-run.js +68 -0
  121. package/packages/application/src/workflow/feature-governed.js +420 -0
  122. package/packages/application/src/workflow/gate-signals.js +40 -0
  123. package/packages/application/src/workflow/prompts.js +81 -0
  124. package/packages/config/src/config.js +372 -0
  125. package/packages/config/src/index.js +1 -0
  126. package/packages/domain/src/capabilities.js +13 -0
  127. package/packages/domain/src/capability-matrix.js +63 -0
  128. package/packages/domain/src/enforcement.js +95 -0
  129. package/packages/domain/src/index.js +4 -0
  130. package/packages/domain/src/policy.js +32 -0
  131. package/packages/rules/src/glob.js +47 -0
  132. package/packages/rules/src/index.js +5 -0
  133. package/packages/rules/src/inherit.js +19 -0
  134. package/packages/rules/src/lists.js +41 -0
  135. package/packages/rules/src/rules.js +79 -0
  136. package/packages/rules/src/shell.js +83 -0
  137. package/packages/skills/src/index.js +1 -0
  138. package/packages/skills/src/skills.js +108 -0
  139. package/skills/code-review/SKILL.md +51 -0
  140. package/skills/egm-design/LICENSE +202 -0
  141. package/skills/egm-design/SKILL.md +68 -0
  142. package/skills/egm-design/references/feature-spec-standard.md +39 -0
  143. package/skills/egm-implementation-readiness/LICENSE +202 -0
  144. package/skills/egm-implementation-readiness/SKILL.md +67 -0
  145. package/skills/egm-implementation-readiness/references/implementation-readiness-standard.md +37 -0
  146. package/skills/first-party.lock.json +10 -0
  147. package/skills/planning-contract/SKILL.md +51 -0
  148. package/skills/ponytail/LICENSE +21 -0
  149. package/skills/ponytail/SKILL.md +56 -0
  150. package/skills/security-review/SKILL.md +58 -0
  151. package/skills/tdd/SKILL.md +52 -0
  152. package/skills/unslop/LICENSE +396 -0
  153. package/skills/unslop/SKILL.md +239 -0
  154. package/skills/unslop/references/cjk.md +34 -0
  155. package/skills/unslop/references/effects.md +113 -0
  156. package/skills/unslop/references/refs.md +17 -0
  157. package/skills/unslop/references/rtl.md +111 -0
  158. package/skills/unslop/references/signs.md +122 -0
  159. package/skills/unslop/references/tokens.md +139 -0
  160. package/skills/unslop/references/visuals.md +84 -0
@@ -0,0 +1,139 @@
1
+ /**
2
+ * Raw-mode key decoding. The decoder is stateful only for a bracketed paste split over chunks. Pure.
3
+ * A 'char' key is never a control, bidi or invisible character (neutral.ts's strict set): those are 'unknown'.
4
+ * 'unknown.seq' and 'paste.text' are raw input: neutralise them before they are shown.
5
+ */
6
+ import { neutralize } from "./neutral.js";
7
+ const ESC = String.fromCharCode(0x1b);
8
+ const PASTE_END = ESC + '[201~';
9
+ const MAX_PASTE = 64 * 1024;
10
+ const LETTER = { A: 'up', B: 'down', C: 'right', D: 'left', H: 'home', F: 'end', Z: 'backtab' };
11
+ const TILDE = { '1': 'home', '7': 'home', '4': 'end', '8': 'end', '5': 'pageup', '6': 'pagedown' };
12
+ const SS3 = { A: 'up', B: 'down', C: 'right', D: 'left', H: 'home', F: 'end' };
13
+ const named = (name) => ({ name });
14
+ export function keyDecoder() {
15
+ let paste; // inside a bracketed paste: the text so far ('' once over the limit)
16
+ let over = false;
17
+ let pending = ''; // an incomplete escape sequence (or half a surrogate pair) held until the next chunk or flush()
18
+ const wrap = (keys) => (keys.length ? [{ keys, multi: keys.length > 1 }] : []);
19
+ return {
20
+ feed(chunk) {
21
+ const keys = [];
22
+ let s = chunk;
23
+ if (pending !== '') {
24
+ // A held lone ESC is a real Esc unless this chunk continues a sequence.
25
+ if (pending === ESC && !/^[[O]/.test(chunk))
26
+ keys.push(named('esc'));
27
+ else
28
+ s = pending + chunk;
29
+ pending = '';
30
+ }
31
+ while (s !== '') {
32
+ if (paste !== undefined) {
33
+ const joined = over ? paste.slice(-PASTE_END.length) + s : paste + s;
34
+ const end = joined.indexOf(PASTE_END);
35
+ if (end < 0) {
36
+ if (over || joined.length > MAX_PASTE) {
37
+ over = true;
38
+ paste = joined.slice(-PASTE_END.length);
39
+ }
40
+ else
41
+ paste = joined;
42
+ return wrap(keys);
43
+ }
44
+ if (!over && end <= MAX_PASTE)
45
+ keys.push({ name: 'paste', text: joined.slice(0, end) });
46
+ s = joined.slice(end + PASTE_END.length);
47
+ paste = undefined;
48
+ over = false;
49
+ continue;
50
+ }
51
+ const c = s[0];
52
+ if (c === ESC) {
53
+ if (s.length === 1) {
54
+ pending = s;
55
+ break;
56
+ }
57
+ if (s[1] === '[') {
58
+ let j = 2;
59
+ while (j < s.length && /[0-9;:?<=>]/.test(s[j]))
60
+ j++;
61
+ while (j < s.length && /[ -/]/.test(s[j]))
62
+ j++;
63
+ if (j >= s.length) { // incomplete: wait for the rest
64
+ if (s.length > 64) {
65
+ keys.push({ name: 'unknown', seq: s });
66
+ s = '';
67
+ }
68
+ else
69
+ pending = s;
70
+ break;
71
+ }
72
+ if (!/[@-~]/.test(s[j])) { // malformed: report what was read, go on from the offending character
73
+ keys.push({ name: 'unknown', seq: s.slice(0, j) });
74
+ s = s.slice(j);
75
+ continue;
76
+ }
77
+ const seq = s.slice(0, j + 1), params = /^\x1b\[([0-9;:?<=>]*)/.exec(seq)[1], final = s[j];
78
+ s = s.slice(j + 1);
79
+ if (final === '~' && params === '200') {
80
+ paste = '';
81
+ over = false;
82
+ continue;
83
+ }
84
+ const first = params.split(';')[0];
85
+ let name;
86
+ if (!/^[0-9;]*$/.test(params) || seq.length !== 3 + params.length)
87
+ name = undefined;
88
+ else if (final === '~')
89
+ name = TILDE[first];
90
+ else if (first === '' || first === '1')
91
+ name = LETTER[final];
92
+ keys.push(name ? named(name) : { name: 'unknown', seq });
93
+ continue;
94
+ }
95
+ if (s[1] === 'O') {
96
+ if (s.length === 2) {
97
+ pending = s;
98
+ break;
99
+ }
100
+ const name = SS3[s[2]];
101
+ keys.push(name ? named(name) : { name: 'unknown', seq: s.slice(0, 3) });
102
+ s = s.slice(3);
103
+ continue;
104
+ }
105
+ const take = String.fromCodePoint(s.codePointAt(1));
106
+ keys.push({ name: 'unknown', seq: ESC + take });
107
+ s = s.slice(1 + take.length);
108
+ continue;
109
+ }
110
+ const cp = s.codePointAt(0);
111
+ if (cp >= 0xd800 && cp <= 0xdbff && s.length === 1) {
112
+ pending = s;
113
+ break;
114
+ } // half a pair
115
+ const ch = String.fromCodePoint(cp);
116
+ s = s.slice(ch.length);
117
+ if (ch === '\r' || ch === '\n')
118
+ keys.push(named('enter'));
119
+ else if (ch === '\t')
120
+ keys.push(named('tab'));
121
+ else if (ch === '\x7f' || ch === '\b')
122
+ keys.push(named('backspace'));
123
+ else if (ch === '\x03')
124
+ keys.push(named('ctrl-c'));
125
+ else
126
+ keys.push(neutralize(ch).marked === 0 ? { name: 'char', ch } : { name: 'unknown', seq: ch });
127
+ }
128
+ return wrap(keys);
129
+ },
130
+ /** The caller's short timer (about 50 ms) fires this when no more input came: a held lone ESC is the Esc key. */
131
+ flush() {
132
+ const p = pending;
133
+ pending = '';
134
+ if (p === '')
135
+ return [];
136
+ return wrap([p === ESC ? named('esc') : { name: 'unknown', seq: p }]);
137
+ },
138
+ };
139
+ }
@@ -0,0 +1,68 @@
1
+ /**
2
+ * Untrusted text made inert and visible (reference: .claude/skills/tui-design-expert/untrusted-text.md).
3
+ * A terminal executes what it prints: every string from an agent, a process, a file name, an artifact, the network
4
+ * or a config value goes through here before a human sees it. Each hostile character becomes a visible marker
5
+ * and is counted; nothing is stripped silently. `strict` is for what a human judges, `log` keeps ZWJ/ZWNJ.
6
+ * This file holds no literal control or bidi character: ranges are written as escapes.
7
+ */
8
+ import { displayWidth } from "../i18n/width.js";
9
+ const NAMES = { 0x07: 'BEL', 0x08: 'BS', 0x0a: 'LF', 0x09: 'TAB', 0x0d: 'CR', 0x1b: 'ESC', 0x7f: 'DEL', 0x9b: 'CSI', 0x9d: 'OSC', 0x90: 'DCS' };
10
+ const STRICT = /[\u0000-\u0008\u000b-\u001f\u007f-\u009f\u00ad\u034f\u061c\u115f\u1160\u17b4\u17b5\u180b-\u180f\u200b-\u200f\u2028-\u202e\u2060-\u206f\u3164\ufe00-\ufe0f\ufeff\uffa0\ufff9-\ufffb]|[\u{1bca0}-\u{1bca3}\u{e0000}-\u{e007f}\u{e0100}-\u{e01ef}]/gu;
11
+ const LOG = /[\u0000-\u0008\u000b-\u001f\u007f-\u009f\u00ad\u034f\u061c\u115f\u1160\u17b4\u17b5\u180b-\u180f\u200b\u200e\u200f\u2028-\u202e\u2060-\u206f\u3164\ufe00-\ufe0d\ufeff\uffa0\ufff9-\ufffb]|[\u{1bca0}-\u{1bca3}\u{e0000}-\u{e007f}\u{e0100}-\u{e01ef}]/gu;
12
+ const OPEN = String.fromCharCode(0x2039), CLOSE = String.fromCharCode(0x203a);
13
+ export function neutralize(text, o = {}) {
14
+ let marked = 0;
15
+ const mark = (ch) => {
16
+ marked++;
17
+ const cp = ch.codePointAt(0);
18
+ return `${OPEN}${NAMES[cp] ?? 'U+' + cp.toString(16).toUpperCase().padStart(4, '0')}${CLOSE}`;
19
+ };
20
+ let s = text.replace(/\r\n/g, '\n').replace(o.profile === 'log' ? LOG : STRICT, mark);
21
+ if (o.singleLine)
22
+ s = s.replace(/[\n\t]/g, mark);
23
+ return { text: s, marked };
24
+ }
25
+ /** One-line contexts (a name, a reason, a table cell): newlines and tabs are marked too. */
26
+ export const n = (text) => neutralize(text, { singleLine: true }).text;
27
+ /** A unit a cut never splits: a whole marker, or one code point. */
28
+ const UNIT = new RegExp(`${OPEN}(?:[A-Z]{2,3}|U\\+[0-9A-F]{4,6})${CLOSE}|[\\s\\S]`, 'gu');
29
+ /**
30
+ * An already neutral text cut to `max` display columns: what fits is returned as is; otherwise the text ends with `…`
31
+ * (`...` in ASCII) within `max`, and a marker is never split — the cut backs off to the marker's start, so a half
32
+ * marker never hides which character was sent and the ellipsis says that something was cut.
33
+ */
34
+ export function cutNeutral(text, max, o = {}) {
35
+ if (displayWidth(text) <= max)
36
+ return text;
37
+ const more = o.ascii ? '...' : '\u2026', room = max - displayWidth(more);
38
+ if (room < 0)
39
+ return '';
40
+ let out = '', w = 0;
41
+ for (const [unit] of text.matchAll(UNIT)) {
42
+ const uw = displayWidth(unit);
43
+ if (w + uw > room)
44
+ break;
45
+ out += unit;
46
+ w += uw;
47
+ }
48
+ return (out + more);
49
+ }
50
+ /** One-line, then cut to `max` display columns AFTER neutralising: a hostile text cannot overflow its column. */
51
+ export function nCut(text, max, o = {}) {
52
+ return cutNeutral(neutralize(text, { singleLine: true }).text, max, o);
53
+ }
54
+ /** Whole messages from outside (a thrown error): `log` profile, so Taskquoin's own ZWNJ/ZWJ are not marked. */
55
+ export const nLog = (text) => neutralize(text, { profile: 'log', singleLine: true }).text;
56
+ /**
57
+ * What `--json` escapes beyond JSON.stringify (which escapes C0, ESC included): only what can act on a terminal or
58
+ * reorder what it displays — DEL and C1, the Bidi_Control characters, and U+2028/U+2029 (line breaks that measuring
59
+ * code does not see). Invisible characters (ZWNJ, ZWJ, variation selectors, tags…) stay: they are data a JSON consumer
60
+ * parses, inert on a terminal, and legitimate in Persian, Hindi and emoji.
61
+ */
62
+ const JSON_UNSAFE = /[\u007f-\u009f\u061c\u200e\u200f\u202a-\u202e\u2066-\u2069\u2028\u2029]/g;
63
+ /** `--json` output made inert: the parsed value is identical, and the bytes too for any output without those characters. */
64
+ export function jsonOut(value, space = 2) {
65
+ return JSON.stringify(value, null, space).replace(JSON_UNSAFE, (ch) => '\\u' + ch.charCodeAt(0).toString(16).padStart(4, '0'));
66
+ }
67
+ /** Multi-line content (an artifact): line breaks and tabs kept, everything else neutralised. */
68
+ export const nBlock = (text) => neutralize(text).text;
@@ -0,0 +1,111 @@
1
+ /**
2
+ * The full-screen terminal: alternate screen, raw mode, line-diff painting, and the terminal ALWAYS given back
3
+ * (cursor, alternate screen, bracketed paste, raw mode) on return, error, SIGINT, SIGTERM, SIGHUP and process exit.
4
+ * IO is injected (TtyIO, Signals) so every exit path is testable without a terminal.
5
+ */
6
+ import { clip } from "./text.js";
7
+ export const ENTER = '\x1b[?1049h\x1b[?25l\x1b[?2004h\x1b[2J';
8
+ export const RESTORE = '\x1b[0m\x1b[?2004l\x1b[?25h\x1b[?1049l';
9
+ const EXIT_CODE = { SIGINT: 130, SIGTERM: 143, SIGHUP: 129 };
10
+ const rowAt = (row) => `\x1b[${row};1H\x1b[2K`;
11
+ export async function withTerminal(io, sig, body) {
12
+ let prev;
13
+ let dirty = 0; // rows that may hold stale text after invalidate() or a resize: the next draw clears those past its frame
14
+ const screen = {
15
+ invalidate() { dirty = Math.max(dirty, prev?.length ?? 0); prev = undefined; },
16
+ draw(lines) {
17
+ const { columns, rows: height } = io.size();
18
+ const next = lines.slice(0, Math.max(0, height)).map((l) => clip(l, columns));
19
+ let out = '', rows = 0;
20
+ for (let i = 0; i < next.length; i++) {
21
+ if (prev === undefined || prev[i] !== next[i]) {
22
+ out += rowAt(i + 1) + next[i];
23
+ rows++;
24
+ }
25
+ }
26
+ for (let i = next.length; i < Math.max(prev?.length ?? 0, dirty); i++) {
27
+ out += rowAt(i + 1);
28
+ rows++;
29
+ }
30
+ if (rows > 0) {
31
+ try {
32
+ io.write(out);
33
+ }
34
+ catch (e) {
35
+ dirty = Math.max(dirty, prev?.length ?? 0, next.length);
36
+ prev = undefined;
37
+ throw e;
38
+ }
39
+ }
40
+ prev = next;
41
+ dirty = 0;
42
+ return rows;
43
+ },
44
+ };
45
+ const offs = [];
46
+ let restored = false;
47
+ const restore = () => {
48
+ if (restored)
49
+ return;
50
+ restored = true;
51
+ try {
52
+ io.setRawMode(false);
53
+ }
54
+ catch { /* terminal already gone */ }
55
+ try {
56
+ io.write(RESTORE);
57
+ }
58
+ catch { /* terminal already gone */ }
59
+ for (const off of offs) {
60
+ try {
61
+ off();
62
+ }
63
+ catch { /* nothing to undo */ }
64
+ }
65
+ };
66
+ const bind = (ev, f) => { sig.on(ev, f); offs.push(() => { sig.off(ev, f); }); };
67
+ for (const ev of ['SIGINT', 'SIGTERM', 'SIGHUP'])
68
+ bind(ev, () => { restore(); sig.exit(EXIT_CODE[ev]); });
69
+ bind('exit', restore);
70
+ offs.push(io.onResize(() => { dirty = Math.max(dirty, io.size().rows); prev = undefined; }));
71
+ try {
72
+ io.write(ENTER);
73
+ io.setRawMode(true);
74
+ return await body(screen);
75
+ }
76
+ finally {
77
+ restore();
78
+ }
79
+ }
80
+ /** The real process: signals and exit. */
81
+ export const processSignals = {
82
+ on: (ev, f) => process.on(ev, f),
83
+ off: (ev, f) => process.off(ev, f),
84
+ exit: (code) => process.exit(code),
85
+ };
86
+ export function nodeTty(stdin, stdout) {
87
+ const subs = new Set();
88
+ const onChunk = (c) => { const s = typeof c === 'string' ? c : c.toString('utf8'); for (const f of [...subs])
89
+ f(s); };
90
+ return {
91
+ write: (s) => { stdout.write(s); },
92
+ setRawMode: (on) => { if (stdin.isTTY)
93
+ stdin.setRawMode(on); },
94
+ onData(f) {
95
+ if (subs.size === 0) {
96
+ stdin.setEncoding('utf8');
97
+ stdin.on('data', onChunk);
98
+ stdin.resume();
99
+ }
100
+ subs.add(f);
101
+ return () => {
102
+ if (!subs.delete(f) || subs.size > 0)
103
+ return;
104
+ stdin.off('data', onChunk);
105
+ stdin.pause();
106
+ };
107
+ },
108
+ onResize(f) { stdout.on('resize', f); return () => { stdout.off('resize', f); }; },
109
+ size: () => ({ columns: stdout.columns > 0 ? stdout.columns : 80, rows: stdout.rows > 0 ? stdout.rows : 24 }),
110
+ };
111
+ }
@@ -0,0 +1,165 @@
1
+ /**
2
+ * Plain-text layout helpers (width by display columns, never by code units). Plain text in, plain text out: cut and
3
+ * pad first, paint after. Pass `ellipsis(caps)` (tokens.ts) so an ASCII terminal gets `...`. Text from outside Taskquoin is neutralised (neutral.ts) before it gets here. Pure.
4
+ */
5
+ import { t } from "../i18n/index.js";
6
+ import { displayWidth } from "../i18n/width.js";
7
+ const ESC = String.fromCharCode(0x1b);
8
+ /** Longest prefix of `s` within `width` columns; a wide character that does not fit is left out whole. */
9
+ function prefix(s, width) {
10
+ let out = '', w = 0;
11
+ for (const ch of s) {
12
+ const cw = displayWidth(ch);
13
+ if (w + cw > width)
14
+ break;
15
+ out += ch;
16
+ w += cw;
17
+ }
18
+ return out;
19
+ }
20
+ export function cut(s, width, ellipsis = '…') {
21
+ if (width <= 0)
22
+ return '';
23
+ if (displayWidth(s) <= width)
24
+ return s;
25
+ const ew = displayWidth(ellipsis);
26
+ if (ew > width)
27
+ return prefix(ellipsis, width);
28
+ return prefix(s, width - ew) + ellipsis;
29
+ }
30
+ export function pad(s, width) {
31
+ return s + ' '.repeat(Math.max(0, width - displayWidth(s)));
32
+ }
33
+ /** Exactly `width` columns: cut with an ellipsis, then padded. */
34
+ export function fit(s, width, ellipsis = '…') {
35
+ return pad(cut(s, width, ellipsis), width);
36
+ }
37
+ /** `left` at the left edge, `right` at the right edge, exactly `width` columns; the left is cut first, the right kept. */
38
+ export function spread(left, right, width) {
39
+ const rw = displayWidth(right);
40
+ if (rw + 1 > width)
41
+ return fit(right, width);
42
+ return pad(cut(left, width - rw - 1), width - rw) + right;
43
+ }
44
+ const SGR_STICKY = /\x1b\[[0-9;]{0,20}m/y; // Taskquoin's own colour codes, at most 24 characters
45
+ const CSI_STICKY = /\x1b\[[0-9;:?<=>]*[ -/]*[@-~]/y; // any other CSI: dropped whole, never left as visible text
46
+ /**
47
+ * SGR-aware clip to `width` columns, and the last cleaning before the terminal: colour codes (plain `;` form, up to 24
48
+ * characters) are kept and closed; every other escape sequence, C0 control, DEL and C1 control is dropped.
49
+ */
50
+ export function clip(line, width) {
51
+ let out = '', w = 0, sgr = false, over = false;
52
+ for (let i = 0; i < line.length;) {
53
+ const cp = line.codePointAt(i);
54
+ if (cp === 0x1b) {
55
+ SGR_STICKY.lastIndex = i;
56
+ const m = SGR_STICKY.exec(line);
57
+ if (m) {
58
+ sgr = true;
59
+ out += m[0];
60
+ i += m[0].length;
61
+ continue;
62
+ }
63
+ CSI_STICKY.lastIndex = i;
64
+ const o = CSI_STICKY.exec(line);
65
+ i += o ? o[0].length : 1;
66
+ continue;
67
+ }
68
+ const ch = String.fromCodePoint(cp);
69
+ i += ch.length;
70
+ if (cp < 0x20 || (cp >= 0x7f && cp <= 0x9f) || over)
71
+ continue;
72
+ const cw = cp < 0x7f ? 1 : displayWidth(ch);
73
+ if (w + cw > width) {
74
+ over = true;
75
+ continue;
76
+ }
77
+ out += ch;
78
+ w += cw;
79
+ }
80
+ return sgr && over ? out + ESC + '[0m' : out;
81
+ }
82
+ /** Word wrap by display width; blank lines kept, words longer than a line split (a character is never split). */
83
+ export function wrap(s, width) {
84
+ const max = Math.max(1, width);
85
+ const out = [];
86
+ for (const para of s.split('\n')) {
87
+ let line = '', w = 0;
88
+ const push = () => { out.push(line); line = ''; w = 0; };
89
+ for (const word of para.split(' ').filter((x) => x !== '')) {
90
+ const ww = displayWidth(word);
91
+ if (line !== '' && w + 1 + ww <= max) {
92
+ line += ' ' + word;
93
+ w += 1 + ww;
94
+ continue;
95
+ }
96
+ if (line !== '')
97
+ push();
98
+ if (ww <= max) {
99
+ line = word;
100
+ w = ww;
101
+ continue;
102
+ }
103
+ for (const ch of word) {
104
+ const cw = displayWidth(ch);
105
+ if (w + cw > max && line !== '')
106
+ push();
107
+ line += ch;
108
+ w += cw;
109
+ }
110
+ }
111
+ if (line !== '' || para.trim() === '')
112
+ out.push(line);
113
+ }
114
+ return out;
115
+ }
116
+ export function expandTabs(s, stop = 4) {
117
+ let out = '', col = 0;
118
+ for (const ch of s) {
119
+ if (ch === '\t') {
120
+ const n = stop - (col % stop);
121
+ out += ' '.repeat(n);
122
+ col += n;
123
+ }
124
+ else if (ch === '\n') {
125
+ out += ch;
126
+ col = 0;
127
+ }
128
+ else {
129
+ out += ch;
130
+ col += displayWidth(ch);
131
+ }
132
+ }
133
+ return out;
134
+ }
135
+ const two = (x) => String(x).padStart(2, '0');
136
+ const valid = (iso) => { const ms = iso ? Date.parse(iso) : NaN; return Number.isFinite(ms) ? ms : undefined; };
137
+ /** HH:MM:SS, local time; `?` when unknown (an empty or unparsable time is never formatted as a date). The one copy: the timeline uses it too. */
138
+ export function clock(iso) {
139
+ const ms = valid(iso);
140
+ if (ms === undefined)
141
+ return '?';
142
+ const d = new Date(ms);
143
+ return `${two(d.getHours())}:${two(d.getMinutes())}:${two(d.getSeconds())}`;
144
+ }
145
+ /** For lists: `HH:MM` today, `YYYY-MM-DD HH:MM` another day, `?` when unknown. */
146
+ export function localWhen(iso, nowMs) {
147
+ const ms = valid(iso);
148
+ if (ms === undefined)
149
+ return '?';
150
+ const d = new Date(ms), now = new Date(nowMs);
151
+ const hm = clock(iso).slice(0, 5);
152
+ const same = d.getFullYear() === now.getFullYear() && d.getMonth() === now.getMonth() && d.getDate() === now.getDate();
153
+ return same ? hm : `${d.getFullYear()}-${two(d.getMonth() + 1)}-${two(d.getDate())} ${hm}`;
154
+ }
155
+ /** `49 s`, `1 min 38 s`, `1 h 02 min` (translated units); `?` when not recorded. The one copy: the timeline uses it too. */
156
+ export function duration(ms) {
157
+ if (ms === undefined || !Number.isFinite(ms) || ms < 0)
158
+ return '?';
159
+ const s = Math.floor(ms / 1000);
160
+ if (s < 60)
161
+ return t('timeline.dur.s', { s });
162
+ if (s < 3600)
163
+ return t('timeline.dur.min', { m: Math.floor(s / 60), s: s % 60 });
164
+ return t('timeline.dur.h', { h: Math.floor(s / 3600), m: two(Math.floor(s / 60) % 60) });
165
+ }
@@ -0,0 +1,89 @@
1
+ export const TOKEN_HEX = {
2
+ muted: { dark: '#9AA5CE', light: '#5A607A' },
3
+ line: { dark: '#5F6A99', light: '#7F87A6' },
4
+ mint: { dark: '#5EF2C2', light: '#0B7A5E' },
5
+ cyan: { dark: '#7DCFFF', light: '#0B6FA4' },
6
+ violet: { dark: '#BB9AF7', light: '#7340C8' },
7
+ orange: { dark: '#FF9E64', light: '#B5480C' },
8
+ green: { dark: '#9ECE6A', light: '#3E7A1E' },
9
+ amber: { dark: '#E0AF68', light: '#8A5A00' },
10
+ red: { dark: '#F7768E', light: '#C21E45' },
11
+ };
12
+ /** xterm-256 index, dark / light. */
13
+ const IDX256 = {
14
+ muted: [110, 60], line: [61, 103], mint: [85, 29], cyan: [117, 25], violet: [141, 62],
15
+ orange: [215, 130], green: [149, 28], amber: [179, 94], red: [210, 125],
16
+ };
17
+ /** 16-colour SGR opening parameters. */
18
+ const SGR16 = {
19
+ muted: '2', line: '90', mint: '36', cyan: '96', violet: '35', orange: '1;33', green: '32', amber: '33', red: '31',
20
+ };
21
+ const ESC = '\x1b';
22
+ export function paint(token, text, caps) {
23
+ if (caps.colorDepth === 0)
24
+ return text;
25
+ const light = caps.theme === 'light';
26
+ if (caps.colorDepth === 24) {
27
+ const hex = TOKEN_HEX[token][light ? 'light' : 'dark'];
28
+ const [r, g, b] = [1, 3, 5].map((i) => parseInt(hex.slice(i, i + 2), 16));
29
+ return `${ESC}[38;2;${r};${g};${b}m${text}${ESC}[39m`;
30
+ }
31
+ if (caps.colorDepth === 8)
32
+ return `${ESC}[38;5;${IDX256[token][light ? 1 : 0]}m${text}${ESC}[39m`;
33
+ if (token === 'muted')
34
+ return `${ESC}[2m${text}${ESC}[22m`;
35
+ if (token === 'orange')
36
+ return `${ESC}[1;33m${text}${ESC}[22;39m`;
37
+ return `${ESC}[${SGR16[token]}m${text}${ESC}[39m`;
38
+ }
39
+ const GLYPHS = {
40
+ ready: ['●', '[ok]'], risk: ['◐', '[~]'], blocked: ['○', '[x]'], unknown: ['?', '[?]'], running: ['◉', '[>]'],
41
+ waiting: ['◆', '[!]'], done: ['✔', '[v]'], failed: ['✖', '[x]'], pending: ['·', '[ ]'], interrupted: ['‖', '[=]'],
42
+ };
43
+ export function glyph(state, caps) {
44
+ return GLYPHS[state][caps.charset === 'utf8' ? 0 : 1];
45
+ }
46
+ const STATE_TOKEN = {
47
+ ready: 'green', risk: 'amber', blocked: 'red', unknown: 'muted', running: 'cyan',
48
+ waiting: 'orange', done: 'green', failed: 'red', pending: 'muted', interrupted: 'amber',
49
+ };
50
+ export function stateToken(state) {
51
+ return STATE_TOKEN[state];
52
+ }
53
+ export function bold(text, caps) {
54
+ return caps.colorDepth === 0 ? text : `${ESC}[1m${text}${ESC}[22m`;
55
+ }
56
+ /** The selected row: the design system's `sel` background (24-bit), 256-colour index, or reverse video in 16 colours. */
57
+ export function selected(text, caps) {
58
+ if (caps.colorDepth === 0)
59
+ return text;
60
+ const light = caps.theme === 'light';
61
+ if (caps.colorDepth === 24)
62
+ return `${ESC}[48;2;${light ? '240;241;247' : '43;49;80'}m${text}${ESC}[49m`;
63
+ if (caps.colorDepth === 8)
64
+ return `${ESC}[48;5;${light ? 255 : 237}m${text}${ESC}[49m`;
65
+ return `${ESC}[7m${text}${ESC}[27m`;
66
+ }
67
+ /**
68
+ * The background of an added or removed diff line (`addBg` / `delBg`): 24-bit, xterm-256 index, none in 16 colours and
69
+ * at 0 (the `+` / `−` column carries the meaning there).
70
+ */
71
+ export function lineBg(kind, text, caps) {
72
+ if (caps.colorDepth === 0 || caps.colorDepth === 4)
73
+ return text;
74
+ const light = caps.theme === 'light', add = kind === 'add';
75
+ if (caps.colorDepth === 24) {
76
+ const rgb = add ? (light ? '230;244;234' : '32;48;59') : (light ? '251;233;236' : '55;34;44');
77
+ return `${ESC}[48;2;${rgb}m${text}${ESC}[49m`;
78
+ }
79
+ const idx = add ? (light ? 194 : 22) : (light ? 224 : 52);
80
+ return `${ESC}[48;5;${idx}m${text}${ESC}[49m`;
81
+ }
82
+ const MARKS = {
83
+ ellipsis: ['…', '...'], warn: ['⚠', '!'], cursor: ['▸', '>'], arrow: ['→', '->'], caret: ['█', '#'], sep: ['·', '-'],
84
+ };
85
+ /** Small typographic marks with their ASCII twins (design-system glyph table). */
86
+ export function mark(name, caps) {
87
+ return MARKS[name][caps.charset === 'utf8' ? 0 : 1];
88
+ }
89
+ export const ellipsis = (caps) => mark('ellipsis', caps);
@@ -0,0 +1,64 @@
1
+ import { t } from "../i18n/index.js";
2
+ import { cutNeutral, neutralize } from "./neutral.js";
3
+ /** A copy of plain data (objects, arrays, scalars) with every string neutralised; `marked` summed over all of them. */
4
+ function neutralizeAll(value) {
5
+ let marked = 0;
6
+ const walk = (v) => {
7
+ if (typeof v === 'string') {
8
+ const r = neutralize(v, { singleLine: true });
9
+ marked += r.marked;
10
+ return r.text;
11
+ }
12
+ if (Array.isArray(v))
13
+ return v.map(walk);
14
+ if (v !== null && typeof v === 'object')
15
+ return Object.fromEntries(Object.entries(v).map(([k, x]) => [k, walk(x)]));
16
+ return v;
17
+ };
18
+ return { value: walk(value), marked };
19
+ }
20
+ /** A run as a screen may show it: every free-text field neutralised, once. */
21
+ export function shownRun(v) {
22
+ const r = neutralizeAll(v);
23
+ return { view: r.value, marked: r.marked };
24
+ }
25
+ const ROLE = { planner: 'console.role.planner', implementer: 'console.role.implementer', challenger: 'console.role.challenger', security: 'console.role.security' };
26
+ /** Taskquoin's own words (a translated label or message): trusted text, never marked (parameters, not messages). */
27
+ const own = (text) => text;
28
+ /** A blocked member's reason is cut to this many columns, once, after neutralising (a marker is never split). */
29
+ const NOTE_COLUMNS = 70;
30
+ /**
31
+ * The squad as a screen may show it: a known role and every note code in the user's language, the agent id, runtime,
32
+ * gate reason, skill error and capabilities neutralised (one-line strict profile), a blocked member's reason cut.
33
+ * `marked` counts the characters marked in what a screen prints of a member: its role, `who` and note. The raw
34
+ * `detail` is not carried (the note says it); `agent` and `runtime` are, neutralised, for a screen that keys its rows
35
+ * by agent and shows each runtime's version (the dashboard's Agents panel); both are already counted inside `who`.
36
+ */
37
+ export function shownSquad(squad) {
38
+ let marked = 0;
39
+ const raw = (text) => { const r = neutralize(text, { singleLine: true }); marked += r.marked; return r.text; };
40
+ const view = squad.map((m) => {
41
+ const role = m.agent === undefined ? own(t('console.role.tester'))
42
+ : Object.hasOwn(ROLE, m.agent) ? own(t(ROLE[m.agent])) : raw(m.agent ? m.agent[0].toUpperCase() + m.agent.slice(1) : m.agent);
43
+ const cut = (text) => (m.state === 'blocked' ? cutNeutral(text, NOTE_COLUMNS) : text);
44
+ let note;
45
+ switch (m.noteKind) {
46
+ case 'absent':
47
+ note = own(t('console.squad.absent', { runtime: raw(m.detail ?? '') }));
48
+ break;
49
+ case 'tester':
50
+ note = own(t('console.squad.testerUnavailable'));
51
+ break;
52
+ case undefined:
53
+ note = m.note === undefined ? undefined : cut(raw(m.note));
54
+ break; // no code: all of it is raw
55
+ default: note = cut(raw(m.detail ?? m.note ?? ''));
56
+ }
57
+ return {
58
+ role, who: raw(m.who), state: m.state, ...(m.agent !== undefined ? { agent: neutralize(m.agent, { singleLine: true }).text } : {}),
59
+ ...(m.runtime !== undefined ? { runtime: neutralize(m.runtime, { singleLine: true }).text } : {}), // the dashboard looks its version up by it
60
+ ...(note ? { note } : {}), ...(m.noteKind ? { noteKind: m.noteKind } : {}),
61
+ };
62
+ });
63
+ return { view, marked };
64
+ }