@cjhyy/code-shell-capability-coding 0.8.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 (134) hide show
  1. package/README.md +69 -0
  2. package/THIRD_PARTY_NOTICES.md +206 -0
  3. package/dist/bin/agent-server-stdio.d.ts +1 -0
  4. package/dist/bin/agent-server-stdio.js +4 -0
  5. package/dist/capability-runtime.d.ts +22 -0
  6. package/dist/capability-runtime.js +88 -0
  7. package/dist/cc-orchestrator/agent-adapter.d.ts +55 -0
  8. package/dist/cc-orchestrator/agent-adapter.js +143 -0
  9. package/dist/cc-orchestrator/cc-capability.d.ts +20 -0
  10. package/dist/cc-orchestrator/cc-capability.js +57 -0
  11. package/dist/cc-orchestrator/codex-session-discovery.d.ts +45 -0
  12. package/dist/cc-orchestrator/codex-session-discovery.js +251 -0
  13. package/dist/cc-orchestrator/codex-session-history.d.ts +39 -0
  14. package/dist/cc-orchestrator/codex-session-history.js +249 -0
  15. package/dist/cc-orchestrator/codex-user-text.d.ts +9 -0
  16. package/dist/cc-orchestrator/codex-user-text.js +25 -0
  17. package/dist/cc-orchestrator/external-agent-bindings.d.ts +27 -0
  18. package/dist/cc-orchestrator/external-agent-bindings.js +150 -0
  19. package/dist/cc-orchestrator/external-agent-changes.d.ts +19 -0
  20. package/dist/cc-orchestrator/external-agent-changes.js +231 -0
  21. package/dist/cc-orchestrator/external-agent-driver.d.ts +19 -0
  22. package/dist/cc-orchestrator/external-agent-driver.js +284 -0
  23. package/dist/cc-orchestrator/external-agent-session-store.d.ts +36 -0
  24. package/dist/cc-orchestrator/external-agent-session-store.js +185 -0
  25. package/dist/cc-orchestrator/index.d.ts +10 -0
  26. package/dist/cc-orchestrator/index.js +10 -0
  27. package/dist/cc-orchestrator/related-session-discovery.d.ts +21 -0
  28. package/dist/cc-orchestrator/related-session-discovery.js +77 -0
  29. package/dist/cc-orchestrator/relevance-judge.d.ts +16 -0
  30. package/dist/cc-orchestrator/relevance-judge.js +38 -0
  31. package/dist/cc-orchestrator/session-discovery.d.ts +99 -0
  32. package/dist/cc-orchestrator/session-discovery.js +295 -0
  33. package/dist/cc-orchestrator/session-history.d.ts +55 -0
  34. package/dist/cc-orchestrator/session-history.js +150 -0
  35. package/dist/external-agents/config.d.ts +3 -0
  36. package/dist/external-agents/config.js +16 -0
  37. package/dist/external-agents/types.d.ts +32 -0
  38. package/dist/external-agents/types.js +1 -0
  39. package/dist/external-runtimes/claude-code/event-translator.d.ts +54 -0
  40. package/dist/external-runtimes/claude-code/event-translator.js +201 -0
  41. package/dist/external-runtimes/claude-code/mcp-config.d.ts +84 -0
  42. package/dist/external-runtimes/claude-code/mcp-config.js +175 -0
  43. package/dist/external-runtimes/claude-code/runtime.d.ts +56 -0
  44. package/dist/external-runtimes/claude-code/runtime.js +168 -0
  45. package/dist/external-runtimes/codex/app-server-client.d.ts +66 -0
  46. package/dist/external-runtimes/codex/app-server-client.js +244 -0
  47. package/dist/external-runtimes/codex/event-translator.d.ts +68 -0
  48. package/dist/external-runtimes/codex/event-translator.js +187 -0
  49. package/dist/external-runtimes/codex/index.d.ts +7 -0
  50. package/dist/external-runtimes/codex/index.js +6 -0
  51. package/dist/external-runtimes/codex/runtime.d.ts +128 -0
  52. package/dist/external-runtimes/codex/runtime.js +216 -0
  53. package/dist/external-runtimes/index.d.ts +37 -0
  54. package/dist/external-runtimes/index.js +27 -0
  55. package/dist/external-runtimes/session-factory.d.ts +97 -0
  56. package/dist/external-runtimes/session-factory.js +110 -0
  57. package/dist/external-runtimes/shared/mcp-bridge.d.ts +66 -0
  58. package/dist/external-runtimes/shared/mcp-bridge.js +365 -0
  59. package/dist/external-runtimes/shared/session-context-store.d.ts +83 -0
  60. package/dist/external-runtimes/shared/session-context-store.js +114 -0
  61. package/dist/external-runtimes/shared/spawn-env.d.ts +30 -0
  62. package/dist/external-runtimes/shared/spawn-env.js +41 -0
  63. package/dist/git/parse-log.d.ts +14 -0
  64. package/dist/git/parse-log.js +21 -0
  65. package/dist/git/utils.d.ts +49 -0
  66. package/dist/git/utils.js +161 -0
  67. package/dist/git/worktree/crud.d.ts +108 -0
  68. package/dist/git/worktree/crud.js +415 -0
  69. package/dist/git/worktree/diff.d.ts +14 -0
  70. package/dist/git/worktree/diff.js +83 -0
  71. package/dist/git/worktree/git-exec.d.ts +7 -0
  72. package/dist/git/worktree/git-exec.js +86 -0
  73. package/dist/git/worktree/index.d.ts +6 -0
  74. package/dist/git/worktree/index.js +6 -0
  75. package/dist/git/worktree/query.d.ts +43 -0
  76. package/dist/git/worktree/query.js +128 -0
  77. package/dist/git/worktree/slug.d.ts +12 -0
  78. package/dist/git/worktree/slug.js +59 -0
  79. package/dist/git/worktree.d.ts +1 -0
  80. package/dist/git/worktree.js +5 -0
  81. package/dist/index.capability.d.ts +7 -0
  82. package/dist/index.capability.js +190 -0
  83. package/dist/index.d.ts +18 -0
  84. package/dist/index.git.d.ts +4 -0
  85. package/dist/index.git.js +4 -0
  86. package/dist/index.js +18 -0
  87. package/dist/index.orchestration.d.ts +7 -0
  88. package/dist/index.orchestration.js +5 -0
  89. package/dist/lsp/client.d.ts +41 -0
  90. package/dist/lsp/client.js +192 -0
  91. package/dist/lsp/manager.d.ts +53 -0
  92. package/dist/lsp/manager.js +248 -0
  93. package/dist/lsp/root-path.d.ts +9 -0
  94. package/dist/lsp/root-path.js +12 -0
  95. package/dist/lsp/servers.d.ts +16 -0
  96. package/dist/lsp/servers.js +60 -0
  97. package/dist/prompt/coding.md +42 -0
  98. package/dist/quota/credentials.d.ts +3 -0
  99. package/dist/quota/credentials.js +80 -0
  100. package/dist/quota/index.d.ts +36 -0
  101. package/dist/quota/index.js +161 -0
  102. package/dist/quota/types.d.ts +48 -0
  103. package/dist/quota/types.js +13 -0
  104. package/dist/review/review-prompt.d.ts +28 -0
  105. package/dist/review/review-prompt.js +81 -0
  106. package/dist/tools/apply-patch/LICENSE-codex +201 -0
  107. package/dist/tools/apply-patch/NOTICE.md +29 -0
  108. package/dist/tools/apply-patch/applier.d.ts +26 -0
  109. package/dist/tools/apply-patch/applier.js +306 -0
  110. package/dist/tools/apply-patch/backup-targets.d.ts +10 -0
  111. package/dist/tools/apply-patch/backup-targets.js +30 -0
  112. package/dist/tools/apply-patch/eol.d.ts +4 -0
  113. package/dist/tools/apply-patch/eol.js +9 -0
  114. package/dist/tools/apply-patch/index.d.ts +20 -0
  115. package/dist/tools/apply-patch/index.js +106 -0
  116. package/dist/tools/apply-patch/parser.d.ts +17 -0
  117. package/dist/tools/apply-patch/parser.js +209 -0
  118. package/dist/tools/apply-patch/seek-sequence.d.ts +18 -0
  119. package/dist/tools/apply-patch/seek-sequence.js +123 -0
  120. package/dist/tools/apply-patch/types.d.ts +49 -0
  121. package/dist/tools/apply-patch/types.js +13 -0
  122. package/dist/tools/brief.d.ts +6 -0
  123. package/dist/tools/brief.js +41 -0
  124. package/dist/tools/check-quota.d.ts +14 -0
  125. package/dist/tools/check-quota.js +38 -0
  126. package/dist/tools/drive-agent.d.ts +52 -0
  127. package/dist/tools/drive-agent.js +1184 -0
  128. package/dist/tools/lsp.d.ts +6 -0
  129. package/dist/tools/lsp.js +220 -0
  130. package/dist/tools/notebook-edit.d.ts +6 -0
  131. package/dist/tools/notebook-edit.js +127 -0
  132. package/dist/tools/worktree.d.ts +10 -0
  133. package/dist/tools/worktree.js +363 -0
  134. package/package.json +60 -0
@@ -0,0 +1,363 @@
1
+ /**
2
+ * EnterWorktree / ExitWorktree tools — switch a session between git workspaces.
3
+ */
4
+ import { existsSync } from "node:fs";
5
+ import { isAbsolute, resolve } from "node:path";
6
+ import { createWorktree, removeWorktree, listWorktrees, validateWorktreeSlug, selectPlatformScript, runWorktreeSetup, worktreeHasUncommittedOrAheadChanges, currentBranch, cleanupAbortedWorktree, } from "../git/worktree.js";
7
+ import { codingToolService } from "../capability-runtime.js";
8
+ export const switchSessionWorkspaceToolDef = {
9
+ name: "SwitchSessionWorkspace",
10
+ description: "Switch this current conversation session into or out of a workspace through the host UI path. " +
11
+ "Use this when you need isolated or parallel work in a git worktree, when you need to move " +
12
+ "this conversation to an existing worktree path/branch, or when you are done and should return " +
13
+ "this current conversation to main. This is the correct way to move THIS conversation's session " +
14
+ "into or out of a worktree on desktop.",
15
+ inputSchema: {
16
+ type: "object",
17
+ properties: {
18
+ target: {
19
+ type: "string",
20
+ description: "Workspace target: 'main', a new slug, an existing worktree path, or an existing branch name.",
21
+ },
22
+ },
23
+ required: ["target"],
24
+ },
25
+ };
26
+ export async function switchSessionWorkspaceTool(args, ctx) {
27
+ const target = stringArg(args.target);
28
+ if (!target)
29
+ return "Error: target is required";
30
+ const bridge = ctx?.workspace;
31
+ if (!bridge) {
32
+ return ("SwitchSessionWorkspace is not available in this host. " +
33
+ "Use the host's supported workspace controls instead.");
34
+ }
35
+ try {
36
+ const workspace = await bridge.switch(target);
37
+ ctx?.setSessionWorkspace?.(workspace);
38
+ const details = workspace.kind === "worktree" && workspace.worktree
39
+ ? `\n Branch: ${workspace.worktree.branch}`
40
+ : "";
41
+ return (`Switched session workspace:\n` +
42
+ ` Path: ${workspace.root}` +
43
+ details +
44
+ `\n\n` +
45
+ nextTurnNotice(workspace.root, ctx?.cwd ?? workspace.root));
46
+ }
47
+ catch (err) {
48
+ return `Error: switching workspace failed: ${err.message}`;
49
+ }
50
+ }
51
+ export const enterWorktreeToolDef = {
52
+ name: "EnterWorktree",
53
+ description: "Switch the current session workspace. Target can be a new worktree slug, " +
54
+ "an existing worktree path or branch, or 'main' to return to the main repository. " +
55
+ "Switching leaves the previous worktree on disk.",
56
+ inputSchema: {
57
+ type: "object",
58
+ properties: {
59
+ target: {
60
+ type: "string",
61
+ description: "Workspace target: 'main', a new slug (alphanumeric, dots, dashes, underscores), " +
62
+ "or an existing worktree path/branch to switch to.",
63
+ },
64
+ slug: {
65
+ type: "string",
66
+ description: "Deprecated alias for target. Prefer target.",
67
+ },
68
+ },
69
+ required: [],
70
+ },
71
+ };
72
+ export async function enterWorktreeTool(args, ctx) {
73
+ const target = stringArg(args.target) ?? stringArg(args.slug);
74
+ if (!target)
75
+ return "Error: target is required";
76
+ const resolved = sessionServices(ctx);
77
+ if (!resolved.ok)
78
+ return resolved.error;
79
+ const { sessionId, sessionManager } = resolved;
80
+ const mainRoot = sessionManager.readSessionMainRoot(sessionId) ?? ctx?.cwd ?? process.cwd();
81
+ const fromWorkspace = sessionManager.getSessionWorkspace(sessionId) ?? {
82
+ root: mainRoot,
83
+ kind: "main",
84
+ };
85
+ const fromRoot = fromWorkspace.root;
86
+ const currentTurnRoot = ctx?.cwd ?? fromRoot;
87
+ const branchPrefix = codingToolService(ctx)?.readWorktreeBranchPrefix(mainRoot);
88
+ try {
89
+ if (target === "main") {
90
+ ctx?.signal?.throwIfAborted();
91
+ const workspace = { root: mainRoot, kind: "main" };
92
+ persistSessionWorkspace(sessionManager, sessionId, workspace, ctx);
93
+ sessionManager.recordWorkspaceHandoff(sessionId, fromWorkspace, workspace);
94
+ return (`Switched to main workspace:\n` +
95
+ ` Path: ${mainRoot}\n` +
96
+ ` From: ${fromRoot}\n\n` +
97
+ nextTurnNotice(mainRoot, currentTurnRoot));
98
+ }
99
+ const selected = await resolveWorktreeTarget({
100
+ target,
101
+ cwd: ctx?.cwd ?? mainRoot,
102
+ mainRoot,
103
+ sessionId,
104
+ currentWorkspace: fromWorkspace,
105
+ branchPrefix,
106
+ signal: ctx?.signal,
107
+ });
108
+ if (ctx?.signal?.aborted) {
109
+ if (selected.created) {
110
+ await cleanupAbortedWorktree(mainRoot, selected.session.worktreePath, selected.session.worktreeBranch);
111
+ }
112
+ throw new Error("Worktree creation aborted");
113
+ }
114
+ const workspace = toSessionWorkspace(selected, fromWorkspace);
115
+ const setupNote = selected.created
116
+ ? await runSetupIfConfigured(selected.session.worktreePath, mainRoot, ctx)
117
+ : "";
118
+ if (ctx?.signal?.aborted) {
119
+ if (selected.created) {
120
+ await cleanupAbortedWorktree(mainRoot, selected.session.worktreePath, selected.session.worktreeBranch);
121
+ }
122
+ throw new Error("Worktree creation aborted");
123
+ }
124
+ persistSessionWorkspace(sessionManager, sessionId, workspace, ctx);
125
+ sessionManager.recordWorkspaceHandoff(sessionId, fromWorkspace, workspace);
126
+ const verb = selected.created ? "Worktree created and switched" : "Switched to worktree";
127
+ return (`${verb}:\n` +
128
+ ` Path: ${workspace.worktree.path}\n` +
129
+ ` Branch: ${workspace.worktree.branch}\n` +
130
+ ` From: ${selected.from}\n` +
131
+ ` Previous: ${fromRoot}\n\n` +
132
+ nextTurnNotice(workspace.root, currentTurnRoot) +
133
+ setupNote);
134
+ }
135
+ catch (err) {
136
+ return `Error: switching worktree failed: ${err.message}`;
137
+ }
138
+ }
139
+ /** Keep setup output from bloating the tool result — head+tail-ish trim. */
140
+ function truncate(s, max = 2000) {
141
+ return s.length <= max ? s : `${s.slice(0, max)}\n…(${s.length - max} more chars)`;
142
+ }
143
+ function persistSessionWorkspace(sessionManager, sessionId, workspace, ctx) {
144
+ const stateRevision = sessionManager.setSessionWorkspace(sessionId, workspace);
145
+ ctx?.setSessionWorkspace?.(workspace, stateRevision);
146
+ }
147
+ function nextTurnNotice(nextRoot, currentTurnRoot) {
148
+ return (`Workspace switched to ${nextRoot}. This takes effect on the next turn - ` +
149
+ `file/shell/sandbox tools in the CURRENT turn still target ${currentTurnRoot}.`);
150
+ }
151
+ export const exitWorktreeToolDef = {
152
+ name: "ExitWorktree",
153
+ description: "Switch the current session back to the main working directory. " +
154
+ "Choose whether to keep the worktree, detach it while preserving the branch, " +
155
+ "or discard it entirely.",
156
+ inputSchema: {
157
+ type: "object",
158
+ properties: {
159
+ action: {
160
+ type: "string",
161
+ enum: ["keep", "detach", "discard"],
162
+ description: "'keep' preserves the worktree directory and branch for later. " +
163
+ "'detach' removes the directory but keeps the branch. " +
164
+ "'discard' removes the directory and its branch entirely. " +
165
+ "If omitted, a clean worktree is detached automatically; a dirty worktree requires keep/discard.",
166
+ },
167
+ },
168
+ required: [],
169
+ },
170
+ };
171
+ export async function exitWorktreeTool(args, ctx) {
172
+ const resolved = sessionServices(ctx);
173
+ if (!resolved.ok)
174
+ return resolved.error;
175
+ const { sessionId, sessionManager } = resolved;
176
+ const workspace = sessionManager.getSessionWorkspace(sessionId);
177
+ if (!workspace || workspace.kind !== "worktree" || !workspace.worktree) {
178
+ return "Not currently in a worktree.";
179
+ }
180
+ const requested = args.action;
181
+ if (requested !== undefined &&
182
+ requested !== "keep" &&
183
+ requested !== "detach" &&
184
+ requested !== "discard") {
185
+ return `Error: unknown action "${requested}" (expected keep, detach, or discard).`;
186
+ }
187
+ const hasPendingChanges = existsSync(workspace.worktree.path) &&
188
+ (await worktreeHasUncommittedOrAheadChanges(workspace.worktree.path, workspace.worktree.baseRef));
189
+ const action = requested ?? (hasPendingChanges ? undefined : "detach");
190
+ if (!action) {
191
+ return (`Error: worktree has uncommitted changes or new commits. Choose action "keep" to preserve ` +
192
+ `the directory or "discard" to delete the worktree and branch.`);
193
+ }
194
+ if (action === "detach" && hasPendingChanges) {
195
+ return (`Error: detach would drop uncommitted changes or new commits. Choose action "keep" to preserve ` +
196
+ `the directory or "discard" to delete the worktree and branch.`);
197
+ }
198
+ const mainRoot = sessionManager.readSessionMainRoot(sessionId) ?? workspace.root;
199
+ const currentTurnRoot = ctx?.cwd ?? workspace.root;
200
+ const branchPrefix = codingToolService(ctx)?.readWorktreeBranchPrefix(mainRoot);
201
+ try {
202
+ let removal;
203
+ if (action === "discard" || action === "detach") {
204
+ const otherOwners = await otherSessionOwnersForWorktree(sessionManager, sessionId, mainRoot, workspace.worktree.path);
205
+ if (otherOwners.length > 0) {
206
+ const mainWorkspace = { root: mainRoot, kind: "main" };
207
+ persistSessionWorkspace(sessionManager, sessionId, mainWorkspace, ctx);
208
+ sessionManager.recordWorkspaceHandoff(sessionId, workspace, mainWorkspace);
209
+ return sharedWorktreeRemovalSkippedMessage(otherOwners, mainRoot, currentTurnRoot);
210
+ }
211
+ }
212
+ if (action === "discard") {
213
+ removal = removeWorktree(workspace.worktree.path, true, { prefix: branchPrefix });
214
+ }
215
+ else if (action === "detach") {
216
+ removal = removeWorktree(workspace.worktree.path, false);
217
+ }
218
+ const mainWorkspace = { root: mainRoot, kind: "main" };
219
+ persistSessionWorkspace(sessionManager, sessionId, mainWorkspace, ctx);
220
+ sessionManager.recordWorkspaceHandoff(sessionId, workspace, mainWorkspace);
221
+ if (action === "keep") {
222
+ return (`Worktree preserved at ${workspace.worktree.path}. ` +
223
+ `Branch ${workspace.worktree.branch} preserved.\n` +
224
+ `Back to ${mainRoot} starting next turn.\n` +
225
+ nextTurnNotice(mainRoot, currentTurnRoot));
226
+ }
227
+ if (action === "discard") {
228
+ if (removal?.branchDeleted === false) {
229
+ const branch = removal.branch ?? workspace.worktree.branch;
230
+ return (`WARNING: worktree removed; branch ${branch} could not be deleted: ` +
231
+ `${removal.branchError ?? "unknown error"}\n` +
232
+ `Delete it manually with git branch -D ${branch}.\n` +
233
+ `Back to ${mainRoot} starting next turn.\n` +
234
+ nextTurnNotice(mainRoot, currentTurnRoot));
235
+ }
236
+ return (`Worktree removed and branch ${workspace.worktree.branch} deleted. ` +
237
+ `Back to ${mainRoot} starting next turn.\n` +
238
+ nextTurnNotice(mainRoot, currentTurnRoot));
239
+ }
240
+ return (`Worktree removed${requested ? "" : " (auto-detached clean worktree)"}. ` +
241
+ `Branch ${workspace.worktree.branch} preserved.\n` +
242
+ `To merge: git merge ${workspace.worktree.branch}\n` +
243
+ `Back to ${mainRoot} starting next turn.\n` +
244
+ nextTurnNotice(mainRoot, currentTurnRoot));
245
+ }
246
+ catch (err) {
247
+ return `Error: exiting worktree failed: ${err.message}`;
248
+ }
249
+ }
250
+ function sessionServices(ctx) {
251
+ const sessionId = ctx?.sessionId;
252
+ if (!sessionId)
253
+ return { ok: false, error: "Error: worktree tools require a sessionId." };
254
+ const sessionManager = codingToolService(ctx)?.getSessionManager();
255
+ if (!sessionManager) {
256
+ return { ok: false, error: "Error: worktree tools require a session manager." };
257
+ }
258
+ return { ok: true, sessionId, sessionManager };
259
+ }
260
+ async function otherSessionOwnersForWorktree(sessionManager, sessionId, mainRoot, worktreePath) {
261
+ const workspaceOwners = sessionManager
262
+ .list(Number.MAX_SAFE_INTEGER)
263
+ .map((session) => ({ sessionId: session.sessionId, workspace: session.workspace }))
264
+ .filter((owner) => owner.workspace !== undefined);
265
+ const entry = (await listWorktrees(mainRoot, {
266
+ currentSessionId: sessionId,
267
+ workspaceOwners,
268
+ })).find((worktree) => resolve(worktree.path) === resolve(worktreePath));
269
+ return (entry?.occupiedBySessionIds ?? []).filter((owner) => owner !== sessionId);
270
+ }
271
+ function sharedWorktreeRemovalSkippedMessage(otherOwners, mainRoot, currentTurnRoot) {
272
+ return (`Error: this worktree is also in use by session(s) ${otherOwners.join(", ")}; ` +
273
+ `switching to main, but removal has been skipped.\n` +
274
+ `Back to ${mainRoot} starting next turn.\n` +
275
+ nextTurnNotice(mainRoot, currentTurnRoot));
276
+ }
277
+ async function resolveWorktreeTarget(opts) {
278
+ const entries = await listWorktrees(opts.mainRoot);
279
+ opts.signal?.throwIfAborted();
280
+ const pathTarget = pathLike(opts.target) ? resolvePathTarget(opts.target, opts.cwd) : undefined;
281
+ const branchTarget = normalizeBranchName(opts.target);
282
+ const match = entries.find((entry) => {
283
+ if (pathTarget && resolve(entry.path) === pathTarget)
284
+ return true;
285
+ return entry.branch === branchTarget;
286
+ });
287
+ if (match) {
288
+ const originalBranch = await currentBranch(opts.mainRoot);
289
+ opts.signal?.throwIfAborted();
290
+ return {
291
+ created: false,
292
+ session: {
293
+ originalCwd: opts.mainRoot,
294
+ worktreePath: match.path,
295
+ worktreeName: match.path.split(/[\\/]/).pop() ?? match.branch,
296
+ worktreeBranch: match.branch,
297
+ originalBranch,
298
+ sessionId: opts.sessionId,
299
+ createdAt: Date.now(),
300
+ },
301
+ from: opts.currentWorkspace.root,
302
+ };
303
+ }
304
+ if (pathTarget) {
305
+ throw new Error(`no existing worktree found at ${opts.target}`);
306
+ }
307
+ validateWorktreeSlug(opts.target);
308
+ const created = await createWorktree(opts.mainRoot, opts.target, opts.sessionId, {
309
+ prefix: opts.branchPrefix,
310
+ signal: opts.signal,
311
+ });
312
+ return { created: true, session: created, from: created.originalBranch ?? "HEAD" };
313
+ }
314
+ function toSessionWorkspace(selected, currentWorkspace) {
315
+ const previous = currentWorkspace.kind === "worktree" &&
316
+ currentWorkspace.worktree &&
317
+ resolve(currentWorkspace.worktree.path) === resolve(selected.session.worktreePath)
318
+ ? currentWorkspace.worktree
319
+ : undefined;
320
+ return {
321
+ root: selected.session.worktreePath,
322
+ kind: "worktree",
323
+ worktree: {
324
+ path: selected.session.worktreePath,
325
+ branch: selected.session.worktreeBranch,
326
+ baseRef: previous?.baseRef ?? selected.session.originalBranch ?? "HEAD",
327
+ createdBy: "codeshell",
328
+ },
329
+ };
330
+ }
331
+ async function runSetupIfConfigured(worktreePath, mainRoot, ctx) {
332
+ const services = codingToolService(ctx);
333
+ const setupScripts = services?.readWorktreeSetupScripts(mainRoot);
334
+ const script = selectPlatformScript(setupScripts);
335
+ if (!script)
336
+ return "";
337
+ const setupSandbox = services
338
+ ? await services.resolveWorktreeSetupSandbox(worktreePath)
339
+ : ctx?.sandbox;
340
+ const setupShellEnv = services?.readWorktreeSetupShellEnv(worktreePath) ?? ctx?.shellEnv;
341
+ const setup = await runWorktreeSetup(worktreePath, script, {
342
+ sandbox: setupSandbox,
343
+ shellEnv: setupShellEnv,
344
+ signal: ctx?.signal,
345
+ });
346
+ if (setup.ok) {
347
+ return `\n\nRan setup script (exit 0).${setup.output ? `\n${truncate(setup.output)}` : ""}`;
348
+ }
349
+ return (`\n\n⚠️ Setup script failed (exit ${setup.exitCode ?? "?"}) — continuing anyway. ` +
350
+ `You may need to run setup manually.${setup.output ? `\n${truncate(setup.output)}` : ""}`);
351
+ }
352
+ function stringArg(value) {
353
+ return typeof value === "string" && value.length > 0 ? value : undefined;
354
+ }
355
+ function pathLike(target) {
356
+ return (isAbsolute(target) || target.startsWith(".") || target.includes("/") || target.includes("\\"));
357
+ }
358
+ function resolvePathTarget(target, cwd) {
359
+ return resolve(cwd, target);
360
+ }
361
+ function normalizeBranchName(branch) {
362
+ return branch.replace(/^refs\/heads\//, "");
363
+ }
package/package.json ADDED
@@ -0,0 +1,60 @@
1
+ {
2
+ "name": "@cjhyy/code-shell-capability-coding",
3
+ "version": "0.8.0",
4
+ "description": "Coding capability pack for the generic code-shell agent core.",
5
+ "type": "module",
6
+ "main": "./dist/index.js",
7
+ "types": "./dist/index.d.ts",
8
+ "exports": {
9
+ ".": {
10
+ "types": "./dist/index.d.ts",
11
+ "import": "./dist/index.js"
12
+ },
13
+ "./capability": {
14
+ "types": "./dist/index.capability.d.ts",
15
+ "import": "./dist/index.capability.js"
16
+ },
17
+ "./git": {
18
+ "types": "./dist/index.git.d.ts",
19
+ "import": "./dist/index.git.js"
20
+ },
21
+ "./orchestration": {
22
+ "types": "./dist/index.orchestration.d.ts",
23
+ "import": "./dist/index.orchestration.js"
24
+ },
25
+ "./bin/agent-server-stdio": "./dist/bin/agent-server-stdio.js",
26
+ "./external-runtimes": {
27
+ "types": "./dist/external-runtimes/index.d.ts",
28
+ "import": "./dist/external-runtimes/index.js"
29
+ }
30
+ },
31
+ "files": [
32
+ "dist",
33
+ "THIRD_PARTY_NOTICES.md"
34
+ ],
35
+ "scripts": {
36
+ "build": "bun run clean && tsc -p tsconfig.json && bun run copy-assets",
37
+ "copy-assets": "node ../../scripts/copy-assets.mjs dist/prompt src/prompt/*.md && node ../../scripts/copy-assets.mjs dist/tools/apply-patch src/tools/apply-patch/NOTICE.md src/tools/apply-patch/LICENSE-codex",
38
+ "dev": "bun run copy-assets && tsc -p tsconfig.json --watch --preserveWatchOutput",
39
+ "clean": "node -e \"require('node:fs').rmSync('dist',{recursive:true,force:true})\""
40
+ },
41
+ "dependencies": {
42
+ "@cjhyy/code-shell-core": "0.8.0"
43
+ },
44
+ "engines": {
45
+ "node": ">=20.10"
46
+ },
47
+ "repository": {
48
+ "type": "git",
49
+ "url": "git+https://github.com/cjhyy/codeshell.git",
50
+ "directory": "packages/coding"
51
+ },
52
+ "homepage": "https://github.com/cjhyy/codeshell/tree/main/packages/coding#readme",
53
+ "bugs": {
54
+ "url": "https://github.com/cjhyy/codeshell/issues"
55
+ },
56
+ "license": "MIT",
57
+ "publishConfig": {
58
+ "access": "public"
59
+ }
60
+ }