@oneworks/cli 0.1.0-alpha.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 (87) hide show
  1. package/LICENSE +21 -0
  2. package/channel.js +7 -0
  3. package/cli.js +5 -0
  4. package/mem.js +7 -0
  5. package/package.json +59 -0
  6. package/postinstall.js +75 -0
  7. package/src/AGENTS.md +169 -0
  8. package/src/channel-cli.ts +19 -0
  9. package/src/cli-argv.ts +27 -0
  10. package/src/cli.ts +63 -0
  11. package/src/commands/@core/adapter-option.ts +85 -0
  12. package/src/commands/@core/extra-options.ts +12 -0
  13. package/src/commands/@core/plugin-install.ts +1 -0
  14. package/src/commands/@core/plugin-source.ts +1 -0
  15. package/src/commands/accounts.ts +204 -0
  16. package/src/commands/adapter/prepare-selection.ts +181 -0
  17. package/src/commands/adapter/prepare.ts +104 -0
  18. package/src/commands/adapter.ts +48 -0
  19. package/src/commands/agent/actions.ts +176 -0
  20. package/src/commands/agent/runtime-store-commands.ts +56 -0
  21. package/src/commands/agent/runtime-store-events.ts +23 -0
  22. package/src/commands/agent/runtime-store-session.ts +170 -0
  23. package/src/commands/agent/runtime-store-shared.ts +139 -0
  24. package/src/commands/agent/runtime-store.ts +4 -0
  25. package/src/commands/agent.ts +81 -0
  26. package/src/commands/benchmark.ts +198 -0
  27. package/src/commands/channel.ts +594 -0
  28. package/src/commands/clear.ts +140 -0
  29. package/src/commands/config/actions.ts +196 -0
  30. package/src/commands/config/display-state.ts +108 -0
  31. package/src/commands/config/index.ts +135 -0
  32. package/src/commands/config/interactive.ts +121 -0
  33. package/src/commands/config/read-state.ts +56 -0
  34. package/src/commands/config/section-state.ts +109 -0
  35. package/src/commands/config/shared.ts +195 -0
  36. package/src/commands/kill.ts +41 -0
  37. package/src/commands/list.ts +224 -0
  38. package/src/commands/memory/context.ts +76 -0
  39. package/src/commands/memory/entries.ts +131 -0
  40. package/src/commands/memory/shared.ts +89 -0
  41. package/src/commands/memory/store.ts +69 -0
  42. package/src/commands/memory/target.ts +54 -0
  43. package/src/commands/memory.ts +97 -0
  44. package/src/commands/plugin.ts +62 -0
  45. package/src/commands/report-targets.ts +149 -0
  46. package/src/commands/report.ts +232 -0
  47. package/src/commands/run/adapter-cli-version.ts +65 -0
  48. package/src/commands/run/command.ts +982 -0
  49. package/src/commands/run/input-bridge.ts +108 -0
  50. package/src/commands/run/input-control.ts +112 -0
  51. package/src/commands/run/input-decision.ts +88 -0
  52. package/src/commands/run/options.ts +104 -0
  53. package/src/commands/run/output.ts +179 -0
  54. package/src/commands/run/permission-decision.ts +19 -0
  55. package/src/commands/run/permission-recovery.ts +194 -0
  56. package/src/commands/run/permission-state.ts +177 -0
  57. package/src/commands/run/print-idle-timeout.ts +47 -0
  58. package/src/commands/run/protocol-envelope.ts +111 -0
  59. package/src/commands/run/protocol-stdio.ts +71 -0
  60. package/src/commands/run/protocol.ts +391 -0
  61. package/src/commands/run/runtime-command-bridge.ts +190 -0
  62. package/src/commands/run/runtime-event-sink.ts +560 -0
  63. package/src/commands/run/session-exit-controller.ts +45 -0
  64. package/src/commands/run/types.ts +65 -0
  65. package/src/commands/run.ts +62 -0
  66. package/src/commands/session-control.ts +133 -0
  67. package/src/commands/skills/add-command.ts +88 -0
  68. package/src/commands/skills/install-command.ts +105 -0
  69. package/src/commands/skills/install.ts +216 -0
  70. package/src/commands/skills/progress.ts +126 -0
  71. package/src/commands/skills/publish-command.ts +85 -0
  72. package/src/commands/skills/register.ts +17 -0
  73. package/src/commands/skills/remove-command.ts +102 -0
  74. package/src/commands/skills/shared.ts +117 -0
  75. package/src/commands/skills/sync.ts +571 -0
  76. package/src/commands/skills/types.ts +33 -0
  77. package/src/commands/skills.ts +1 -0
  78. package/src/commands/stop.ts +41 -0
  79. package/src/config.ts +1 -0
  80. package/src/default-skill-plugin.ts +29 -0
  81. package/src/env.ts +1 -0
  82. package/src/hooks/plugins/index.ts +66 -0
  83. package/src/mem-cli.ts +19 -0
  84. package/src/session-cache.ts +250 -0
  85. package/src/session-permission-cache.ts +40 -0
  86. package/src/utils.ts +25 -0
  87. package/src/workspace.ts +12 -0
package/LICENSE ADDED
@@ -0,0 +1,21 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2026-present One Works contributors
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in all
13
+ copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
+ SOFTWARE.
package/channel.js ADDED
@@ -0,0 +1,7 @@
1
+ #!/usr/bin/env node
2
+
3
+ require('@oneworks/cli-helper/entry').runCliPackageEntrypoint({
4
+ packageDir: __dirname,
5
+ sourceEntry: './src/channel-cli',
6
+ distEntry: './dist/channel-cli.js'
7
+ })
package/cli.js ADDED
@@ -0,0 +1,5 @@
1
+ #!/usr/bin/env node
2
+
3
+ require('@oneworks/cli-helper/entry').runCliPackageEntrypoint({
4
+ packageDir: __dirname
5
+ })
package/mem.js ADDED
@@ -0,0 +1,7 @@
1
+ #!/usr/bin/env node
2
+
3
+ require('@oneworks/cli-helper/entry').runCliPackageEntrypoint({
4
+ packageDir: __dirname,
5
+ sourceEntry: './src/mem-cli',
6
+ distEntry: './dist/mem-cli.js'
7
+ })
package/package.json ADDED
@@ -0,0 +1,59 @@
1
+ {
2
+ "name": "@oneworks/cli",
3
+ "version": "0.1.0-alpha.0",
4
+ "repository": {
5
+ "type": "git",
6
+ "url": "https://github.com/oneworks-ai/app.git",
7
+ "directory": "apps/cli"
8
+ },
9
+ "description": "One Works CLI",
10
+ "imports": {
11
+ "#~/*.js": {
12
+ "__oneworks__": {
13
+ "default": "./src/*.ts"
14
+ }
15
+ }
16
+ },
17
+ "exports": {
18
+ "./package.json": "./package.json",
19
+ "./config": {
20
+ "__oneworks__": {
21
+ "default": "./src/config.ts"
22
+ },
23
+ "default": {
24
+ "import": "./dist/config.mjs",
25
+ "require": "./dist/config.js"
26
+ }
27
+ }
28
+ },
29
+ "bin": {
30
+ "oneworks": "./cli.js",
31
+ "ow": "./cli.js",
32
+ "owo": "./cli.js"
33
+ },
34
+ "dependencies": {
35
+ "commander": "^12.1.0",
36
+ "fast-glob": "^3.3.3",
37
+ "node-notifier": "^10.0.1",
38
+ "@oneworks/app-runtime": "0.1.0-alpha.0",
39
+ "@oneworks/cli-helper": "0.1.0-alpha.0",
40
+ "@oneworks/config": "0.1.0-alpha.0",
41
+ "@oneworks/hooks": "0.1.0-alpha.0",
42
+ "@oneworks/core": "0.1.0-alpha.0",
43
+ "@oneworks/managed-plugins": "0.1.0-alpha.0",
44
+ "@oneworks/plugin-cli-skills": "0.1.0-alpha.0",
45
+ "@oneworks/runtime-protocol": "0.1.0-alpha.0",
46
+ "@oneworks/types": "0.1.0-alpha.0",
47
+ "@oneworks/register": "0.1.0-alpha.0",
48
+ "@oneworks/runtime-store": "0.1.0-alpha.0",
49
+ "@oneworks/utils": "0.1.0-alpha.0",
50
+ "@oneworks/workspace-assets": "0.1.0-alpha.0"
51
+ },
52
+ "devDependencies": {
53
+ "@types/node-notifier": "^8.0.5"
54
+ },
55
+ "scripts": {
56
+ "postinstall": "node postinstall.js",
57
+ "test": "pnpm -C ../.. exec vitest run --workspace vitest.workspace.ts --project node apps/cli/__tests__"
58
+ }
59
+ }
package/postinstall.js ADDED
@@ -0,0 +1,75 @@
1
+ #!/usr/bin/env node
2
+ const { spawnSync } = require('node:child_process')
3
+ const { existsSync, readFileSync } = require('node:fs')
4
+ const { join, resolve } = require('node:path')
5
+ const process = require('node:process')
6
+
7
+ const isFalseLike = value => ['0', 'false', 'no', 'off'].includes(String(value ?? '').trim().toLowerCase())
8
+ const isTrueLike = value => ['1', 'true', 'yes', 'on'].includes(String(value ?? '').trim().toLowerCase())
9
+
10
+ const shouldSkip = () => (
11
+ isTrueLike(process.env.ONEWORKS_SKIP_POSTINSTALL) ||
12
+ isTrueLike(process.env.ONEWORKS_SKIP_ADAPTER_PREPARE) ||
13
+ process.env.ONEWORKS_ADAPTER_PREPARE_POSTINSTALL_ACTIVE === '1' ||
14
+ (
15
+ process.env.CI != null &&
16
+ !isFalseLike(process.env.CI) &&
17
+ !isTrueLike(process.env.ONEWORKS_POSTINSTALL_PREPARE)
18
+ )
19
+ )
20
+
21
+ const isPlainObject = value => value != null && typeof value === 'object' && !Array.isArray(value)
22
+
23
+ const readJsonConfig = projectDir => {
24
+ for (const relativePath of ['.oo.config.json', 'infra/.oo.config.json']) {
25
+ const configPath = join(projectDir, relativePath)
26
+ if (!existsSync(configPath)) continue
27
+ try {
28
+ return JSON.parse(readFileSync(configPath, 'utf8'))
29
+ } catch (error) {
30
+ console.warn(`[oneworks] Skipping adapter CLI postinstall prepare: failed to read ${relativePath}.`)
31
+ console.warn(error instanceof Error ? error.message : String(error))
32
+ return undefined
33
+ }
34
+ }
35
+ return undefined
36
+ }
37
+
38
+ const hasPrepareOnInstallTarget = config => {
39
+ const adapters = isPlainObject(config?.adapters) ? config.adapters : undefined
40
+ if (adapters == null) return false
41
+
42
+ return Object.values(adapters).some(adapterConfig => {
43
+ if (!isPlainObject(adapterConfig)) return false
44
+ return ['cli', 'routerCli'].some(key => (
45
+ isPlainObject(adapterConfig[key]) && adapterConfig[key].prepareOnInstall === true
46
+ ))
47
+ })
48
+ }
49
+
50
+ if (!shouldSkip()) {
51
+ const projectDir = resolve(process.env.INIT_CWD || process.cwd())
52
+ const config = readJsonConfig(projectDir)
53
+ if (hasPrepareOnInstallTarget(config)) {
54
+ const result = spawnSync(
55
+ process.execPath,
56
+ [join(__dirname, 'cli.js'), 'adapter', 'prepare', '--from-postinstall'],
57
+ {
58
+ cwd: projectDir,
59
+ env: {
60
+ ...process.env,
61
+ ONEWORKS_ADAPTER_PREPARE_POSTINSTALL_ACTIVE: '1'
62
+ },
63
+ stdio: 'inherit'
64
+ }
65
+ )
66
+
67
+ if (result.status !== 0) {
68
+ const strict = isTrueLike(process.env.ONEWORKS_POSTINSTALL_STRICT)
69
+ console.warn('[oneworks] Adapter CLI postinstall prepare failed.')
70
+ if (strict) {
71
+ process.exit(result.status ?? 1)
72
+ }
73
+ }
74
+ }
75
+ }
package/src/AGENTS.md ADDED
@@ -0,0 +1,169 @@
1
+ # CLI Src 目录说明
2
+
3
+ CLI 侧只负责命令入口、参数归并、hook/plugin 调用、agent runtime command 写入与把任务交给 app-facing runtime / adapter。
4
+ app-facing 的 task / benchmark 入口位于 `@oneworks/app-runtime`。
5
+ MCP stdio server 入口位于 `@oneworks/mcp`。
6
+ 默认内建 `OneWorks` MCP 的解析位于 `@oneworks/config`,由 task runtime 在 prepare 阶段注入,但不承担 task domain;发布态的 `@oneworks/mcp` 安装锚点由 `@oneworks/app-runtime` 提供。
7
+ agent runtime 标准入口是 `oneworks --input-format json|stream-json --output-format json|stream-json` 的 runtime protocol mode;`oneworks agent ...` 是 runtime protocol command 入口。命令写入 runtime protocol/store 后由 runtime consumer 处理。
8
+ adapter 契约与 loader 位于 `@oneworks/types`。
9
+ task-facing workspace asset helper 位于 `@oneworks/workspace-assets`。
10
+ definition loader 位于 `@oneworks/definition-loader`。
11
+ 通用 hooks runtime、`oneworks-call-hook` 与 native helper 位于 `@oneworks/hooks`。
12
+ `defineConfig()`、通用配置加载、默认 system prompt 策略和默认内建 MCP 解析位于 `@oneworks/config`,共享 logger / log-level / key-transform / system helper / model-selection / cache 位于 `@oneworks/utils`。
13
+ config、cache、definition、workspace asset 共享 contract 位于 `@oneworks/types`。
14
+
15
+ ## 什么时候先读这里
16
+
17
+ - 用户问题是通过 `npx oneworks ...` 复现出来的
18
+ - 想知道某个命令最终调用了哪个 adapter / runtime
19
+ - `init`、`run --print`、hook/plugin logger 的行为不符合预期
20
+ - 想确认环境变量是从 CLI 哪一层注入进去的
21
+
22
+ 文档交叉入口:
23
+
24
+ - `.oo/rules/HOOKS.md`
25
+ - `.oo/rules/HOOKS-REFERENCE.md`
26
+ - `packages/types/AGENTS.md`
27
+ - `packages/app-runtime/AGENTS.md`
28
+ - `packages/workspace-assets/AGENTS.md`
29
+ - `packages/mcp/AGENTS.md`
30
+ - `packages/task/AGENTS.md`
31
+ - `packages/adapters/codex/AGENTS.md`
32
+ - `packages/adapters/claude-code/AGENTS.md`
33
+ - `packages/adapters/opencode/AGENTS.md`
34
+
35
+ 优先入口:
36
+
37
+ - `commands/run.ts`
38
+ - `commands/agent.ts`
39
+ - `commands/agent/*`
40
+ - `../../packages/hooks/src/entry.ts`
41
+ - `../../packages/cli-helper/loader.js`
42
+ - `../../packages/hooks/call-hook.js`
43
+
44
+ ## Hooks bridge 入口
45
+
46
+ hooks 相关问题先按这条链路看:
47
+
48
+ - `packages/hooks/call-hook.js`
49
+ - 通用 hook 进程入口
50
+ - 负责把 `HOME` 指到 home project 下的 `.mock`,再执行 hooks runtime
51
+ - `packages/hooks/src/entry.ts`
52
+ - 动态发现已安装 adapter 的 `./hook-bridge`,命中 active env 后执行,否则回退默认 `runHookCli()`
53
+ - `packages/hooks/src/runtime.ts`
54
+ - 默认 hook runtime,负责读取输入、装载插件、执行 middleware
55
+ - `packages/config/src/load.ts`
56
+ - hooks runtime 的配置读取、变量替换与缓存
57
+ - `packages/utils/src/create-logger.ts`
58
+ - hooks runtime 与主会话共用的 markdown logger
59
+ - `packages/utils/src/string-transform.ts`
60
+ - hook 输入 key 转换
61
+ - `packages/adapters/claude-code/src/hook-bridge.ts`
62
+ - Claude native payload -> 统一 hook input/output
63
+ - `packages/adapters/codex/src/hook-bridge.ts`
64
+ - Codex native payload -> 统一 hook input/output
65
+
66
+ 维护约定:
67
+
68
+ - CLI 只做入口分发和最小 env 补齐,不承载 adapter 私有协议翻译
69
+ - adapter-native plugin 的标准安装动作、目录约定和失败回滚在 CLI core;adapter 自己的 `./plugins` 导出只提供 native 格式解析、marketplace 规则和转换钩子
70
+ - 业务 hook 执行放在 `packages/hooks/src/*`
71
+ - 通用 `call-hook.js` 运行时与 `oneworks-call-hook` bin 都归 `packages/hooks`
72
+ - project mock home 的 native 资产写入放在 adapter / `packages/hooks/src/native.ts`,不要散落到 CLI 命令层
73
+ - 真实 adapter E2E 验证优先走仓库根的 `pnpm test:e2e:adapters`
74
+ - 定向排查时走 `pnpm tools adapter-e2e run <selection>`
75
+ - `pnpm test:e2e:adapters` 和 `pnpm tools adapter-e2e run <selection>` 默认都会起本地 mock LLM server;对应模型服务配置在仓库根 `.oo.config.json`
76
+ - `hook-smoke-mock` 给 Codex / OpenCode
77
+ - `hook-smoke-mock-ccr` 给 Claude Code Router
78
+ - adapter E2E 的 shared harness 在 `scripts/adapter-e2e/`,scripts CLI 入口在 `scripts/cli.ts`
79
+ - 新增场景优先改 `scripts/__tests__/adapter-e2e/cases.ts` 和 `mock-llm/rules.ts`,不要再往脚本入口堆逻辑
80
+ - 真实 CLI 结果统一写进 Vitest file snapshot;更新时用 `pnpm tools adapter-e2e test <case-id> --update`
81
+
82
+ ## 什么时候继续往下读别的目录
83
+
84
+ ### 1. 看到的是命令入口问题
85
+
86
+ 继续留在本目录:
87
+
88
+ - `commands/*.ts`
89
+ - `hooks/*.ts`
90
+
91
+ 适合排查:
92
+
93
+ - 参数没有传下去
94
+ - `sessionId` / `ctxId` 生成不对
95
+ - `--print` / `--resume` / `--spec` / `--entity` / `--no-default-oneworks-mcp-server` 行为异常
96
+ - runtime protocol mode 或 `oneworks agent start/send/stop/kill/submit/resume/status/events` 行为异常
97
+
98
+ ### 2. 看到的是 agent runtime protocol/store 问题
99
+
100
+ 转到:
101
+
102
+ - `commands/agent.ts`
103
+ - `commands/agent/*`
104
+ - `packages/runtime-protocol`
105
+ - `packages/runtime-store`
106
+ - `packages/task-runtime`
107
+
108
+ 原因:
109
+
110
+ - CLI 负责把 runtime protocol envelope 或 `oneworks agent ...` 参数转换为 runtime command / status / event 读写
111
+ - task domain 不通过 MCP 暴露,也不维护 MCP 到 runtime protocol 的转换层
112
+ - server 和 UI 依赖 runtime store projection,不直接消费 CLI stdout 作为长期状态源
113
+
114
+ ### 3. 看到的是主会话日志级别问题
115
+
116
+ 转到:
117
+
118
+ - `packages/task/src/prepare.ts`
119
+ - `packages/utils/src/create-logger.ts`
120
+ - `packages/utils/src/log-level.ts`
121
+ - `packages/core/src/env.ts`
122
+
123
+ 原因:
124
+
125
+ - CLI 只是把环境变量和 runtime 带入 task
126
+ - 真正决定主会话 markdown 日志怎么写的是 `packages/utils` 加 `task prepare`
127
+
128
+ ### 4. 看到的是 Claude Code adapter / CCR / transformer 问题
129
+
130
+ 转到:
131
+
132
+ - `packages/adapters/claude-code/AGENTS.md`
133
+
134
+ 进入条件:
135
+
136
+ - `Claude Code CLI stdout` 日志内容不对
137
+ - CCR transformer 日志文件缺失或异常
138
+ - create/resume 流程不对
139
+ - adapter CLI 参数、settings、mcp config 需要追踪
140
+
141
+ ### 5. 看到的是独立 MCP server 问题
142
+
143
+ 转到:
144
+
145
+ - `packages/mcp/AGENTS.md`
146
+ - `packages/mcp/src/cli.ts`
147
+ - `packages/mcp/src/command.ts`
148
+
149
+ 进入条件:
150
+
151
+ - `oneworks-mcp` 无法启动
152
+ - MCP tools 注册/过滤不对
153
+ - 非 task MCP tool 结果异常,例如 `AskUserQuestion`
154
+
155
+ ### 6. 看到的是 server 控制台 / session jsonl 问题
156
+
157
+ 转到:
158
+
159
+ - `apps/server/src/utils/logger.ts`
160
+ - `apps/server/src/AGENTS.md`
161
+
162
+ ## CLI 调试建议
163
+
164
+ - 复现前先执行 `npx oneworks clear`
165
+ - 独立 MCP server 冒烟先执行 `oneworks-mcp --help`
166
+ - 如果只想看本次日志,先 `touch /tmp/<marker>` 再执行命令
167
+ - `run --print` 的最终 session 行为由 task + adapter 决定,CLI 只负责入口编排,不要在 CLI 里追完整生命周期
168
+ - CLI loader 共享实现位置:`packages/cli-helper/loader.js`
169
+ - 适配器错误 / `stream-json` 冒烟流程见:`.oo/rules/adapter-error-debugging.md`
@@ -0,0 +1,19 @@
1
+ import process from 'node:process'
2
+
3
+ import { Command } from 'commander'
4
+
5
+ import { getCliVersion } from '#~/utils.js'
6
+
7
+ import { registerChannelSubcommands } from './commands/channel'
8
+
9
+ const program = new Command()
10
+
11
+ program
12
+ .name('oneworks channel')
13
+ .description('Send messages through OneWorks channels from agent sessions')
14
+ .version(getCliVersion())
15
+ .showHelpAfterError()
16
+
17
+ registerChannelSubcommands(program)
18
+
19
+ program.parse(process.argv)
@@ -0,0 +1,27 @@
1
+ const ROOT_ONLY_ARGS = new Set(['-h', '--help', '-V', '--version', 'help'])
2
+ const ROOT_SUBCOMMANDS = new Set([
3
+ 'agent',
4
+ 'adapter',
5
+ 'benchmark',
6
+ 'channel',
7
+ 'clear',
8
+ 'config',
9
+ 'kill',
10
+ 'list',
11
+ 'ls',
12
+ 'mem',
13
+ 'plugin',
14
+ 'report',
15
+ 'skills',
16
+ 'stop'
17
+ ])
18
+
19
+ export const normalizeCliArgs = (args: string[]) => {
20
+ const [firstArg] = args
21
+
22
+ if (firstArg == null) return ['__run']
23
+ if (ROOT_ONLY_ARGS.has(firstArg)) return args
24
+ if (!firstArg.startsWith('-') && ROOT_SUBCOMMANDS.has(firstArg)) return args
25
+
26
+ return ['__run', ...args]
27
+ }
package/src/cli.ts ADDED
@@ -0,0 +1,63 @@
1
+ import './commands/@core/extra-options'
2
+
3
+ import process from 'node:process'
4
+
5
+ import { program } from 'commander'
6
+
7
+ import { getCliDescription, getCliVersion } from '#~/utils.js'
8
+
9
+ import { normalizeCliArgs } from './cli-argv'
10
+ import { registerAccountsCommand } from './commands/accounts'
11
+ import { registerAdapterCommand } from './commands/adapter'
12
+ import { registerAgentCommand } from './commands/agent'
13
+ import { registerBenchmarkCommand } from './commands/benchmark'
14
+ import { registerChannelCommand } from './commands/channel'
15
+ import { registerClearCommand } from './commands/clear'
16
+ import { registerConfigCommand } from './commands/config'
17
+ import { registerKillCommand } from './commands/kill'
18
+ import { registerListCommand } from './commands/list'
19
+ import { registerMemoryCommand } from './commands/memory'
20
+ import { registerPluginCommand } from './commands/plugin'
21
+ import { registerReportCommand } from './commands/report'
22
+ import { registerRunCommand } from './commands/run'
23
+ import { registerSkillsCommand } from './commands/skills'
24
+ import { registerStopCommand } from './commands/stop'
25
+
26
+ program
27
+ .name('oneworks')
28
+ .description(getCliDescription())
29
+ .version(getCliVersion())
30
+ .showHelpAfterError()
31
+ .addHelpText(
32
+ 'after',
33
+ `
34
+ Examples:
35
+ oneworks 读取 README 并给出改进建议
36
+ oneworks --include-skill oneworks-cli-quickstart 介绍 One Works CLI 的常用命令
37
+ oneworks 帮我创建一个前端评审实体
38
+ oneworks list
39
+ oneworks list --view full
40
+ oneworks config list
41
+ oneworks --resume [sessionId]
42
+ oneworks --fork [sessionId]
43
+ oneworks list --running
44
+ `
45
+ )
46
+
47
+ registerRunCommand(program)
48
+ registerAccountsCommand(program)
49
+ registerAgentCommand(program)
50
+ registerAdapterCommand(program)
51
+ registerBenchmarkCommand(program)
52
+ registerChannelCommand(program)
53
+ registerClearCommand(program)
54
+ registerConfigCommand(program)
55
+ registerListCommand(program)
56
+ registerPluginCommand(program)
57
+ registerReportCommand(program)
58
+ registerStopCommand(program)
59
+ registerSkillsCommand(program)
60
+ registerKillCommand(program)
61
+ registerMemoryCommand(program)
62
+
63
+ program.parse(normalizeCliArgs(process.argv.slice(2)), { from: 'user' })
@@ -0,0 +1,85 @@
1
+ import { Option } from 'commander'
2
+
3
+ import { normalizeAdapterPackageId } from '@oneworks/types'
4
+
5
+ const ADAPTER_PREFIX = 'adapter-'
6
+
7
+ export interface CliAdapterOptionValue {
8
+ adapter: string
9
+ cliVersion?: string
10
+ }
11
+
12
+ const splitAdapterVersionSelector = (value: string) => {
13
+ const lastAt = value.lastIndexOf('@')
14
+ if (lastAt <= 0) {
15
+ return {
16
+ adapter: value
17
+ }
18
+ }
19
+
20
+ if (value.startsWith('@')) {
21
+ const slash = value.indexOf('/')
22
+ if (slash < 0 || lastAt <= slash) {
23
+ return {
24
+ adapter: value
25
+ }
26
+ }
27
+ }
28
+
29
+ const adapter = value.slice(0, lastAt).trim()
30
+ const cliVersion = value.slice(lastAt + 1).trim()
31
+ if (adapter === '' || cliVersion === '') {
32
+ throw new TypeError('Adapter version selector must be formatted as <adapter>@<version>.')
33
+ }
34
+ if (/\s/.test(cliVersion)) {
35
+ throw new TypeError('Adapter CLI version must not contain whitespace.')
36
+ }
37
+
38
+ return {
39
+ adapter,
40
+ cliVersion
41
+ }
42
+ }
43
+
44
+ export const parseCliAdapterOptionValue = (value: string): CliAdapterOptionValue => {
45
+ const trimmed = value.trim()
46
+ if (trimmed === '') {
47
+ return {
48
+ adapter: trimmed
49
+ }
50
+ }
51
+
52
+ const selector = splitAdapterVersionSelector(trimmed)
53
+ const normalized = normalizeAdapterPackageId(selector.adapter)
54
+ const adapter = normalized.startsWith(ADAPTER_PREFIX)
55
+ ? normalized.slice(ADAPTER_PREFIX.length)
56
+ : normalized
57
+
58
+ return {
59
+ adapter,
60
+ cliVersion: selector.cliVersion
61
+ }
62
+ }
63
+
64
+ export const normalizeCliAdapterOptionValue = (value: string) => {
65
+ return parseCliAdapterOptionValue(value).adapter
66
+ }
67
+
68
+ const normalizeCliAdapterSelectorOptionValue = (value: string) => {
69
+ const parsed = parseCliAdapterOptionValue(value)
70
+ return parsed.cliVersion == null ? parsed.adapter : `${parsed.adapter}@${parsed.cliVersion}`
71
+ }
72
+
73
+ export const createAdapterOption = (
74
+ description: string,
75
+ options?: {
76
+ allowCliVersion?: boolean
77
+ }
78
+ ) => (
79
+ new Option('-A, --adapter <adapter>', description)
80
+ .argParser(
81
+ options?.allowCliVersion === true
82
+ ? normalizeCliAdapterSelectorOptionValue
83
+ : normalizeCliAdapterOptionValue
84
+ )
85
+ )
@@ -0,0 +1,12 @@
1
+ import process from 'node:process'
2
+
3
+ // 获取通过 -- 参数传递的额外选项
4
+ const extraOptionsStartIndex = process.argv.indexOf('--')
5
+ export const extraOptions = extraOptionsStartIndex !== -1
6
+ ? process.argv.slice(extraOptionsStartIndex + 1)
7
+ : []
8
+
9
+ if (extraOptions.length > 0) {
10
+ // 删除 process.argv 中的额外选项
11
+ process.argv.splice(extraOptionsStartIndex, extraOptions.length + 1)
12
+ }
@@ -0,0 +1 @@
1
+ export { addAdapterPlugin, installAdapterPluginWithInstaller } from '@oneworks/managed-plugins'
@@ -0,0 +1 @@
1
+ export { installManagedPluginSource, pathExists, resolveManagedPluginSource } from '@oneworks/managed-plugins'