@twinklerg/coden 0.1.0 → 0.1.2

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (44) hide show
  1. package/README.md +40 -17
  2. package/dist/index.js +121 -21232
  3. package/dist/plugin/index.d.ts +25 -0
  4. package/dist/plugin/index.js +1 -0
  5. package/package.json +8 -6
  6. package/src/cli/agent-command.ts +0 -497
  7. package/src/cli/format.ts +0 -42
  8. package/src/cli/index.ts +0 -149
  9. package/src/cli/plugin-command.ts +0 -217
  10. package/src/config/config.ts +0 -96
  11. package/src/config/trust.ts +0 -35
  12. package/src/context/manager.ts +0 -186
  13. package/src/context/truncate.ts +0 -9
  14. package/src/core/events.ts +0 -32
  15. package/src/core/runtime.ts +0 -402
  16. package/src/core/types.ts +0 -97
  17. package/src/index.ts +0 -14
  18. package/src/observability/terminal.ts +0 -201
  19. package/src/observability/trace.ts +0 -30
  20. package/src/permissions/policy.ts +0 -56
  21. package/src/permissions/workspace.ts +0 -139
  22. package/src/plugins/api.ts +0 -68
  23. package/src/plugins/bun-package-manager.ts +0 -35
  24. package/src/plugins/installed-loader.ts +0 -144
  25. package/src/plugins/installer.ts +0 -314
  26. package/src/plugins/manifest.ts +0 -89
  27. package/src/plugins/package-manager.ts +0 -10
  28. package/src/plugins/package-metadata.ts +0 -95
  29. package/src/plugins/paths.ts +0 -43
  30. package/src/plugins/specifier.ts +0 -63
  31. package/src/plugins/transaction.ts +0 -403
  32. package/src/process/runner.ts +0 -134
  33. package/src/providers/anthropic.ts +0 -117
  34. package/src/providers/openai.ts +0 -96
  35. package/src/providers/scripted.ts +0 -28
  36. package/src/sessions/store.ts +0 -278
  37. package/src/tools/builtin/bash.ts +0 -56
  38. package/src/tools/builtin/edit.ts +0 -42
  39. package/src/tools/builtin/index.ts +0 -9
  40. package/src/tools/builtin/read.ts +0 -91
  41. package/src/tools/builtin/write.ts +0 -34
  42. package/src/tools/executor.ts +0 -90
  43. package/src/tools/plugin-loader.ts +0 -122
  44. package/src/tools/registry.ts +0 -97
package/README.md CHANGED
@@ -4,7 +4,19 @@
4
4
 
5
5
  CodeN(Code NJU)是一个用 TypeScript 独立实现的极简编程智能体。它直接使用模型原生 Tool Calling,在本地读取、修改文件和执行命令;不依赖 Agent 框架或服务端代码执行。
6
6
 
7
- ## 要求与安装
7
+ ## 安装与使用
8
+
9
+ ### 从 npm 安装(发布后的 CLI)
10
+
11
+ ```bash
12
+ bun add -g @twinklerg/coden # 或 npm install -g @twinklerg/coden
13
+ coden --version # 0.1.2
14
+ coden --help
15
+ ```
16
+
17
+ 发布产物是构建后的单文件 Node CLI(`dist/index.js`,已 minify),运行时只需 Node,不需要 Bun。
18
+
19
+ ### 从源码运行(开发)
8
20
 
9
21
  - [Bun](https://bun.sh/) 1.1+
10
22
  - [Just](https://github.com/casey/just)
@@ -16,26 +28,27 @@ just check
16
28
 
17
29
  源码仅使用标准 Web/Node.js API;Bun 负责依赖、脚本和 TypeScript 插件运行。
18
30
 
19
- ## 使用
31
+ ### 使用示例
20
32
 
21
33
  ```bash
22
34
  export CODEN_OPENAI_API_KEY=...
23
- bun run src/cli/index.ts "修复当前项目的测试失败"
24
- bun run src/cli/index.ts -p --auto "实现功能并运行测试"
35
+ coden "修复当前项目的测试失败"
36
+ coden -p --auto "实现功能并运行测试"
25
37
 
26
38
  export CODEN_ANTHROPIC_API_KEY=...
27
- bun run src/cli/index.ts --provider anthropic --model claude-sonnet-4-20250514
39
+ coden --provider anthropic --model claude-sonnet-4-20250514
28
40
 
29
- bun run src/cli/index.ts --resume <session-id>
41
+ coden --resume <session-id> # 恢复指定会话
42
+ coden --resume # 列出当前工作区的会话
30
43
  ```
31
44
 
32
- 也可执行 `just run -- --help`。无 prompt 时进入 REPL,支持 `/help`、`/session`、`/compact`、`/reload`、`/new` 和 `/quit`。
45
+ prompt 时进入 REPL,支持 `/help`、`/session`、`/sessions`、`/compact`、`/reload`、`/new` 和 `/quit`。启动横幅会显示当前版本与 16 位 workspace hash。
33
46
 
34
- 核心选项:`--provider`、`--model`、`--resume`、`--auto`、`--verbose`、`--max-steps` 和可重复的 `--plugin`。
47
+ 核心选项:`--provider`、`--model`、`-p/--print`、`--resume [session-id]`、`--auto`、`--verbose`、`--max-steps`、可重复的 `--plugin` `--version`。
35
48
 
36
49
  ## 配置
37
50
 
38
- 优先级:CLI > 环境变量 > `<workspace>/.coden/config.json` > `~/.config/coden/config.json` > 默认值。
51
+ 配置字段来自五层(从高到低):CLI 参数 > `CODEN_*` 环境变量 > `<workspace>/.coden/config.json`(项目级)> `~/.config/coden/config.json`(用户级)> 默认值。
39
52
 
40
53
  ```json
41
54
  {
@@ -45,11 +58,16 @@ bun run src/cli/index.ts --resume <session-id>
45
58
  "contextWindow": 128000,
46
59
  "reservedOutputTokens": 8192,
47
60
  "safetyMargin": 4096,
48
- "plugins": []
61
+ "plugins": [],
62
+ "env": {
63
+ "CODEN_OPENAI_API_KEY": "sk-..."
64
+ }
49
65
  }
50
66
  ```
51
67
 
52
- 支持 `CODEN_PROVIDER`、`CODEN_MODEL`、`CODEN_MAX_STEPS`、`CODEN_OPENAI_API_KEY`、`CODEN_OPENAI_BASE_URL`、`CODEN_ANTHROPIC_API_KEY`、`XDG_CONFIG_HOME` 和 `XDG_DATA_HOME`。凭据只从环境读取。
68
+ 支持 `CODEN_PROVIDER`、`CODEN_MODEL`、`CODEN_MAX_STEPS`、`CODEN_OPENAI_API_KEY`、`CODEN_OPENAI_BASE_URL`、`CODEN_ANTHROPIC_API_KEY`、`XDG_CONFIG_HOME` 和 `XDG_DATA_HOME`。
69
+
70
+ `env` 字段(用户级与项目级均可)声明环境变量(含敏感密钥),加载配置时注入进程环境,无需手动 `export`。两级 `env` 合并时**项目级逐键覆盖用户级**;注入**不覆盖** `shell` 中已导出的同名变量(CLI > 环境变量 > 配置 env)。密钥请放 `~/.config/coden/` 或 `.coden/`(已被 `gitignore` 忽略、默认不入库),不要放进会被提交、共享或分发的目录。
53
71
 
54
72
  会话和 trace 位于 `$XDG_DATA_HOME/coden/sessions/<workspace-hash>/`(默认 `~/.local/share/coden`)。
55
73
 
@@ -147,7 +165,7 @@ coden plugin remove @scope/coden-plugin-example
147
165
  单工具默认导出一个兼容 `ToolDefinition` 的对象:
148
166
 
149
167
  ```ts
150
- import type { ToolDefinition } from "coden/plugin";
168
+ import type { ToolDefinition } from "@twinklerg/coden/plugin";
151
169
 
152
170
  const tool: ToolDefinition = {
153
171
  name: "example_echo",
@@ -171,7 +189,7 @@ export default tool;
171
189
  多工具默认导出 `CodeNPlugin`,其中 `name` 必须等于 npm 包名:
172
190
 
173
191
  ```ts
174
- import type { CodeNPlugin, ToolDefinition } from "coden/plugin";
192
+ import type { CodeNPlugin, ToolDefinition } from "@twinklerg/coden/plugin";
175
193
 
176
194
  const readTool: ToolDefinition = {
177
195
  name: "example_read",
@@ -202,14 +220,19 @@ const plugin: CodeNPlugin = {
202
220
  export default plugin;
203
221
  ```
204
222
 
205
- 插件可以把 `coden` 放入 `devDependencies` 以获得 `coden/plugin` 类型;构建产物中的类型导入会被移除,运行时不应加载另一份 CodeN。
223
+ `@twinklerg/coden/plugin` 是 CodeN 提供给插件作者的公共契约子路径。插件把 `@twinklerg/coden` 放入 `devDependencies` 以在构建时获得类型;`import type` 会在构建时被移除,运行时不加载另一份 CodeN。`ToolContext.signal` 使用 `AbortSignal`,请确保 tsconfig 提供一个定义它的 lib(如 `@types/node` DOM)。
224
+
225
+ 插件契约以 `src/plugin/index.ts` 为唯一来源;构建时自动生成 `dist/plugin/index.d.ts` 和仅包含公开常量的最小 JavaScript 入口,不发布 `src`。CodeN 的 npm 包只暴露 `/plugin` 这一条子路径,主入口 `"."` 未公开,`import "@twinklerg/coden"` 会被拒绝——它定位为 CLI,不作为程序化导入库。
206
226
 
207
227
  ## 开发与测试
208
228
 
209
229
  ```bash
210
- just fmt # Biome format
211
- just test # offline Vitest
212
- just check # Biome lint + strict tsc + complete offline tests
230
+ just fmt # Biome format
231
+ just test # offline Vitest
232
+ just check # Biome lint + strict tsc + complete offline tests
233
+ just build # build the CLI and generate the public plugin contract in dist/
234
+ just publish-dry-run # verify exactly what npm would publish (no upload)
235
+ just publish # lint + typecheck + test, then publish to npm (--access public)
213
236
  ```
214
237
 
215
238
  离线集成测试用 `ScriptedProvider` 覆盖工具循环、拒绝、重试和恢复。真实 API 冒烟测试(`test/live.test.ts`)默认跳过,仅在显式设置后运行: