toc-ocra 0.3.0 → 0.3.2

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 (86) hide show
  1. package/README.md +11 -5
  2. package/dist/cli/cli.mjs +3916 -1884
  3. package/dist/service/agent.mjs +3856 -1824
  4. package/dist/src/acp/agent-process.d.ts +34 -0
  5. package/dist/src/acp/agent-process.js +90 -0
  6. package/dist/src/acp/agent-process.js.map +1 -0
  7. package/dist/src/acp/chat-agents.d.ts +53 -0
  8. package/dist/src/acp/chat-agents.js +120 -0
  9. package/dist/src/acp/chat-agents.js.map +1 -0
  10. package/dist/src/acp/chat-forwarder.d.ts +30 -0
  11. package/dist/src/acp/chat-forwarder.js +101 -0
  12. package/dist/src/acp/chat-forwarder.js.map +1 -0
  13. package/dist/src/acp/chat-host.d.ts +28 -0
  14. package/dist/src/acp/chat-host.js +102 -0
  15. package/dist/src/acp/chat-host.js.map +1 -0
  16. package/dist/src/acp/chat-session.d.ts +112 -0
  17. package/dist/src/acp/chat-session.js +465 -0
  18. package/dist/src/acp/chat-session.js.map +1 -0
  19. package/dist/src/acp/connection.d.ts +77 -0
  20. package/dist/src/acp/connection.js +204 -0
  21. package/dist/src/acp/connection.js.map +1 -0
  22. package/dist/src/acp/rpc.d.ts +40 -0
  23. package/dist/src/acp/rpc.js +137 -0
  24. package/dist/src/acp/rpc.js.map +1 -0
  25. package/dist/src/acp/transcript.d.ts +39 -0
  26. package/dist/src/acp/transcript.js +273 -0
  27. package/dist/src/acp/transcript.js.map +1 -0
  28. package/dist/src/acp/vendor.d.ts +21 -0
  29. package/dist/src/acp/vendor.js +137 -0
  30. package/dist/src/acp/vendor.js.map +1 -0
  31. package/dist/src/config.d.ts +1 -1
  32. package/dist/src/providers/acp/acp-agents.d.ts +9 -0
  33. package/dist/src/providers/acp/acp-agents.js +8 -8
  34. package/dist/src/providers/acp/acp-agents.js.map +1 -1
  35. package/dist/src/providers/acp/acp-driver.d.ts +2 -2
  36. package/dist/src/providers/acp/acp-driver.js +9 -3
  37. package/dist/src/providers/acp/acp-driver.js.map +1 -1
  38. package/dist/src/providers/chat/codex-app-server.d.ts +1 -1
  39. package/dist/src/providers/chat/codex-app-server.js +6 -4
  40. package/dist/src/providers/chat/codex-app-server.js.map +1 -1
  41. package/dist/src/providers/chat/codex-goal.d.ts +17 -0
  42. package/dist/src/providers/chat/codex-goal.js +187 -0
  43. package/dist/src/providers/chat/codex-goal.js.map +1 -0
  44. package/dist/src/providers/cli/claude.d.ts +6 -0
  45. package/dist/src/providers/cli/claude.js +120 -8
  46. package/dist/src/providers/cli/claude.js.map +1 -1
  47. package/dist/src/providers/cli/codex-fork.d.ts +11 -0
  48. package/dist/src/providers/cli/codex-fork.js +84 -0
  49. package/dist/src/providers/cli/codex-fork.js.map +1 -0
  50. package/dist/src/providers/cli/codex.d.ts +12 -1
  51. package/dist/src/providers/cli/codex.js +33 -2
  52. package/dist/src/providers/cli/codex.js.map +1 -1
  53. package/dist/src/providers/cli/kiro.js +4 -3
  54. package/dist/src/providers/cli/kiro.js.map +1 -1
  55. package/dist/src/providers/cli-failure.js +1 -1
  56. package/dist/src/providers/provider.d.ts +46 -1
  57. package/dist/src/providers/provider.js +19 -0
  58. package/dist/src/providers/provider.js.map +1 -1
  59. package/dist/src/providers/registry.d.ts +7 -2
  60. package/dist/src/providers/registry.js +24 -8
  61. package/dist/src/providers/registry.js.map +1 -1
  62. package/dist/src/runs/run-supervisor.d.ts +53 -7
  63. package/dist/src/runs/run-supervisor.js +307 -61
  64. package/dist/src/runs/run-supervisor.js.map +1 -1
  65. package/dist/src/runtime/agent-runtime.js +26 -11
  66. package/dist/src/runtime/agent-runtime.js.map +1 -1
  67. package/dist/src/session/terminal-line-sanitizer.d.ts +5 -0
  68. package/dist/src/session/terminal-line-sanitizer.js +18 -0
  69. package/dist/src/session/terminal-line-sanitizer.js.map +1 -1
  70. package/dist/src/smoke/cli-smoke.js +1 -1
  71. package/dist/src/smoke/cli-smoke.js.map +1 -1
  72. package/dist/src/transport/gateway-client.d.ts +3 -1
  73. package/dist/src/transport/gateway-client.js +6 -0
  74. package/dist/src/transport/gateway-client.js.map +1 -1
  75. package/dist/src/types/protocol.d.ts +41 -4
  76. package/dist/src/types/protocol.js +30 -3
  77. package/dist/src/types/protocol.js.map +1 -1
  78. package/locales/en.json +1 -1
  79. package/locales/zh-CN.json +1 -1
  80. package/package.json +4 -2
  81. package/vendor/acp/claude/LICENSE +191 -0
  82. package/vendor/acp/claude/index.mjs +167 -0
  83. package/vendor/acp/claude/runtime.json +7 -0
  84. package/vendor/acp/codex/LICENSE +190 -0
  85. package/vendor/acp/codex/index.mjs +158 -0
  86. package/vendor/acp/codex/runtime.json +3 -0
@@ -1,10 +1,14 @@
1
1
  import type { AgentConfig } from '../config.js';
2
2
  import type { DiagnosticLogger } from '../logging/diagnostic-log.js';
3
3
  import type { ChatContentEvent } from '../providers/provider.js';
4
+ import { type AgentAccess } from '../providers/provider.js';
5
+ import { type CliFailure } from '../providers/cli-failure.js';
6
+ import { type CliCatalogEntry } from '../providers/registry.js';
4
7
  import { type TerminalTailRead } from '../session/terminal-tail-buffer.js';
5
- import type { RunFinishedReport, RunStartPayload, RunStartedReport, RunStepCategory } from '../types/protocol.js';
8
+ import type { RunFinishedReport, RunGoalReport, RunGoalTurnReport, RunStartPayload, RunStartedReport, RunStepCategory } from '../types/protocol.js';
6
9
  import { OrphanRegistry } from './orphan-registry.js';
7
10
  import { type TaskFileDownload } from './task-attachments.js';
11
+ import type { SteerOutcome } from '../acp/chat-session.js';
8
12
  /**
9
13
  * Supervises headless CLI turns. One process per turn:
10
14
  *
@@ -13,7 +17,7 @@ import { type TaskFileDownload } from './task-attachments.js';
13
17
  *
14
18
  * "Done" is the process exit. If the CLI already declared the turn finished
15
19
  * but its process lingers, it is stopped after COMPLETION_EXIT_GRACE_MS, so
16
- * a finished turn can never keep the workstation busy. Stop kills the whole
20
+ * a finished turn can never keep the session busy. Stop kills the whole
17
21
  * process tree.
18
22
  */
19
23
  export declare const COMPLETION_EXIT_GRACE_MS = 15000;
@@ -26,6 +30,30 @@ export declare const STALL_CHECK_INTERVAL_MS = 5000;
26
30
  /** Run-log row markers (see the providers' display rows) → broad step kind. */
27
31
  export declare function rowCategory(row: string): RunStepCategory;
28
32
  export declare const STALL_CATEGORY_LABELS: Record<RunStepCategory, string>;
33
+ /** Put before the prompt on CLIs without a plan mode of their own (the turn also runs read-only). */
34
+ export declare const PLAN_MODE_PREFIX = "\u3010\u8BA1\u5212\u6A21\u5F0F\u3011\u8FD9\u4E00\u8F6E\u53EA\u505A\u5206\u6790\u548C\u8BA1\u5212\uFF1A\u9605\u8BFB\u9700\u8981\u7684\u6587\u4EF6\uFF0C\u7ED9\u51FA\u5177\u4F53\u65B9\u6848\u548C\u6B65\u9AA4\uFF0C\u4E0D\u8981\u4FEE\u6539\u4EFB\u4F55\u6587\u4EF6\uFF0C\u4E5F\u4E0D\u8981\u6267\u884C\u4F1A\u6539\u52A8\u73AF\u5883\u7684\u547D\u4EE4\u3002";
35
+ /** This turn's permission level, plan and fast mode, as the CLI will apply them. */
36
+ export type TurnSettings = {
37
+ /** Level under a full cap; absent = full access (or the restricted cap). */
38
+ access?: AgentAccess;
39
+ /** The CLI's own plan mode. */
40
+ plan: boolean;
41
+ /** Plan mode by instruction: the prompt gets `PLAN_MODE_PREFIX` and the turn runs read-only. */
42
+ planPrompt: boolean;
43
+ fast: boolean;
44
+ /** Run-log notes on settings that could not apply. */
45
+ notes: string[];
46
+ };
47
+ /**
48
+ * The session's permission level, plan and fast mode for this CLI. The
49
+ * owner's restricted cap always wins; a level or plan mode the CLI cannot
50
+ * enforce refuses the turn rather than running with more access than chosen.
51
+ */
52
+ export declare function resolveTurnSettings(payload: Pick<RunStartPayload, 'cli_policy' | 'permission_mode' | 'plan_mode' | 'fast_mode'>, cli: Pick<CliCatalogEntry, 'label' | 'runSettings'>): TurnSettings | {
53
+ failure: CliFailure;
54
+ };
55
+ /** `本轮设置:计划模式 · 只读 · 快速模式`, when the session chose any of them. */
56
+ export declare function turnSettingsLabel(turn: TurnSettings, payload: Pick<RunStartPayload, 'cli_policy' | 'permission_mode' | 'plan_mode' | 'fast_mode'>): string;
29
57
  export type RunReporter = {
30
58
  taskFile?: TaskFileDownload;
31
59
  chatEvents?(runId: string, events: Array<ChatContentEvent & {
@@ -34,6 +62,9 @@ export type RunReporter = {
34
62
  chatMedia?(runId: string, mediaId: string): Promise<Uint8Array>;
35
63
  started(runId: string, report: RunStartedReport): Promise<void>;
36
64
  finished(runId: string, report: RunFinishedReport): Promise<void>;
65
+ /** Goal runs: the CLI's goal snapshot and each finished turn. */
66
+ goal?(runId: string, report: RunGoalReport): Promise<void>;
67
+ goalTurn?(runId: string, report: RunGoalTurnReport): Promise<void>;
37
68
  };
38
69
  export type TailResult = TerminalTailRead & {
39
70
  status: 'running' | 'finished' | 'idle';
@@ -45,37 +76,50 @@ export declare class RunSupervisor {
45
76
  private readonly reporter;
46
77
  private readonly orphans?;
47
78
  private readonly active;
79
+ private readonly acpRuns;
48
80
  private readonly recent;
49
81
  /** Run ids whose finish report has not been acknowledged yet. */
50
82
  private readonly unreported;
51
83
  private readonly chatRunIds;
52
84
  private readonly preparing;
85
+ private readonly acpChats;
53
86
  constructor(config: AgentConfig, logger: DiagnosticLogger, reporter: RunReporter, orphans?: OrphanRegistry | undefined);
54
87
  get activeCount(): number;
55
88
  /** Runs to list in the heartbeat: still running, or finished but not yet reported. */
56
89
  activeRunIds(): string[];
90
+ /** Whether another turn of this session is running or preparing. */
91
+ private sessionBusy;
57
92
  activeChatRunIds(): string[];
58
93
  activeTaskRunIds(): string[];
59
94
  markReported(runId: string): void;
60
95
  recentRuns(): Array<{
61
96
  runId: string;
62
- workstationId: string;
97
+ sessionKey: string;
63
98
  status: string;
64
99
  at: number;
65
100
  }>;
66
101
  /**
67
- * Starts a turn. Refusals (busy workstation, concurrency limit, bad work
102
+ * Starts a turn. Refusals (busy session, concurrency limit, bad work
68
103
  * directory, unknown CLI) are reported as a failed run, never thrown.
69
104
  */
70
105
  /**
71
- * Different workstations run in parallel without a machine-wide cap by
72
- * default; each workstation still runs one turn at a time. A cap applies
106
+ * Different sessions run in parallel without a machine-wide cap by
107
+ * default; each session still runs one turn at a time. A cap applies
73
108
  * only when the operator sets TOC_OCRA_MAX_RUNS / maxConcurrentRuns.
74
109
  * The run being started is already counted in `preparing`.
75
110
  */
76
111
  private overConcurrencyCap;
77
112
  start(payload: RunStartPayload): Promise<void>;
78
113
  private startPrepared;
114
+ /**
115
+ * A chat turn on the session's long-lived ACP agent (acp/chat-session.ts):
116
+ * no process per turn, so "done" is the prompt's stopReason, not an exit.
117
+ * Returns `{ fallback }` when this device cannot run the CLI over ACP and
118
+ * the per-turn chat driver should answer instead.
119
+ */
120
+ private startAcpChat;
121
+ /** Delivers a user message into a running chat turn (`chat.run.steer`). */
122
+ steer(runId: string, steerId: string, prompt: string): Promise<SteerOutcome>;
79
123
  private onStdout;
80
124
  private applyParsed;
81
125
  private onExit;
@@ -92,9 +136,11 @@ export declare class RunSupervisor {
92
136
  private report;
93
137
  /** Stops a run: the whole process tree, then a `cancelled` report. */
94
138
  cancel(runId: string): Promise<boolean>;
139
+ /** Pauses or clears the goal of a running goal run; false when there is none. */
140
+ controlGoal(runId: string, action: 'pause' | 'clear'): boolean;
95
141
  tail(query: {
96
142
  runId?: string;
97
- workstationId?: string;
143
+ taskChainId?: string;
98
144
  }, limit: number, beforeCursor?: number): TailResult;
99
145
  disposeAll(): Promise<void>;
100
146
  private remember;