@namzu/sdk 69.0.0 → 69.1.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 +61 -0
- package/dist/agents/QueryAgent.d.ts.map +1 -1
- package/dist/agents/QueryAgent.js +2 -0
- package/dist/agents/QueryAgent.js.map +1 -1
- package/dist/authorization/skill-grant.d.ts.map +1 -1
- package/dist/authorization/skill-grant.js +1 -0
- package/dist/authorization/skill-grant.js.map +1 -1
- package/dist/bridge/acp/permission.d.ts +10 -0
- package/dist/bridge/acp/permission.d.ts.map +1 -1
- package/dist/bridge/acp/permission.js.map +1 -1
- package/dist/bridge/acp/server.d.ts.map +1 -1
- package/dist/bridge/acp/server.js +1 -0
- package/dist/bridge/acp/server.js.map +1 -1
- package/dist/connector/index.d.ts +2 -2
- package/dist/connector/index.d.ts.map +1 -1
- package/dist/connector/index.js +1 -1
- package/dist/connector/index.js.map +1 -1
- package/dist/connector/mcp/client.d.ts +29 -0
- package/dist/connector/mcp/client.d.ts.map +1 -1
- package/dist/connector/mcp/client.js +59 -2
- package/dist/connector/mcp/client.js.map +1 -1
- package/dist/connector/mcp/errors.d.ts +7 -0
- package/dist/connector/mcp/errors.d.ts.map +1 -1
- package/dist/connector/mcp/errors.js +14 -0
- package/dist/connector/mcp/errors.js.map +1 -1
- package/dist/connector/mcp/index.d.ts +5 -1
- package/dist/connector/mcp/index.d.ts.map +1 -1
- package/dist/connector/mcp/index.js +3 -1
- package/dist/connector/mcp/index.js.map +1 -1
- package/dist/connector/mcp/skill-source.d.ts +144 -0
- package/dist/connector/mcp/skill-source.d.ts.map +1 -0
- package/dist/connector/mcp/skill-source.js +375 -0
- package/dist/connector/mcp/skill-source.js.map +1 -0
- package/dist/connector/mcp/skills.d.ts +137 -0
- package/dist/connector/mcp/skills.d.ts.map +1 -0
- package/dist/connector/mcp/skills.js +303 -0
- package/dist/connector/mcp/skills.js.map +1 -0
- package/dist/network/audit.d.ts +1 -1
- package/dist/network/audit.d.ts.map +1 -1
- package/dist/network/audit.js +2 -0
- package/dist/network/audit.js.map +1 -1
- package/dist/network/computer.d.ts +107 -0
- package/dist/network/computer.d.ts.map +1 -0
- package/dist/network/computer.js +250 -0
- package/dist/network/computer.js.map +1 -0
- package/dist/network/index.d.ts +2 -0
- package/dist/network/index.d.ts.map +1 -1
- package/dist/network/index.js +1 -0
- package/dist/network/index.js.map +1 -1
- package/dist/network/join.d.ts +3 -1
- package/dist/network/join.d.ts.map +1 -1
- package/dist/network/join.js +6 -3
- package/dist/network/join.js.map +1 -1
- package/dist/network/roster.d.ts +5 -0
- package/dist/network/roster.d.ts.map +1 -1
- package/dist/network/roster.js.map +1 -1
- package/dist/network/service.d.ts +12 -2
- package/dist/network/service.d.ts.map +1 -1
- package/dist/network/service.js +377 -52
- package/dist/network/service.js.map +1 -1
- package/dist/network/store.d.ts +10 -0
- package/dist/network/store.d.ts.map +1 -1
- package/dist/network/store.js +25 -3
- package/dist/network/store.js.map +1 -1
- package/dist/network/wire.d.ts +2 -0
- package/dist/network/wire.d.ts.map +1 -1
- package/dist/network/wire.js +5 -0
- package/dist/network/wire.js.map +1 -1
- package/dist/plugin/shell-hook-tool-names.d.ts.map +1 -1
- package/dist/plugin/shell-hook-tool-names.js +1 -0
- package/dist/plugin/shell-hook-tool-names.js.map +1 -1
- package/dist/plugin/shell-hook.d.ts +8 -3
- package/dist/plugin/shell-hook.d.ts.map +1 -1
- package/dist/plugin/shell-hook.js +132 -7
- package/dist/plugin/shell-hook.js.map +1 -1
- package/dist/provider/fallback.d.ts.map +1 -1
- package/dist/provider/fallback.js +4 -0
- package/dist/provider/fallback.js.map +1 -1
- package/dist/provider/idle-timeout.d.ts.map +1 -1
- package/dist/provider/idle-timeout.js +3 -0
- package/dist/provider/idle-timeout.js.map +1 -1
- package/dist/provider/model-window-suffix.d.ts.map +1 -1
- package/dist/provider/model-window-suffix.js +1 -0
- package/dist/provider/model-window-suffix.js.map +1 -1
- package/dist/provider/retry.d.ts.map +1 -1
- package/dist/provider/retry.js +3 -0
- package/dist/provider/retry.js.map +1 -1
- package/dist/public-runtime.d.ts +9 -6
- package/dist/public-runtime.d.ts.map +1 -1
- package/dist/public-runtime.js +11 -4
- package/dist/public-runtime.js.map +1 -1
- package/dist/public-tools.d.ts +5 -4
- package/dist/public-tools.d.ts.map +1 -1
- package/dist/public-tools.js +5 -3
- package/dist/public-tools.js.map +1 -1
- package/dist/public-types.d.ts +3 -1
- package/dist/public-types.d.ts.map +1 -1
- package/dist/runtime/query/executor/tool-call-admission.d.ts.map +1 -1
- package/dist/runtime/query/executor/tool-call-admission.js +10 -1
- package/dist/runtime/query/executor/tool-call-admission.js.map +1 -1
- package/dist/runtime/query/executor.d.ts +12 -0
- package/dist/runtime/query/executor.d.ts.map +1 -1
- package/dist/runtime/query/executor.js +43 -9
- package/dist/runtime/query/executor.js.map +1 -1
- package/dist/runtime/query/index.d.ts +4 -0
- package/dist/runtime/query/index.d.ts.map +1 -1
- package/dist/runtime/query/index.js +32 -0
- package/dist/runtime/query/index.js.map +1 -1
- package/dist/runtime/query/review-policy.d.ts +2 -2
- package/dist/runtime/query/review-policy.d.ts.map +1 -1
- package/dist/runtime/query/review-policy.js +2 -2
- package/dist/runtime/query/review-policy.js.map +1 -1
- package/dist/runtime/query/shell-line-escalation.d.ts +24 -0
- package/dist/runtime/query/shell-line-escalation.d.ts.map +1 -0
- package/dist/runtime/query/shell-line-escalation.js +38 -0
- package/dist/runtime/query/shell-line-escalation.js.map +1 -0
- package/dist/runtime/query/tooling.d.ts +7 -0
- package/dist/runtime/query/tooling.d.ts.map +1 -1
- package/dist/runtime/query/tooling.js +2 -0
- package/dist/runtime/query/tooling.js.map +1 -1
- package/dist/runtime/query/turn/outcome-ledger.d.ts.map +1 -1
- package/dist/runtime/query/turn/outcome-ledger.js +11 -0
- package/dist/runtime/query/turn/outcome-ledger.js.map +1 -1
- package/dist/scheduler/local.d.ts.map +1 -1
- package/dist/scheduler/local.js +3 -1
- package/dist/scheduler/local.js.map +1 -1
- package/dist/skills/index.d.ts +4 -0
- package/dist/skills/index.d.ts.map +1 -1
- package/dist/skills/index.js +2 -0
- package/dist/skills/index.js.map +1 -1
- package/dist/skills/inline-shell-host.d.ts +103 -0
- package/dist/skills/inline-shell-host.d.ts.map +1 -0
- package/dist/skills/inline-shell-host.js +238 -0
- package/dist/skills/inline-shell-host.js.map +1 -0
- package/dist/skills/inline-shell.d.ts +176 -0
- package/dist/skills/inline-shell.d.ts.map +1 -0
- package/dist/skills/inline-shell.js +646 -0
- package/dist/skills/inline-shell.js.map +1 -0
- package/dist/store/index.d.ts +2 -0
- package/dist/store/index.d.ts.map +1 -1
- package/dist/store/index.js +1 -0
- package/dist/store/index.js.map +1 -1
- package/dist/store/task/file.d.ts +124 -0
- package/dist/store/task/file.d.ts.map +1 -0
- package/dist/store/task/file.js +498 -0
- package/dist/store/task/file.js.map +1 -0
- package/dist/teams/backend.d.ts +28 -0
- package/dist/teams/backend.d.ts.map +1 -0
- package/dist/teams/backend.js +2 -0
- package/dist/teams/backend.js.map +1 -0
- package/dist/teams/fs-sync.d.ts +19 -0
- package/dist/teams/fs-sync.d.ts.map +1 -0
- package/dist/teams/fs-sync.js +81 -0
- package/dist/teams/fs-sync.js.map +1 -0
- package/dist/teams/index.d.ts +14 -0
- package/dist/teams/index.d.ts.map +1 -0
- package/dist/teams/index.js +11 -0
- package/dist/teams/index.js.map +1 -0
- package/dist/teams/names.d.ts +15 -0
- package/dist/teams/names.d.ts.map +1 -0
- package/dist/teams/names.js +43 -0
- package/dist/teams/names.js.map +1 -0
- package/dist/teams/store.d.ts +133 -0
- package/dist/teams/store.d.ts.map +1 -0
- package/dist/teams/store.js +536 -0
- package/dist/teams/store.js.map +1 -0
- package/dist/teams/types.d.ts +97 -0
- package/dist/teams/types.d.ts.map +1 -0
- package/dist/teams/types.js +70 -0
- package/dist/teams/types.js.map +1 -0
- package/dist/tools/admit-facts.d.ts.map +1 -1
- package/dist/tools/admit-facts.js +9 -1
- package/dist/tools/admit-facts.js.map +1 -1
- package/dist/tools/builtins/computer-use.d.ts +56 -2
- package/dist/tools/builtins/computer-use.d.ts.map +1 -1
- package/dist/tools/builtins/computer-use.js +604 -90
- package/dist/tools/builtins/computer-use.js.map +1 -1
- package/dist/tools/builtins/index.d.ts +1 -1
- package/dist/tools/builtins/index.d.ts.map +1 -1
- package/dist/tools/builtins/index.js.map +1 -1
- package/dist/tools/builtins/skill.d.ts +31 -0
- package/dist/tools/builtins/skill.d.ts.map +1 -1
- package/dist/tools/builtins/skill.js +232 -88
- package/dist/tools/builtins/skill.js.map +1 -1
- package/dist/tools/task/create.d.ts.map +1 -1
- package/dist/tools/task/create.js +11 -2
- package/dist/tools/task/create.js.map +1 -1
- package/dist/tools/task/get.d.ts +8 -0
- package/dist/tools/task/get.d.ts.map +1 -0
- package/dist/tools/task/get.js +51 -0
- package/dist/tools/task/get.js.map +1 -0
- package/dist/tools/task/index.d.ts +7 -0
- package/dist/tools/task/index.d.ts.map +1 -1
- package/dist/tools/task/index.js +10 -2
- package/dist/tools/task/index.js.map +1 -1
- package/dist/tools/task/list.d.ts.map +1 -1
- package/dist/tools/task/list.js +10 -2
- package/dist/tools/task/list.js.map +1 -1
- package/dist/tools/task/number.d.ts +13 -0
- package/dist/tools/task/number.d.ts.map +1 -0
- package/dist/tools/task/number.js +30 -0
- package/dist/tools/task/number.js.map +1 -0
- package/dist/tools/task/present.d.ts.map +1 -1
- package/dist/tools/task/present.js +17 -3
- package/dist/tools/task/present.js.map +1 -1
- package/dist/tools/task/update.d.ts +2 -1
- package/dist/tools/task/update.d.ts.map +1 -1
- package/dist/tools/task/update.js +86 -19
- package/dist/tools/task/update.js.map +1 -1
- package/dist/types/acp/index.d.ts +10 -0
- package/dist/types/acp/index.d.ts.map +1 -1
- package/dist/types/agent/base.d.ts +4 -0
- package/dist/types/agent/base.d.ts.map +1 -1
- package/dist/types/agent/scheduler.d.ts +9 -0
- package/dist/types/agent/scheduler.d.ts.map +1 -1
- package/dist/types/computer-use/index.d.ts +7 -0
- package/dist/types/computer-use/index.d.ts.map +1 -1
- package/dist/types/computer-use/index.js.map +1 -1
- package/dist/types/connector/mcp.d.ts +10 -0
- package/dist/types/connector/mcp.d.ts.map +1 -1
- package/dist/types/permission/index.d.ts +20 -0
- package/dist/types/permission/index.d.ts.map +1 -1
- package/dist/types/permission/index.js +25 -0
- package/dist/types/permission/index.js.map +1 -1
- package/dist/types/plugin/index.d.ts +47 -3
- package/dist/types/plugin/index.d.ts.map +1 -1
- package/dist/types/plugin/index.js +4 -0
- package/dist/types/plugin/index.js.map +1 -1
- package/dist/types/provider/interface.d.ts +6 -0
- package/dist/types/provider/interface.d.ts.map +1 -1
- package/dist/types/tool/index.d.ts +28 -2
- package/dist/types/tool/index.d.ts.map +1 -1
- package/dist/types/tool/index.js.map +1 -1
- package/dist/types/tool/presentation.d.ts +4 -0
- package/dist/types/tool/presentation.d.ts.map +1 -1
- package/package.json +1 -1
- package/src/agents/QueryAgent.ts +2 -0
- package/src/authorization/skill-grant.ts +1 -0
- package/src/bridge/acp/permission.ts +11 -1
- package/src/bridge/acp/server.ts +1 -0
- package/src/connector/index.ts +27 -0
- package/src/connector/mcp/client.ts +71 -2
- package/src/connector/mcp/errors.ts +14 -0
- package/src/connector/mcp/index.ts +36 -0
- package/src/connector/mcp/skill-source.ts +499 -0
- package/src/connector/mcp/skills.ts +367 -0
- package/src/network/audit.ts +2 -0
- package/src/network/computer.ts +347 -0
- package/src/network/index.ts +20 -0
- package/src/network/join.ts +4 -2
- package/src/network/roster.ts +5 -0
- package/src/network/service.ts +492 -75
- package/src/network/store.ts +29 -3
- package/src/network/wire.ts +5 -0
- package/src/plugin/shell-hook-tool-names.ts +1 -0
- package/src/plugin/shell-hook.ts +144 -7
- package/src/provider/fallback.ts +4 -0
- package/src/provider/idle-timeout.ts +3 -0
- package/src/provider/model-window-suffix.ts +1 -0
- package/src/provider/retry.ts +3 -0
- package/src/public-runtime.ts +99 -0
- package/src/public-tools.ts +9 -0
- package/src/public-types.ts +28 -0
- package/src/runtime/query/executor/tool-call-admission.ts +10 -1
- package/src/runtime/query/executor.ts +57 -8
- package/src/runtime/query/index.ts +43 -0
- package/src/runtime/query/review-policy.ts +7 -1
- package/src/runtime/query/shell-line-escalation.ts +49 -0
- package/src/runtime/query/tooling.ts +6 -0
- package/src/runtime/query/turn/outcome-ledger.ts +11 -0
- package/src/scheduler/local.ts +3 -1
- package/src/skills/index.ts +43 -0
- package/src/skills/inline-shell-host.ts +303 -0
- package/src/skills/inline-shell.ts +765 -0
- package/src/store/index.ts +8 -0
- package/src/store/task/file.ts +641 -0
- package/src/teams/backend.ts +29 -0
- package/src/teams/fs-sync.ts +91 -0
- package/src/teams/index.ts +47 -0
- package/src/teams/names.ts +49 -0
- package/src/teams/store.ts +607 -0
- package/src/teams/types.ts +102 -0
- package/src/tools/admit-facts.ts +9 -1
- package/src/tools/builtins/computer-use.ts +689 -95
- package/src/tools/builtins/index.ts +1 -0
- package/src/tools/builtins/skill.ts +291 -95
- package/src/tools/task/create.ts +11 -2
- package/src/tools/task/get.ts +53 -0
- package/src/tools/task/index.ts +14 -2
- package/src/tools/task/list.ts +10 -2
- package/src/tools/task/number.ts +32 -0
- package/src/tools/task/present.ts +18 -3
- package/src/tools/task/update.ts +93 -19
- package/src/types/acp/index.ts +11 -1
- package/src/types/agent/base.ts +6 -0
- package/src/types/agent/scheduler.ts +9 -0
- package/src/types/computer-use/index.ts +7 -0
- package/src/types/connector/mcp.ts +10 -0
- package/src/types/permission/index.ts +29 -0
- package/src/types/plugin/index.ts +95 -39
- package/src/types/provider/interface.ts +7 -0
- package/src/types/tool/index.ts +23 -2
- package/src/types/tool/presentation.ts +2 -0
|
@@ -0,0 +1,238 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* How a host runs the commands a skill's text holds, through the machinery it
|
|
3
|
+
* already has.
|
|
4
|
+
*
|
|
5
|
+
* - {@link skillShellHookVerdict} reads what `pre_skill_shell_command` hooks
|
|
6
|
+
* answered into one verdict for one command.
|
|
7
|
+
* - {@link createSkillShellHook} asks those hooks, and answers `undefined`
|
|
8
|
+
* when none is attached so nothing is asked of nobody.
|
|
9
|
+
* - {@link createPreToolUseShellHook} asks the `pre_tool_use` hooks the shell
|
|
10
|
+
* tool's own calls are asked, for a load that has no turn to ask them in.
|
|
11
|
+
* - {@link createToolSkillShellHost} runs a command as a nested call of the
|
|
12
|
+
* shell tool from inside another tool (the `skill` tool): the same
|
|
13
|
+
* authorization gate, the same sandbox and the same tool a model's own call
|
|
14
|
+
* goes through, and no second executor.
|
|
15
|
+
* - {@link skillShellAllow} turns a skill's `allowed-tools` into a
|
|
16
|
+
* pre-approval that holds for the one expansion.
|
|
17
|
+
*/
|
|
18
|
+
import { SkillGrantSet, compileSkillGrant } from '../authorization/skill-grant.js';
|
|
19
|
+
import { INLINE_SHELL_REASON_CHARS, splitShellToolOutput, } from './inline-shell.js';
|
|
20
|
+
/** The tool a skill's commands run in. */
|
|
21
|
+
export const SKILL_SHELL_TOOL_NAME = 'bash';
|
|
22
|
+
/** The event a host fires before each command, after permission allowed it. */
|
|
23
|
+
export const PRE_SKILL_SHELL_COMMAND_EVENT = 'pre_skill_shell_command';
|
|
24
|
+
/** The event the shell tool's own calls are checked by; a load outside a turn asks it too. */
|
|
25
|
+
export const PRE_TOOL_USE_EVENT = 'pre_tool_use';
|
|
26
|
+
/** The deadline the lifecycle manager gives a hook before it counts as timed out. */
|
|
27
|
+
const MANAGER_TIMEOUT_MESSAGE = 'Hook timeout';
|
|
28
|
+
/**
|
|
29
|
+
* One command's verdict from every hook's answer.
|
|
30
|
+
*
|
|
31
|
+
* - A stop (`halt`) outranks a refusal, which outranks everything else.
|
|
32
|
+
* - A `skip` refuses this command and nothing else.
|
|
33
|
+
* - An in-process hook that asks for approval, or rewrites the command, is
|
|
34
|
+
* refused: a load cannot wait for a person and never runs a changed command.
|
|
35
|
+
* - A hook that did not answer, that crashed or that ran out of time refuses
|
|
36
|
+
* the command: nothing says it is safe. This is how a `pre_tool_use` hook that
|
|
37
|
+
* times out treats the shell tool's own call.
|
|
38
|
+
*/
|
|
39
|
+
export function skillShellHookVerdict(results, attached) {
|
|
40
|
+
if (attached > 0 && results.length === 0) {
|
|
41
|
+
return { kind: 'refuse', reason: "the hook didn't answer" };
|
|
42
|
+
}
|
|
43
|
+
const warnings = [];
|
|
44
|
+
const refusals = [];
|
|
45
|
+
let stop;
|
|
46
|
+
for (const result of results) {
|
|
47
|
+
const notice = 'notice' in result ? result.notice : undefined;
|
|
48
|
+
if (notice)
|
|
49
|
+
warnings.push(notice);
|
|
50
|
+
switch (result.action) {
|
|
51
|
+
case 'skip':
|
|
52
|
+
refusals.push(result.reason);
|
|
53
|
+
break;
|
|
54
|
+
case 'continue':
|
|
55
|
+
if (result.halt !== undefined && stop === undefined)
|
|
56
|
+
stop = result.halt.reason;
|
|
57
|
+
if (result.permission?.decision === 'ask') {
|
|
58
|
+
refusals.push("the hook asked for approval, which a skill can't wait for");
|
|
59
|
+
}
|
|
60
|
+
break;
|
|
61
|
+
case 'modify':
|
|
62
|
+
refusals.push("the hook changed the command, which isn't supported here");
|
|
63
|
+
break;
|
|
64
|
+
case 'error':
|
|
65
|
+
refusals.push(result.message === MANAGER_TIMEOUT_MESSAGE
|
|
66
|
+
? 'the hook timed out'
|
|
67
|
+
: "the hook couldn't run");
|
|
68
|
+
break;
|
|
69
|
+
default:
|
|
70
|
+
break;
|
|
71
|
+
}
|
|
72
|
+
}
|
|
73
|
+
const warning = warnings.length > 0 ? warnings.join('\n') : undefined;
|
|
74
|
+
if (stop !== undefined)
|
|
75
|
+
return { kind: 'stop', reason: stop };
|
|
76
|
+
if (refusals.length > 0) {
|
|
77
|
+
const reason = refusals.join('; ').slice(0, INLINE_SHELL_REASON_CHARS * 2);
|
|
78
|
+
return { kind: 'refuse', reason, ...(warning ? { warning } : {}) };
|
|
79
|
+
}
|
|
80
|
+
return { kind: 'run', ...(warning ? { warning } : {}) };
|
|
81
|
+
}
|
|
82
|
+
/**
|
|
83
|
+
* Ask the hooks about one command. `undefined` when the manager has none for
|
|
84
|
+
* the event, so a session with no such hook pays nothing and fires nothing.
|
|
85
|
+
*/
|
|
86
|
+
export function createSkillShellHook(options) {
|
|
87
|
+
return createShellEventHook(PRE_SKILL_SHELL_COMMAND_EVENT, options, {
|
|
88
|
+
skillShell: options.info,
|
|
89
|
+
});
|
|
90
|
+
}
|
|
91
|
+
/**
|
|
92
|
+
* Ask the session's `pre_tool_use` hooks about one command, as they are asked
|
|
93
|
+
* about the shell tool's own call. Inside a turn the executor does it for a
|
|
94
|
+
* nested call; a load outside a turn (a typed command, a headless prompt, a
|
|
95
|
+
* preload) has no executor, so the host asks here. A refusal, a stop, a request
|
|
96
|
+
* for approval, a rewrite, a timeout or a crash all refuse the command: a load
|
|
97
|
+
* cannot wait for a person and never runs a changed command. `undefined` when
|
|
98
|
+
* no such hook is attached.
|
|
99
|
+
*/
|
|
100
|
+
export function createPreToolUseShellHook(options) {
|
|
101
|
+
return createShellEventHook(PRE_TOOL_USE_EVENT, options, {});
|
|
102
|
+
}
|
|
103
|
+
function createShellEventHook(event, options, extra) {
|
|
104
|
+
const manager = options.manager;
|
|
105
|
+
if (manager === undefined)
|
|
106
|
+
return undefined;
|
|
107
|
+
const countAttached = () => manager.listHooks().filter((hook) => hook.event === event).length;
|
|
108
|
+
if (countAttached() === 0)
|
|
109
|
+
return undefined;
|
|
110
|
+
const toolName = options.toolName ?? SKILL_SHELL_TOOL_NAME;
|
|
111
|
+
return async (command, toolUseId) => {
|
|
112
|
+
// Read again for each command: a hook a skill attaches while it loads counts.
|
|
113
|
+
const attached = countAttached();
|
|
114
|
+
if (attached === 0)
|
|
115
|
+
return { kind: 'run' };
|
|
116
|
+
try {
|
|
117
|
+
const results = await manager.executeHooks(event, {
|
|
118
|
+
sessionId: options.sessionId,
|
|
119
|
+
...(options.turnId !== undefined ? { turnId: options.turnId } : {}),
|
|
120
|
+
toolName,
|
|
121
|
+
toolInput: { command },
|
|
122
|
+
toolCallId: toolUseId,
|
|
123
|
+
...extra,
|
|
124
|
+
...(options.signal ? { signal: options.signal } : {}),
|
|
125
|
+
});
|
|
126
|
+
return skillShellHookVerdict(results, attached);
|
|
127
|
+
}
|
|
128
|
+
catch (error) {
|
|
129
|
+
if (options.signal?.aborted)
|
|
130
|
+
throw error;
|
|
131
|
+
return { kind: 'refuse', reason: "the hook couldn't run" };
|
|
132
|
+
}
|
|
133
|
+
};
|
|
134
|
+
}
|
|
135
|
+
/**
|
|
136
|
+
* The pre-approval a skill's `allowed-tools` gives to its own commands, for
|
|
137
|
+
* one expansion. Only entries for the shell tool count; any other entry is
|
|
138
|
+
* not read here. Absent when the skill grants the shell tool nothing.
|
|
139
|
+
*/
|
|
140
|
+
export function skillShellAllow(allowedTools, options = {}) {
|
|
141
|
+
if (allowedTools === undefined || allowedTools.length === 0)
|
|
142
|
+
return undefined;
|
|
143
|
+
const toolName = options.toolName ?? SKILL_SHELL_TOOL_NAME;
|
|
144
|
+
const compiled = compileSkillGrant(allowedTools, {
|
|
145
|
+
resolveTool: (name) => name.toLowerCase() === toolName ? { name: toolName, commandArgument: 'command' } : undefined,
|
|
146
|
+
...(options.skillDirectory ? { skillDirectory: options.skillDirectory } : {}),
|
|
147
|
+
});
|
|
148
|
+
if (compiled.entries.length === 0)
|
|
149
|
+
return undefined;
|
|
150
|
+
const held = new SkillGrantSet();
|
|
151
|
+
held.grant('inline-shell', compiled);
|
|
152
|
+
return (call) => held.coveringSkill(call) !== undefined;
|
|
153
|
+
}
|
|
154
|
+
/** Strip the tool's closing `Error: ...` line off a failed result's text. */
|
|
155
|
+
function withoutErrorLine(text) {
|
|
156
|
+
const at = text.lastIndexOf('\n\nError: ');
|
|
157
|
+
if (at !== -1)
|
|
158
|
+
return text.slice(0, at);
|
|
159
|
+
return text.startsWith('Error: ') ? '' : text;
|
|
160
|
+
}
|
|
161
|
+
/**
|
|
162
|
+
* A host that runs each command by dispatching the shell tool from inside the
|
|
163
|
+
* tool that is loading the text. A command a rule does not allow is refused
|
|
164
|
+
* with the rule's reason, because a person cannot be asked from inside
|
|
165
|
+
* another tool's call.
|
|
166
|
+
*/
|
|
167
|
+
export function createToolSkillShellHost(options) {
|
|
168
|
+
const toolName = options.toolName ?? SKILL_SHELL_TOOL_NAME;
|
|
169
|
+
const dispatch = options.context.dispatchTool;
|
|
170
|
+
return {
|
|
171
|
+
async run(command, beforeRun) {
|
|
172
|
+
if (dispatch === undefined) {
|
|
173
|
+
return {
|
|
174
|
+
kind: 'denied',
|
|
175
|
+
reason: 'this turn cannot run a tool from inside another one',
|
|
176
|
+
};
|
|
177
|
+
}
|
|
178
|
+
let hook;
|
|
179
|
+
let result;
|
|
180
|
+
try {
|
|
181
|
+
result = await dispatch(toolName, { command }, {
|
|
182
|
+
...(options.allow ? { allow: options.allow } : {}),
|
|
183
|
+
beforeRun: async () => {
|
|
184
|
+
const verdict = await beforeRun();
|
|
185
|
+
if (verdict.kind === 'run')
|
|
186
|
+
return undefined;
|
|
187
|
+
hook = verdict;
|
|
188
|
+
return 'refused by a hook';
|
|
189
|
+
},
|
|
190
|
+
});
|
|
191
|
+
}
|
|
192
|
+
catch (error) {
|
|
193
|
+
if (options.context.abortSignal.aborted) {
|
|
194
|
+
return { kind: 'ran', stdout: '', stderr: '', exitCode: null, interrupted: true };
|
|
195
|
+
}
|
|
196
|
+
throw error;
|
|
197
|
+
}
|
|
198
|
+
if (hook !== undefined)
|
|
199
|
+
return { kind: 'hook', verdict: hook };
|
|
200
|
+
return outcomeOf(result);
|
|
201
|
+
},
|
|
202
|
+
};
|
|
203
|
+
}
|
|
204
|
+
/** A shell tool result as the host's outcome of one command. */
|
|
205
|
+
export function outcomeOf(result) {
|
|
206
|
+
const data = result.data !== null && typeof result.data === 'object'
|
|
207
|
+
? result.data
|
|
208
|
+
: undefined;
|
|
209
|
+
const exitCode = typeof data?.exitCode === 'number' ? data.exitCode : undefined;
|
|
210
|
+
const ran = data !== undefined && ('exitCode' in data || 'timedOut' in data);
|
|
211
|
+
if (!ran && !result.success) {
|
|
212
|
+
return { kind: 'denied', reason: deniedReason(result.error ?? result.output) };
|
|
213
|
+
}
|
|
214
|
+
// Through a nested dispatch a failure's text is in `error` (output and the closing line
|
|
215
|
+
// joined); from the tool itself it is in `output`, with the closing line in `error`.
|
|
216
|
+
const text = result.success
|
|
217
|
+
? result.output
|
|
218
|
+
: result.output !== ''
|
|
219
|
+
? result.output
|
|
220
|
+
: withoutErrorLine(result.error ?? '');
|
|
221
|
+
const { stdout, stderr } = splitShellToolOutput(text);
|
|
222
|
+
if (result.success) {
|
|
223
|
+
return { kind: 'ran', stdout, stderr, exitCode: exitCode ?? 0 };
|
|
224
|
+
}
|
|
225
|
+
return {
|
|
226
|
+
kind: 'ran',
|
|
227
|
+
stdout,
|
|
228
|
+
stderr,
|
|
229
|
+
exitCode: exitCode ?? null,
|
|
230
|
+
};
|
|
231
|
+
}
|
|
232
|
+
/** The words after `Tool "x" was not executed.` when that is how the refusal begins. */
|
|
233
|
+
function deniedReason(text) {
|
|
234
|
+
const trimmed = text.replace(/^Error:\s*/, '');
|
|
235
|
+
const match = /^Tool "[^"]*" was not executed\.\s*/.exec(trimmed);
|
|
236
|
+
return (match ? trimmed.slice(match[0].length) : trimmed).trim() || 'refused';
|
|
237
|
+
}
|
|
238
|
+
//# sourceMappingURL=inline-shell-host.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"inline-shell-host.js","sourceRoot":"","sources":["../../src/skills/inline-shell-host.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;GAgBG;AAEH,OAAO,EAAE,aAAa,EAAE,iBAAiB,EAAE,MAAM,iCAAiC,CAAA;AAKlF,OAAO,EACN,yBAAyB,EAIzB,oBAAoB,GACpB,MAAM,mBAAmB,CAAA;AAE1B,0CAA0C;AAC1C,MAAM,CAAC,MAAM,qBAAqB,GAAG,MAAM,CAAA;AAE3C,+EAA+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YACrB,CAAC,CAAC,MAAM,CAAC,MAAM;YACf,CAAC,CAAC,gBAAgB,CAAC,MAAM,CAAC,KAAK,IAAI,EAAE,CAAC,CAAA;IACxC,MAAM,EAAE,MAAM,EAAE,MAAM,EAAE,GAAG,oBAAoB,CAAC,IAAI,CAAC,CAAA;IACrD,IAAI,MAAM,CAAC,OAAO,EAAE,CAAC;QACpB,OAAO,EAAE,IAAI,EAAE,KAAK,EAAE,MAAM,EAAE,MAAM,EAAE,QAAQ,EAAE,QAAQ,IAAI,CAAC,EAAE,CAAA;IAChE,CAAC;IACD,OAAO;QACN,IAAI,EAAE,KAAK;QACX,MAAM;QACN,MAAM;QACN,QAAQ,EAAE,QAAQ,IAAI,IAAI;KAC1B,CAAA;AACF,CAAC;AAED,wFAAwF;AACxF,SAAS,YAAY,CAAC,IAAY;IACjC,MAAM,OAAO,GAAG,IAAI,CAAC,OAAO,CAAC,YAAY,EAAE,EAAE,CAAC,CAAA;IAC9C,MAAM,KAAK,GAAG,qCAAqC,CAAC,IAAI,CAAC,OAAO,CAAC,CAAA;IACjE,OAAO,CAAC,KAAK,CAAC,CAAC,CAAC,OAAO,CAAC,KAAK,CAAC,KAAK,CAAC,CAAC,CAAC,CAAC,MAAM,CAAC,CAAC,CAAC,CAAC,OAAO,CAAC,CAAC,IAAI,EAAE,IAAI,SAAS,CAAA;AAC9E,CAAC"}
|
|
@@ -0,0 +1,176 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Shell commands written inside a skill or a custom command, run while the
|
|
3
|
+
* text loads.
|
|
4
|
+
*
|
|
5
|
+
* Two forms, both read by {@link findInlineShell}:
|
|
6
|
+
*
|
|
7
|
+
* - A fenced block opened by a line that is three backticks and a bang, closed
|
|
8
|
+
* by a line of three backticks. Everything between is ONE command, so a
|
|
9
|
+
* multi-line script runs as a single shell call.
|
|
10
|
+
* - Inline: a bang and a backtick span, `!` then a backtick, the command, a
|
|
11
|
+
* backtick, where the bang starts the text or follows whitespace.
|
|
12
|
+
*
|
|
13
|
+
* An ordinary backtick span and an ordinary fence are masked first, so the
|
|
14
|
+
* documentation a skill shows (a command in code font, an example block)
|
|
15
|
+
* never runs. An unterminated shell fence is plain text.
|
|
16
|
+
*
|
|
17
|
+
* This file reads no permission and no file; the one thing it asks of the process is which
|
|
18
|
+
* shell reads a command, when a value lands inside one. {@link expandInlineShell}
|
|
19
|
+
* takes the host's way of running one command (permission check, the hook, the
|
|
20
|
+
* shell tool) and decides everything around it: limits, placeholders, how the
|
|
21
|
+
* output replaces the marker, what fails the load.
|
|
22
|
+
*
|
|
23
|
+
* ## A value never becomes a command
|
|
24
|
+
*
|
|
25
|
+
* The order is: substitute `$ARGUMENTS` and the variables, then read the
|
|
26
|
+
* commands. A value a person typed (or a model sent), and any path or name the
|
|
27
|
+
* host wrote into the text, is therefore text that the reader sees, so
|
|
28
|
+
* {@link substituteEscaped} does two things. Outside a command it rewrites the
|
|
29
|
+
* shapes that would begin one. Inside a command it quotes the value for the
|
|
30
|
+
* shell, one word at a time, so it is read as arguments and never as shell
|
|
31
|
+
* syntax. It refuses the load if a value managed to add a command anyway.
|
|
32
|
+
*/
|
|
33
|
+
import type { ShellDialect } from '../types/tool/index.js';
|
|
34
|
+
/** Most commands one expansion may run. */
|
|
35
|
+
export declare const INLINE_SHELL_MAX_COMMANDS = 256;
|
|
36
|
+
/** Longest command text, in characters. */
|
|
37
|
+
export declare const INLINE_SHELL_MAX_COMMAND_CHARS = 32768;
|
|
38
|
+
/** Most characters of command output one expansion may put into the text. */
|
|
39
|
+
export declare const INLINE_SHELL_MAX_OUTPUT_CHARS = 4000000;
|
|
40
|
+
/** The longest reason from a hook that is shown. */
|
|
41
|
+
export declare const INLINE_SHELL_REASON_CHARS = 500;
|
|
42
|
+
/** The longest command shown in a warning. */
|
|
43
|
+
export declare const INLINE_SHELL_COMMAND_SHOWN_CHARS = 80;
|
|
44
|
+
export type InlineShellKind = 'fence' | 'inline';
|
|
45
|
+
/** One command found in a text: the marker as written, and where it sits. */
|
|
46
|
+
export interface InlineShellMarker {
|
|
47
|
+
readonly kind: InlineShellKind;
|
|
48
|
+
/** Offset of the first character of the marker, in the normalised text. */
|
|
49
|
+
readonly start: number;
|
|
50
|
+
/** Offset just past the last character of the marker. */
|
|
51
|
+
readonly end: number;
|
|
52
|
+
/** The command, trimmed. */
|
|
53
|
+
readonly command: string;
|
|
54
|
+
/** The marker as written. */
|
|
55
|
+
readonly raw: string;
|
|
56
|
+
}
|
|
57
|
+
/** The text with line endings as `\n`, which is the text every offset refers to. */
|
|
58
|
+
export declare function normalizeInlineShellText(text: string): string;
|
|
59
|
+
/**
|
|
60
|
+
* Every command in the text, in order. Offsets refer to
|
|
61
|
+
* {@link normalizeInlineShellText} of the text; {@link expandInlineShell} does
|
|
62
|
+
* that first, and a caller that splices by hand must do the same.
|
|
63
|
+
*/
|
|
64
|
+
export declare function findInlineShell(text: string): InlineShellMarker[];
|
|
65
|
+
/**
|
|
66
|
+
* A value made safe to put into a text that is read for commands afterwards:
|
|
67
|
+
* the shapes that open a command are broken by a space, and a leading bang is
|
|
68
|
+
* escaped so the template's own backtick after it cannot complete one.
|
|
69
|
+
*/
|
|
70
|
+
export declare function escapeInlineShell(value: string): string;
|
|
71
|
+
/** A load that cannot go on: the reason is the message, and what to do about it is in it. */
|
|
72
|
+
export declare class InlineShellError extends Error {
|
|
73
|
+
readonly reason: 'failed' | 'interrupted' | 'permission' | 'limit' | 'stopped' | 'injection';
|
|
74
|
+
constructor(message: string, reason: 'failed' | 'interrupted' | 'permission' | 'limit' | 'stopped' | 'injection');
|
|
75
|
+
}
|
|
76
|
+
/**
|
|
77
|
+
* Put values into a template, each escaped, and prove no value added a
|
|
78
|
+
* command. `values` maps the token written in the text (`$ARGUMENTS`) to its
|
|
79
|
+
* value.
|
|
80
|
+
*
|
|
81
|
+
* A value outside a command is rewritten so that no shape of it begins one
|
|
82
|
+
* ({@link escapeInlineShell}). A value inside a command is quoted so the shell
|
|
83
|
+
* reads it as data ({@link quoteForCommand}), by where it sits: a person's
|
|
84
|
+
* `-n 5` stays two arguments, and `x; touch f #` stays words of an argument
|
|
85
|
+
* list. Throws {@link InlineShellError} when a value cannot be made safe, or the
|
|
86
|
+
* substituted text holds more commands than the template does.
|
|
87
|
+
*/
|
|
88
|
+
export declare function substituteEscaped(template: string, values: Readonly<Record<string, string>>, options?: {
|
|
89
|
+
readonly dialect?: ShellDialect;
|
|
90
|
+
}): string;
|
|
91
|
+
export declare const SHELL_OFF_PLACEHOLDER = "[shell commands are turned off (disableSkillShellExecution), so this command was not run]";
|
|
92
|
+
export declare const SHELL_REMOTE_PLACEHOLDER = "[shell commands are not run in text that comes from a tool server or another remote source, so this command was not run]";
|
|
93
|
+
export declare const SHELL_UNTRUSTED_PLACEHOLDER = "[shell commands are not run until this folder is trusted, so this command was not run]";
|
|
94
|
+
export declare const SHELL_PRELOAD_PLACEHOLDER = "[shell commands in a skill preloaded into an agent are not run when the agent is set up, so this command was not run]";
|
|
95
|
+
/** Why a command in this text may not run at all, before any is tried. */
|
|
96
|
+
export type InlineShellBlock = 'off' | 'remote' | 'untrusted' | 'preload';
|
|
97
|
+
/** What a hook said about one command. */
|
|
98
|
+
export type InlineShellHookVerdict = {
|
|
99
|
+
readonly kind: 'run';
|
|
100
|
+
readonly warning?: string;
|
|
101
|
+
}
|
|
102
|
+
/** Not this command; the rest of the text loads. */
|
|
103
|
+
| {
|
|
104
|
+
readonly kind: 'refuse';
|
|
105
|
+
readonly reason?: string;
|
|
106
|
+
readonly warning?: string;
|
|
107
|
+
}
|
|
108
|
+
/** The whole load stops. */
|
|
109
|
+
| {
|
|
110
|
+
readonly kind: 'stop';
|
|
111
|
+
readonly reason: string;
|
|
112
|
+
};
|
|
113
|
+
/** How the host ended one command. */
|
|
114
|
+
export type InlineShellOutcome =
|
|
115
|
+
/** The permission rules said no, or would have asked a person who is not there. */
|
|
116
|
+
{
|
|
117
|
+
readonly kind: 'denied';
|
|
118
|
+
readonly reason: string;
|
|
119
|
+
}
|
|
120
|
+
/** The hook, which runs after permission and before the shell, refused or stopped. */
|
|
121
|
+
| {
|
|
122
|
+
readonly kind: 'hook';
|
|
123
|
+
readonly verdict: Exclude<InlineShellHookVerdict, {
|
|
124
|
+
kind: 'run';
|
|
125
|
+
}>;
|
|
126
|
+
} | {
|
|
127
|
+
readonly kind: 'ran';
|
|
128
|
+
readonly stdout: string;
|
|
129
|
+
readonly stderr: string;
|
|
130
|
+
/** Zero is success. `null` when the command did not report one. */
|
|
131
|
+
readonly exitCode: number | null;
|
|
132
|
+
readonly interrupted?: boolean;
|
|
133
|
+
};
|
|
134
|
+
export interface InlineShellHost {
|
|
135
|
+
/**
|
|
136
|
+
* Run one command: check permission, then call `beforeRun`, then start it.
|
|
137
|
+
* `beforeRun` must be called exactly when the permission check has allowed
|
|
138
|
+
* the command and the command has not started, and a verdict other than
|
|
139
|
+
* `run` must end the call with `{ kind: 'hook', verdict }`.
|
|
140
|
+
*/
|
|
141
|
+
run(command: string, beforeRun: () => Promise<InlineShellHookVerdict>): Promise<InlineShellOutcome>;
|
|
142
|
+
}
|
|
143
|
+
export interface InlineShellOptions {
|
|
144
|
+
readonly host: InlineShellHost;
|
|
145
|
+
/** The skill or command, for the line a warning names. */
|
|
146
|
+
readonly commandName: string;
|
|
147
|
+
/** Set when no command may run; each is replaced by the matching placeholder. */
|
|
148
|
+
readonly block?: InlineShellBlock;
|
|
149
|
+
/** Absent when no hook is attached for the event: nothing is asked. */
|
|
150
|
+
readonly hook?: (command: string) => Promise<InlineShellHookVerdict>;
|
|
151
|
+
/** A line for the person, for a refused command and a warning from a hook. */
|
|
152
|
+
readonly warn?: (line: string) => void;
|
|
153
|
+
readonly signal?: AbortSignal;
|
|
154
|
+
}
|
|
155
|
+
/** Trimmed standard output, then a `[stderr]` block when there is any standard error. */
|
|
156
|
+
export declare function shapeShellOutput(stdout: string, stderr: string): string;
|
|
157
|
+
/**
|
|
158
|
+
* Run every command in `text` and put each one's output where it was written.
|
|
159
|
+
*
|
|
160
|
+
* Commands run one after another, in order. A load fails (throws
|
|
161
|
+
* {@link InlineShellError}) on: more than 256 commands, a command over 32 KB,
|
|
162
|
+
* more than 4 MB of output in all, a permission refusal, a non-zero exit, an
|
|
163
|
+
* interrupt, or a hook's request to stop. A hook that refuses one command
|
|
164
|
+
* leaves `[not run: blocked by hook: <reason>]` in its place and loads the rest.
|
|
165
|
+
*/
|
|
166
|
+
export declare function expandInlineShell(text: string, options: InlineShellOptions): Promise<string>;
|
|
167
|
+
/**
|
|
168
|
+
* Turn the text of a bash tool result into its two streams. The tool labels
|
|
169
|
+
* them `STDOUT:` and `STDERR:`; a result with neither label is all standard
|
|
170
|
+
* output, and `(no output)` is nothing.
|
|
171
|
+
*/
|
|
172
|
+
export declare function splitShellToolOutput(output: string): {
|
|
173
|
+
stdout: string;
|
|
174
|
+
stderr: string;
|
|
175
|
+
};
|
|
176
|
+
//# sourceMappingURL=inline-shell.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"inline-shell.d.ts","sourceRoot":"","sources":["../../src/skills/inline-shell.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GA+BG;AAGH,OAAO,KAAK,EAAE,YAAY,EAAE,MAAM,wBAAwB,CAAA;AAE1D,2CAA2C;AAC3C,eAAO,MAAM,yBAAyB,MAAM,CAAA;AAC5C,2CAA2C;AAC3C,eAAO,MAAM,8BAA8B,QAAS,CAAA;AACpD,6EAA6E;AAC7E,eAAO,MAAM,6BAA6B,UAAY,CAAA;AACtD,oDAAoD;AACpD,eAAO,MAAM,yBAAyB,MAAM,CAAA;AAC5C,8CAA8C;AAC9C,eAAO,MAAM,gCAAgC,KAAK,CAAA;AAElD,MAAM,MAAM,eAAe,GAAG,OAAO,GAAG,QAAQ,CAAA;AAEhD,6EAA6E;AAC7E,MAAM,WAAW,iBAAiB;IACjC,QAAQ,CAAC,IAAI,EAAE,eAAe,CAAA;IAC9B,2EAA2E;IAC3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