@cjhyy/code-shell-core 0.7.0 → 0.7.1
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/dist/arena/arena.d.ts +2 -0
- package/dist/arena/arena.js +30 -1
- package/dist/arena/phases/adjudication.d.ts +2 -1
- package/dist/arena/phases/adjudication.js +2 -1
- package/dist/arena/phases/build-consensus.d.ts +2 -1
- package/dist/arena/phases/build-consensus.js +3 -1
- package/dist/arena/phases/cross-review.d.ts +3 -1
- package/dist/arena/phases/cross-review.js +8 -2
- package/dist/arena/phases/debate-rounds.d.ts +2 -1
- package/dist/arena/phases/debate-rounds.js +4 -2
- package/dist/arena/phases/participant-research.d.ts +2 -1
- package/dist/arena/phases/participant-research.js +3 -1
- package/dist/arena/phases/planning-detail-expansion.d.ts +2 -1
- package/dist/arena/phases/planning-detail-expansion.js +2 -1
- package/dist/arena/planner.d.ts +2 -1
- package/dist/arena/planner.js +2 -1
- package/dist/arena/types.d.ts +5 -1
- package/dist/cli/agent-server-tcp.js +13 -2
- package/dist/context/manager.d.ts +3 -3
- package/dist/context/manager.js +6 -6
- package/dist/context/token-counter.js +5 -3
- package/dist/context/tool-result-storage.d.ts +6 -0
- package/dist/context/tool-result-storage.js +25 -4
- package/dist/credentials/access.d.ts +10 -1
- package/dist/credentials/access.js +76 -2
- package/dist/credentials/index.d.ts +3 -2
- package/dist/credentials/index.js +2 -1
- package/dist/credentials/oauth.d.ts +6 -1
- package/dist/credentials/oauth.js +66 -1
- package/dist/credentials/store.d.ts +1 -1
- package/dist/credentials/store.js +16 -7
- package/dist/credentials/types.d.ts +38 -1
- package/dist/credentials/types.js +16 -1
- package/dist/engine/engine.d.ts +61 -32
- package/dist/engine/engine.js +289 -55
- package/dist/engine/goal.d.ts +5 -3
- package/dist/engine/session-title.d.ts +2 -1
- package/dist/engine/session-title.js +4 -1
- package/dist/engine/turn-loop.d.ts +18 -0
- package/dist/engine/turn-loop.js +202 -27
- package/dist/engine/types.d.ts +6 -2
- package/dist/git/worktree/crud.d.ts +3 -0
- package/dist/git/worktree/crud.js +32 -3
- package/dist/git/worktree/git-exec.d.ts +2 -2
- package/dist/git/worktree/git-exec.js +47 -11
- package/dist/git/worktree/query.d.ts +8 -7
- package/dist/git/worktree/query.js +27 -20
- package/dist/hooks/events.d.ts +3 -0
- package/dist/hooks/events.js +0 -3
- package/dist/hooks/goal-stop-hook.d.ts +14 -4
- package/dist/hooks/goal-stop-hook.js +626 -71
- package/dist/hooks/registry.js +3 -0
- package/dist/hooks/shell-runner.d.ts +12 -1
- package/dist/hooks/shell-runner.js +160 -9
- package/dist/index.d.ts +7 -6
- package/dist/index.js +6 -5
- package/dist/llm/client-base.js +12 -10
- package/dist/llm/types.d.ts +12 -5
- package/dist/plugins/pluginCommandHook.d.ts +4 -4
- package/dist/plugins/pluginCommandHook.js +111 -13
- package/dist/protocol/chat-session-manager.d.ts +13 -2
- package/dist/protocol/chat-session-manager.js +90 -18
- package/dist/protocol/chat-session.d.ts +12 -0
- package/dist/protocol/chat-session.js +30 -5
- package/dist/protocol/client.d.ts +5 -2
- package/dist/protocol/client.js +22 -1
- package/dist/protocol/server.d.ts +25 -11
- package/dist/protocol/server.js +290 -72
- package/dist/protocol/types.d.ts +34 -2
- package/dist/protocol/types.js +2 -0
- package/dist/services/dream-consolidation.d.ts +3 -0
- package/dist/services/dream-consolidation.js +4 -1
- package/dist/services/index.d.ts +1 -1
- package/dist/services/index.js +1 -1
- package/dist/services/oauth.d.ts +34 -10
- package/dist/services/oauth.js +233 -98
- package/dist/session/session-manager.d.ts +35 -6
- package/dist/session/session-manager.js +362 -26
- package/dist/session/transcript.d.ts +30 -1
- package/dist/session/transcript.js +119 -4
- package/dist/tool-system/builtin/agent.js +5 -1
- package/dist/tool-system/builtin/arena.js +1 -0
- package/dist/tool-system/builtin/background-jobs.d.ts +8 -5
- package/dist/tool-system/builtin/background-jobs.js +15 -11
- package/dist/tool-system/builtin/background-work.d.ts +6 -1
- package/dist/tool-system/builtin/background-work.js +5 -1
- package/dist/tool-system/builtin/bash.d.ts +3 -5
- package/dist/tool-system/builtin/bash.js +10 -5
- package/dist/tool-system/builtin/browser-tools.d.ts +2 -2
- package/dist/tool-system/builtin/edit.d.ts +2 -1
- package/dist/tool-system/builtin/edit.js +12 -4
- package/dist/tool-system/builtin/generate-video.d.ts +4 -0
- package/dist/tool-system/builtin/generate-video.js +138 -21
- package/dist/tool-system/builtin/glob.d.ts +2 -1
- package/dist/tool-system/builtin/glob.js +28 -3
- package/dist/tool-system/builtin/grep.d.ts +1 -0
- package/dist/tool-system/builtin/grep.js +82 -17
- package/dist/tool-system/builtin/index.d.ts +25 -11
- package/dist/tool-system/builtin/index.js +45 -2
- package/dist/tool-system/builtin/video-providers.d.ts +12 -15
- package/dist/tool-system/builtin/video-providers.js +1 -0
- package/dist/tool-system/builtin/view-image.d.ts +2 -2
- package/dist/tool-system/builtin/web-fetch.js +44 -3
- package/dist/tool-system/builtin/worktree.js +25 -7
- package/dist/tool-system/builtin/write.d.ts +2 -1
- package/dist/tool-system/builtin/write.js +14 -4
- package/dist/tool-system/context.d.ts +17 -5
- package/dist/tool-system/executor.js +24 -8
- package/dist/tool-system/mcp-manager.d.ts +6 -0
- package/dist/tool-system/mcp-manager.js +55 -5
- package/dist/tool-system/path-policy.d.ts +19 -0
- package/dist/tool-system/path-policy.js +62 -1
- package/dist/tool-system/permission.d.ts +43 -3
- package/dist/tool-system/permission.js +383 -30
- package/dist/tool-system/registry.d.ts +3 -2
- package/dist/tool-system/registry.js +52 -34
- package/dist/types.d.ts +15 -0
- package/package.json +1 -1
|
@@ -2,7 +2,7 @@
|
|
|
2
2
|
* Unified tool registry — built-in tools + MCP tools.
|
|
3
3
|
*/
|
|
4
4
|
import { ConfigError, ToolNotFoundError, ToolExecutionError, ToolTimeoutError, } from "../exceptions.js";
|
|
5
|
-
import { BUILTIN_TOOLS } from "./builtin/index.js";
|
|
5
|
+
import { BUILTIN_TOOLS, toToolExecutionResult } from "./builtin/index.js";
|
|
6
6
|
import { validateToolMetadata } from "./validate-tool-metadata.js";
|
|
7
7
|
/**
|
|
8
8
|
* Default execution timeout for any tool that does not declare its own
|
|
@@ -42,7 +42,7 @@ export class ToolRegistry {
|
|
|
42
42
|
validateToolMetadata(tool);
|
|
43
43
|
this.tools.set(tool.name, tool);
|
|
44
44
|
if (executor) {
|
|
45
|
-
this.builtinExecutors.set(tool.name, executor);
|
|
45
|
+
this.builtinExecutors.set(tool.name, async (args, ctx) => toToolExecutionResult(await executor(args, ctx)));
|
|
46
46
|
}
|
|
47
47
|
}
|
|
48
48
|
unregisterTool(name) {
|
|
@@ -54,6 +54,7 @@ export class ToolRegistry {
|
|
|
54
54
|
name: t.name,
|
|
55
55
|
description: t.description,
|
|
56
56
|
inputSchema: t.inputSchema,
|
|
57
|
+
sensitiveResult: t.sensitiveResult,
|
|
57
58
|
}));
|
|
58
59
|
}
|
|
59
60
|
getTool(name) {
|
|
@@ -88,61 +89,78 @@ export class ToolRegistry {
|
|
|
88
89
|
}
|
|
89
90
|
// Create a child AbortController that aborts on timeout OR parent abort
|
|
90
91
|
const childController = new AbortController();
|
|
92
|
+
let timedOut = false;
|
|
91
93
|
const timerId = timeout > 0
|
|
92
|
-
? setTimeout(() =>
|
|
94
|
+
? setTimeout(() => {
|
|
95
|
+
timedOut = true;
|
|
96
|
+
childController.abort(new ToolTimeoutError(name, timeout));
|
|
97
|
+
}, timeout)
|
|
93
98
|
: undefined;
|
|
94
99
|
// Cascade parent abort to child
|
|
95
100
|
const onParentAbort = () => childController.abort(parentSignal?.reason);
|
|
96
101
|
parentSignal?.addEventListener("abort", onParentAbort, { once: true });
|
|
102
|
+
if (parentSignal?.aborted)
|
|
103
|
+
onParentAbort();
|
|
97
104
|
// Inject the abort signal into args so tools (like Agent) can use it
|
|
98
105
|
const argsWithSignal = { ...args, __signal: childController.signal };
|
|
99
106
|
// Build per-call ctx: caller's ctx (if any) + this call's signal
|
|
100
107
|
const ctx = options?.ctx
|
|
101
108
|
? { ...options.ctx, signal: childController.signal }
|
|
102
109
|
: undefined;
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
110
|
+
let onChildAbort;
|
|
111
|
+
const aborted = new Promise((_, reject) => {
|
|
112
|
+
onChildAbort = () => {
|
|
113
|
+
const reason = childController.signal.reason;
|
|
114
|
+
reject(reason instanceof Error
|
|
115
|
+
? reason
|
|
116
|
+
: Object.assign(new Error("Tool aborted"), { name: "AbortError" }));
|
|
117
|
+
};
|
|
118
|
+
childController.signal.addEventListener("abort", onChildAbort, { once: true });
|
|
119
|
+
if (childController.signal.aborted)
|
|
120
|
+
onChildAbort();
|
|
121
|
+
});
|
|
122
|
+
const cleanup = () => {
|
|
113
123
|
clearTimeout(timerId);
|
|
114
124
|
parentSignal?.removeEventListener("abort", onParentAbort);
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
125
|
+
if (onChildAbort)
|
|
126
|
+
childController.signal.removeEventListener("abort", onChildAbort);
|
|
127
|
+
};
|
|
128
|
+
try {
|
|
129
|
+
const rawResult = await Promise.race([executor(argsWithSignal, ctx), aborted]);
|
|
130
|
+
const result = toToolExecutionResult(rawResult);
|
|
131
|
+
if (childController.signal.aborted) {
|
|
132
|
+
throw childController.signal.reason instanceof Error
|
|
133
|
+
? childController.signal.reason
|
|
134
|
+
: Object.assign(new Error("Tool aborted"), { name: "AbortError" });
|
|
135
|
+
}
|
|
136
|
+
cleanup();
|
|
137
|
+
if (!result.ok) {
|
|
138
|
+
return {
|
|
139
|
+
id,
|
|
140
|
+
toolName: name,
|
|
141
|
+
error: result.error,
|
|
142
|
+
isError: true,
|
|
143
|
+
sandbox: result.sandbox,
|
|
144
|
+
};
|
|
120
145
|
}
|
|
121
|
-
// 结构化返回:图片块(view_image)或沙箱标记(Bash 等)。两者互斥,
|
|
122
|
-
// 各取所有,缺的字段为 undefined。
|
|
123
|
-
const contentBlocks = "contentBlocks" in result ? result.contentBlocks : undefined;
|
|
124
|
-
const sandbox = "sandbox" in result ? result.sandbox : undefined;
|
|
125
|
-
const sensitive = "sensitive" in result ? result.sensitive : undefined;
|
|
126
|
-
const displayResult = "displayResult" in result ? result.displayResult : undefined;
|
|
127
|
-
const transcriptResult = "transcriptResult" in result ? result.transcriptResult : undefined;
|
|
128
146
|
return {
|
|
129
147
|
id,
|
|
130
148
|
toolName: name,
|
|
131
|
-
result: result.result ?? (contentBlocks ? "(image)" : ""),
|
|
132
|
-
contentBlocks,
|
|
133
|
-
sandbox,
|
|
134
|
-
sensitive,
|
|
135
|
-
displayResult,
|
|
136
|
-
transcriptResult,
|
|
149
|
+
result: result.result ?? (result.contentBlocks ? "(image)" : ""),
|
|
150
|
+
contentBlocks: result.contentBlocks,
|
|
151
|
+
sandbox: result.sandbox,
|
|
152
|
+
sensitive: result.sensitive,
|
|
153
|
+
displayResult: result.displayResult,
|
|
154
|
+
transcriptResult: result.transcriptResult,
|
|
155
|
+
isError: false,
|
|
137
156
|
};
|
|
138
157
|
}
|
|
139
158
|
catch (err) {
|
|
140
|
-
|
|
141
|
-
parentSignal?.removeEventListener("abort", onParentAbort);
|
|
159
|
+
cleanup();
|
|
142
160
|
// Always return error as ToolResult, never throw
|
|
143
161
|
let errorMsg;
|
|
144
162
|
const isAbort = err?.name === "AbortError" || parentSignal?.aborted === true;
|
|
145
|
-
if (err instanceof ToolTimeoutError) {
|
|
163
|
+
if (timedOut || err instanceof ToolTimeoutError) {
|
|
146
164
|
errorMsg = `Tool timed out after ${timeout}ms: ${name}`;
|
|
147
165
|
}
|
|
148
166
|
else if (isAbort) {
|
package/dist/types.d.ts
CHANGED
|
@@ -33,6 +33,8 @@ export interface ToolDefinition {
|
|
|
33
33
|
name: string;
|
|
34
34
|
description: string;
|
|
35
35
|
inputSchema: Record<string, unknown>;
|
|
36
|
+
/** Omit this tool's result body from retained Goal-judge evidence. */
|
|
37
|
+
sensitiveResult?: boolean;
|
|
36
38
|
}
|
|
37
39
|
export interface ToolCall {
|
|
38
40
|
id: string;
|
|
@@ -114,6 +116,8 @@ export interface RegisteredTool {
|
|
|
114
116
|
permissionDefault: PermissionDecision;
|
|
115
117
|
isConcurrencySafe?: boolean;
|
|
116
118
|
isReadOnly?: boolean;
|
|
119
|
+
/** Declaratively marks result bodies as sensitive for retained Goal evidence. */
|
|
120
|
+
sensitiveResult?: boolean;
|
|
117
121
|
/**
|
|
118
122
|
* Declarative file-path safety metadata. ToolExecutor enforces this before
|
|
119
123
|
* dispatching the tool, so file access cannot depend on each tool handler
|
|
@@ -171,6 +175,15 @@ export interface ContextUsageAnchor {
|
|
|
171
175
|
provider?: string;
|
|
172
176
|
model?: string;
|
|
173
177
|
}
|
|
178
|
+
/** Provenance for a user-visible session fork. Optional on legacy sessions. */
|
|
179
|
+
export interface SessionForkLineage {
|
|
180
|
+
sessionId: string;
|
|
181
|
+
mode: "full" | "summary";
|
|
182
|
+
fromEventId?: string;
|
|
183
|
+
throughEventId?: string;
|
|
184
|
+
sourceEventCount: number;
|
|
185
|
+
createdAt: number;
|
|
186
|
+
}
|
|
174
187
|
export interface SessionState {
|
|
175
188
|
sessionId: string;
|
|
176
189
|
cwd: string;
|
|
@@ -215,6 +228,8 @@ export interface SessionState {
|
|
|
215
228
|
* "key present && null" to tell a new top-level session apart from legacy.
|
|
216
229
|
*/
|
|
217
230
|
parentSessionId?: string | null;
|
|
231
|
+
/** User-fork lineage; deliberately separate from sub-agent ownership. */
|
|
232
|
+
forkedFrom?: SessionForkLineage;
|
|
218
233
|
/**
|
|
219
234
|
* Which host/context created this session. Desktop disk-rebuild shows only
|
|
220
235
|
* `desktop` + `automation`. Absent on legacy sessions.
|
package/package.json
CHANGED