@namzu/sdk 57.0.0 → 58.0.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/dist/agents/QueryAgent.d.ts.map +1 -1
- package/dist/agents/QueryAgent.js +3 -0
- package/dist/agents/QueryAgent.js.map +1 -1
- package/dist/agents/file-definitions.d.ts +35 -4
- package/dist/agents/file-definitions.d.ts.map +1 -1
- package/dist/agents/file-definitions.js +98 -8
- package/dist/agents/file-definitions.js.map +1 -1
- package/dist/authorization/protected-paths.d.ts +9 -0
- package/dist/authorization/protected-paths.d.ts.map +1 -1
- package/dist/authorization/protected-paths.js +29 -3
- package/dist/authorization/protected-paths.js.map +1 -1
- package/dist/compaction/index.d.ts +1 -0
- package/dist/compaction/index.d.ts.map +1 -1
- package/dist/compaction/index.js.map +1 -1
- package/dist/compaction/manual.d.ts +7 -0
- package/dist/compaction/manual.d.ts.map +1 -1
- package/dist/compaction/manual.js +31 -12
- package/dist/compaction/manual.js.map +1 -1
- package/dist/compaction/model-summary.d.ts +101 -0
- package/dist/compaction/model-summary.d.ts.map +1 -0
- package/dist/compaction/model-summary.js +333 -0
- package/dist/compaction/model-summary.js.map +1 -0
- package/dist/compaction/verifier.d.ts +6 -1
- package/dist/compaction/verifier.d.ts.map +1 -1
- package/dist/compaction/verifier.js +3 -3
- package/dist/compaction/verifier.js.map +1 -1
- package/dist/config/runtime.d.ts +62 -0
- package/dist/config/runtime.d.ts.map +1 -1
- package/dist/config/runtime.js +16 -0
- package/dist/config/runtime.js.map +1 -1
- package/dist/connector/mcp/client.d.ts +8 -0
- package/dist/connector/mcp/client.d.ts.map +1 -1
- package/dist/connector/mcp/client.js +75 -2
- package/dist/connector/mcp/client.js.map +1 -1
- package/dist/constants/mcp/index.d.ts +2 -0
- package/dist/constants/mcp/index.d.ts.map +1 -1
- package/dist/constants/mcp/index.js +2 -0
- package/dist/constants/mcp/index.js.map +1 -1
- package/dist/constants/plugin/index.d.ts +2 -0
- package/dist/constants/plugin/index.d.ts.map +1 -1
- package/dist/constants/plugin/index.js +2 -0
- package/dist/constants/plugin/index.js.map +1 -1
- package/dist/manager/agent/lifecycle.d.ts +1 -1
- package/dist/manager/agent/lifecycle.d.ts.map +1 -1
- package/dist/manager/agent/lifecycle.js +25 -4
- package/dist/manager/agent/lifecycle.js.map +1 -1
- package/dist/manager/session/turn-recorder.d.ts.map +1 -1
- package/dist/manager/session/turn-recorder.js +2 -1
- package/dist/manager/session/turn-recorder.js.map +1 -1
- package/dist/persona/assembler.d.ts.map +1 -1
- package/dist/persona/assembler.js +2 -2
- package/dist/persona/assembler.js.map +1 -1
- package/dist/plugin/index.d.ts +1 -1
- package/dist/plugin/index.d.ts.map +1 -1
- package/dist/plugin/lifecycle.d.ts +8 -1
- package/dist/plugin/lifecycle.d.ts.map +1 -1
- package/dist/plugin/lifecycle.js +9 -2
- package/dist/plugin/lifecycle.js.map +1 -1
- package/dist/plugin/shell-hook-http.d.ts +39 -0
- package/dist/plugin/shell-hook-http.d.ts.map +1 -0
- package/dist/plugin/shell-hook-http.js +163 -0
- package/dist/plugin/shell-hook-http.js.map +1 -0
- package/dist/plugin/shell-hook.d.ts +93 -11
- package/dist/plugin/shell-hook.d.ts.map +1 -1
- package/dist/plugin/shell-hook.js +223 -39
- package/dist/plugin/shell-hook.js.map +1 -1
- package/dist/prompt/coding-agent-doctrine.d.ts +1 -1
- package/dist/prompt/coding-agent-doctrine.d.ts.map +1 -1
- package/dist/prompt/coding-agent-doctrine.js +2 -1
- package/dist/prompt/coding-agent-doctrine.js.map +1 -1
- package/dist/public-runtime.d.ts +3 -2
- package/dist/public-runtime.d.ts.map +1 -1
- package/dist/public-runtime.js +2 -2
- package/dist/public-runtime.js.map +1 -1
- package/dist/public-tools.d.ts +1 -0
- package/dist/public-tools.d.ts.map +1 -1
- package/dist/public-tools.js +2 -0
- package/dist/public-tools.js.map +1 -1
- package/dist/public-types.d.ts +1 -1
- package/dist/public-types.d.ts.map +1 -1
- package/dist/runtime/query/executor.d.ts +4 -0
- package/dist/runtime/query/executor.d.ts.map +1 -1
- package/dist/runtime/query/executor.js +47 -9
- package/dist/runtime/query/executor.js.map +1 -1
- package/dist/runtime/query/index.d.ts +8 -0
- package/dist/runtime/query/index.d.ts.map +1 -1
- package/dist/runtime/query/index.js +29 -1
- package/dist/runtime/query/index.js.map +1 -1
- package/dist/runtime/query/iteration/index.d.ts.map +1 -1
- package/dist/runtime/query/iteration/index.js +6 -2
- package/dist/runtime/query/iteration/index.js.map +1 -1
- package/dist/runtime/query/iteration/phases/compaction-breaker.d.ts +18 -8
- package/dist/runtime/query/iteration/phases/compaction-breaker.d.ts.map +1 -1
- package/dist/runtime/query/iteration/phases/compaction-breaker.js +33 -9
- package/dist/runtime/query/iteration/phases/compaction-breaker.js.map +1 -1
- package/dist/runtime/query/iteration/phases/compaction.d.ts.map +1 -1
- package/dist/runtime/query/iteration/phases/compaction.js +52 -5
- package/dist/runtime/query/iteration/phases/compaction.js.map +1 -1
- package/dist/runtime/query/iteration/phases/context.d.ts +5 -0
- package/dist/runtime/query/iteration/phases/context.d.ts.map +1 -1
- package/dist/runtime/query/iteration/phases/context.js.map +1 -1
- package/dist/runtime/query/iteration/phases/tool-review.d.ts.map +1 -1
- package/dist/runtime/query/iteration/phases/tool-review.js +70 -3
- package/dist/runtime/query/iteration/phases/tool-review.js.map +1 -1
- package/dist/runtime/query/path-escalation.d.ts +2 -0
- package/dist/runtime/query/path-escalation.d.ts.map +1 -1
- package/dist/runtime/query/path-escalation.js +7 -4
- package/dist/runtime/query/path-escalation.js.map +1 -1
- package/dist/runtime/query/plugin-hooks.js +2 -2
- package/dist/runtime/query/plugin-hooks.js.map +1 -1
- package/dist/runtime/query/prepare-turn.d.ts +2 -0
- package/dist/runtime/query/prepare-turn.d.ts.map +1 -1
- package/dist/runtime/query/prepare-turn.js +25 -0
- package/dist/runtime/query/prepare-turn.js.map +1 -1
- package/dist/runtime/query/review-policy.d.ts +3 -2
- package/dist/runtime/query/review-policy.d.ts.map +1 -1
- package/dist/runtime/query/review-policy.js +32 -13
- package/dist/runtime/query/review-policy.js.map +1 -1
- package/dist/scheduler/local.js +1 -1
- package/dist/scheduler/local.js.map +1 -1
- package/dist/session/retention/archive.js +1 -1
- package/dist/session/retention/archive.js.map +1 -1
- package/dist/session/workspace/driver.d.ts +6 -0
- package/dist/session/workspace/driver.d.ts.map +1 -1
- package/dist/session/workspace/git-worktree.d.ts.map +1 -1
- package/dist/session/workspace/git-worktree.js +28 -0
- package/dist/session/workspace/git-worktree.js.map +1 -1
- package/dist/skills/index.d.ts +1 -1
- package/dist/skills/index.d.ts.map +1 -1
- package/dist/skills/index.js +1 -1
- package/dist/skills/index.js.map +1 -1
- package/dist/skills/loader.d.ts +7 -0
- package/dist/skills/loader.d.ts.map +1 -1
- package/dist/skills/loader.js +53 -0
- package/dist/skills/loader.js.map +1 -1
- package/dist/skills/registry.d.ts +1 -1
- package/dist/skills/registry.d.ts.map +1 -1
- package/dist/skills/registry.js +2 -1
- package/dist/skills/registry.js.map +1 -1
- package/dist/tools/builtins/bash-cwd.d.ts +52 -0
- package/dist/tools/builtins/bash-cwd.d.ts.map +1 -0
- package/dist/tools/builtins/bash-cwd.js +127 -0
- package/dist/tools/builtins/bash-cwd.js.map +1 -0
- package/dist/tools/builtins/bash.d.ts.map +1 -1
- package/dist/tools/builtins/bash.js +41 -6
- package/dist/tools/builtins/bash.js.map +1 -1
- package/dist/tools/builtins/bounded-file-read.d.ts +10 -0
- package/dist/tools/builtins/bounded-file-read.d.ts.map +1 -0
- package/dist/tools/builtins/bounded-file-read.js +67 -0
- package/dist/tools/builtins/bounded-file-read.js.map +1 -0
- package/dist/tools/builtins/grep.d.ts +6 -1
- package/dist/tools/builtins/grep.d.ts.map +1 -1
- package/dist/tools/builtins/grep.js +187 -24
- package/dist/tools/builtins/grep.js.map +1 -1
- package/dist/tools/builtins/read-file.d.ts +1 -0
- package/dist/tools/builtins/read-file.d.ts.map +1 -1
- package/dist/tools/builtins/read-file.js +113 -28
- package/dist/tools/builtins/read-file.js.map +1 -1
- package/dist/tools/builtins/read-media.d.ts +68 -0
- package/dist/tools/builtins/read-media.d.ts.map +1 -0
- package/dist/tools/builtins/read-media.js +397 -0
- package/dist/tools/builtins/read-media.js.map +1 -0
- package/dist/tools/builtins/search-tools.js +1 -1
- package/dist/tools/builtins/search-tools.js.map +1 -1
- package/dist/tools/builtins/skill.d.ts +4 -2
- package/dist/tools/builtins/skill.d.ts.map +1 -1
- package/dist/tools/builtins/skill.js +61 -2
- package/dist/tools/builtins/skill.js.map +1 -1
- package/dist/tools/builtins/sleep-guard.d.ts +15 -0
- package/dist/tools/builtins/sleep-guard.d.ts.map +1 -0
- package/dist/tools/builtins/sleep-guard.js +33 -0
- package/dist/tools/builtins/sleep-guard.js.map +1 -0
- package/dist/tools/builtins/view-image.d.ts +23 -1
- package/dist/tools/builtins/view-image.d.ts.map +1 -1
- package/dist/tools/builtins/view-image.js +66 -58
- package/dist/tools/builtins/view-image.js.map +1 -1
- package/dist/tools/file-read-tracker.d.ts.map +1 -1
- package/dist/tools/file-read-tracker.js +31 -0
- package/dist/tools/file-read-tracker.js.map +1 -1
- package/dist/toolsets/manager.js +3 -3
- package/dist/toolsets/manager.js.map +1 -1
- package/dist/types/agent/base.d.ts +8 -0
- package/dist/types/agent/base.d.ts.map +1 -1
- package/dist/types/agent/query.d.ts +2 -0
- package/dist/types/agent/query.d.ts.map +1 -1
- package/dist/types/agent/scheduler.d.ts +8 -0
- package/dist/types/agent/scheduler.d.ts.map +1 -1
- package/dist/types/agent/task.d.ts +6 -2
- package/dist/types/agent/task.d.ts.map +1 -1
- package/dist/types/agent/task.js.map +1 -1
- package/dist/types/connector/mcp.d.ts +46 -0
- package/dist/types/connector/mcp.d.ts.map +1 -1
- package/dist/types/hitl/index.d.ts +1 -1
- package/dist/types/plugin/index.d.ts +74 -7
- package/dist/types/plugin/index.d.ts.map +1 -1
- package/dist/types/plugin/index.js +12 -1
- package/dist/types/plugin/index.js.map +1 -1
- package/dist/types/session/sub-session.d.ts +6 -2
- package/dist/types/session/sub-session.d.ts.map +1 -1
- package/dist/types/skills/index.d.ts +36 -0
- package/dist/types/skills/index.d.ts.map +1 -1
- package/dist/types/skills/index.js +9 -0
- package/dist/types/skills/index.js.map +1 -1
- package/dist/types/tool/index.d.ts +37 -0
- package/dist/types/tool/index.d.ts.map +1 -1
- package/dist/types/tool/index.js.map +1 -1
- package/dist/types/workspace/ref.d.ts +2 -0
- package/dist/types/workspace/ref.d.ts.map +1 -1
- package/dist/utils/frontmatter.d.ts +12 -0
- package/dist/utils/frontmatter.d.ts.map +1 -1
- package/dist/utils/frontmatter.js +6 -0
- package/dist/utils/frontmatter.js.map +1 -1
- package/package.json +1 -1
- package/src/agents/QueryAgent.ts +3 -0
- package/src/agents/file-definitions.ts +126 -6
- package/src/authorization/protected-paths.ts +30 -2
- package/src/compaction/index.ts +1 -0
- package/src/compaction/manual.ts +68 -30
- package/src/compaction/model-summary.ts +412 -0
- package/src/compaction/verifier.ts +3 -3
- package/src/config/runtime.ts +16 -0
- package/src/connector/mcp/client.ts +87 -1
- package/src/constants/mcp/index.ts +3 -0
- package/src/constants/plugin/index.ts +2 -0
- package/src/manager/agent/lifecycle.ts +24 -5
- package/src/manager/session/turn-recorder.ts +2 -1
- package/src/persona/assembler.ts +2 -2
- package/src/plugin/index.ts +5 -0
- package/src/plugin/lifecycle.ts +16 -2
- package/src/plugin/shell-hook-http.ts +181 -0
- package/src/plugin/shell-hook.ts +386 -89
- package/src/prompt/coding-agent-doctrine.ts +2 -1
- package/src/public-runtime.ts +6 -0
- package/src/public-tools.ts +2 -0
- package/src/public-types.ts +5 -0
- package/src/runtime/query/executor.ts +54 -10
- package/src/runtime/query/index.ts +44 -0
- package/src/runtime/query/iteration/index.ts +11 -3
- package/src/runtime/query/iteration/phases/compaction-breaker.ts +38 -9
- package/src/runtime/query/iteration/phases/compaction.ts +67 -5
- package/src/runtime/query/iteration/phases/context.ts +6 -0
- package/src/runtime/query/iteration/phases/tool-review.ts +74 -3
- package/src/runtime/query/path-escalation.ts +11 -5
- package/src/runtime/query/plugin-hooks.ts +2 -2
- package/src/runtime/query/prepare-turn.ts +33 -0
- package/src/runtime/query/review-policy.ts +45 -16
- package/src/scheduler/local.ts +1 -1
- package/src/session/retention/archive.ts +1 -1
- package/src/session/workspace/driver.ts +6 -0
- package/src/session/workspace/git-worktree.ts +31 -0
- package/src/skills/index.ts +6 -1
- package/src/skills/loader.ts +54 -0
- package/src/skills/registry.ts +7 -6
- package/src/tools/builtins/bash-cwd.ts +156 -0
- package/src/tools/builtins/bash.ts +79 -34
- package/src/tools/builtins/bounded-file-read.ts +80 -0
- package/src/tools/builtins/grep.ts +198 -28
- package/src/tools/builtins/read-file.ts +151 -30
- package/src/tools/builtins/read-media.ts +483 -0
- package/src/tools/builtins/search-tools.ts +1 -1
- package/src/tools/builtins/skill.ts +91 -2
- package/src/tools/builtins/sleep-guard.ts +31 -0
- package/src/tools/builtins/view-image.ts +74 -62
- package/src/tools/file-read-tracker.ts +30 -0
- package/src/toolsets/manager.ts +3 -3
- package/src/types/agent/base.ts +9 -0
- package/src/types/agent/query.ts +2 -0
- package/src/types/agent/scheduler.ts +9 -0
- package/src/types/agent/task.ts +6 -2
- package/src/types/connector/mcp.ts +48 -0
- package/src/types/hitl/index.ts +1 -1
- package/src/types/plugin/index.ts +102 -16
- package/src/types/session/sub-session.ts +6 -2
- package/src/types/skills/index.ts +48 -0
- package/src/types/tool/index.ts +38 -0
- package/src/types/workspace/ref.ts +2 -0
- package/src/utils/frontmatter.ts +21 -0
|
@@ -0,0 +1,163 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* An HTTP hook: the event as a JSON POST, the response as the hook's answer.
|
|
3
|
+
*
|
|
4
|
+
* A 2xx response is exit `0` with the body as stdout, so the JSON answer is
|
|
5
|
+
* read exactly as a command's is. Any other status, a network error and a
|
|
6
|
+
* deadline are the hook's own failure. The address is checked where the
|
|
7
|
+
* connection is made, not before it: a name that resolves to a private or
|
|
8
|
+
* link-local address (a cloud metadata service, a router) is refused, so a
|
|
9
|
+
* hook cannot be pointed at the machine's neighbours and a name cannot be
|
|
10
|
+
* re-resolved between the check and the connect. Loopback stays allowed for
|
|
11
|
+
* local development. Redirects are not followed.
|
|
12
|
+
*/
|
|
13
|
+
import { lookup } from 'node:dns';
|
|
14
|
+
import { request as httpRequest } from 'node:http';
|
|
15
|
+
import { request as httpsRequest } from 'node:https';
|
|
16
|
+
import { isIP } from 'node:net';
|
|
17
|
+
/** Captured response bound. */
|
|
18
|
+
const MAX_BODY_BYTES = 64 * 1024;
|
|
19
|
+
/**
|
|
20
|
+
* Replace `$NAME` and `${NAME}` in a header value with the environment's
|
|
21
|
+
* value, but only for names the hook listed. Any other reference becomes the
|
|
22
|
+
* empty string, so a header can never carry a variable its author did not
|
|
23
|
+
* name. Line breaks and NUL are removed from the result, so a value cannot add
|
|
24
|
+
* a header of its own.
|
|
25
|
+
*/
|
|
26
|
+
export function interpolateHookHeader(value, allowed, env) {
|
|
27
|
+
return value
|
|
28
|
+
.replace(/\$\{([A-Za-z_][A-Za-z0-9_]*)\}|\$([A-Za-z_][A-Za-z0-9_]*)/g, (_all, braced, bare) => {
|
|
29
|
+
const name = (braced ?? bare);
|
|
30
|
+
return allowed.has(name) ? (env[name] ?? '') : '';
|
|
31
|
+
})
|
|
32
|
+
.replace(/[\r\n\0]/g, '');
|
|
33
|
+
}
|
|
34
|
+
/** Whether an address may be connected to: public, or loopback. */
|
|
35
|
+
export function isReachableHookAddress(address) {
|
|
36
|
+
const family = isIP(address);
|
|
37
|
+
if (family === 4) {
|
|
38
|
+
const [a = 0, b = 0] = address.split('.').map(Number);
|
|
39
|
+
if (a === 127)
|
|
40
|
+
return true;
|
|
41
|
+
if (a === 0 || a === 10)
|
|
42
|
+
return false;
|
|
43
|
+
if (a === 169 && b === 254)
|
|
44
|
+
return false;
|
|
45
|
+
if (a === 172 && b >= 16 && b <= 31)
|
|
46
|
+
return false;
|
|
47
|
+
if (a === 192 && b === 168)
|
|
48
|
+
return false;
|
|
49
|
+
if (a === 100 && b >= 64 && b <= 127)
|
|
50
|
+
return false;
|
|
51
|
+
if (a >= 224)
|
|
52
|
+
return false;
|
|
53
|
+
return true;
|
|
54
|
+
}
|
|
55
|
+
if (family === 6) {
|
|
56
|
+
const lower = address.toLowerCase();
|
|
57
|
+
if (lower === '::1')
|
|
58
|
+
return true;
|
|
59
|
+
if (lower === '::')
|
|
60
|
+
return false;
|
|
61
|
+
const mapped = /^::ffff:(\d+\.\d+\.\d+\.\d+)$/.exec(lower);
|
|
62
|
+
if (mapped?.[1])
|
|
63
|
+
return isReachableHookAddress(mapped[1]);
|
|
64
|
+
if (/^f[cd]/.test(lower) || /^fe[89ab]/.test(lower))
|
|
65
|
+
return false;
|
|
66
|
+
return true;
|
|
67
|
+
}
|
|
68
|
+
return false;
|
|
69
|
+
}
|
|
70
|
+
/** `dns.lookup` that refuses an address a hook may not reach. */
|
|
71
|
+
function guardedLookup(hostname, options, callback) {
|
|
72
|
+
lookup(hostname, { ...options, all: true }, (error, addresses) => {
|
|
73
|
+
if (error) {
|
|
74
|
+
callback(error);
|
|
75
|
+
return;
|
|
76
|
+
}
|
|
77
|
+
const list = addresses;
|
|
78
|
+
const refused = list.find((entry) => !isReachableHookAddress(entry.address));
|
|
79
|
+
if (refused || list.length === 0) {
|
|
80
|
+
callback(new Error(`${hostname} resolves to ${refused?.address ?? 'nothing'}, a private or link-local address`));
|
|
81
|
+
return;
|
|
82
|
+
}
|
|
83
|
+
if (options.all) {
|
|
84
|
+
callback(null, list);
|
|
85
|
+
return;
|
|
86
|
+
}
|
|
87
|
+
const first = list[0];
|
|
88
|
+
callback(null, first.address, first.family);
|
|
89
|
+
});
|
|
90
|
+
}
|
|
91
|
+
export function postHookJson(input) {
|
|
92
|
+
return new Promise((resolve) => {
|
|
93
|
+
let url;
|
|
94
|
+
try {
|
|
95
|
+
url = new URL(input.url);
|
|
96
|
+
}
|
|
97
|
+
catch {
|
|
98
|
+
resolve({ status: null, body: '', timedOut: false, error: 'the url is not valid' });
|
|
99
|
+
return;
|
|
100
|
+
}
|
|
101
|
+
if (url.protocol !== 'http:' && url.protocol !== 'https:') {
|
|
102
|
+
resolve({ status: null, body: '', timedOut: false, error: 'the url must be http or https' });
|
|
103
|
+
return;
|
|
104
|
+
}
|
|
105
|
+
// A literal address never reaches the resolver, so it is checked here.
|
|
106
|
+
const literal = url.hostname.replace(/^\[|\]$/g, '');
|
|
107
|
+
if (isIP(literal) !== 0 && !isReachableHookAddress(literal)) {
|
|
108
|
+
resolve({
|
|
109
|
+
status: null,
|
|
110
|
+
body: '',
|
|
111
|
+
timedOut: false,
|
|
112
|
+
error: `${literal} is a private or link-local address`,
|
|
113
|
+
});
|
|
114
|
+
return;
|
|
115
|
+
}
|
|
116
|
+
const allowed = new Set(input.allowedEnvVars ?? []);
|
|
117
|
+
const env = input.env ?? process.env;
|
|
118
|
+
const headers = {
|
|
119
|
+
'Content-Type': 'application/json',
|
|
120
|
+
'Content-Length': String(Buffer.byteLength(input.body)),
|
|
121
|
+
};
|
|
122
|
+
for (const [name, value] of Object.entries(input.headers ?? {})) {
|
|
123
|
+
headers[name] = interpolateHookHeader(value, allowed, env);
|
|
124
|
+
}
|
|
125
|
+
let settled = false;
|
|
126
|
+
let timedOut = false;
|
|
127
|
+
const finish = (response) => {
|
|
128
|
+
if (settled)
|
|
129
|
+
return;
|
|
130
|
+
settled = true;
|
|
131
|
+
clearTimeout(timer);
|
|
132
|
+
input.signal?.removeEventListener('abort', onAbort);
|
|
133
|
+
resolve(response);
|
|
134
|
+
};
|
|
135
|
+
const onAbort = () => {
|
|
136
|
+
req.destroy();
|
|
137
|
+
finish({ status: null, body: '', timedOut: false, error: 'cancelled' });
|
|
138
|
+
};
|
|
139
|
+
const send = url.protocol === 'https:' ? httpsRequest : httpRequest;
|
|
140
|
+
const req = send(url, { method: 'POST', headers, lookup: guardedLookup }, (res) => {
|
|
141
|
+
let body = '';
|
|
142
|
+
res.setEncoding('utf8');
|
|
143
|
+
res.on('data', (chunk) => {
|
|
144
|
+
if (body.length < MAX_BODY_BYTES)
|
|
145
|
+
body = (body + chunk).slice(0, MAX_BODY_BYTES);
|
|
146
|
+
});
|
|
147
|
+
res.on('end', () => finish({ status: res.statusCode ?? null, body, timedOut: false }));
|
|
148
|
+
res.on('error', (error) => finish({ status: null, body, timedOut, error: error.message }));
|
|
149
|
+
});
|
|
150
|
+
const timer = setTimeout(() => {
|
|
151
|
+
timedOut = true;
|
|
152
|
+
req.destroy();
|
|
153
|
+
finish({ status: null, body: '', timedOut: true });
|
|
154
|
+
}, input.timeoutMs);
|
|
155
|
+
req.on('error', (error) => finish({ status: null, body: '', timedOut, error: error.message }));
|
|
156
|
+
if (input.signal?.aborted)
|
|
157
|
+
onAbort();
|
|
158
|
+
else
|
|
159
|
+
input.signal?.addEventListener('abort', onAbort, { once: true });
|
|
160
|
+
req.end(input.body);
|
|
161
|
+
});
|
|
162
|
+
}
|
|
163
|
+
//# sourceMappingURL=shell-hook-http.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"shell-hook-http.js","sourceRoot":"","sources":["../../src/plugin/shell-hook-http.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;GAWG;AAEH,OAAO,EAAsB,MAAM,EAAE,MAAM,UAAU,CAAA;AACrD,OAAO,EAAE,OAAO,IAAI,WAAW,EAAE,MAAM,WAAW,CAAA;AAClD,OAAO,EAAE,OAAO,IAAI,YAAY,EAAE,MAAM,YAAY,CAAA;AACpD,OAAO,EAAE,IAAI,EAAE,MAAM,UAAU,CAAA;AAE/B,+BAA+B;AAC/B,MAAM,cAAc,GAAG,EAAE,GAAG,IAAI,CAAA;AAmBhC;;;;;;GAMG;AACH,MAAM,UAAU,qBAAqB,CACpC,KAAa,EACb,OAA4B,EAC5B,GAAiD;IAEjD,OAAO,KAAK;SACV,OAAO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K,EAAE,EAAE,CAAC,MAAM,CAAC,EAAE,MAAM,EAAE,IAAI,EAAE,IAAI,EAAE,EAAE,EAAE,QAAQ,EAAE,KAAK,EAAE,KAAK,CAAC,OAAO,EAAE,CAAC,CAAC,CAAA;QAC9F,IAAI,KAAK,CAAC,MAAM,EAAE,OAAO;YAAE,OAAO,EAAE,CAAA;;YAC/B,KAAK,CAAC,MAAM,EAAE,gBAAgB,CAAC,OAAO,EAAE,OAAO,EAAE,EAAE,IAAI,EAAE,IAAI,EAAE,CAAC,CAAA;QACrE,GAAG,CAAC,GAAG,CAAC,KAAK,CAAC,IAAI,CAAC,CAAA;IACpB,CAAC,CAAC,CAAA;AACH,CAAC"}
|
|
@@ -99,7 +99,7 @@
|
|
|
99
99
|
* and does not block: one that could not answer in time has not answered no.
|
|
100
100
|
*/
|
|
101
101
|
import type { PluginId } from '../types/ids/index.js';
|
|
102
|
-
import type { PluginCompactionInfo, PluginHookDefinition, PluginHookEvent, PluginHookResult, PluginNotificationInfo } from '../types/plugin/index.js';
|
|
102
|
+
import type { PluginCompactionInfo, PluginHookDefinition, PluginHookEvent, PluginHookResult, PluginNotificationInfo, PluginToolBatchCall } from '../types/plugin/index.js';
|
|
103
103
|
import type { Logger } from '../utils/logger.js';
|
|
104
104
|
import type { PluginLifecycleManager } from './lifecycle.js';
|
|
105
105
|
/**
|
|
@@ -107,12 +107,12 @@ import type { PluginLifecycleManager } from './lifecycle.js';
|
|
|
107
107
|
* from a script. The model-call and iteration events stay in-process —
|
|
108
108
|
* they carry the messages, and a shell is not where those go.
|
|
109
109
|
*/
|
|
110
|
-
export type ShellHookEvent = Extract<PluginHookEvent, 'user_prompt_submit' | 'session_start' | 'session_end' | 'pre_tool_use' | 'post_tool_use' | 'post_tool_use_failure' | 'permission_request' | 'notification' | 'pre_compact' | 'post_compact' | 'subagent_stop' | 'turn_start' | 'turn_end'>;
|
|
110
|
+
export type ShellHookEvent = Extract<PluginHookEvent, 'user_prompt_submit' | 'session_start' | 'session_end' | 'pre_tool_use' | 'post_tool_use' | 'post_tool_use_failure' | 'permission_request' | 'notification' | 'pre_compact' | 'post_compact' | 'subagent_start' | 'subagent_stop' | 'post_tool_batch' | 'permission_denied' | 'turn_failure' | 'turn_start' | 'turn_end'>;
|
|
111
111
|
export declare const SHELL_HOOK_EVENTS: readonly ShellHookEvent[];
|
|
112
|
-
/**
|
|
113
|
-
export
|
|
114
|
-
|
|
115
|
-
|
|
112
|
+
/** What a failed hook does to the action it guards. */
|
|
113
|
+
export type ShellHookOnFailure = 'continue' | 'block';
|
|
114
|
+
/** What every kind of hook entry takes. */
|
|
115
|
+
interface ShellHookEntryBase {
|
|
116
116
|
/**
|
|
117
117
|
* What this applies to. On a tool event (and `permission_request`) the tool
|
|
118
118
|
* name; on `notification` the notification type. `*` or absent matches
|
|
@@ -134,10 +134,62 @@ export interface ShellHookEntry {
|
|
|
134
134
|
readonly once?: boolean;
|
|
135
135
|
/** Text for the operator's status line while the hook runs. */
|
|
136
136
|
readonly statusMessage?: string;
|
|
137
|
+
/**
|
|
138
|
+
* What the hook's own failure does: it could not start, it timed out, it
|
|
139
|
+
* exited with a code other than `0` or `2`, or it printed JSON that is not
|
|
140
|
+
* valid. `continue` (the default) reports it and lets the action go ahead;
|
|
141
|
+
* `block` counts it as exit `2`, so the action the event guards is refused.
|
|
142
|
+
* Not read on a `prompt` hook or an `async` command.
|
|
143
|
+
*/
|
|
144
|
+
readonly onFailure?: ShellHookOnFailure;
|
|
137
145
|
}
|
|
146
|
+
/** One shell command at one event. */
|
|
147
|
+
export interface ShellHookEntry extends ShellHookEntryBase {
|
|
148
|
+
readonly type?: 'command';
|
|
149
|
+
/**
|
|
150
|
+
* Run with `sh -c`, in the working directory, with the event JSON on stdin.
|
|
151
|
+
* With `args` it is the program to run instead, and no shell is involved.
|
|
152
|
+
*/
|
|
153
|
+
readonly command: string;
|
|
154
|
+
/**
|
|
155
|
+
* Argument list for the exec form: `command` is spawned directly with these
|
|
156
|
+
* arguments, so a path with a quote, a space or a `$` never reaches a shell
|
|
157
|
+
* parser. An empty list runs `command` with no arguments.
|
|
158
|
+
*/
|
|
159
|
+
readonly args?: readonly string[];
|
|
160
|
+
/**
|
|
161
|
+
* Start the command and carry on without waiting. Its exit code and output
|
|
162
|
+
* decide nothing (a failure is logged), and `onFailure` is not read.
|
|
163
|
+
*/
|
|
164
|
+
readonly async?: boolean;
|
|
165
|
+
}
|
|
166
|
+
/** One HTTP POST at one event. See {@link postHookJson} for the address rules. */
|
|
167
|
+
export interface HttpHookEntry extends ShellHookEntryBase {
|
|
168
|
+
readonly type: 'http';
|
|
169
|
+
/** Where the event JSON is posted. `http` or `https`. */
|
|
170
|
+
readonly url: string;
|
|
171
|
+
/** Extra headers. A value may name `$NAME` or `${NAME}` listed in `allowedEnvVars`. */
|
|
172
|
+
readonly headers?: Readonly<Record<string, string>>;
|
|
173
|
+
/** The environment variables a header value may use; any other reference becomes empty. */
|
|
174
|
+
readonly allowedEnvVars?: readonly string[];
|
|
175
|
+
}
|
|
176
|
+
/** A question put to the small model at one event. */
|
|
177
|
+
export interface PromptHookEntry extends ShellHookEntryBase {
|
|
178
|
+
readonly type: 'prompt';
|
|
179
|
+
/**
|
|
180
|
+
* The condition to judge. `$ARGUMENTS` is replaced by the event JSON; with
|
|
181
|
+
* no placeholder the event follows the text. The model answers
|
|
182
|
+
* `{"ok": true}` or `{"ok": false, "reason": "..."}`, and `false` refuses
|
|
183
|
+
* the action as exit `2` does. No model, an error or an unreadable answer
|
|
184
|
+
* lets the action go ahead.
|
|
185
|
+
*/
|
|
186
|
+
readonly prompt: string;
|
|
187
|
+
}
|
|
188
|
+
/** Any hook entry a config may carry. */
|
|
189
|
+
export type ShellHookHandler = ShellHookEntry | HttpHookEntry | PromptHookEntry;
|
|
138
190
|
/** Event → entries, the shape a host's config file carries. */
|
|
139
191
|
export type ShellHooksConfig = {
|
|
140
|
-
readonly [event in ShellHookEvent]?: readonly
|
|
192
|
+
readonly [event in ShellHookEvent]?: readonly ShellHookHandler[];
|
|
141
193
|
};
|
|
142
194
|
/** The plugin id host shell hooks register under when the host names none. */
|
|
143
195
|
export declare const SHELL_HOOKS_PLUGIN_ID: PluginId;
|
|
@@ -178,10 +230,12 @@ export interface ShellHookInput {
|
|
|
178
230
|
readonly sessionId: string;
|
|
179
231
|
/** The turn the hook fired in. Absent on `session_start` and `session_end`. */
|
|
180
232
|
readonly turnId?: string;
|
|
181
|
-
/** The delegating session, on `subagent_stop`. */
|
|
233
|
+
/** The delegating session, on `subagent_start` and `subagent_stop`. */
|
|
182
234
|
readonly parentSessionId?: string;
|
|
183
|
-
/** The parent turn whose tool call spawned the child, on `subagent_stop`. */
|
|
235
|
+
/** The parent turn whose tool call spawned the child, on `subagent_start` and `subagent_stop`. */
|
|
184
236
|
readonly parentTurnId?: string;
|
|
237
|
+
/** The agent the child runs, on `subagent_start` and `subagent_stop`. */
|
|
238
|
+
readonly agentType?: string;
|
|
185
239
|
readonly prompt?: string;
|
|
186
240
|
readonly compaction?: PluginCompactionInfo;
|
|
187
241
|
readonly toolName?: string;
|
|
@@ -191,6 +245,12 @@ export interface ShellHookInput {
|
|
|
191
245
|
readonly output: string;
|
|
192
246
|
readonly error?: string;
|
|
193
247
|
};
|
|
248
|
+
/** On `post_tool_batch`: every call of the step with its outcome. */
|
|
249
|
+
readonly toolCalls?: readonly PluginToolBatchCall[];
|
|
250
|
+
/** On `permission_denied`: why the call was refused. */
|
|
251
|
+
readonly reason?: string;
|
|
252
|
+
/** On `turn_failure`: the failure's message. */
|
|
253
|
+
readonly error?: string;
|
|
194
254
|
/** On `notification`: what the host is telling the operator. */
|
|
195
255
|
readonly notification?: PluginNotificationInfo;
|
|
196
256
|
/** On `turn_end` and `subagent_stop`: an earlier answer already kept this turn going. */
|
|
@@ -200,6 +260,8 @@ export interface ShellHookInput {
|
|
|
200
260
|
/** How tool calls are being decided right now. Sent as `permission_mode`. */
|
|
201
261
|
readonly permissionMode?: string;
|
|
202
262
|
}
|
|
263
|
+
/** The JSON a hook receives on stdin (or as an HTTP body). */
|
|
264
|
+
export declare function shellHookPayload(input: ShellHookInput): string;
|
|
203
265
|
/** Run one hook command to completion, bounded by its deadline and capture. */
|
|
204
266
|
export declare function runShellHook(entry: ShellHookEntry, input: ShellHookInput, signal?: AbortSignal): Promise<ShellHookOutcome>;
|
|
205
267
|
/**
|
|
@@ -207,8 +269,25 @@ export declare function runShellHook(entry: ShellHookEntry, input: ShellHookInpu
|
|
|
207
269
|
* so the mapping — the part that decides what the model is told — is
|
|
208
270
|
* testable without a process.
|
|
209
271
|
*/
|
|
210
|
-
export declare function shellHookVerdict(event: ShellHookEvent, entry:
|
|
272
|
+
export declare function shellHookVerdict(event: ShellHookEvent, entry: ShellHookHandler, outcome: ShellHookOutcome, log?: Logger): PluginHookResult;
|
|
273
|
+
/** A short name for a hook in logs: its command, its url, or the start of its prompt. */
|
|
274
|
+
export declare function describeShellHook(entry: ShellHookHandler): string;
|
|
275
|
+
/**
|
|
276
|
+
* Puts a question to a model and returns its reply text, or `undefined` when
|
|
277
|
+
* it cannot answer. The host supplies it (the kernel has no model of its
|
|
278
|
+
* own for a hook); it should use a small, cheap model, and it should honour
|
|
279
|
+
* `signal`.
|
|
280
|
+
*/
|
|
281
|
+
export type ShellHookJudge = (request: {
|
|
282
|
+
readonly instruction: string;
|
|
283
|
+
readonly body: string;
|
|
284
|
+
readonly sessionId: string;
|
|
285
|
+
readonly turnId?: string;
|
|
286
|
+
readonly signal: AbortSignal;
|
|
287
|
+
}) => Promise<string | undefined>;
|
|
211
288
|
export interface ShellHookOptions {
|
|
289
|
+
/** Answers `prompt` hooks. Without it a `prompt` hook is logged and lets the action go ahead. */
|
|
290
|
+
readonly judge?: ShellHookJudge;
|
|
212
291
|
/** Where the command runs and what `cwd` says on stdin. */
|
|
213
292
|
readonly cwd: string;
|
|
214
293
|
readonly log?: Logger;
|
|
@@ -221,8 +300,10 @@ export interface ShellHookOptions {
|
|
|
221
300
|
/** The permission mode in force now, sent as `permission_mode`. Called at each run. */
|
|
222
301
|
readonly permissionMode?: () => string | undefined;
|
|
223
302
|
}
|
|
303
|
+
/** The deadline for `prompt` hooks when they name none. */
|
|
304
|
+
export declare const DEFAULT_PROMPT_HOOK_TIMEOUT_MS = 30000;
|
|
224
305
|
/** One entry as a hook definition the lifecycle manager accepts. */
|
|
225
|
-
export declare function createShellHook(event: ShellHookEvent, entry:
|
|
306
|
+
export declare function createShellHook(event: ShellHookEvent, entry: ShellHookHandler, options: ShellHookOptions): PluginHookDefinition;
|
|
226
307
|
/**
|
|
227
308
|
* Register every entry on the manager, in file order within an event. The
|
|
228
309
|
* manager starts all of an event's hooks together and reads their answers in
|
|
@@ -234,4 +315,5 @@ export declare function createShellHook(event: ShellHookEvent, entry: ShellHookE
|
|
|
234
315
|
export declare function attachShellHooks(manager: Pick<PluginLifecycleManager, 'registerHook'>, hooks: ShellHooksConfig, options: ShellHookOptions & {
|
|
235
316
|
readonly pluginId?: PluginId;
|
|
236
317
|
}): number;
|
|
318
|
+
export {};
|
|
237
319
|
//# sourceMappingURL=shell-hook.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"shell-hook.d.ts","sourceRoot":"","sources":["../../src/plugin/shell-hook.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GAmGG;AAUH,OAAO,KAAK,EAAE,QAAQ,EAAE,MAAM,uBAAuB,CAAA;AACrD,OAAO,KAAK,EACX,oBAAoB,EAEpB,oBAAoB,EACpB,eAAe,EAEf,gBAAgB,EAChB,sBAAsB,EACtB,MAAM,0BAA0B,CAAA;AAIjC,OAAO,KAAK,EAAE,MAAM,EAAE,MAAM,oBAAoB,CAAA;AAChD,OAAO,KAAK,EAAE,sBAAsB,EAAE,MAAM,gBAAgB,CAAA;
|
|
1
|
+
{"version":3,"file":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