@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
@@ -4,10 +4,11 @@
4
4
  import type { LLMConfig, StreamCallback } from "../types.js";
5
5
  import { ToolRegistry } from "../tool-system/registry.js";
6
6
  import { type BuiltinToolFn } from "../tool-system/builtin/index.js";
7
+ import { type ApprovalRouter } from "../tool-system/permission.js";
7
8
  import { HookRegistry } from "../hooks/registry.js";
8
9
  import { type GoalConfig, type GoalExtension } from "./goal.js";
9
10
  import { type CompactStrategy } from "../context/manager.js";
10
- import { SessionManager } from "../session/session-manager.js";
11
+ import { SessionManager, type ForkSessionOptions, type ForkSessionResult } from "../session/session-manager.js";
11
12
  import type { AskUserFn } from "../tool-system/builtin/ask-user.js";
12
13
  import type { CapabilityOverride } from "../settings/schema.js";
13
14
  import { type FeatureFlagName } from "../settings/feature-flags.js";
@@ -34,6 +35,38 @@ export interface EnqueueSteerResult {
34
35
  accepted: boolean;
35
36
  id: string;
36
37
  }
38
+ interface EngineRunOptions {
39
+ cwd?: string;
40
+ onStream?: StreamCallback;
41
+ signal?: AbortSignal;
42
+ sessionId?: string;
43
+ /** Immutable permission context for this run only. Omitted uses Engine config. */
44
+ permissionMode?: NonNullable<EngineConfig["permissionMode"]>;
45
+ /** Immutable plan context for this run only. Omitted follows permissionMode. */
46
+ planMode?: boolean;
47
+ /** Protocol connection's approval owner router for this run. */
48
+ approvalRouter?: ApprovalRouter;
49
+ /**
50
+ * Goal mode for this run: the engine registers a GoalStopHook so the
51
+ * turn loop runs until the session model judges this goal met. Falls
52
+ * back to config.goal. Orthogonal to permissionMode. Accepts a raw
53
+ * string or a full GoalConfig; normalized once at the run boundary.
54
+ */
55
+ goal?: string | GoalConfig;
56
+ /**
57
+ * Marks this turn's task as a SYNTHETIC system-reminder injection (e.g. a
58
+ * background-job completion notification the server re-injects to wake an
59
+ * idle session) rather than the user's own input. The task is still sent
60
+ * to the model as a `role:"user"` message, but it is persisted with an
61
+ * `injected` flag so the disk reader skips rendering it as a user bubble
62
+ * on replay (matching the live UI, which shows only the assistant reply).
63
+ */
64
+ injected?: boolean;
65
+ /** Stable id for this user-intent, used to make duplicate submits idempotent. */
66
+ clientMessageId?: string;
67
+ /** Structured input attachments. Legacy `<codeshell-image>` blocks remain supported. */
68
+ attachments?: InputAttachmentMeta[];
69
+ }
37
70
  export { diskDefaultsFrom, type DiskDefaultPatch } from "../settings/disk-defaults.js";
38
71
  /**
39
72
  * Resolve the LLM config for a spawned child Engine.
@@ -122,6 +155,8 @@ export declare class Engine {
122
155
  /** Shared resources supplied at construction (adapter pattern — null when self-constructed). */
123
156
  readonly runtime: EngineRuntime | null;
124
157
  private readonly sandboxCache;
158
+ private readonly interactiveBackends;
159
+ private activeApprovalRouter;
125
160
  /** Active permission mode for this Engine instance. */
126
161
  permissionMode: NonNullable<EngineConfig["permissionMode"]>;
127
162
  /** True when permissionMode === "plan". */
@@ -154,6 +189,7 @@ export declare class Engine {
154
189
  * LLM response arrives.
155
190
  */
156
191
  private ctxOverheadBySid;
192
+ private lastCacheReadBySid;
157
193
  /**
158
194
  * Step-gap steering queue (per sessionId, in-memory). Host pushes user
159
195
  * messages here via enqueueSteer while a run is in flight; the turn loop
@@ -187,6 +223,19 @@ export declare class Engine {
187
223
  * Null when idle; set at run start, cleared in run's finally.
188
224
  */
189
225
  private activeRunSession;
226
+ /**
227
+ * Same-instance run guard. Engine owns single-valued live controls and one
228
+ * HookRegistry, so a second run must not enter until the first has completed
229
+ * all state persistence and end hooks. This prevents handle contamination and
230
+ * whole-state saveState overlap only within this Engine instance. It does not
231
+ * coordinate different Engine instances sharing a sessionId, Workers, or
232
+ * processes; session-level locking/CAS for those cases is a separate finding.
233
+ */
234
+ private runInProgress;
235
+ /** Permission update requested while runInProgress. Applied in run() finally. */
236
+ private pendingPermissionMode;
237
+ /** Plan update paired with pendingPermissionMode for one atomic boundary apply. */
238
+ private pendingPlanMode;
190
239
  /** Public accessor so UI/clients can read the resolved per-model window. */
191
240
  get maxContextTokens(): number;
192
241
  private resolveMaxContextTokens;
@@ -278,7 +327,7 @@ export declare class Engine {
278
327
  * the queued draft) and is the handle `unsteer` uses to revoke a still-pending
279
328
  * entry. A blank id is tolerated but means the entry can't be revoked.
280
329
  */
281
- enqueueSteer(sessionId: string, text: string, id?: string, clientMessageId?: string): EnqueueSteerResult;
330
+ enqueueSteer(sessionId: string, text: string, id?: string, clientMessageId?: string, attachments?: InputAttachmentMeta[]): EnqueueSteerResult;
282
331
  /**
283
332
  * Revoke a still-pending steer entry (the 撤回 path). Returns true if it was
284
333
  * removed, false if it was already consumed by the turn loop (can't take it
@@ -287,6 +336,8 @@ export declare class Engine {
287
336
  unsteer(sessionId: string, id: string): boolean;
288
337
  /** Drain + clear the steer queue for a session (turn loop consumes per step). */
289
338
  private consumeSteer;
339
+ /** Put failed steer preparation back ahead of messages queued while it was being prepared. */
340
+ private restoreSteer;
290
341
  /** Wire the cookie→browser injection callback (InjectCredential tool). Same
291
342
  * post-construction injection model as setBrowserBridge. */
292
343
  setInjectCredential(fn: import("../tool-system/context.js").InjectCredentialFn | undefined): void;
@@ -303,35 +354,14 @@ export declare class Engine {
303
354
  * against a blank session. A stat probe, not a load.
304
355
  */
305
356
  sessionExistsOnDisk(sessionId: string): boolean;
357
+ forkSession(sourceSessionId: string, options?: ForkSessionOptions): ForkSessionResult;
306
358
  /**
307
- * Run a task from start to finish.
308
- */
309
- run(task: string, options?: {
310
- cwd?: string;
311
- onStream?: StreamCallback;
312
- signal?: AbortSignal;
313
- sessionId?: string;
314
- /**
315
- * Goal mode for this run: the engine registers a GoalStopHook so the
316
- * turn loop runs until the session model judges this goal met. Falls
317
- * back to config.goal. Orthogonal to permissionMode. Accepts a raw
318
- * string or a full GoalConfig; normalized once at the run boundary.
319
- */
320
- goal?: string | GoalConfig;
321
- /**
322
- * Marks this turn's task as a SYNTHETIC system-reminder injection (e.g. a
323
- * background-job completion notification the server re-injects to wake an
324
- * idle session) rather than the user's own input. The task is still sent
325
- * to the model as a `role:"user"` message, but it is persisted with an
326
- * `injected` flag so the disk reader skips rendering it as a user bubble
327
- * on replay (matching the live UI, which shows only the assistant reply).
328
- */
329
- injected?: boolean;
330
- /** Stable id for this user-intent, used to make duplicate submits idempotent. */
331
- clientMessageId?: string;
332
- /** Structured input attachments. Legacy `<codeshell-image>` blocks remain supported. */
333
- attachments?: InputAttachmentMeta[];
334
- }): Promise<EngineResult>;
359
+ * Run a task from start to finish. Rejects immediately when this Engine
360
+ * instance already has a run in progress; hosts that want queueing own that
361
+ * policy (for example ChatSession's FIFO queue).
362
+ */
363
+ run(task: string, options?: EngineRunOptions): Promise<EngineResult>;
364
+ private runExclusive;
335
365
  /**
336
366
  * Run the end-of-session memory pipeline as a fire-and-forget background
337
367
  * task. Extracts durable memories from the transcript, saves a session
@@ -482,7 +512,8 @@ export declare class Engine {
482
512
  after: number;
483
513
  strategy: "none (no active session)" | "no compaction needed" | "compacted" | CompactStrategy;
484
514
  }>;
485
- private stripUserContextMessage;
515
+ private stripInjectedContextMessages;
516
+ private recordCacheReadDiagnostics;
486
517
  private getSettingsManager;
487
518
  /**
488
519
  * Update a config setting at runtime.
@@ -495,12 +526,14 @@ export declare class Engine {
495
526
  readSetting(key: string): unknown;
496
527
  private buildPermissionConfig;
497
528
  /**
498
- * Switch permission mode at runtime. Takes effect immediately for any
499
- * in-flight ToolExecutor (which holds a reference to the same classifier),
500
- * and the new mode is used for any subsequent run() calls.
529
+ * Switch permission mode at runtime. Idle updates apply immediately; busy
530
+ * updates are committed atomically when the current run settles, so its
531
+ * classifier and ToolContext retain the immutable start-of-run snapshot.
501
532
  * Session-only — does not persist to settings.
502
533
  */
503
534
  setPermissionMode(mode: NonNullable<EngineConfig["permissionMode"]>): void;
535
+ private applyPermissionState;
536
+ private applyPendingPermissionState;
504
537
  getPermissionMode(): NonNullable<EngineConfig["permissionMode"]>;
505
538
  /**
506
539
  * Extend the in-flight run's turn ceiling and/or goal budgets (TODO 3.1 —