tr-plugin-meta-harness 0.3.0 → 0.5.27

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 (94) hide show
  1. package/DESIGN.md +86 -0
  2. package/README.md +257 -11
  3. package/capability/BRICK.md +1 -1
  4. package/capability/index.mjs +154 -13
  5. package/cli.mjs +426 -41
  6. package/package.json +15 -3
  7. package/plugin.json +1457 -119
  8. package/skills/meta-harness/SKILL.md +63 -25
  9. package/src/adoption.mjs +102 -0
  10. package/src/agent-user.mjs +194 -0
  11. package/src/alerts.mjs +220 -14
  12. package/src/cascade.mjs +185 -0
  13. package/src/chat.mjs +80 -0
  14. package/src/codex-models.mjs +54 -0
  15. package/src/compat-harness.mjs +117 -0
  16. package/src/control.mjs +145 -0
  17. package/src/coordinator.mjs +267 -358
  18. package/src/dispatch-request.mjs +76 -0
  19. package/src/dispatch.mjs +119 -0
  20. package/src/documentation-authority.mjs +57 -0
  21. package/src/documentation.mjs +120 -32
  22. package/src/executor.mjs +101 -22
  23. package/src/gate-adapters/agy.mjs +155 -0
  24. package/src/gate-adapters/claude.mjs +303 -0
  25. package/src/gate-adapters/cline.mjs +111 -0
  26. package/src/gate-adapters/codex.mjs +164 -0
  27. package/src/gate-adapters/cursor.mjs +164 -0
  28. package/src/gate-adapters/devin.mjs +116 -0
  29. package/src/gate-adapters/dsh.mjs +284 -0
  30. package/src/gate-adapters/grok.mjs +112 -0
  31. package/src/gate-adapters/hermes.mjs +217 -0
  32. package/src/gate-adapters/hook-files.mjs +156 -0
  33. package/src/gate-adapters/index.mjs +131 -0
  34. package/src/gate-adapters/openclaw-plugin/gate-client.js +205 -0
  35. package/src/gate-adapters/openclaw-plugin/index.js +25 -0
  36. package/src/gate-adapters/openclaw-plugin/openclaw.plugin.json +9 -0
  37. package/src/gate-adapters/openclaw-plugin/package.json +15 -0
  38. package/src/gate-adapters/openclaw.mjs +288 -0
  39. package/src/gate-adapters/pi.mjs +146 -0
  40. package/src/gate.mjs +18 -0
  41. package/src/harness-updates.mjs +170 -0
  42. package/src/included-usage.mjs +344 -0
  43. package/src/jobs.mjs +135 -0
  44. package/src/json-reply.mjs +22 -0
  45. package/src/learner.mjs +97 -67
  46. package/src/maintenance.mjs +18 -0
  47. package/src/mcp-server.mjs +228 -0
  48. package/src/model-catalog.mjs +195 -0
  49. package/src/model-selection.mjs +67 -0
  50. package/src/paths.mjs +23 -0
  51. package/src/pool.mjs +69 -0
  52. package/src/process-manager.mjs +246 -0
  53. package/src/process-worker.mjs +18 -0
  54. package/src/reasoning.mjs +231 -0
  55. package/src/remote-operation.mjs +76 -0
  56. package/src/review.mjs +241 -0
  57. package/src/reviews.mjs +25 -0
  58. package/src/router-benchmark-corpus.mjs +16 -0
  59. package/src/router-benchmark.mjs +208 -0
  60. package/src/router.mjs +265 -346
  61. package/src/runtime.mjs +30 -8
  62. package/src/session/claude.mjs +358 -0
  63. package/src/session/codex.mjs +501 -0
  64. package/src/session/result.mjs +90 -0
  65. package/src/session/resume.mjs +393 -0
  66. package/src/session/run.mjs +258 -0
  67. package/src/session-jobs.mjs +77 -0
  68. package/src/setup.mjs +6 -3
  69. package/src/ssss-store.mjs +20 -0
  70. package/src/telemetry.mjs +267 -0
  71. package/src/termination.mjs +28 -0
  72. package/src/threads.mjs +150 -0
  73. package/src/usage-queue.mjs +137 -0
  74. package/src/verify-ssss.mjs +102 -0
  75. package/src/worker.mjs +955 -84
  76. package/src/worktree.mjs +244 -0
  77. package/ui/chunks/adapter-docs-freshness.md +16 -0
  78. package/ui/chunks/chat-handoff.md +26 -0
  79. package/ui/chunks/fleet-maintenance.md +21 -0
  80. package/ui/chunks/harness-inventory.md +21 -0
  81. package/ui/chunks/included-access.md +18 -0
  82. package/ui/chunks/included-usage-verification.md +15 -0
  83. package/ui/chunks/independent-review.md +17 -0
  84. package/ui/chunks/managed-execution.md +20 -0
  85. package/ui/chunks/official-documentation.md +18 -0
  86. package/ui/chunks/quota-recovery.md +21 -0
  87. package/ui/chunks/review-routing-decision.md +16 -0
  88. package/ui/chunks/route-work.md +18 -0
  89. package/ui/chunks/routing-evidence.md +18 -0
  90. package/ui/chunks/run-ledger.md +18 -0
  91. package/ui/chunks/session-controls.md +16 -0
  92. package/ui/home.js +198 -0
  93. package/ui/DESIGN.md +0 -32
  94. package/ui/card.js +0 -845
@@ -0,0 +1,111 @@
1
+ /**
2
+ * Cline Agent SDK & plugin hook adapter.
3
+ * Official doc: https://docs.cline.bot/sdk/plugins.md
4
+ */
5
+ import fs from 'node:fs';
6
+ import path from 'node:path';
7
+ import os from 'node:os';
8
+
9
+ import { removeDeadGateFile } from './hook-files.mjs';
10
+
11
+ const ACK_COMMAND = 'total-recall tr-preflight --ack --task "<task>" --action read,edit,test';
12
+
13
+ const DEAD_FILE = (home) => path.join(home, 'Documents', 'Cline', 'Hooks', 'preflight-hook.json');
14
+
15
+ export const clineAdapter = {
16
+ id: 'cline',
17
+ level: 'not wired',
18
+ warnings: {
19
+ delivery: 'unconfirmed',
20
+ via: 'appendContext',
21
+ source: 'https://docs.cline.bot/sdk/plugins.md',
22
+ why: 'The documentation does not say how appendContext reaches the model.',
23
+ },
24
+ source: {
25
+ url: 'https://docs.cline.bot/sdk/plugins.md',
26
+ retrieved: '2026-11-04',
27
+ note: 'Cline SDK plugin beforeTool hooks; hookErrorMode default is ignore (fail-open)'
28
+ },
29
+ limits: [
30
+ 'Cline defaults hookErrorMode to ignore (fail-open); requires explicit strict config',
31
+ 'Returns { skip: true, reason } or { cancel: true } on denied calls'
32
+ ],
33
+
34
+ parse(input = {}) {
35
+ const event = input.event || 'beforeTool';
36
+ const toolName = input.toolName || input.tool || '';
37
+ const toolInput = input.input || input.params || input.toolInput || {};
38
+ const cwd = input.cwd || process.cwd();
39
+
40
+ let tool = 'other';
41
+ let command;
42
+ let filePath;
43
+
44
+ if (toolName === 'execute_command' || toolName === 'Bash' || toolName === 'shell') {
45
+ tool = 'shell';
46
+ command = toolInput.command || toolInput.cmd || '';
47
+ } else if (toolName === 'write_to_file' || toolName === 'replace_in_file' || toolName === 'Edit' || toolName === 'Write') {
48
+ tool = 'write';
49
+ filePath = toolInput.path || toolInput.file_path || '';
50
+ } else if (toolName === 'read_file' || toolName === 'list_files') {
51
+ tool = 'read';
52
+ filePath = toolInput.path || '';
53
+ }
54
+
55
+ return {
56
+ event,
57
+ tool,
58
+ command,
59
+ path: filePath,
60
+ cwd,
61
+ raw: input
62
+ };
63
+ },
64
+
65
+ emit(decision, event, cwd = process.cwd()) {
66
+ if (decision?.decision === 'allow') {
67
+ const payload = decision.warning ? { skip: false, cancel: false, appendContext: decision.warning } : { skip: false, cancel: false };
68
+ return { stdout: `${JSON.stringify(payload)}\n`, exitCode: 0 };
69
+ }
70
+
71
+ const reason = decision?.reason || `TR-PREFLIGHT gate: action denied. Run: ${decision?.fix || ACK_COMMAND}`;
72
+ const payload = {
73
+ skip: true,
74
+ cancel: true,
75
+ reason,
76
+ errorMessage: reason,
77
+ fix: decision?.fix || ACK_COMMAND
78
+ };
79
+ return { stdout: `${JSON.stringify(payload)}\n`, exitCode: 2 };
80
+ },
81
+
82
+ async run({ stdin, decideWith }) {
83
+ const parsed = this.parse(stdin);
84
+ const decision = decideWith({
85
+ tool: parsed.tool,
86
+ command: parsed.command,
87
+ path: parsed.path,
88
+ cwd: parsed.cwd
89
+ });
90
+ return this.emit(decision, parsed.event, parsed.cwd);
91
+ },
92
+
93
+ install({ home = os.homedir(), dryRun = false } = {}) {
94
+ const removed = removeDeadGateFile(DEAD_FILE(home), 'cline', { dryRun });
95
+ return { settings: null, added: [], removed, unsupported: 'Cline runs hooks from an SDK plugin, and no plugin is built yet. Cline is not installed on any machine this was tested on.' };
96
+ },
97
+
98
+ verify({ home = os.homedir() } = {}) {
99
+ const installed = false;
100
+ const out = this.emit({ decision: 'deny', reason: 'receipt missing', fix: ACK_COMMAND }, 'beforeTool', '/nonexistent-directory-without-receipt');
101
+ return {
102
+ installed,
103
+ exercised: out.exitCode === 2 && out.stdout.includes('"cancel":true'),
104
+ level: this.level,
105
+ native: out.stdout.trim(),
106
+ note: 'Cline runs hooks from an SDK plugin, and no plugin is built yet. Cline is not installed on any machine this was tested on.'
107
+ };
108
+ }
109
+ };
110
+
111
+ export default clineAdapter;
@@ -0,0 +1,164 @@
1
+ /**
2
+ * OpenAI Codex tool gate and lifecycle hooks.
3
+ * Official doc: https://learn.chatgpt.com/docs/hooks
4
+ */
5
+ import fs from 'node:fs';
6
+ import path from 'node:path';
7
+ import os from 'node:os';
8
+
9
+ import { hasGate, mergeGate, readJsonFile, readJsonQuietly, writeJsonFile } from './hook-files.mjs';
10
+
11
+ const lifecycle = {
12
+ UserPromptSubmit: { verb: 'remind' },
13
+ SessionStart: { verb: 'session-start', matcher: 'compact|clear' },
14
+ };
15
+
16
+ function lifecycleCommand(verb) {
17
+ return 'total-recall preflight ' + verb + ' --harness codex';
18
+ }
19
+
20
+ function mergeLifecycle(groups, { verb, matcher }, remove) {
21
+ const entries = Array.isArray(groups) ? groups : [];
22
+ const command = lifecycleCommand(verb);
23
+ const owned = hook => hook?.type === 'command' && hook.command === command;
24
+ if (!remove) {
25
+ if (entries.some(group => group?.matcher === matcher && Array.isArray(group?.hooks) && group.hooks.some(owned))) {
26
+ return { entries, changed: false };
27
+ }
28
+ return { entries: [...entries, { ...(matcher && { matcher }), hooks: [{ type: 'command', command, timeout: 10 }] }], changed: true };
29
+ }
30
+ let changed = false;
31
+ const kept = entries.flatMap(group => {
32
+ if (!Array.isArray(group?.hooks) || !group.hooks.some(owned)) return [group];
33
+ changed = true;
34
+ const hooks = group.hooks.filter(hook => !owned(hook));
35
+ return hooks.length ? [{ ...group, hooks }] : [];
36
+ });
37
+ return { entries: kept, changed };
38
+ }
39
+
40
+ const ACK_COMMAND = 'total-recall tr-preflight --ack --task "<task>" --action read,edit,test';
41
+
42
+ export const codexAdapter = {
43
+ id: 'codex',
44
+ level: 'enforced',
45
+ warnings: {
46
+ delivery: 'documented',
47
+ via: 'hookSpecificOutput.additionalContext',
48
+ source: 'https://learn.chatgpt.com/docs/hooks.md',
49
+ },
50
+ source: {
51
+ url: 'https://learn.chatgpt.com/docs/hooks',
52
+ retrieved: '2026-11-21',
53
+ note: 'Codex CLI hooks in ~/.codex/hooks.json or inline in config.toml'
54
+ },
55
+ limits: [
56
+ 'Non-managed hooks require trust in config.toml [hooks.state]',
57
+ 'Blocks with exit 2 and decision: "block" / permissionDecision: "deny"'
58
+ ],
59
+
60
+ parse(input = {}) {
61
+ const event = input.hook_event_name || input.event || 'PreToolUse';
62
+ const toolName = input.tool_name || input.toolName || '';
63
+ const toolInput = input.tool_input || input.toolInput || {};
64
+ const cwd = input.cwd || process.cwd();
65
+
66
+ let tool = 'other';
67
+ let command;
68
+ let filePath;
69
+
70
+ if (toolName === 'exec_command' || toolName === 'Bash' || toolName === 'shell') {
71
+ tool = 'shell';
72
+ command = toolInput.cmd || toolInput.command || '';
73
+ } else if (toolName === 'apply_patch' || toolName === 'Edit' || toolName === 'Write') {
74
+ tool = 'write';
75
+ filePath = toolInput.path || toolInput.file_path || '';
76
+ } else if (toolName === 'read_file' || toolName === 'view_image' || toolName === 'Read' || /^(Glob|Grep)$/.test(toolName)) {
77
+ tool = 'read';
78
+ filePath = toolInput.path || toolInput.file_path || '';
79
+ } else if (toolName === 'spawn_agent' || toolName === 'Agent' || /^collaboration/.test(toolName)) {
80
+ // Real sessions report these with the dot removed, such as collaborationsend_message.
81
+ tool = 'agent';
82
+ } else if (/^mcp__/.test(toolName)) {
83
+ tool = 'mcp';
84
+ } else if (/^web/.test(toolName)) {
85
+ tool = 'web';
86
+ } else if (toolName === 'update_plan' || /^clock/.test(toolName)) {
87
+ tool = 'meta';
88
+ }
89
+
90
+ return {
91
+ event,
92
+ tool,
93
+ command,
94
+ path: filePath,
95
+ cwd,
96
+ raw: input
97
+ };
98
+ },
99
+
100
+ emit(decision, event, cwd = process.cwd()) {
101
+ if (decision?.decision === 'allow') {
102
+ if (decision.warning) {
103
+ const payload = { hookSpecificOutput: { hookEventName: 'PreToolUse', additionalContext: decision.warning } };
104
+ return { stdout: `${JSON.stringify(payload)}\n`, exitCode: 0 };
105
+ }
106
+ return { stdout: '', exitCode: 0 };
107
+ }
108
+
109
+ const reason = decision?.reason || `TR-PREFLIGHT gate: action denied. Run: ${decision?.fix || ACK_COMMAND}`;
110
+ const payload = {
111
+ decision: 'block',
112
+ hookSpecificOutput: {
113
+ permissionDecision: 'deny',
114
+ permissionDecisionReason: reason
115
+ },
116
+ reason,
117
+ fix: decision?.fix || ACK_COMMAND
118
+ };
119
+ return { stdout: `${JSON.stringify(payload)}\n`, exitCode: 2 };
120
+ },
121
+
122
+ async run({ stdin, decideWith }) {
123
+ const parsed = this.parse(stdin);
124
+ const decision = decideWith({
125
+ tool: parsed.tool,
126
+ command: parsed.command,
127
+ path: parsed.path,
128
+ cwd: parsed.cwd
129
+ });
130
+ return this.emit(decision, parsed.event, parsed.cwd);
131
+ },
132
+
133
+ install({ home = os.homedir(), dryRun = false, remove = false, off = false } = {}) {
134
+ const hooksPath = path.join(home, '.codex', 'hooks.json');
135
+ const config = readJsonFile(hooksPath, { hooks: {} });
136
+ config.hooks = config.hooks || {};
137
+ // A hand-made gate from an earlier release stays until this one is trusted in /hooks,
138
+ // because Codex skips a new hook until then.
139
+ const { groups, added, removed } = mergeGate(config.hooks.PreToolUse, 'codex', { remove: remove || off });
140
+ config.hooks.PreToolUse = groups;
141
+ for (const [event, entry] of Object.entries(lifecycle)) {
142
+ const result = mergeLifecycle(config.hooks[event], entry, remove || off);
143
+ if (!result.changed) continue;
144
+ config.hooks[event] = result.entries;
145
+ (remove || off ? removed : added).push('managed ' + event + ' lifecycle hook');
146
+ }
147
+ if (!dryRun && (added.length || removed.length)) writeJsonFile(hooksPath, config);
148
+ return { settings: hooksPath, added, removed, note: this.limits[0] };
149
+ },
150
+
151
+ verify({ home = os.homedir() } = {}) {
152
+ const installed = hasGate(readJsonQuietly(path.join(home, '.codex', 'hooks.json')).hooks?.PreToolUse, 'codex');
153
+ const out = this.emit({ decision: 'deny', reason: 'receipt missing', fix: ACK_COMMAND }, 'PreToolUse', '/nonexistent-directory-without-receipt');
154
+ return {
155
+ installed,
156
+ exercised: out.exitCode === 2 && out.stdout.includes('"permissionDecision":"deny"'),
157
+ level: this.level,
158
+ native: out.stdout.trim(),
159
+ note: 'Codex skips a new or changed hook until it is trusted in /hooks.'
160
+ };
161
+ }
162
+ };
163
+
164
+ export default codexAdapter;
@@ -0,0 +1,164 @@
1
+ /**
2
+ * Cursor IDE & agent hook adapter.
3
+ * Official doc: https://cursor.com/docs/hooks
4
+ */
5
+ import fs from 'node:fs';
6
+ import path from 'node:path';
7
+ import os from 'node:os';
8
+
9
+ import { gateBinary, gateLauncherScript, writeGateLauncher, readJsonFile, readJsonQuietly, writeJsonFile, LAUNCHER_HOOK_TIMEOUT_SECONDS } from './hook-files.mjs';
10
+
11
+ const ACK_COMMAND = 'total-recall tr-preflight --ack --task "<task>" --action read,edit,test';
12
+
13
+ const GATE = 'preflight gate --harness cursor';
14
+ /** Named like the command, and outside its package, so an update cannot remove what the hook runs. */
15
+ export const launcherPath = (home = os.homedir()) => path.join(home, '.cursor', 'hooks', 'total-recall');
16
+ const isGate = (row) => String(row?.command || '').includes(GATE);
17
+
18
+ export const cursorAdapter = {
19
+ id: 'cursor',
20
+ level: 'enforced (unverified live)',
21
+ warnings: {
22
+ delivery: 'unconfirmed',
23
+ via: 'agent_message',
24
+ source: 'https://cursor.com/docs/agent/hooks',
25
+ why: 'The documentation ties agent_message to denial for preToolUse, so delivery on allow is unconfirmed.',
26
+ },
27
+ source: {
28
+ url: 'https://cursor.com/docs/hooks',
29
+ retrieved: '2026-11-04',
30
+ note: 'Cursor hooks in ~/.cursor/hooks.json and .cursor/hooks.json'
31
+ },
32
+ limits: [
33
+ 'Cursor defaults to fail-open unless failClosed: true is set',
34
+ 'User-level hooks apply across workspaces; requires failClosed flag',
35
+ 'A failClosed hook whose command is missing blocks every call, so the hook runs a launcher outside the Total Recall package'
36
+ ],
37
+
38
+ parse(input = {}) {
39
+ const event = input.hook_event_name || input.event || input.hookEventName || 'preToolUse';
40
+ const toolName = input.tool_name || input.toolName || input.tool || '';
41
+ const toolInput = input.tool_input || input.toolInput || input.input || {};
42
+ const cwd = input.cwd || input.workspace_roots?.[0] || input.workspaceRoot || process.cwd();
43
+
44
+ let tool = 'other';
45
+ let command;
46
+ let filePath;
47
+
48
+ if (event === 'beforeShellExecution' || toolName === 'Shell' || toolName === 'execute' || toolName === 'terminal' || toolName === 'Bash') {
49
+ tool = 'shell';
50
+ command = input.command || toolInput.command || toolInput.cmd || '';
51
+ } else if (event === 'beforeReadFile' || toolName === 'readFile' || toolName === 'Read' || toolName === 'Grep') {
52
+ tool = 'read';
53
+ filePath = input.file || input.path || toolInput.file_path || toolInput.file || toolInput.path || '';
54
+ } else if (toolName === 'edit' || toolName === 'Write' || toolName === 'Edit' || toolName === 'Delete') {
55
+ tool = 'write';
56
+ filePath = input.file || input.path || toolInput.file_path || toolInput.file || toolInput.path || '';
57
+ } else if (toolName === 'Task') {
58
+ tool = 'agent';
59
+ } else if (toolName.startsWith('MCP:')) {
60
+ tool = 'mcp';
61
+ }
62
+
63
+ return {
64
+ event,
65
+ tool,
66
+ command,
67
+ path: filePath,
68
+ cwd,
69
+ raw: input
70
+ };
71
+ },
72
+
73
+ emit(decision, event, cwd = process.cwd()) {
74
+ if (decision?.decision === 'allow') {
75
+ const payload = decision.warning ? { permission: 'allow', agent_message: decision.warning } : { permission: 'allow' };
76
+ return { stdout: `${JSON.stringify(payload)}\n`, exitCode: 0 };
77
+ }
78
+
79
+ const reason = decision?.reason || `TR-PREFLIGHT gate: action denied. Run: ${decision?.fix || ACK_COMMAND}`;
80
+ const payload = {
81
+ permission: 'deny',
82
+ user_message: reason,
83
+ agent_message: reason
84
+ };
85
+ return { stdout: `${JSON.stringify(payload)}\n`, exitCode: 2 };
86
+ },
87
+
88
+ async run({ stdin, decideWith }) {
89
+ const parsed = this.parse(stdin);
90
+ const decision = decideWith({
91
+ tool: parsed.tool,
92
+ command: parsed.command,
93
+ path: parsed.path,
94
+ cwd: parsed.cwd
95
+ });
96
+ return this.emit(decision, parsed.event, parsed.cwd);
97
+ },
98
+
99
+ install({ home = os.homedir(), dryRun = false, remove = false, off = false, env = process.env } = {}) {
100
+ const hooksPath = path.join(home, '.cursor', 'hooks.json');
101
+ const launcher = launcherPath(home);
102
+ const config = readJsonFile(hooksPath, {});
103
+ const added = [];
104
+ const removed = [];
105
+ if (remove || off) {
106
+ const gates = config.hooks?.preToolUse;
107
+ const kept = Array.isArray(gates) ? gates.filter((row) => !isGate(row)) : [];
108
+ if (Array.isArray(gates) && kept.length !== gates.length) {
109
+ config.hooks.preToolUse = kept;
110
+ removed.push('managed gate');
111
+ if (!dryRun) writeJsonFile(hooksPath, config);
112
+ }
113
+ // Only after the hook line is gone: a line left pointing at a deleted launcher blocks every call.
114
+ if (fs.existsSync(launcher)) {
115
+ if (!dryRun) fs.rmSync(launcher);
116
+ removed.push('gate launcher');
117
+ }
118
+ return { settings: hooksPath, added, removed };
119
+ }
120
+ config.version = config.version || 1;
121
+ // failClosed is a field on each hook, not on the file.
122
+ if ('failClosed' in config) { delete config.failClosed; removed.push('file-level failClosed, which Cursor does not read'); }
123
+ config.hooks = config.hooks || {};
124
+ // The launcher goes in before the hook line that names it.
125
+ const wrote = writeGateLauncher(launcher, gateLauncherScript(gateBinary('cursor', env),
126
+ (message) => ({ permission: 'deny', user_message: message, agent_message: message })), { dryRun });
127
+ if (wrote) added.push(wrote);
128
+ const command = `${launcher} ${GATE}`;
129
+ const list = config.hooks.preToolUse = config.hooks.preToolUse || [];
130
+ const entry = list.find(isGate);
131
+ if (!entry) {
132
+ list.push({ command, matcher: '*', timeout: LAUNCHER_HOOK_TIMEOUT_SECONDS, failClosed: true });
133
+ added.push('managed preToolUse gate (failClosed: true)');
134
+ } else {
135
+ if (entry.failClosed !== true) {
136
+ entry.failClosed = true;
137
+ added.push('failClosed on the managed gate');
138
+ }
139
+ // An entry that runs the command directly is the one an update breaks.
140
+ if (entry.command !== command) {
141
+ entry.command = command;
142
+ entry.timeout = LAUNCHER_HOOK_TIMEOUT_SECONDS;
143
+ added.push('managed gate (now runs through the launcher)');
144
+ }
145
+ }
146
+ if (!dryRun && (added.length || removed.length)) writeJsonFile(hooksPath, config);
147
+ return { settings: hooksPath, added, removed };
148
+ },
149
+
150
+ verify({ home = os.homedir() } = {}) {
151
+ // A hook line that names a launcher which is not there blocks every call, so it is not installed.
152
+ const installed = (readJsonQuietly(path.join(home, '.cursor', 'hooks.json')).hooks?.preToolUse || []).some((row) => isGate(row) && row.failClosed === true
153
+ && (!String(row.command).includes(launcherPath(home)) || fs.existsSync(launcherPath(home))));
154
+ const out = this.emit({ decision: 'deny', reason: 'receipt missing', fix: ACK_COMMAND }, 'preToolUse', '/nonexistent-directory-without-receipt');
155
+ return {
156
+ installed,
157
+ exercised: out.exitCode === 2 && out.stdout.includes('"permission":"deny"'),
158
+ level: this.level,
159
+ native: out.stdout.trim()
160
+ };
161
+ }
162
+ };
163
+
164
+ export default cursorAdapter;
@@ -0,0 +1,116 @@
1
+ /**
2
+ * Devin CLI & Windsurf Cascade hook adapter.
3
+ * Official doc: https://docs.devin.ai/cli/extensibility/hooks/lifecycle-hooks
4
+ */
5
+ import fs from 'node:fs';
6
+ import path from 'node:path';
7
+ import os from 'node:os';
8
+
9
+ import { hasGate, mergeGate, readJsonFile, readJsonQuietly, removeDeadGateFile, writeJsonFile } from './hook-files.mjs';
10
+
11
+ const ACK_COMMAND = 'total-recall tr-preflight --ack --task "<task>" --action read,edit,test';
12
+
13
+ /** Devin's documented tool names. Anything else counts as a working tool. */
14
+ const TOOL_CLASSES = {
15
+ exec: 'shell', Bash: 'shell', shell: 'shell',
16
+ read: 'read', notebook_read: 'read', grep: 'read', glob: 'read', get_output: 'read',
17
+ write: 'write', edit: 'write', apply_patch: 'write', notebook_edit: 'write',
18
+ webfetch: 'web',
19
+ run_subagent: 'agent', read_subagent: 'agent',
20
+ todo_write: 'meta', exit_plan_mode: 'meta', skill: 'meta', request_scope: 'meta',
21
+ mcp_list_servers: 'meta', mcp_list_tools: 'meta', mcp_call_tool: 'mcp', mcp_read_resource: 'mcp',
22
+ };
23
+
24
+ export const devinAdapter = {
25
+ id: 'devin',
26
+ aliases: ['windsurf'],
27
+ level: 'enforced (unverified live)',
28
+ warnings: {
29
+ delivery: 'none',
30
+ via: null,
31
+ source: 'https://docs.devin.ai/cli/extensibility/hooks/lifecycle-hooks',
32
+ why: 'additionalContext is documented only for UserPromptSubmit and SessionStart.',
33
+ },
34
+ source: {
35
+ url: 'https://docs.devin.ai/cli/extensibility/hooks/lifecycle-hooks',
36
+ retrieved: '2026-11-04',
37
+ note: 'Devin/Windsurf hooks in ~/.config/devin/config.json or .devin/hooks.v1.json'
38
+ },
39
+ limits: [
40
+ 'Hooks do not run when Devin operates in Restricted Mode',
41
+ 'Exit 2 blocks tool execution in PreToolUse'
42
+ ],
43
+
44
+ parse(input = {}) {
45
+ const event = input.hook_event_name || input.event || input.hookEventName || 'PreToolUse';
46
+ const toolName = input.tool || input.toolName || input.tool_name || '';
47
+ const toolInput = input.tool_input || input.toolInput || input.input || {};
48
+ const cwd = input.cwd || process.cwd();
49
+
50
+ const tool = /^mcp__/.test(toolName) ? 'mcp' : (TOOL_CLASSES[toolName] || 'other');
51
+ let command;
52
+ let filePath;
53
+
54
+ if (tool === 'shell') command = toolInput.cmd || toolInput.command || '';
55
+ else if (tool === 'write' || tool === 'read') filePath = toolInput.file_path || toolInput.path || toolInput.file || '';
56
+
57
+ return {
58
+ event,
59
+ tool,
60
+ command,
61
+ path: filePath,
62
+ cwd,
63
+ raw: input
64
+ };
65
+ },
66
+
67
+ emit(decision, event, cwd = process.cwd()) {
68
+ if (decision?.decision === 'allow') {
69
+ return { stdout: '', exitCode: 0 };
70
+ }
71
+
72
+ const reason = decision?.reason || `TR-PREFLIGHT gate: action denied. Run: ${decision?.fix || ACK_COMMAND}`;
73
+ const payload = {
74
+ decision: 'deny',
75
+ reason,
76
+ fix: decision?.fix || ACK_COMMAND
77
+ };
78
+ return { stdout: `${JSON.stringify(payload)}\n`, exitCode: 2 };
79
+ },
80
+
81
+ async run({ stdin, decideWith }) {
82
+ const parsed = this.parse(stdin);
83
+ const decision = decideWith({
84
+ tool: parsed.tool,
85
+ command: parsed.command,
86
+ path: parsed.path,
87
+ cwd: parsed.cwd
88
+ });
89
+ return this.emit(decision, parsed.event, parsed.cwd);
90
+ },
91
+
92
+ install({ home = os.homedir(), dryRun = false, remove = false, off = false } = {}) {
93
+ const devinDir = path.join(home, '.config', 'devin');
94
+ const configPath = path.join(devinDir, 'config.json');
95
+ const config = readJsonFile(configPath, {});
96
+ config.hooks = config.hooks || {};
97
+ const { groups, added, removed } = mergeGate(config.hooks.PreToolUse, 'devin', { remove: remove || off });
98
+ config.hooks.PreToolUse = groups;
99
+ if (!dryRun && (added.length || removed.length)) writeJsonFile(configPath, config);
100
+ removed.push(...removeDeadGateFile(path.join(devinDir, 'hooks.json'), 'devin', { dryRun }));
101
+ return { settings: configPath, added, removed };
102
+ },
103
+
104
+ verify({ home = os.homedir() } = {}) {
105
+ const installed = hasGate(readJsonQuietly(path.join(home, '.config', 'devin', 'config.json')).hooks?.PreToolUse, 'devin');
106
+ const out = this.emit({ decision: 'deny', reason: 'receipt missing', fix: ACK_COMMAND }, 'PreToolUse', '/nonexistent-directory-without-receipt');
107
+ return {
108
+ installed,
109
+ exercised: out.exitCode === 2 && out.stdout.includes('"decision":"deny"'),
110
+ level: this.level,
111
+ native: out.stdout.trim()
112
+ };
113
+ }
114
+ };
115
+
116
+ export default devinAdapter;