@cjhyy/code-shell-core 0.7.0-beta.1 → 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.
Files changed (146) hide show
  1. package/dist/arena/arena.d.ts +2 -0
  2. package/dist/arena/arena.js +30 -1
  3. package/dist/arena/phases/adjudication.d.ts +2 -1
  4. package/dist/arena/phases/adjudication.js +2 -1
  5. package/dist/arena/phases/build-consensus.d.ts +2 -1
  6. package/dist/arena/phases/build-consensus.js +3 -1
  7. package/dist/arena/phases/cross-review.d.ts +3 -1
  8. package/dist/arena/phases/cross-review.js +8 -2
  9. package/dist/arena/phases/debate-rounds.d.ts +2 -1
  10. package/dist/arena/phases/debate-rounds.js +4 -2
  11. package/dist/arena/phases/participant-research.d.ts +2 -1
  12. package/dist/arena/phases/participant-research.js +3 -1
  13. package/dist/arena/phases/planning-detail-expansion.d.ts +2 -1
  14. package/dist/arena/phases/planning-detail-expansion.js +2 -1
  15. package/dist/arena/planner.d.ts +2 -1
  16. package/dist/arena/planner.js +2 -1
  17. package/dist/arena/types.d.ts +5 -1
  18. package/dist/cc-orchestrator/agent-adapter.d.ts +2 -0
  19. package/dist/cc-orchestrator/agent-adapter.js +4 -0
  20. package/dist/cc-orchestrator/codex-session-history.d.ts +14 -1
  21. package/dist/cc-orchestrator/codex-session-history.js +64 -4
  22. package/dist/cc-orchestrator/external-agent-changes.js +22 -5
  23. package/dist/cc-orchestrator/external-agent-driver.d.ts +1 -1
  24. package/dist/cc-orchestrator/external-agent-driver.js +202 -38
  25. package/dist/cc-orchestrator/session-history.d.ts +35 -0
  26. package/dist/cc-orchestrator/session-history.js +96 -13
  27. package/dist/cli/agent-server-tcp.js +13 -2
  28. package/dist/context/manager.d.ts +3 -3
  29. package/dist/context/manager.js +6 -6
  30. package/dist/context/token-counter.js +5 -3
  31. package/dist/context/tool-result-storage.d.ts +6 -0
  32. package/dist/context/tool-result-storage.js +25 -4
  33. package/dist/credentials/access.d.ts +11 -1
  34. package/dist/credentials/access.js +77 -1
  35. package/dist/credentials/index.d.ts +3 -1
  36. package/dist/credentials/index.js +2 -0
  37. package/dist/credentials/oauth.d.ts +25 -0
  38. package/dist/credentials/oauth.js +179 -0
  39. package/dist/credentials/store.d.ts +2 -1
  40. package/dist/credentials/store.js +19 -8
  41. package/dist/credentials/types.d.ts +84 -1
  42. package/dist/credentials/types.js +16 -1
  43. package/dist/engine/engine.d.ts +67 -34
  44. package/dist/engine/engine.js +448 -247
  45. package/dist/engine/goal.d.ts +19 -0
  46. package/dist/engine/goal.js +16 -6
  47. package/dist/engine/input-attachments.js +156 -13
  48. package/dist/engine/run-image-input.d.ts +22 -0
  49. package/dist/engine/run-image-input.js +195 -0
  50. package/dist/engine/session-title.d.ts +2 -1
  51. package/dist/engine/session-title.js +4 -1
  52. package/dist/engine/steer-queue.d.ts +3 -1
  53. package/dist/engine/steer-queue.js +10 -2
  54. package/dist/engine/turn-loop.d.ts +48 -1
  55. package/dist/engine/turn-loop.js +307 -37
  56. package/dist/engine/types.d.ts +6 -2
  57. package/dist/git/worktree/crud.d.ts +3 -0
  58. package/dist/git/worktree/crud.js +32 -3
  59. package/dist/git/worktree/git-exec.d.ts +2 -2
  60. package/dist/git/worktree/git-exec.js +47 -11
  61. package/dist/git/worktree/query.d.ts +8 -7
  62. package/dist/git/worktree/query.js +27 -20
  63. package/dist/hooks/events.d.ts +3 -0
  64. package/dist/hooks/events.js +0 -3
  65. package/dist/hooks/goal-stop-hook.d.ts +44 -2
  66. package/dist/hooks/goal-stop-hook.js +775 -52
  67. package/dist/hooks/registry.js +3 -0
  68. package/dist/hooks/shell-runner.d.ts +12 -1
  69. package/dist/hooks/shell-runner.js +160 -9
  70. package/dist/index.d.ts +7 -6
  71. package/dist/index.js +6 -5
  72. package/dist/llm/client-base.js +12 -10
  73. package/dist/llm/types.d.ts +12 -5
  74. package/dist/plugins/pluginCommandHook.d.ts +4 -4
  75. package/dist/plugins/pluginCommandHook.js +111 -13
  76. package/dist/preset/index.js +14 -4
  77. package/dist/protocol/chat-session-manager.d.ts +13 -2
  78. package/dist/protocol/chat-session-manager.js +90 -18
  79. package/dist/protocol/chat-session.d.ts +12 -0
  80. package/dist/protocol/chat-session.js +30 -5
  81. package/dist/protocol/client.d.ts +5 -2
  82. package/dist/protocol/client.js +22 -1
  83. package/dist/protocol/server.d.ts +25 -11
  84. package/dist/protocol/server.js +291 -73
  85. package/dist/protocol/types.d.ts +36 -2
  86. package/dist/protocol/types.js +2 -0
  87. package/dist/services/dream-consolidation.d.ts +3 -0
  88. package/dist/services/dream-consolidation.js +4 -1
  89. package/dist/services/index.d.ts +1 -1
  90. package/dist/services/index.js +1 -1
  91. package/dist/services/oauth.d.ts +34 -10
  92. package/dist/services/oauth.js +233 -98
  93. package/dist/session/session-manager.d.ts +35 -6
  94. package/dist/session/session-manager.js +396 -27
  95. package/dist/session/transcript.d.ts +30 -1
  96. package/dist/session/transcript.js +119 -4
  97. package/dist/tool-system/builtin/agent-notifications.d.ts +11 -4
  98. package/dist/tool-system/builtin/agent-notifications.js +19 -7
  99. package/dist/tool-system/builtin/agent.js +5 -1
  100. package/dist/tool-system/builtin/arena.js +1 -0
  101. package/dist/tool-system/builtin/background-jobs.d.ts +28 -5
  102. package/dist/tool-system/builtin/background-jobs.js +109 -7
  103. package/dist/tool-system/builtin/background-work.d.ts +6 -1
  104. package/dist/tool-system/builtin/background-work.js +5 -1
  105. package/dist/tool-system/builtin/bash.d.ts +3 -5
  106. package/dist/tool-system/builtin/bash.js +10 -5
  107. package/dist/tool-system/builtin/browser-tools.d.ts +2 -2
  108. package/dist/tool-system/builtin/cron-list.definition.d.ts +3 -0
  109. package/dist/tool-system/builtin/cron-list.definition.js +6 -0
  110. package/dist/tool-system/builtin/cron.d.ts +1 -2
  111. package/dist/tool-system/builtin/cron.js +9 -7
  112. package/dist/tool-system/builtin/drive-claude-code.d.ts +7 -0
  113. package/dist/tool-system/builtin/drive-claude-code.js +307 -20
  114. package/dist/tool-system/builtin/edit.d.ts +2 -1
  115. package/dist/tool-system/builtin/edit.js +12 -4
  116. package/dist/tool-system/builtin/generate-video.d.ts +4 -0
  117. package/dist/tool-system/builtin/generate-video.js +138 -21
  118. package/dist/tool-system/builtin/glob.d.ts +2 -1
  119. package/dist/tool-system/builtin/glob.js +28 -3
  120. package/dist/tool-system/builtin/grep.d.ts +1 -0
  121. package/dist/tool-system/builtin/grep.js +82 -17
  122. package/dist/tool-system/builtin/index.d.ts +25 -11
  123. package/dist/tool-system/builtin/index.js +60 -5
  124. package/dist/tool-system/builtin/sleep.d.ts +1 -2
  125. package/dist/tool-system/builtin/sleep.definition.d.ts +8 -0
  126. package/dist/tool-system/builtin/sleep.definition.js +28 -0
  127. package/dist/tool-system/builtin/sleep.js +1 -22
  128. package/dist/tool-system/builtin/video-providers.d.ts +12 -15
  129. package/dist/tool-system/builtin/video-providers.js +1 -0
  130. package/dist/tool-system/builtin/view-image.d.ts +2 -2
  131. package/dist/tool-system/builtin/web-fetch.js +44 -3
  132. package/dist/tool-system/builtin/worktree.js +25 -7
  133. package/dist/tool-system/builtin/write.d.ts +2 -1
  134. package/dist/tool-system/builtin/write.js +14 -4
  135. package/dist/tool-system/context.d.ts +35 -5
  136. package/dist/tool-system/executor.js +24 -8
  137. package/dist/tool-system/mcp-manager.d.ts +20 -2
  138. package/dist/tool-system/mcp-manager.js +111 -12
  139. package/dist/tool-system/path-policy.d.ts +19 -0
  140. package/dist/tool-system/path-policy.js +62 -1
  141. package/dist/tool-system/permission.d.ts +43 -3
  142. package/dist/tool-system/permission.js +383 -30
  143. package/dist/tool-system/registry.d.ts +3 -2
  144. package/dist/tool-system/registry.js +52 -34
  145. package/dist/types.d.ts +38 -7
  146. 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(() => childController.abort(new ToolTimeoutError(name, timeout)), timeout)
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
- try {
104
- const result = await Promise.race([
105
- executor(argsWithSignal, ctx),
106
- new Promise((_, reject) => {
107
- childController.signal.addEventListener("abort", () => {
108
- const reason = childController.signal.reason;
109
- reject(reason instanceof ToolTimeoutError ? reason : new Error("Tool aborted"));
110
- }, { once: true });
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
- // executor 可返回纯字符串,或 { contentBlocks, result? }(view_image
116
- // 用后者回传图片块)。归一化成 ToolResult:有 contentBlocks 就带上,
117
- // result 始终保留一份文本镜像供 transcript / 摘要使用。
118
- if (typeof result === "string") {
119
- return { id, toolName: name, result };
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
- clearTimeout(timerId);
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
@@ -1,7 +1,7 @@
1
1
  /**
2
2
  * Core type definitions for the code-shell orchestration framework.
3
3
  */
4
- import type { GoalConfig } from "./engine/goal.js";
4
+ import type { GoalConfig, GoalTerminal } from "./engine/goal.js";
5
5
  export interface ContentBlock {
6
6
  type: "text" | "tool_use" | "tool_result" | "image" | "reasoning";
7
7
  text?: string;
@@ -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
@@ -133,7 +137,7 @@ export interface RegisteredTool {
133
137
  */
134
138
  timeoutMs?: number;
135
139
  }
136
- export type TranscriptEventType = "message" | "tool_use" | "tool_result" | "summary" | "content_replace" | "file_history" | "plan_operation" | "session_meta" | "subagent" | "turn_boundary" | "goal_progress" | "turn_stopped" | "error";
140
+ export type TranscriptEventType = "message" | "tool_use" | "tool_result" | "summary" | "content_replace" | "file_history" | "plan_operation" | "session_meta" | "subagent" | "external_file_changes" | "turn_boundary" | "goal_progress" | "turn_stopped" | "error";
137
141
  export interface TranscriptEvent {
138
142
  id: string;
139
143
  type: TranscriptEventType;
@@ -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.
@@ -242,6 +257,12 @@ export interface SessionState {
242
257
  * baselines reset (matching CC). See engine.run goal-resolution.
243
258
  */
244
259
  activeGoal?: GoalConfig;
260
+ /**
261
+ * Last force-terminated goal instance. Kept separately from activeGoal so an
262
+ * old whole-state writer cannot make that same exhausted goal armable again.
263
+ * Optional for backward compatibility with pre-tombstone state.json files.
264
+ */
265
+ goalTerminal?: GoalTerminal;
245
266
  }
246
267
  export interface TokenUsage {
247
268
  promptTokens: number;
@@ -506,7 +527,7 @@ export type StreamEvent = {
506
527
  agentId: string;
507
528
  name?: string;
508
529
  description: string;
509
- status: "completed" | "failed";
530
+ status: "completed" | "failed" | "cancelled";
510
531
  /**
511
532
  * What kind of background work this was. Lets UIs localize the
512
533
  * completion toast (e.g. a shell shows "命令完成" not the raw English
@@ -518,8 +539,16 @@ export type StreamEvent = {
518
539
  command?: string;
519
540
  /** Final assistant text (status === "completed" only). */
520
541
  finalText?: string;
521
- /** Error message (status === "failed" only). */
542
+ /** Error message (status === "failed" or "cancelled" only). */
522
543
  error?: string;
544
+ /** External Claude/Codex session id, when workKind === "cc". */
545
+ ccSessionId?: string;
546
+ /** Files attributed to an external DriveAgent transcript. */
547
+ changedFiles?: string[];
548
+ /** Working directory used to canonicalize relative/absolute path aliases. */
549
+ cwd?: string;
550
+ /** Client id of the real user turn that launched this background work. */
551
+ originClientMessageId?: string;
523
552
  /** When the bg agent finished (Date.now() value). */
524
553
  enqueuedAt: number;
525
554
  };
@@ -652,9 +681,10 @@ export interface MCPServerConfig {
652
681
  */
653
682
  envHeaders?: Record<string, string>;
654
683
  /**
655
- * (HTTP) id of a stored credential (CredentialStore) to use as the Bearer
656
- * token. Resolved at connect time via a resolver passed to buildHttpHeaders;
657
- * the secret is never stored in the MCP config. Wins over bearerTokenEnvVar.
684
+ * (HTTP) id of a stored credential (token/link/oauth) to use as Bearer auth.
685
+ * OAuth credentials inject their current access token. Resolved at connect
686
+ * time via CredentialStore; the secret is never stored in MCP config. Wins
687
+ * over bearerTokenEnvVar.
658
688
  */
659
689
  credentialRef?: string;
660
690
  /**
@@ -677,6 +707,7 @@ export interface MCPServerConfig {
677
707
  export interface MCPServerOverride {
678
708
  env?: Record<string, string>;
679
709
  envVars?: string[];
710
+ /** (HTTP) id of a stored token/link/oauth credential used as Bearer auth. */
680
711
  credentialRef?: string;
681
712
  bearerTokenEnvVar?: string;
682
713
  envHeaders?: Record<string, string>;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@cjhyy/code-shell-core",
3
- "version": "0.7.0-beta.1",
3
+ "version": "0.7.1",
4
4
  "description": "Core engine for code-shell — agent orchestration, tool execution, hooks, protocol. UI-agnostic.",
5
5
  "type": "module",
6
6
  "main": "./dist/index.js",