@cjhyy/code-shell-core 0.6.0-rc.9 → 0.7.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.
Files changed (193) hide show
  1. package/THIRD_PARTY_NOTICES.md +206 -0
  2. package/dist/automation/scheduler.d.ts +13 -7
  3. package/dist/automation/scheduler.js +116 -37
  4. package/dist/capability-control/service.d.ts +2 -0
  5. package/dist/capability-control/service.js +4 -2
  6. package/dist/cc-orchestrator/agent-adapter.d.ts +4 -0
  7. package/dist/cc-orchestrator/agent-adapter.js +11 -1
  8. package/dist/cc-orchestrator/codex-session-history.d.ts +14 -1
  9. package/dist/cc-orchestrator/codex-session-history.js +65 -5
  10. package/dist/cc-orchestrator/cwd-normalize.d.ts +2 -0
  11. package/dist/cc-orchestrator/cwd-normalize.js +19 -0
  12. package/dist/cc-orchestrator/external-agent-bindings.d.ts +27 -0
  13. package/dist/cc-orchestrator/external-agent-bindings.js +150 -0
  14. package/dist/cc-orchestrator/external-agent-changes.js +22 -5
  15. package/dist/cc-orchestrator/external-agent-driver.d.ts +1 -0
  16. package/dist/cc-orchestrator/external-agent-driver.js +265 -50
  17. package/dist/cc-orchestrator/external-agent-session-store.d.ts +23 -0
  18. package/dist/cc-orchestrator/external-agent-session-store.js +146 -0
  19. package/dist/cc-orchestrator/session-history.d.ts +35 -0
  20. package/dist/cc-orchestrator/session-history.js +98 -15
  21. package/dist/cli/agent-server-stdio.js +9 -2
  22. package/dist/context/compaction.d.ts +8 -1
  23. package/dist/context/compaction.js +49 -4
  24. package/dist/context/manager.d.ts +16 -2
  25. package/dist/context/manager.js +103 -19
  26. package/dist/credentials/access.d.ts +57 -0
  27. package/dist/credentials/access.js +185 -0
  28. package/dist/credentials/index.d.ts +3 -1
  29. package/dist/credentials/index.js +2 -0
  30. package/dist/credentials/inject-credential-tool.d.ts +3 -1
  31. package/dist/credentials/inject-credential-tool.js +30 -11
  32. package/dist/credentials/oauth.d.ts +20 -0
  33. package/dist/credentials/oauth.js +114 -0
  34. package/dist/credentials/store.d.ts +1 -0
  35. package/dist/credentials/store.js +3 -1
  36. package/dist/credentials/types.d.ts +49 -3
  37. package/dist/credentials/use-credential-tool.d.ts +9 -1
  38. package/dist/credentials/use-credential-tool.js +58 -45
  39. package/dist/engine/engine.d.ts +23 -3
  40. package/dist/engine/engine.js +380 -255
  41. package/dist/engine/goal.d.ts +17 -0
  42. package/dist/engine/goal.js +16 -6
  43. package/dist/engine/image-policy.d.ts +6 -0
  44. package/dist/engine/image-policy.js +17 -6
  45. package/dist/engine/input-attachments.d.ts +13 -0
  46. package/dist/engine/input-attachments.js +398 -0
  47. package/dist/engine/model-facade.d.ts +5 -2
  48. package/dist/engine/model-facade.js +4 -4
  49. package/dist/engine/parse-task.d.ts +10 -0
  50. package/dist/engine/parse-task.js +5 -0
  51. package/dist/engine/run-image-input.d.ts +22 -0
  52. package/dist/engine/run-image-input.js +195 -0
  53. package/dist/engine/steer-queue.d.ts +3 -1
  54. package/dist/engine/steer-queue.js +10 -2
  55. package/dist/engine/streaming-tool-queue.d.ts +11 -7
  56. package/dist/engine/streaming-tool-queue.js +11 -7
  57. package/dist/engine/turn-loop.d.ts +37 -2
  58. package/dist/engine/turn-loop.js +228 -43
  59. package/dist/engine/types.d.ts +8 -0
  60. package/dist/git/worktree/crud.d.ts +69 -0
  61. package/dist/git/worktree/crud.js +206 -0
  62. package/dist/git/worktree/diff.d.ts +14 -0
  63. package/dist/git/worktree/diff.js +82 -0
  64. package/dist/git/worktree/git-exec.d.ts +7 -0
  65. package/dist/git/worktree/git-exec.js +51 -0
  66. package/dist/git/worktree/index.d.ts +5 -0
  67. package/dist/git/worktree/index.js +5 -0
  68. package/dist/git/worktree/query.d.ts +42 -0
  69. package/dist/git/worktree/query.js +121 -0
  70. package/dist/git/worktree/slug.d.ts +11 -0
  71. package/dist/git/worktree/slug.js +58 -0
  72. package/dist/git/worktree.d.ts +1 -84
  73. package/dist/git/worktree.js +5 -230
  74. package/dist/hooks/goal-stop-hook.d.ts +33 -1
  75. package/dist/hooks/goal-stop-hook.js +202 -34
  76. package/dist/index.d.ts +31 -28
  77. package/dist/index.js +27 -25
  78. package/dist/logging/logger.js +6 -6
  79. package/dist/logging/sanitize-messages.d.ts +10 -2
  80. package/dist/logging/sanitize-messages.js +21 -6
  81. package/dist/plugins/installer/checkUpdate.d.ts +4 -1
  82. package/dist/plugins/installer/checkUpdate.js +4 -2
  83. package/dist/plugins/installer/install.js +2 -0
  84. package/dist/plugins/installer/installFromSource.js +9 -1
  85. package/dist/plugins/installer/parseSource.d.ts +4 -1
  86. package/dist/plugins/installer/parseSource.js +28 -10
  87. package/dist/plugins/installer/sourcePath.d.ts +9 -0
  88. package/dist/plugins/installer/sourcePath.js +50 -0
  89. package/dist/plugins/installer/update.d.ts +4 -1
  90. package/dist/plugins/installer/update.js +5 -3
  91. package/dist/plugins/parseMarketplaceInput.d.ts +4 -1
  92. package/dist/plugins/parseMarketplaceInput.js +4 -3
  93. package/dist/plugins/pluginInstaller.js +24 -22
  94. package/dist/preset/index.d.ts +1 -0
  95. package/dist/preset/index.js +30 -13
  96. package/dist/prompt/sections/base.md +1 -1
  97. package/dist/protocol/chat-session-manager.d.ts +2 -0
  98. package/dist/protocol/chat-session-manager.js +38 -2
  99. package/dist/protocol/chat-session.d.ts +3 -0
  100. package/dist/protocol/chat-session.js +1 -0
  101. package/dist/protocol/client.d.ts +9 -4
  102. package/dist/protocol/client.js +18 -1
  103. package/dist/protocol/server.d.ts +30 -0
  104. package/dist/protocol/server.js +247 -47
  105. package/dist/protocol/types.d.ts +49 -0
  106. package/dist/protocol/types.js +6 -0
  107. package/dist/run/FileRunStore.js +10 -1
  108. package/dist/run/Heartbeat.js +12 -0
  109. package/dist/run/RunApprovalBackend.d.ts +3 -0
  110. package/dist/run/RunApprovalBackend.js +41 -6
  111. package/dist/run/RunLock.js +2 -0
  112. package/dist/run/RunManager.d.ts +2 -0
  113. package/dist/run/RunManager.js +64 -24
  114. package/dist/run/ids.d.ts +2 -0
  115. package/dist/run/ids.js +23 -0
  116. package/dist/runtime/background-shell.d.ts +1 -0
  117. package/dist/runtime/background-shell.js +23 -13
  118. package/dist/runtime/spawn-common.js +10 -0
  119. package/dist/services/auto-dream.d.ts +15 -4
  120. package/dist/services/auto-dream.js +20 -20
  121. package/dist/services/dream-consolidation.d.ts +2 -3
  122. package/dist/services/dream-consolidation.js +65 -15
  123. package/dist/services/extract-memories.d.ts +14 -5
  124. package/dist/services/extract-memories.js +20 -3
  125. package/dist/services/global-dream-promotion.d.ts +23 -0
  126. package/dist/services/global-dream-promotion.js +112 -0
  127. package/dist/services/memory-orchestrator.js +347 -34
  128. package/dist/session/memory.d.ts +61 -18
  129. package/dist/session/memory.js +342 -79
  130. package/dist/session/session-manager.d.ts +35 -1
  131. package/dist/session/session-manager.js +224 -4
  132. package/dist/session/transcript.d.ts +1 -1
  133. package/dist/session/transcript.js +17 -5
  134. package/dist/settings/manager.d.ts +1 -0
  135. package/dist/settings/manager.js +87 -37
  136. package/dist/settings/schema-export.d.ts +2 -3
  137. package/dist/settings/schema-export.js +2 -3
  138. package/dist/settings/schema.d.ts +21 -0
  139. package/dist/settings/schema.js +12 -0
  140. package/dist/skills/scanner.d.ts +3 -2
  141. package/dist/skills/scanner.js +12 -9
  142. package/dist/tool-system/builtin/agent-notifications.d.ts +11 -4
  143. package/dist/tool-system/builtin/agent-notifications.js +19 -7
  144. package/dist/tool-system/builtin/background-jobs.d.ts +35 -6
  145. package/dist/tool-system/builtin/background-jobs.js +116 -7
  146. package/dist/tool-system/builtin/background-work.d.ts +17 -18
  147. package/dist/tool-system/builtin/background-work.js +51 -5
  148. package/dist/tool-system/builtin/config.d.ts +2 -1
  149. package/dist/tool-system/builtin/config.js +16 -11
  150. package/dist/tool-system/builtin/cron-list.definition.d.ts +3 -0
  151. package/dist/tool-system/builtin/cron-list.definition.js +6 -0
  152. package/dist/tool-system/builtin/cron.d.ts +1 -2
  153. package/dist/tool-system/builtin/cron.js +9 -7
  154. package/dist/tool-system/builtin/drive-claude-code.d.ts +23 -2
  155. package/dist/tool-system/builtin/drive-claude-code.js +589 -48
  156. package/dist/tool-system/builtin/edit.js +5 -2
  157. package/dist/tool-system/builtin/generate-video.d.ts +1 -0
  158. package/dist/tool-system/builtin/generate-video.js +13 -4
  159. package/dist/tool-system/builtin/index.d.ts +8 -3
  160. package/dist/tool-system/builtin/index.js +50 -22
  161. package/dist/tool-system/builtin/lsp.d.ts +2 -1
  162. package/dist/tool-system/builtin/lsp.js +6 -3
  163. package/dist/tool-system/builtin/memory.js +40 -8
  164. package/dist/tool-system/builtin/notebook-edit.js +5 -2
  165. package/dist/tool-system/builtin/powershell.d.ts +5 -2
  166. package/dist/tool-system/builtin/powershell.js +11 -7
  167. package/dist/tool-system/builtin/read.js +118 -6
  168. package/dist/tool-system/builtin/sleep.d.ts +1 -2
  169. package/dist/tool-system/builtin/sleep.definition.d.ts +8 -0
  170. package/dist/tool-system/builtin/sleep.definition.js +28 -0
  171. package/dist/tool-system/builtin/sleep.js +1 -22
  172. package/dist/tool-system/builtin/view-image.d.ts +2 -2
  173. package/dist/tool-system/builtin/view-image.js +109 -19
  174. package/dist/tool-system/builtin/worktree.d.ts +4 -4
  175. package/dist/tool-system/builtin/worktree.js +297 -74
  176. package/dist/tool-system/builtin/write.js +5 -3
  177. package/dist/tool-system/context.d.ts +41 -1
  178. package/dist/tool-system/executor.d.ts +1 -5
  179. package/dist/tool-system/executor.js +94 -115
  180. package/dist/tool-system/mcp-manager.d.ts +31 -6
  181. package/dist/tool-system/mcp-manager.js +193 -78
  182. package/dist/tool-system/path-policy.d.ts +2 -0
  183. package/dist/tool-system/path-policy.js +41 -12
  184. package/dist/tool-system/permission.d.ts +28 -7
  185. package/dist/tool-system/permission.js +130 -49
  186. package/dist/tool-system/registry.js +11 -4
  187. package/dist/tool-system/tool-result-redaction.d.ts +7 -0
  188. package/dist/tool-system/tool-result-redaction.js +48 -0
  189. package/dist/tool-system/workspace-bridge.d.ts +11 -0
  190. package/dist/tool-system/workspace-bridge.js +1 -0
  191. package/dist/types.d.ts +78 -11
  192. package/dist/utils/toolDisplay.js +1 -1
  193. package/package.json +4 -3
@@ -0,0 +1,206 @@
1
+ # Third-party notices
2
+
3
+ This package includes code derived from third-party open source projects.
4
+
5
+ ## OpenAI Codex apply-patch
6
+
7
+ Files under `src/tool-system/builtin/apply-patch/` contain TypeScript code
8
+ adapted from OpenAI Codex `codex-rs/apply-patch`.
9
+
10
+ - Source: https://github.com/openai/codex/tree/main/codex-rs/apply-patch
11
+ - License: Apache License 2.0
12
+ - Copyright: Copyright 2025 OpenAI
13
+
14
+ The CodeShell implementation includes modifications, including a two-phase
15
+ commit/rollback behavior for failed patches.
16
+
17
+ ### Adapted files
18
+
19
+ | Source (Rust) | Target (TypeScript) | Notes |
20
+ | ---------------------------------- | ----------------------------- | --------------------------------------------------- |
21
+ | `src/seek_sequence.rs` | `seek-sequence.ts` | Direct port; same four-pass strategy |
22
+ | `src/parser.rs` | `parser.ts` | Direct port of the V4A grammar parser |
23
+ | `src/lib.rs` | `applier.ts` | `compute_replacements` algorithm port |
24
+ | `apply_patch_tool_instructions.md` | tool description (`index.ts`) | Patch-format instructions adapted from the original |
25
+ | `tests/fixtures/scenarios/` | `tests/fixtures/apply-patch/` | Golden scenarios used for conformance |
26
+
27
+ ### Apache License 2.0
28
+
29
+ ```
30
+ Apache License
31
+ Version 2.0, January 2004
32
+ http://www.apache.org/licenses/
33
+
34
+ TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION
35
+
36
+ 1. Definitions.
37
+
38
+ "License" shall mean the terms and conditions for use, reproduction,
39
+ and distribution as defined by Sections 1 through 9 of this document.
40
+
41
+ "Licensor" shall mean the copyright owner or entity authorized by
42
+ the copyright owner that is granting the License.
43
+
44
+ "Legal Entity" shall mean the union of the acting entity and all
45
+ other entities that control, are controlled by, or are under common
46
+ control with that entity. For the purposes of this definition,
47
+ "control" means (i) the power, direct or indirect, to cause the
48
+ direction or management of such entity, whether by contract or
49
+ otherwise, or (ii) ownership of fifty percent (50%) or more of the
50
+ outstanding shares, or (iii) beneficial ownership of such entity.
51
+
52
+ "You" (or "Your") shall mean an individual or Legal Entity
53
+ exercising permissions granted by this License.
54
+
55
+ "Source" form shall mean the preferred form for making modifications,
56
+ including but not limited to software source code, documentation
57
+ source, and configuration files.
58
+
59
+ "Object" form shall mean any form resulting from mechanical
60
+ transformation or translation of a Source form, including but
61
+ not limited to compiled object code, generated documentation,
62
+ and conversions to other media types.
63
+
64
+ "Work" shall mean the work of authorship, whether in Source or
65
+ Object form, made available under the License, as indicated by a
66
+ copyright notice that is included in or attached to the work
67
+ (an example is provided in the Appendix below).
68
+
69
+ "Derivative Works" shall mean any work, whether in Source or Object
70
+ form, that is based on (or derived from) the Work and for which the
71
+ editorial revisions, annotations, elaborations, or other modifications
72
+ represent, as a whole, an original work of authorship. For the purposes
73
+ of this License, Derivative Works shall not include works that remain
74
+ separable from, or merely link (or bind by name) to the interfaces of,
75
+ the Work and Derivative Works thereof.
76
+
77
+ "Contribution" shall mean any work of authorship, including
78
+ the original version of the Work and any modifications or additions
79
+ to that Work or Derivative Works thereof, that is intentionally
80
+ submitted to Licensor for inclusion in the Work by the copyright owner
81
+ or by an individual or Legal Entity authorized to submit on behalf of
82
+ the copyright owner. For the purposes of this definition, "submitted"
83
+ means any form of electronic, verbal, or written communication sent
84
+ to the Licensor or its representatives, including but not limited to
85
+ communication on electronic mailing lists, source code control systems,
86
+ and issue tracking systems that are managed by, or on behalf of the
87
+ Licensor for the purpose of discussing and improving the Work, but
88
+ excluding communication that is conspicuously marked or otherwise
89
+ designated in writing by the copyright owner as "Not a Contribution."
90
+
91
+ "Contributor" shall mean Licensor and any individual or Legal Entity
92
+ on behalf of whom a Contribution has been received by Licensor and
93
+ subsequently incorporated within the Work.
94
+
95
+ 2. Grant of Copyright License. Subject to the terms and conditions of
96
+ this License, each Contributor hereby grants to You a perpetual,
97
+ worldwide, non-exclusive, no-charge, royalty-free, irrevocable
98
+ copyright license to reproduce, prepare Derivative Works of,
99
+ publicly display, publicly perform, sublicense, and distribute the
100
+ Work and such Derivative Works in Source or Object form.
101
+
102
+ 3. Grant of Patent License. Subject to the terms and conditions of
103
+ this License, each Contributor hereby grants to You a perpetual,
104
+ worldwide, non-exclusive, no-charge, royalty-free, irrevocable
105
+ (except as stated in this section) patent license to make, have made,
106
+ use, offer to sell, sell, import, and otherwise transfer the Work,
107
+ where such license applies only to those patent claims licensable
108
+ by such Contributor that are necessarily infringed by their
109
+ Contribution(s) alone or by combination of their Contribution(s)
110
+ with the Work to which such Contribution(s) was submitted. If You
111
+ institute patent litigation against any entity (including a
112
+ cross-claim or counterclaim in a lawsuit) alleging that the Work
113
+ or a Contribution incorporated within the Work constitutes direct
114
+ or contributory patent infringement, then any patent licenses
115
+ granted to You under this License for that Work shall terminate
116
+ as of the date such litigation is filed.
117
+
118
+ 4. Redistribution. You may reproduce and distribute copies of the
119
+ Work or Derivative Works thereof in any medium, with or without
120
+ modifications, and in Source or Object form, provided that You
121
+ meet the following conditions:
122
+
123
+ (a) You must give any other recipients of the Work or
124
+ Derivative Works a copy of this License; and
125
+
126
+ (b) You must cause any modified files to carry prominent notices
127
+ stating that You changed the files; and
128
+
129
+ (c) You must retain, in the Source form of any Derivative Works
130
+ that You distribute, all copyright, patent, trademark, and
131
+ attribution notices from the Source form of the Work,
132
+ excluding those notices that do not pertain to any part of
133
+ the Derivative Works; and
134
+
135
+ (d) If the Work includes a "NOTICE" text file as part of its
136
+ distribution, then any Derivative Works that You distribute must
137
+ include a readable copy of the attribution notices contained
138
+ within such NOTICE file, excluding those notices that do not
139
+ pertain to any part of the Derivative Works, in at least one
140
+ of the following places: within a NOTICE text file distributed
141
+ as part of the Derivative Works; within the Source form or
142
+ documentation, if provided along with the Derivative Works; or,
143
+ within a display generated by the Derivative Works, if and
144
+ wherever such third-party notices normally appear. The contents
145
+ of the NOTICE file are for informational purposes only and
146
+ do not modify the License. You may add Your own attribution
147
+ notices within Derivative Works that You distribute, alongside
148
+ or as an addendum to the NOTICE text from the Work, provided
149
+ that such additional attribution notices cannot be construed
150
+ as modifying the License.
151
+
152
+ You may add Your own copyright statement to Your modifications and
153
+ may provide additional or different license terms and conditions
154
+ for use, reproduction, or distribution of Your modifications, or
155
+ for any such Derivative Works as a whole, provided Your use,
156
+ reproduction, and distribution of the Work otherwise complies with
157
+ the conditions stated in this License.
158
+
159
+ 5. Submission of Contributions. Unless You explicitly state otherwise,
160
+ any Contribution intentionally submitted for inclusion in the Work
161
+ by You to the Licensor shall be under the terms and conditions of
162
+ this License, without any additional terms or conditions.
163
+ Notwithstanding the above, nothing herein shall supersede or modify
164
+ the terms of any separate license agreement you may have executed
165
+ with Licensor regarding such Contributions.
166
+
167
+ 6. Trademarks. This License does not grant permission to use the trade
168
+ names, trademarks, service marks, or product names of the Licensor,
169
+ except as required for reasonable and customary use in describing the
170
+ origin of the Work and reproducing the content of the NOTICE file.
171
+
172
+ 7. Disclaimer of Warranty. Unless required by applicable law or
173
+ agreed to in writing, Licensor provides the Work (and each
174
+ Contributor provides its Contributions) on an "AS IS" BASIS,
175
+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
176
+ implied, including, without limitation, any warranties or conditions
177
+ of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A
178
+ PARTICULAR PURPOSE. You are solely responsible for determining the
179
+ appropriateness of using or redistributing the Work and assume any
180
+ risks associated with Your exercise of permissions under this License.
181
+
182
+ 8. Limitation of Liability. In no event and under no legal theory,
183
+ whether in tort (including negligence), contract, or otherwise,
184
+ unless required by applicable law (such as deliberate and grossly
185
+ negligent acts) or agreed to in writing, shall any Contributor be
186
+ liable to You for damages, including any direct, indirect, special,
187
+ incidental, or consequential damages of any character arising as a
188
+ result of this License or out of the use or inability to use the
189
+ Work (including but not limited to damages for loss of goodwill,
190
+ work stoppage, computer failure or malfunction, or any and all
191
+ other commercial damages or losses), even if such Contributor
192
+ has been advised of the possibility of such damages.
193
+
194
+ 9. Accepting Warranty or Additional Liability. While redistributing
195
+ the Work or Derivative Works thereof, You may choose to offer,
196
+ and charge a fee for, acceptance of support, warranty, indemnity,
197
+ or other liability obligations and/or rights consistent with this
198
+ License. However, in accepting such obligations, You may act only
199
+ on Your own behalf and on Your sole responsibility, not on behalf
200
+ of any other Contributor, and only if You agree to indemnify,
201
+ defend, and hold each Contributor harmless for any liability
202
+ incurred by, or claims asserted against, such Contributor by reason
203
+ of your accepting any such warranty or additional liability.
204
+
205
+ END OF TERMS AND CONDITIONS
206
+ ```
@@ -120,7 +120,8 @@ export declare class CronScheduler {
120
120
  * created/deleted/changed jobs through the same store. Reconciliation:
121
121
  * - jobs on disk but not in memory → added (and armed if enabled)
122
122
  * - jobs in memory but not on disk → removed + timer cleared
123
- * - jobs whose schedule/enabled differ → re-armed to match disk
123
+ * - jobs whose schedule/enabled/timezone differ → re-armed to match disk
124
+ * - unchanged enabled jobs with live timers → kept as-is, preserving nextRun
124
125
  *
125
126
  * Pass `{ arm: false }` in a host that must NOT execute jobs (the worker —
126
127
  * separate process from the one that owns execution); it still tracks +
@@ -130,6 +131,8 @@ export declare class CronScheduler {
130
131
  arm?: boolean;
131
132
  }): void;
132
133
  private reconcileJobs;
134
+ private jobDefinitionChanged;
135
+ private mergeJobFromDisk;
133
136
  private nextPersistedId;
134
137
  /** Recompute nextRun without arming a timer (for display in disabled/no-arm hosts). */
135
138
  private refreshNextRunForDisplay;
@@ -166,19 +169,22 @@ export declare class CronScheduler {
166
169
  */
167
170
  runNow(id: string): boolean;
168
171
  /**
169
- * Arm a job's timer. Interval schedules ("5m") use setInterval; cron-
170
- * expression schedules ("0 9 * * 1-5") compute the next trigger in the
171
- * job's timezone and use setTimeout, re-arming after each fire. nextRun is
172
- * updated to reflect the scheduled instant.
172
+ * Arm a job's timer from its current definition. This intentionally resets
173
+ * the absolute phase (interval: now+interval; cron: next matching wall-clock
174
+ * instant), so reconcileJobs preserves unchanged live timers instead of
175
+ * calling arm() repeatedly.
173
176
  */
174
177
  private arm;
175
- private refreshIntervalNextRun;
178
+ private armInterval;
179
+ private nextIntervalRunAfter;
176
180
  private armCron;
177
181
  private clearTimer;
178
182
  /**
179
183
  * Shared fire path for both schedule kinds. Re-entrancy guard, run-stat
180
184
  * bookkeeping, persistence, then the executor. `afterStats` updates nextRun
181
- * for the next occurrence (interval: now+interval; cron: re-armed inside).
185
+ * for the next occurrence. Returns false when the run was skipped by enabled
186
+ * state or the re-entrancy guard, so one-shot timers can still schedule the
187
+ * next absolute slot without starting overlapping executions.
182
188
  */
183
189
  private fire;
184
190
  }
@@ -102,7 +102,8 @@ export class CronScheduler {
102
102
  * created/deleted/changed jobs through the same store. Reconciliation:
103
103
  * - jobs on disk but not in memory → added (and armed if enabled)
104
104
  * - jobs in memory but not on disk → removed + timer cleared
105
- * - jobs whose schedule/enabled differ → re-armed to match disk
105
+ * - jobs whose schedule/enabled/timezone differ → re-armed to match disk
106
+ * - unchanged enabled jobs with live timers → kept as-is, preserving nextRun
106
107
  *
107
108
  * Pass `{ arm: false }` in a host that must NOT execute jobs (the worker —
108
109
  * separate process from the one that owns execution); it still tracks +
@@ -127,28 +128,67 @@ export class CronScheduler {
127
128
  let maxId = 0;
128
129
  for (const job of persisted) {
129
130
  const prev = this.jobs.get(job.id);
130
- this.jobs.set(job.id, job);
131
131
  const n = parseInt(job.id, 10);
132
132
  if (Number.isFinite(n) && n > maxId)
133
133
  maxId = n;
134
- // (Re)arm when execution is on. arm() is idempotent (clears any prior
135
- // timer first), so calling it for unchanged jobs is harmless; it also
136
- // refreshes nextRun for display.
137
- if (arm && job.enabled) {
138
- this.arm(job);
134
+ if (!prev) {
135
+ this.jobs.set(job.id, job);
136
+ if (arm && job.enabled) {
137
+ this.arm(job);
138
+ }
139
+ else {
140
+ this.refreshNextRunForDisplay(job);
141
+ }
142
+ continue;
139
143
  }
140
- else {
141
- // Disabled (or arm suppressed): ensure no stale timer survives a
142
- // prior enabled state.
143
- if (prev && this.timers.has(job.id))
144
+ const definitionChanged = this.jobDefinitionChanged(prev, job);
145
+ const hasTimer = this.timers.has(job.id);
146
+ if (!arm || !job.enabled) {
147
+ // Disabled (or arm suppressed): ensure no stale timer survives a prior
148
+ // enabled state. Keep the existing object identity so any in-flight
149
+ // executor bookkeeping still points at the scheduler-visible job.
150
+ this.mergeJobFromDisk(prev, job);
151
+ if (hasTimer)
144
152
  this.clearTimer(job.id);
145
- // Still refresh nextRun for display even when not arming.
146
- if (!arm || !job.enabled)
147
- this.refreshNextRunForDisplay(job);
153
+ this.refreshNextRunForDisplay(prev);
154
+ }
155
+ else if (definitionChanged || !hasTimer) {
156
+ // New scheduling definition, or this process has no live timer (e.g.
157
+ // after stopAll or when taking over from an arm:false worker): reset the
158
+ // absolute phase from now and arm.
159
+ this.mergeJobFromDisk(prev, job);
160
+ this.arm(prev);
161
+ }
162
+ else {
163
+ // Unchanged enabled job with a live timer: preserve the timer and the
164
+ // absolute nextRun. Merge user-editable fields into the same object so
165
+ // the existing timeout closure and scheduler.get(id) never diverge.
166
+ this.mergeJobFromDisk(prev, job, { preserveNextRun: true });
148
167
  }
149
168
  }
150
169
  this.nextId = Math.max(this.nextId, maxId + 1);
151
170
  }
171
+ jobDefinitionChanged(prev, next) {
172
+ return (prev.schedule !== next.schedule ||
173
+ prev.enabled !== next.enabled ||
174
+ prev.timezone !== next.timezone);
175
+ }
176
+ mergeJobFromDisk(target, source, opts) {
177
+ const preservedNextRun = target.nextRun;
178
+ for (const key of Object.keys(target)) {
179
+ if (!(key in source))
180
+ delete target[key];
181
+ }
182
+ Object.assign(target, source);
183
+ if (opts?.preserveNextRun) {
184
+ if (preservedNextRun === undefined) {
185
+ delete target.nextRun;
186
+ }
187
+ else {
188
+ target.nextRun = preservedNextRun;
189
+ }
190
+ }
191
+ }
152
192
  nextPersistedId(jobs) {
153
193
  let maxId = 0;
154
194
  for (const job of jobs) {
@@ -377,6 +417,8 @@ export class CronScheduler {
377
417
  if (patch.schedule !== undefined || patch.timezone !== undefined) {
378
418
  validateSchedule(nextSchedule, nextTimezone);
379
419
  }
420
+ const scheduleChanged = (patch.schedule !== undefined && patch.schedule !== job.schedule) ||
421
+ (patch.timezone !== undefined && patch.timezone !== job.timezone);
380
422
  if (patch.name !== undefined)
381
423
  job.name = patch.name;
382
424
  if (patch.prompt !== undefined)
@@ -389,14 +431,15 @@ export class CronScheduler {
389
431
  job.cwd = patch.cwd;
390
432
  if (patch.permissionLevel !== undefined)
391
433
  job.permissionLevel = patch.permissionLevel;
392
- this.refreshNextRunForDisplay(job);
434
+ if (scheduleChanged)
435
+ this.refreshNextRunForDisplay(job);
393
436
  updated = job;
394
437
  return job;
395
438
  });
396
439
  return { jobs: next, result: updated };
397
440
  });
398
441
  this.reconcileJobs(tx.jobs);
399
- return tx.result ? this.jobs.get(id) ?? tx.result : null;
442
+ return tx.result ? (this.jobs.get(id) ?? tx.result) : null;
400
443
  }
401
444
  const job = this.jobs.get(id);
402
445
  if (!job)
@@ -407,6 +450,8 @@ export class CronScheduler {
407
450
  if (patch.schedule !== undefined || patch.timezone !== undefined) {
408
451
  validateSchedule(nextSchedule, nextTimezone);
409
452
  }
453
+ const scheduleChanged = (patch.schedule !== undefined && patch.schedule !== job.schedule) ||
454
+ (patch.timezone !== undefined && patch.timezone !== job.timezone);
410
455
  if (patch.name !== undefined)
411
456
  job.name = patch.name;
412
457
  if (patch.prompt !== undefined)
@@ -419,11 +464,12 @@ export class CronScheduler {
419
464
  job.cwd = patch.cwd;
420
465
  if (patch.permissionLevel !== undefined)
421
466
  job.permissionLevel = patch.permissionLevel;
422
- // Re-arm so a schedule/timezone change drives execution now. arm() is
423
- // idempotent and respects enabled + executionEnabled (paused no timer,
424
- // but nextRun still refreshed for display).
467
+ // Re-arm only when the schedule definition changed, or when an enabled job
468
+ // has no live timer to preserve. Ordinary field edits keep the absolute
469
+ // nextRun so they do not push an interval job back.
425
470
  if (job.enabled) {
426
- this.arm(job);
471
+ if (scheduleChanged || !this.timers.has(id))
472
+ this.arm(job);
427
473
  }
428
474
  else {
429
475
  this.clearTimer(id);
@@ -454,10 +500,10 @@ export class CronScheduler {
454
500
  return true;
455
501
  }
456
502
  /**
457
- * Arm a job's timer. Interval schedules ("5m") use setInterval; cron-
458
- * expression schedules ("0 9 * * 1-5") compute the next trigger in the
459
- * job's timezone and use setTimeout, re-arming after each fire. nextRun is
460
- * updated to reflect the scheduled instant.
503
+ * Arm a job's timer from its current definition. This intentionally resets
504
+ * the absolute phase (interval: now+interval; cron: next matching wall-clock
505
+ * instant), so reconcileJobs preserves unchanged live timers instead of
506
+ * calling arm() repeatedly.
461
507
  */
462
508
  arm(job) {
463
509
  this.clearTimer(job.id);
@@ -472,15 +518,36 @@ export class CronScheduler {
472
518
  }
473
519
  else {
474
520
  const intervalMs = parseSchedule(job.schedule);
475
- job.nextRun = Date.now() + intervalMs;
521
+ const nextRun = Date.now() + intervalMs;
522
+ job.nextRun = nextRun;
476
523
  if (!this.executionEnabled)
477
524
  return;
478
- const timer = setInterval(() => void this.fire(job, () => this.refreshIntervalNextRun(job, intervalMs)), intervalMs);
479
- this.timers.set(job.id, timer);
525
+ this.armInterval(job, intervalMs, nextRun);
480
526
  }
481
527
  }
482
- refreshIntervalNextRun(job, intervalMs) {
483
- job.nextRun = Date.now() + intervalMs;
528
+ armInterval(job, intervalMs, scheduledFor) {
529
+ job.nextRun = scheduledFor;
530
+ const delay = Math.max(0, scheduledFor - Date.now());
531
+ const timer = setTimeout(() => {
532
+ this.timers.delete(job.id);
533
+ const rearm = () => {
534
+ if (!this.executionEnabled || !job.enabled || !this.jobs.has(job.id))
535
+ return;
536
+ this.armInterval(job, intervalMs, this.nextIntervalRunAfter(scheduledFor, intervalMs, Date.now()));
537
+ };
538
+ void this.fire(job, rearm).then((ran) => {
539
+ if (!ran)
540
+ rearm();
541
+ });
542
+ }, delay);
543
+ this.timers.set(job.id, timer);
544
+ }
545
+ nextIntervalRunAfter(scheduledFor, intervalMs, now) {
546
+ let next = scheduledFor + intervalMs;
547
+ if (next <= now) {
548
+ next += (Math.floor((now - next) / intervalMs) + 1) * intervalMs;
549
+ }
550
+ return next;
484
551
  }
485
552
  armCron(job) {
486
553
  const cron = parseCronExpression(job.schedule);
@@ -495,6 +562,7 @@ export class CronScheduler {
495
562
  const scheduledFor = next;
496
563
  const delay = Math.max(0, next - Date.now());
497
564
  const timer = setTimeout(() => {
565
+ this.timers.delete(job.id);
498
566
  // Misfire guard for sleep/wake drift. A setTimeout pauses while the host
499
567
  // sleeps, then fires the instant the machine wakes — which can be hours
500
568
  // off the scheduled wall-clock (observed: a `0 9 * * *` job running at
@@ -507,12 +575,16 @@ export class CronScheduler {
507
575
  this.armCron(job);
508
576
  return;
509
577
  }
510
- void this.fire(job, () => {
578
+ const rearm = () => {
511
579
  // Re-arm for the following occurrence — but only if the job still
512
580
  // exists. A one-shot (once) job deletes itself in fire()'s finally,
513
581
  // so this closure must not resurrect it via a stale reference.
514
582
  if (job.enabled && this.jobs.has(job.id))
515
583
  this.armCron(job);
584
+ };
585
+ void this.fire(job, rearm).then((ran) => {
586
+ if (!ran)
587
+ rearm();
516
588
  });
517
589
  }, delay);
518
590
  this.timers.set(job.id, timer);
@@ -527,16 +599,18 @@ export class CronScheduler {
527
599
  /**
528
600
  * Shared fire path for both schedule kinds. Re-entrancy guard, run-stat
529
601
  * bookkeeping, persistence, then the executor. `afterStats` updates nextRun
530
- * for the next occurrence (interval: now+interval; cron: re-armed inside).
602
+ * for the next occurrence. Returns false when the run was skipped by enabled
603
+ * state or the re-entrancy guard, so one-shot timers can still schedule the
604
+ * next absolute slot without starting overlapping executions.
531
605
  */
532
606
  async fire(job, afterStats, force = false) {
533
607
  if (!job.enabled && !force)
534
- return;
608
+ return false;
535
609
  // Re-entrancy guard: if this job's previous run is still in flight
536
610
  // (onExecute slower than the interval), skip rather than stacking
537
611
  // overlapping executions that double-count runCount.
538
612
  if (this.running.has(job.id))
539
- return;
613
+ return false;
540
614
  this.running.add(job.id);
541
615
  // One in-flight entry per job. abort(jobId) trips `controller` (Engine.run
542
616
  // cooperates and resolves early) and awaits `done`, which we resolve in the
@@ -573,6 +647,7 @@ export class CronScheduler {
573
647
  // Unblock any abort() awaiting this run's teardown.
574
648
  resolveDone();
575
649
  }
650
+ return true;
576
651
  }
577
652
  }
578
653
  /** Validate a schedule string (interval or cron expr) without scheduling. Throws on invalid. */
@@ -604,10 +679,14 @@ export function parseSchedule(schedule) {
604
679
  // path's `> 0` guard and the "throw on bad input" contract.
605
680
  if (value > 0) {
606
681
  switch (match[2]) {
607
- case "s": return value * 1000;
608
- case "m": return value * 60 * 1000;
609
- case "h": return value * 60 * 60 * 1000;
610
- case "d": return value * 24 * 60 * 60 * 1000;
682
+ case "s":
683
+ return value * 1000;
684
+ case "m":
685
+ return value * 60 * 1000;
686
+ case "h":
687
+ return value * 60 * 60 * 1000;
688
+ case "d":
689
+ return value * 24 * 60 * 60 * 1000;
611
690
  }
612
691
  }
613
692
  }
@@ -31,9 +31,11 @@ export interface CapabilityServiceDeps {
31
31
  readInstalledPlugins: () => InstalledPluginsV2;
32
32
  resolveBuiltinToolNames: (o?: {
33
33
  preset?: string;
34
+ host?: "desktop";
34
35
  enabledBuiltinTools?: string[];
35
36
  disabledBuiltinTools?: string[];
36
37
  }) => string[];
38
+ builtinToolHost?: "desktop";
37
39
  }
38
40
  export declare class CapabilityService {
39
41
  private readonly deps;
@@ -13,7 +13,7 @@
13
13
  */
14
14
  import { CapabilityNotFoundError } from "./types.js";
15
15
  import { projectBuiltin, projectMcp, projectSkills, projectPlugins, projectAgents, } from "./project.js";
16
- import { applyOverride, bucketForKind, overrideTokenForId, overrideFor, } from "./overlay.js";
16
+ import { applyOverride, bucketForKind, overrideTokenForId, overrideFor } from "./overlay.js";
17
17
  export class CapabilityService {
18
18
  deps;
19
19
  constructor(deps) {
@@ -30,12 +30,14 @@ export class CapabilityService {
30
30
  const agent = (s.agent ?? {});
31
31
  const tools = this.deps.registry.listToolsDetailed();
32
32
  const preset = agent.preset;
33
+ const host = this.deps.builtinToolHost;
33
34
  const base = [
34
35
  ...projectBuiltin({
35
36
  tools: tools.filter((t) => t.source === "builtin"),
36
- presetDefaults: this.deps.resolveBuiltinToolNames({ preset }),
37
+ presetDefaults: this.deps.resolveBuiltinToolNames({ preset, host }),
37
38
  effective: this.deps.resolveBuiltinToolNames({
38
39
  preset,
40
+ host,
39
41
  enabledBuiltinTools: agent.enabledBuiltinTools ?? [],
40
42
  disabledBuiltinTools: agent.disabledBuiltinTools ?? [],
41
43
  }),
@@ -2,8 +2,12 @@ export type PermissionMode = "default" | "acceptEdits" | "bypassPermissions";
2
2
  export interface BuildArgsOpts {
3
3
  prompt: string;
4
4
  resumeSessionId?: string;
5
+ /** Optional caller-specified model override. Passed through without validation; the CLI reports unknown models. */
6
+ model?: string;
5
7
  permissionMode: PermissionMode;
6
8
  cwd: string;
9
+ imagePaths?: string[];
10
+ codexImageInputSupported?: boolean;
7
11
  }
8
12
  export interface ParsedResult {
9
13
  sessionId: string;
@@ -14,6 +14,8 @@ export const claudeAdapter = {
14
14
  buildArgs(opts) {
15
15
  // -p (print/headless) + stream-json REQUIRES --verbose (verified).
16
16
  const args = ["-p", opts.prompt, "--output-format", "stream-json", "--verbose"];
17
+ if (opts.model)
18
+ args.push("--model", opts.model);
17
19
  if (opts.resumeSessionId)
18
20
  args.push("--resume", opts.resumeSessionId);
19
21
  // Hard-disallow Workflow: driving CC unattended (esp. bypassPermissions),
@@ -82,6 +84,12 @@ export const codexAdapter = {
82
84
  else {
83
85
  args.push("--sandbox", opts.permissionMode === "acceptEdits" ? "workspace-write" : "read-only");
84
86
  }
87
+ if (opts.model)
88
+ args.push("--model", opts.model);
89
+ if (opts.codexImageInputSupported) {
90
+ for (const imagePath of opts.imagePaths ?? [])
91
+ args.push("-i", imagePath);
92
+ }
85
93
  // `resume <thread_id>` continues a prior codex session; the trailing `-`
86
94
  // tells codex exec to read the prompt from stdin (we feed it there).
87
95
  if (opts.resumeSessionId)
@@ -108,7 +116,9 @@ export const codexAdapter = {
108
116
  }
109
117
  if (d.type === "thread.started" && typeof d.thread_id === "string")
110
118
  sessionId = d.thread_id;
111
- else if (d.type === "item.completed" && d.item?.type === "agent_message" && typeof d.item.text === "string") {
119
+ else if (d.type === "item.completed" &&
120
+ d.item?.type === "agent_message" &&
121
+ typeof d.item.text === "string") {
112
122
  finalText = d.item.text; // keep the LAST agent_message
113
123
  }
114
124
  else if (d.type === "turn.failed") {
@@ -1,4 +1,4 @@
1
- import type { HistoryMessage } from "./session-history.js";
1
+ import type { HistoryMessage, SessionTailEvent } from "./session-history.js";
2
2
  /**
3
3
  * Read the last `limit` user/assistant messages from a codex CLI session,
4
4
  * returning the SAME shape as the claude-side `readRecentHistory` so the room
@@ -23,3 +23,16 @@ export declare function readCodexRecentHistory(cwd: string, threadId: string, li
23
23
  hasMore: boolean;
24
24
  totalCount: number;
25
25
  };
26
+ /** Parse a bounded/raw Codex rollout snapshot. Shared with the desktop tail
27
+ * follower so its initial history and EOF cursor are atomic. */
28
+ export declare function parseCodexRecentHistory(raw: string, limit: number): {
29
+ messages: HistoryMessage[];
30
+ hasMore: boolean;
31
+ totalCount: number;
32
+ };
33
+ /** Parse one newly-appended Codex rollout JSONL line. `response_item` is the
34
+ * authoritative rendered stream; parallel `event_msg.agent_message` records
35
+ * are deliberately ignored to avoid duplicate assistant bubbles. */
36
+ export declare function parseCodexTranscriptLine(line: string): SessionTailEvent[];
37
+ /** Find the rollout file whose `session_meta` matches both `threadId` and `cwd`. */
38
+ export declare function findCodexRolloutFile(codexHome: string, cwd: string, threadId: string): string | undefined;