@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.
- package/README.md +69 -0
- package/THIRD_PARTY_NOTICES.md +206 -0
- package/dist/bin/agent-server-stdio.d.ts +1 -0
- package/dist/bin/agent-server-stdio.js +4 -0
- package/dist/capability-runtime.d.ts +22 -0
- package/dist/capability-runtime.js +88 -0
- package/dist/cc-orchestrator/agent-adapter.d.ts +55 -0
- package/dist/cc-orchestrator/agent-adapter.js +143 -0
- package/dist/cc-orchestrator/cc-capability.d.ts +20 -0
- package/dist/cc-orchestrator/cc-capability.js +57 -0
- package/dist/cc-orchestrator/codex-session-discovery.d.ts +45 -0
- package/dist/cc-orchestrator/codex-session-discovery.js +251 -0
- package/dist/cc-orchestrator/codex-session-history.d.ts +39 -0
- package/dist/cc-orchestrator/codex-session-history.js +249 -0
- package/dist/cc-orchestrator/codex-user-text.d.ts +9 -0
- package/dist/cc-orchestrator/codex-user-text.js +25 -0
- package/dist/cc-orchestrator/external-agent-bindings.d.ts +27 -0
- package/dist/cc-orchestrator/external-agent-bindings.js +150 -0
- package/dist/cc-orchestrator/external-agent-changes.d.ts +19 -0
- package/dist/cc-orchestrator/external-agent-changes.js +231 -0
- package/dist/cc-orchestrator/external-agent-driver.d.ts +19 -0
- package/dist/cc-orchestrator/external-agent-driver.js +284 -0
- package/dist/cc-orchestrator/external-agent-session-store.d.ts +36 -0
- package/dist/cc-orchestrator/external-agent-session-store.js +185 -0
- package/dist/cc-orchestrator/index.d.ts +10 -0
- package/dist/cc-orchestrator/index.js +10 -0
- package/dist/cc-orchestrator/related-session-discovery.d.ts +21 -0
- package/dist/cc-orchestrator/related-session-discovery.js +77 -0
- package/dist/cc-orchestrator/relevance-judge.d.ts +16 -0
- package/dist/cc-orchestrator/relevance-judge.js +38 -0
- package/dist/cc-orchestrator/session-discovery.d.ts +99 -0
- package/dist/cc-orchestrator/session-discovery.js +295 -0
- package/dist/cc-orchestrator/session-history.d.ts +55 -0
- package/dist/cc-orchestrator/session-history.js +150 -0
- package/dist/external-agents/config.d.ts +3 -0
- package/dist/external-agents/config.js +16 -0
- package/dist/external-agents/types.d.ts +32 -0
- package/dist/external-agents/types.js +1 -0
- package/dist/external-runtimes/claude-code/event-translator.d.ts +54 -0
- package/dist/external-runtimes/claude-code/event-translator.js +201 -0
- package/dist/external-runtimes/claude-code/mcp-config.d.ts +84 -0
- package/dist/external-runtimes/claude-code/mcp-config.js +175 -0
- package/dist/external-runtimes/claude-code/runtime.d.ts +56 -0
- package/dist/external-runtimes/claude-code/runtime.js +168 -0
- package/dist/external-runtimes/codex/app-server-client.d.ts +66 -0
- package/dist/external-runtimes/codex/app-server-client.js +244 -0
- package/dist/external-runtimes/codex/event-translator.d.ts +68 -0
- package/dist/external-runtimes/codex/event-translator.js +187 -0
- package/dist/external-runtimes/codex/index.d.ts +7 -0
- package/dist/external-runtimes/codex/index.js +6 -0
- package/dist/external-runtimes/codex/runtime.d.ts +128 -0
- package/dist/external-runtimes/codex/runtime.js +216 -0
- package/dist/external-runtimes/index.d.ts +37 -0
- package/dist/external-runtimes/index.js +27 -0
- package/dist/external-runtimes/session-factory.d.ts +97 -0
- package/dist/external-runtimes/session-factory.js +110 -0
- package/dist/external-runtimes/shared/mcp-bridge.d.ts +66 -0
- package/dist/external-runtimes/shared/mcp-bridge.js +365 -0
- package/dist/external-runtimes/shared/session-context-store.d.ts +83 -0
- package/dist/external-runtimes/shared/session-context-store.js +114 -0
- package/dist/external-runtimes/shared/spawn-env.d.ts +30 -0
- package/dist/external-runtimes/shared/spawn-env.js +41 -0
- package/dist/git/parse-log.d.ts +14 -0
- package/dist/git/parse-log.js +21 -0
- package/dist/git/utils.d.ts +49 -0
- package/dist/git/utils.js +161 -0
- package/dist/git/worktree/crud.d.ts +108 -0
- package/dist/git/worktree/crud.js +415 -0
- package/dist/git/worktree/diff.d.ts +14 -0
- package/dist/git/worktree/diff.js +83 -0
- package/dist/git/worktree/git-exec.d.ts +7 -0
- package/dist/git/worktree/git-exec.js +86 -0
- package/dist/git/worktree/index.d.ts +6 -0
- package/dist/git/worktree/index.js +6 -0
- package/dist/git/worktree/query.d.ts +43 -0
- package/dist/git/worktree/query.js +128 -0
- package/dist/git/worktree/slug.d.ts +12 -0
- package/dist/git/worktree/slug.js +59 -0
- package/dist/git/worktree.d.ts +1 -0
- package/dist/git/worktree.js +5 -0
- package/dist/index.capability.d.ts +7 -0
- package/dist/index.capability.js +190 -0
- package/dist/index.d.ts +18 -0
- package/dist/index.git.d.ts +4 -0
- package/dist/index.git.js +4 -0
- package/dist/index.js +18 -0
- package/dist/index.orchestration.d.ts +7 -0
- package/dist/index.orchestration.js +5 -0
- package/dist/lsp/client.d.ts +41 -0
- package/dist/lsp/client.js +192 -0
- package/dist/lsp/manager.d.ts +53 -0
- package/dist/lsp/manager.js +248 -0
- package/dist/lsp/root-path.d.ts +9 -0
- package/dist/lsp/root-path.js +12 -0
- package/dist/lsp/servers.d.ts +16 -0
- package/dist/lsp/servers.js +60 -0
- package/dist/prompt/coding.md +42 -0
- package/dist/quota/credentials.d.ts +3 -0
- package/dist/quota/credentials.js +80 -0
- package/dist/quota/index.d.ts +36 -0
- package/dist/quota/index.js +161 -0
- package/dist/quota/types.d.ts +48 -0
- package/dist/quota/types.js +13 -0
- package/dist/review/review-prompt.d.ts +28 -0
- package/dist/review/review-prompt.js +81 -0
- package/dist/tools/apply-patch/LICENSE-codex +201 -0
- package/dist/tools/apply-patch/NOTICE.md +29 -0
- package/dist/tools/apply-patch/applier.d.ts +26 -0
- package/dist/tools/apply-patch/applier.js +306 -0
- package/dist/tools/apply-patch/backup-targets.d.ts +10 -0
- package/dist/tools/apply-patch/backup-targets.js +30 -0
- package/dist/tools/apply-patch/eol.d.ts +4 -0
- package/dist/tools/apply-patch/eol.js +9 -0
- package/dist/tools/apply-patch/index.d.ts +20 -0
- package/dist/tools/apply-patch/index.js +106 -0
- package/dist/tools/apply-patch/parser.d.ts +17 -0
- package/dist/tools/apply-patch/parser.js +209 -0
- package/dist/tools/apply-patch/seek-sequence.d.ts +18 -0
- package/dist/tools/apply-patch/seek-sequence.js +123 -0
- package/dist/tools/apply-patch/types.d.ts +49 -0
- package/dist/tools/apply-patch/types.js +13 -0
- package/dist/tools/brief.d.ts +6 -0
- package/dist/tools/brief.js +41 -0
- package/dist/tools/check-quota.d.ts +14 -0
- package/dist/tools/check-quota.js +38 -0
- package/dist/tools/drive-agent.d.ts +52 -0
- package/dist/tools/drive-agent.js +1184 -0
- package/dist/tools/lsp.d.ts +6 -0
- package/dist/tools/lsp.js +220 -0
- package/dist/tools/notebook-edit.d.ts +6 -0
- package/dist/tools/notebook-edit.js +127 -0
- package/dist/tools/worktree.d.ts +10 -0
- package/dist/tools/worktree.js +363 -0
- package/package.json +60 -0
package/README.md
ADDED
|
@@ -0,0 +1,69 @@
|
|
|
1
|
+
# @cjhyy/code-shell-capability-coding
|
|
2
|
+
|
|
3
|
+
Optional coding capability pack for `@cjhyy/code-shell-core`. It owns
|
|
4
|
+
CodeShell's coding policy and implementations: the `terminal-coding` preset,
|
|
5
|
+
coding prompt, Git/worktree behavior, LSP, ApplyPatch, NotebookEdit, Brief,
|
|
6
|
+
review/quota helpers, and external coding-agent adapters.
|
|
7
|
+
|
|
8
|
+
The package is deliberately separate from core. A service building a customer
|
|
9
|
+
support, data, or media agent can install core without pulling a coding preset
|
|
10
|
+
into its default runtime. The TUI and Desktop applications install this pack at
|
|
11
|
+
their composition roots.
|
|
12
|
+
|
|
13
|
+
## Use with core
|
|
14
|
+
|
|
15
|
+
```ts
|
|
16
|
+
import { Engine } from "@cjhyy/code-shell-core";
|
|
17
|
+
import { CODING_CAPABILITY } from "@cjhyy/code-shell-capability-coding/capability";
|
|
18
|
+
|
|
19
|
+
const engine = new Engine({
|
|
20
|
+
llm: {
|
|
21
|
+
provider: "anthropic",
|
|
22
|
+
model: "claude-sonnet-4-6",
|
|
23
|
+
apiKey: process.env.ANTHROPIC_API_KEY!,
|
|
24
|
+
},
|
|
25
|
+
capabilities: [CODING_CAPABILITY],
|
|
26
|
+
});
|
|
27
|
+
|
|
28
|
+
// No preset is required: this capability contributes terminal-coding as its
|
|
29
|
+
// product default. Passing preset: "general" remains supported.
|
|
30
|
+
const result = await engine.run("Inspect this repository and fix the failing test.");
|
|
31
|
+
console.log(result.text);
|
|
32
|
+
```
|
|
33
|
+
|
|
34
|
+
For a process composition root, `registerCapability(CODING_CAPABILITY)` installs
|
|
35
|
+
the same pack for subsequently created Engines and RunManagers. Prefer the
|
|
36
|
+
per-Engine `capabilities` field in reusable libraries and tests.
|
|
37
|
+
|
|
38
|
+
## Focused entry points
|
|
39
|
+
|
|
40
|
+
The package root remains compatible with existing consumers. New hosts should
|
|
41
|
+
prefer the smallest stable entry that matches their responsibility:
|
|
42
|
+
|
|
43
|
+
| Entry | Responsibility |
|
|
44
|
+
| ---------------- | ----------------------------------------------------------------------------------- |
|
|
45
|
+
| `/capability` | `CODING_CAPABILITY`, contributed tools, and coding presets |
|
|
46
|
+
| `/git` | Git, worktree, project-root, and review-prompt helpers |
|
|
47
|
+
| `/orchestration` | Claude Code/Codex discovery, transcripts, drivers, quota, and external-agent config |
|
|
48
|
+
|
|
49
|
+
```ts
|
|
50
|
+
import { createWorktree, resolveProjectRoot } from "@cjhyy/code-shell-capability-coding/git";
|
|
51
|
+
import { probeClaudeCli } from "@cjhyy/code-shell-capability-coding/orchestration";
|
|
52
|
+
```
|
|
53
|
+
|
|
54
|
+
These are subpaths of the same npm package, not independently versioned
|
|
55
|
+
packages. LSP, ApplyPatch, Brief, NotebookEdit, and other compatibility exports
|
|
56
|
+
remain available from the root.
|
|
57
|
+
|
|
58
|
+
## Boundary
|
|
59
|
+
|
|
60
|
+
- Core owns lifecycle contracts and calls generic capability hooks.
|
|
61
|
+
- This package owns repository context, instruction boundary detection,
|
|
62
|
+
worktree-specific tool services, and coding artifact detectors.
|
|
63
|
+
- Desktop owns the Electron host, renderer panels, protocol bridge, and app
|
|
64
|
+
packaging. The Desktop worker uses this package's agent-server wrapper.
|
|
65
|
+
|
|
66
|
+
## License
|
|
67
|
+
|
|
68
|
+
MIT. ApplyPatch carries its upstream Apache-2.0 notice in
|
|
69
|
+
`src/tools/apply-patch/NOTICE.md` and `LICENSE-codex`.
|
|
@@ -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/tools/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
|
+
```
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
import type { CapabilityArtifactDetector, CapabilityDynamicContextProvider, CapabilityToolServiceHost, SessionManager, ToolContext } from "@cjhyy/code-shell-core/extension";
|
|
2
|
+
export declare const CODING_CAPABILITY_ID = "coding";
|
|
3
|
+
type SetupScripts = {
|
|
4
|
+
default?: string;
|
|
5
|
+
macos?: string;
|
|
6
|
+
linux?: string;
|
|
7
|
+
windows?: string;
|
|
8
|
+
};
|
|
9
|
+
export interface CodingToolService {
|
|
10
|
+
getSessionManager(): SessionManager;
|
|
11
|
+
readWorktreeSetupScripts(cwd?: string): SetupScripts | undefined;
|
|
12
|
+
readWorktreeBranchPrefix(cwd?: string): string | undefined;
|
|
13
|
+
resolveWorktreeSetupSandbox: CapabilityToolServiceHost["resolveSandbox"];
|
|
14
|
+
readWorktreeSetupShellEnv: CapabilityToolServiceHost["readShellEnv"];
|
|
15
|
+
}
|
|
16
|
+
export declare function createCodingToolService(host: CapabilityToolServiceHost): CodingToolService;
|
|
17
|
+
export declare function codingToolService(ctx?: ToolContext): CodingToolService | undefined;
|
|
18
|
+
/** Pure-filesystem repository boundary: supports both .git directories and worktree files. */
|
|
19
|
+
export declare function findCodingInstructionBoundary(cwd: string): string | null;
|
|
20
|
+
export declare const gitDynamicContextProvider: CapabilityDynamicContextProvider;
|
|
21
|
+
export declare const codingArtifactDetector: CapabilityArtifactDetector;
|
|
22
|
+
export {};
|
|
@@ -0,0 +1,88 @@
|
|
|
1
|
+
import { existsSync } from "node:fs";
|
|
2
|
+
import { dirname, join, resolve } from "node:path";
|
|
3
|
+
import { getCurrentBranch, getGitLog, getGitStatus } from "./git/utils.js";
|
|
4
|
+
export const CODING_CAPABILITY_ID = "coding";
|
|
5
|
+
export function createCodingToolService(host) {
|
|
6
|
+
return {
|
|
7
|
+
getSessionManager: host.getSessionManager,
|
|
8
|
+
readWorktreeSetupScripts(cwd) {
|
|
9
|
+
if (host.isSubAgent || !cwd)
|
|
10
|
+
return undefined;
|
|
11
|
+
try {
|
|
12
|
+
const scoped = host.settings.getForScope("project", cwd);
|
|
13
|
+
return scoped.localEnvironment?.setupScripts;
|
|
14
|
+
}
|
|
15
|
+
catch {
|
|
16
|
+
return undefined;
|
|
17
|
+
}
|
|
18
|
+
},
|
|
19
|
+
readWorktreeBranchPrefix(cwd) {
|
|
20
|
+
if (host.isSubAgent || !cwd)
|
|
21
|
+
return undefined;
|
|
22
|
+
try {
|
|
23
|
+
return host.settings.get().worktree
|
|
24
|
+
?.branchPrefix;
|
|
25
|
+
}
|
|
26
|
+
catch {
|
|
27
|
+
return undefined;
|
|
28
|
+
}
|
|
29
|
+
},
|
|
30
|
+
resolveWorktreeSetupSandbox: host.resolveSandbox,
|
|
31
|
+
readWorktreeSetupShellEnv: host.readShellEnv,
|
|
32
|
+
};
|
|
33
|
+
}
|
|
34
|
+
export function codingToolService(ctx) {
|
|
35
|
+
return ctx?.capabilityServices?.[CODING_CAPABILITY_ID];
|
|
36
|
+
}
|
|
37
|
+
/** Pure-filesystem repository boundary: supports both .git directories and worktree files. */
|
|
38
|
+
export function findCodingInstructionBoundary(cwd) {
|
|
39
|
+
let current = resolve(cwd);
|
|
40
|
+
while (true) {
|
|
41
|
+
if (existsSync(join(current, ".git")))
|
|
42
|
+
return current;
|
|
43
|
+
const parent = dirname(current);
|
|
44
|
+
if (parent === current)
|
|
45
|
+
return null;
|
|
46
|
+
current = parent;
|
|
47
|
+
}
|
|
48
|
+
}
|
|
49
|
+
export const gitDynamicContextProvider = ({ cwd, preset }) => {
|
|
50
|
+
if (preset.name !== "terminal-coding")
|
|
51
|
+
return undefined;
|
|
52
|
+
const branch = getCurrentBranch(cwd);
|
|
53
|
+
if (!branch)
|
|
54
|
+
return undefined;
|
|
55
|
+
const status = getGitStatus(cwd);
|
|
56
|
+
const log = getGitLog(cwd, 5);
|
|
57
|
+
const parts = [`gitStatus: Current branch: ${branch}`];
|
|
58
|
+
if (status.length > 0) {
|
|
59
|
+
parts.push(`Status:\n${status.map((entry) => `${entry.status} ${entry.path}`).join("\n")}`);
|
|
60
|
+
}
|
|
61
|
+
if (log.length > 0) {
|
|
62
|
+
parts.push(`Recent commits:\n${log.map((entry) => `${entry.hash} ${entry.message}`).join("\n")}`);
|
|
63
|
+
}
|
|
64
|
+
return parts.join("\n\n");
|
|
65
|
+
};
|
|
66
|
+
export const codingArtifactDetector = ({ toolName, args }) => {
|
|
67
|
+
if (toolName === "NotebookEdit" && typeof args.file_path === "string") {
|
|
68
|
+
return {
|
|
69
|
+
kind: "document",
|
|
70
|
+
role: "output",
|
|
71
|
+
title: args.file_path.split(/[\\/]/).pop() || args.file_path,
|
|
72
|
+
locator: args.file_path,
|
|
73
|
+
};
|
|
74
|
+
}
|
|
75
|
+
if (toolName === "Bash" && typeof args.command === "string") {
|
|
76
|
+
const command = args.command.trim();
|
|
77
|
+
if (/^git\s+commit\b/.test(command)) {
|
|
78
|
+
return {
|
|
79
|
+
kind: "resource",
|
|
80
|
+
role: "output",
|
|
81
|
+
title: "git commit",
|
|
82
|
+
locator: "git:HEAD",
|
|
83
|
+
metadata: { command: command.slice(0, 200) },
|
|
84
|
+
};
|
|
85
|
+
}
|
|
86
|
+
}
|
|
87
|
+
return undefined;
|
|
88
|
+
};
|
|
@@ -0,0 +1,55 @@
|
|
|
1
|
+
/** Permission modes understood by external coding CLIs. */
|
|
2
|
+
export type PermissionMode = "default" | "acceptEdits" | "bypassPermissions";
|
|
3
|
+
export interface BuildArgsOpts {
|
|
4
|
+
prompt: string;
|
|
5
|
+
resumeSessionId?: string;
|
|
6
|
+
/** Optional caller-specified model override. Passed through without validation; the CLI reports unknown models. */
|
|
7
|
+
model?: string;
|
|
8
|
+
permissionMode: PermissionMode;
|
|
9
|
+
cwd: string;
|
|
10
|
+
imagePaths?: string[];
|
|
11
|
+
codexImageInputSupported?: boolean;
|
|
12
|
+
}
|
|
13
|
+
export interface ParsedResult {
|
|
14
|
+
sessionId: string;
|
|
15
|
+
finalText: string;
|
|
16
|
+
isError: boolean;
|
|
17
|
+
}
|
|
18
|
+
export interface AgentAdapter {
|
|
19
|
+
/** Display name, e.g. "claude" / "codex". */
|
|
20
|
+
kind: string;
|
|
21
|
+
/** Build the CLI argv (command itself excluded). */
|
|
22
|
+
buildArgs(opts: BuildArgsOpts): string[];
|
|
23
|
+
/** Reduce collected stream-json output lines to {sessionId, finalText, isError}. */
|
|
24
|
+
parseResult(lines: string[]): ParsedResult;
|
|
25
|
+
/**
|
|
26
|
+
* When true, the prompt is fed over stdin instead of being passed in argv.
|
|
27
|
+
* claude takes the prompt as `-p <prompt>` (argv) so leaves this unset; codex
|
|
28
|
+
* `exec` reads the prompt from stdin (its argv ends with a bare `-`).
|
|
29
|
+
*/
|
|
30
|
+
promptViaStdin?: boolean;
|
|
31
|
+
}
|
|
32
|
+
/**
|
|
33
|
+
* Soft cost-guard appended to a driven CC's system prompt. Workflow fans out a
|
|
34
|
+
* fleet of agents and is the main token sink; we ask CC to surface intent and
|
|
35
|
+
* get a go-ahead before running one, so a human can intervene (rooms) and the
|
|
36
|
+
* model stays cost-aware even where Workflow isn't hard-disabled. Shared so the
|
|
37
|
+
* room's resident process can reuse the exact same wording.
|
|
38
|
+
*/
|
|
39
|
+
export declare const CC_COST_GUARD_PROMPT: string;
|
|
40
|
+
export declare const claudeAdapter: AgentAdapter;
|
|
41
|
+
/**
|
|
42
|
+
* Drives the OpenAI Codex CLI via `codex exec`. Mirrors claudeAdapter but for
|
|
43
|
+
* codex's different surface:
|
|
44
|
+
* - prompt is fed over STDIN (argv ends with a bare `-`), not argv → promptViaStdin
|
|
45
|
+
* - permission is a spawn-time SANDBOX choice, not a per-tool approval loop:
|
|
46
|
+
* default → --sandbox read-only (codex can read, not write)
|
|
47
|
+
* acceptEdits → --sandbox workspace-write (codex can write the workspace)
|
|
48
|
+
* bypassPermissions → --dangerously-bypass-approvals-and-sandbox (full auto)
|
|
49
|
+
* (Matches the only model codex supports — same choice the `wand` tool makes;
|
|
50
|
+
* codex has no `--permission-prompt-tool stdio` equivalent.)
|
|
51
|
+
* - JSONL event shape differs: session id is `thread.started`.thread_id, the
|
|
52
|
+
* final answer is the last `item.completed` of item.type "agent_message", and
|
|
53
|
+
* failure is `turn.failed` / `error` events (no `is_error` flag).
|
|
54
|
+
*/
|
|
55
|
+
export declare const codexAdapter: AgentAdapter;
|
|
@@ -0,0 +1,143 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Soft cost-guard appended to a driven CC's system prompt. Workflow fans out a
|
|
3
|
+
* fleet of agents and is the main token sink; we ask CC to surface intent and
|
|
4
|
+
* get a go-ahead before running one, so a human can intervene (rooms) and the
|
|
5
|
+
* model stays cost-aware even where Workflow isn't hard-disabled. Shared so the
|
|
6
|
+
* room's resident process can reuse the exact same wording.
|
|
7
|
+
*/
|
|
8
|
+
export const CC_COST_GUARD_PROMPT = "Cost guard: before invoking the Workflow tool (which fans out many agents and " +
|
|
9
|
+
"burns a lot of tokens), first state in one short message what workflow you intend " +
|
|
10
|
+
"to run and why, and ask for a go-ahead — do NOT launch a Workflow unprompted. A " +
|
|
11
|
+
"single Task sub-agent is fine without asking.";
|
|
12
|
+
export const claudeAdapter = {
|
|
13
|
+
kind: "claude",
|
|
14
|
+
buildArgs(opts) {
|
|
15
|
+
// -p (print/headless) + stream-json REQUIRES --verbose (verified).
|
|
16
|
+
const args = ["-p", opts.prompt, "--output-format", "stream-json", "--verbose"];
|
|
17
|
+
if (opts.model)
|
|
18
|
+
args.push("--model", opts.model);
|
|
19
|
+
if (opts.resumeSessionId)
|
|
20
|
+
args.push("--resume", opts.resumeSessionId);
|
|
21
|
+
// Hard-disallow Workflow: driving CC unattended (esp. bypassPermissions),
|
|
22
|
+
// CC's Workflow tool fans out a FLEET of agents — the real token-burn culprit
|
|
23
|
+
// (user: "自动了 2 个 workflow token 就烧没了"). A single Task (one sub-agent)
|
|
24
|
+
// is cheap, so it stays ALLOWED. (We earlier disallowed Task by mistake;
|
|
25
|
+
// Workflow is the one that fans out.) Disabling outright is cleaner than an
|
|
26
|
+
// approval round-trip this path doesn't have.
|
|
27
|
+
args.push("--disallowedTools", "Workflow");
|
|
28
|
+
// Soft constraint (belt-and-suspenders + carries to rooms where Workflow is
|
|
29
|
+
// allowed): ask CC to check in before expensive multi-agent work.
|
|
30
|
+
args.push("--append-system-prompt", CC_COST_GUARD_PROMPT);
|
|
31
|
+
args.push("--permission-mode", opts.permissionMode);
|
|
32
|
+
return args;
|
|
33
|
+
},
|
|
34
|
+
parseResult(lines) {
|
|
35
|
+
let sessionId = "";
|
|
36
|
+
let finalText = "";
|
|
37
|
+
let isError = false;
|
|
38
|
+
for (const line of lines) {
|
|
39
|
+
const t = line.trim();
|
|
40
|
+
if (!t)
|
|
41
|
+
continue;
|
|
42
|
+
let d;
|
|
43
|
+
try {
|
|
44
|
+
d = JSON.parse(t);
|
|
45
|
+
}
|
|
46
|
+
catch {
|
|
47
|
+
continue;
|
|
48
|
+
}
|
|
49
|
+
if (typeof d.session_id === "string" && !sessionId)
|
|
50
|
+
sessionId = d.session_id;
|
|
51
|
+
if (d.type === "result") {
|
|
52
|
+
if (typeof d.session_id === "string")
|
|
53
|
+
sessionId = d.session_id;
|
|
54
|
+
if (typeof d.result === "string")
|
|
55
|
+
finalText = d.result;
|
|
56
|
+
isError = Boolean(d.is_error);
|
|
57
|
+
}
|
|
58
|
+
}
|
|
59
|
+
return { sessionId, finalText, isError };
|
|
60
|
+
},
|
|
61
|
+
};
|
|
62
|
+
/**
|
|
63
|
+
* Drives the OpenAI Codex CLI via `codex exec`. Mirrors claudeAdapter but for
|
|
64
|
+
* codex's different surface:
|
|
65
|
+
* - prompt is fed over STDIN (argv ends with a bare `-`), not argv → promptViaStdin
|
|
66
|
+
* - permission is a spawn-time SANDBOX choice, not a per-tool approval loop:
|
|
67
|
+
* default → --sandbox read-only (codex can read, not write)
|
|
68
|
+
* acceptEdits → --sandbox workspace-write (codex can write the workspace)
|
|
69
|
+
* bypassPermissions → --dangerously-bypass-approvals-and-sandbox (full auto)
|
|
70
|
+
* (Matches the only model codex supports — same choice the `wand` tool makes;
|
|
71
|
+
* codex has no `--permission-prompt-tool stdio` equivalent.)
|
|
72
|
+
* - JSONL event shape differs: session id is `thread.started`.thread_id, the
|
|
73
|
+
* final answer is the last `item.completed` of item.type "agent_message", and
|
|
74
|
+
* failure is `turn.failed` / `error` events (no `is_error` flag).
|
|
75
|
+
*/
|
|
76
|
+
export const codexAdapter = {
|
|
77
|
+
kind: "codex",
|
|
78
|
+
promptViaStdin: true,
|
|
79
|
+
buildArgs(opts) {
|
|
80
|
+
const args = ["exec", "--json", "--color", "never", "--skip-git-repo-check"];
|
|
81
|
+
if (opts.permissionMode === "bypassPermissions") {
|
|
82
|
+
args.push("--dangerously-bypass-approvals-and-sandbox");
|
|
83
|
+
}
|
|
84
|
+
else {
|
|
85
|
+
args.push("--sandbox", opts.permissionMode === "acceptEdits" ? "workspace-write" : "read-only");
|
|
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
|
+
}
|
|
93
|
+
// `resume <thread_id>` continues a prior codex session; the trailing `-`
|
|
94
|
+
// tells codex exec to read the prompt from stdin (we feed it there).
|
|
95
|
+
if (opts.resumeSessionId)
|
|
96
|
+
args.push("resume", opts.resumeSessionId, "-");
|
|
97
|
+
else
|
|
98
|
+
args.push("-");
|
|
99
|
+
return args;
|
|
100
|
+
},
|
|
101
|
+
parseResult(lines) {
|
|
102
|
+
let sessionId = "";
|
|
103
|
+
let finalText = "";
|
|
104
|
+
let isError = false;
|
|
105
|
+
const errorBits = [];
|
|
106
|
+
for (const line of lines) {
|
|
107
|
+
const t = line.trim();
|
|
108
|
+
if (!t)
|
|
109
|
+
continue;
|
|
110
|
+
let d;
|
|
111
|
+
try {
|
|
112
|
+
d = JSON.parse(t);
|
|
113
|
+
}
|
|
114
|
+
catch {
|
|
115
|
+
continue;
|
|
116
|
+
}
|
|
117
|
+
if (d.type === "thread.started" && typeof d.thread_id === "string")
|
|
118
|
+
sessionId = d.thread_id;
|
|
119
|
+
else if (d.type === "item.completed" &&
|
|
120
|
+
d.item?.type === "agent_message" &&
|
|
121
|
+
typeof d.item.text === "string") {
|
|
122
|
+
finalText = d.item.text; // keep the LAST agent_message
|
|
123
|
+
}
|
|
124
|
+
else if (d.type === "turn.failed") {
|
|
125
|
+
isError = true;
|
|
126
|
+
const msg = d.error?.message ?? d.error ?? "turn failed";
|
|
127
|
+
if (typeof msg === "string")
|
|
128
|
+
errorBits.push(msg);
|
|
129
|
+
}
|
|
130
|
+
else if (d.type === "error") {
|
|
131
|
+
isError = true;
|
|
132
|
+
const msg = d.message ?? d.error?.message ?? d.error ?? "error";
|
|
133
|
+
if (typeof msg === "string")
|
|
134
|
+
errorBits.push(msg);
|
|
135
|
+
}
|
|
136
|
+
}
|
|
137
|
+
// On failure, surface the error text as finalText (so the caller/notification
|
|
138
|
+
// shows *why*), preferring it over any partial agent_message.
|
|
139
|
+
if (isError && errorBits.length)
|
|
140
|
+
finalText = errorBits.join("\n");
|
|
141
|
+
return { sessionId, finalText, isError };
|
|
142
|
+
},
|
|
143
|
+
};
|
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
/** Availability of one external coding CLI. */
|
|
2
|
+
export interface CCAvailability {
|
|
3
|
+
available: boolean;
|
|
4
|
+
command: string;
|
|
5
|
+
version?: string;
|
|
6
|
+
reason?: "not-found" | "not-executable";
|
|
7
|
+
}
|
|
8
|
+
/** macOS GUI-launched Electron has a minimal PATH (no Homebrew). Prepend common
|
|
9
|
+
* CLI dirs so `claude` resolves. Mirrors resident-agent.ts's fix. */
|
|
10
|
+
export declare function pathWithCommonBins(env?: NodeJS.ProcessEnv): string;
|
|
11
|
+
export type ProbeRunner = (command: string) => Promise<{
|
|
12
|
+
ok: boolean;
|
|
13
|
+
stdout: string;
|
|
14
|
+
}>;
|
|
15
|
+
/** Probe a CLI's availability. Injectable runner for tests. */
|
|
16
|
+
export declare function probeCli(command: string, runner?: ProbeRunner): Promise<CCAvailability>;
|
|
17
|
+
/** Cached probe; pass force=true to re-detect (user installed CLI mid-session). */
|
|
18
|
+
export declare function probeClaudeCli(force?: boolean): Promise<CCAvailability>;
|
|
19
|
+
/** Cached probe for the OpenAI Codex CLI; force=true re-detects. */
|
|
20
|
+
export declare function probeCodexCli(force?: boolean): Promise<CCAvailability>;
|