c0de-agent 1.11.0 → 1.13.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 +63 -16
- package/dist/cli/commands/acp.js +26 -8
- package/dist/cli/commands/chat.js +151 -1
- package/dist/cli/commands/config.d.ts +2 -0
- package/dist/cli/commands/config.js +63 -3
- package/dist/cli/commands/serve.js +11 -2
- package/dist/cli/commands/sessions.js +109 -3
- package/dist/cli/commands/trust.d.ts +11 -0
- package/dist/cli/commands/trust.js +31 -0
- package/dist/cli/commands/update.js +4 -0
- package/dist/cli/deps.d.ts +9 -6
- package/dist/cli/deps.js +66 -19
- package/dist/cli/index.d.ts +4 -1
- package/dist/cli/index.js +110 -11
- package/dist/cli/modes/acp.js +39 -8
- package/dist/cli/modes/print.d.ts +3 -0
- package/dist/cli/modes/print.js +78 -8
- package/dist/core/agent.d.ts +1 -1
- package/dist/core/agent.js +9 -4
- package/dist/core/agents/builtin.js +2 -2
- package/dist/core/agents/index.d.ts +0 -1
- package/dist/core/agents/index.js +0 -1
- package/dist/core/compact.d.ts +2 -0
- package/dist/core/compact.js +1 -0
- package/dist/core/config.d.ts +53 -2
- package/dist/core/config.js +235 -19
- package/dist/core/loop/compaction.d.ts +2 -1
- package/dist/core/loop/compaction.js +19 -6
- package/dist/core/loop/segment.d.ts +3 -1
- package/dist/core/loop/segment.js +24 -1
- package/dist/core/loop/stream-collect.js +9 -1
- package/dist/core/loop/subagent.js +88 -37
- package/dist/core/loop.d.ts +7 -0
- package/dist/core/loop.js +90 -6
- package/dist/core/redact.d.ts +11 -0
- package/dist/core/redact.js +49 -0
- package/dist/core/slash.d.ts +10 -0
- package/dist/core/slash.js +237 -65
- package/dist/core/title.js +7 -1
- package/dist/core/types.d.ts +22 -1
- package/dist/core/workflows/context.js +44 -4
- package/dist/core/workflows/discovery.d.ts +2 -2
- package/dist/core/workflows/discovery.js +5 -7
- package/dist/core/workflows/index.d.ts +2 -1
- package/dist/core/workflows/index.js +2 -1
- package/dist/core/workflows/registry.d.ts +13 -3
- package/dist/core/workflows/registry.js +14 -9
- package/dist/core/workflows/resolve.d.ts +22 -0
- package/dist/core/workflows/resolve.js +23 -0
- package/dist/core/workflows/runtime.d.ts +6 -1
- package/dist/core/workflows/runtime.js +19 -2
- package/dist/db/schema.d.ts +373 -1
- package/dist/db/schema.js +60 -4
- package/dist/kanban/index.d.ts +2 -1
- package/dist/kanban/index.js +1 -1
- package/dist/kanban/store.d.ts +87 -1
- package/dist/kanban/store.js +429 -22
- package/dist/llm/index.d.ts +1 -1
- package/dist/llm/index.js +1 -1
- package/dist/llm/provider.js +1 -1
- package/dist/llm/registry.d.ts +7 -1
- package/dist/llm/registry.js +7 -1
- package/dist/llm/retry.d.ts +5 -2
- package/dist/llm/retry.js +6 -5
- package/dist/llm/routing.d.ts +24 -1
- package/dist/llm/routing.js +29 -1
- package/dist/plugins/init.d.ts +7 -0
- package/dist/plugins/init.js +22 -1
- package/dist/plugins/loader.d.ts +7 -1
- package/dist/plugins/loader.js +12 -4
- package/dist/project/index.d.ts +1 -1
- package/dist/project/index.js +1 -1
- package/dist/project/project.d.ts +37 -0
- package/dist/project/project.js +142 -1
- package/dist/project/trust.d.ts +65 -0
- package/dist/project/trust.js +328 -0
- package/dist/server/agent-manager.d.ts +15 -2
- package/dist/server/agent-manager.js +18 -3
- package/dist/server/app.js +45 -30
- package/dist/server/auth-manager.d.ts +26 -9
- package/dist/server/auth-manager.js +78 -42
- package/dist/server/context.js +14 -1
- package/dist/server/index.d.ts +1 -1
- package/dist/server/index.js +1 -1
- package/dist/server/middleware/auth.d.ts +11 -1
- package/dist/server/middleware/auth.js +25 -3
- package/dist/server/permission/interactive.d.ts +11 -3
- package/dist/server/permission/interactive.js +23 -4
- package/dist/server/permission/store.d.ts +14 -2
- package/dist/server/permission/store.js +39 -3
- package/dist/server/registry-config.d.ts +14 -0
- package/dist/server/registry-config.js +44 -0
- package/dist/server/routes/auth.js +66 -10
- package/dist/server/routes/chat.d.ts +21 -0
- package/dist/server/routes/chat.js +685 -52
- package/dist/server/routes/commands.d.ts +4 -2
- package/dist/server/routes/commands.js +9 -4
- package/dist/server/routes/config.js +180 -23
- package/dist/server/routes/files.js +142 -28
- package/dist/server/routes/kanban.js +218 -26
- package/dist/server/routes/permissions.d.ts +0 -4
- package/dist/server/routes/permissions.js +140 -7
- package/dist/server/routes/project.js +132 -29
- package/dist/server/routes/provider.js +54 -3
- package/dist/server/routes/session.js +463 -23
- package/dist/server/routes/tool.js +24 -5
- package/dist/server/routes/update.d.ts +11 -5
- package/dist/server/routes/update.js +145 -29
- package/dist/server/routes/usage.d.ts +4 -0
- package/dist/server/routes/usage.js +133 -0
- package/dist/server/routes/workflows.js +476 -87
- package/dist/server/server.d.ts +16 -13
- package/dist/server/server.js +364 -107
- package/dist/server/terminal/pty-manager.d.ts +12 -0
- package/dist/server/terminal/pty-manager.js +63 -7
- package/dist/server/types.d.ts +16 -0
- package/dist/session/archive.d.ts +3 -1
- package/dist/session/archive.js +13 -1
- package/dist/session/branch.d.ts +2 -1
- package/dist/session/branch.js +92 -9
- package/dist/session/context.js +28 -2
- package/dist/session/import.d.ts +44 -0
- package/dist/session/import.js +83 -0
- package/dist/session/index.d.ts +1 -1
- package/dist/session/index.js +1 -1
- package/dist/session/jobs.d.ts +12 -0
- package/dist/session/jobs.js +53 -0
- package/dist/session/message.d.ts +7 -1
- package/dist/session/message.js +21 -1
- package/dist/session/session.d.ts +186 -12
- package/dist/session/session.js +577 -33
- package/dist/session/snapshot.d.ts +5 -2
- package/dist/session/snapshot.js +10 -2
- package/dist/session/types.d.ts +13 -1
- package/dist/session/usage.d.ts +62 -0
- package/dist/session/usage.js +194 -0
- package/dist/shared/types/agent.d.ts +29 -2
- package/dist/shared/types/config.d.ts +64 -5
- package/dist/shared/types/kanban.d.ts +17 -2
- package/dist/shared/types/message.d.ts +23 -0
- package/dist/tools/builtin/kanban.js +13 -2
- package/dist/tools/index.d.ts +14 -3
- package/dist/tools/index.js +23 -5
- package/dist/tools/websearch/index.d.ts +5 -1
- package/dist/tools/websearch/index.js +46 -7
- package/dist/tools/websearch/providers/brave.js +2 -2
- package/dist/tools/websearch/providers/duckduckgo.js +2 -1
- package/dist/tools/websearch/providers/tavily.js +2 -2
- package/dist/tools/websearch/types.d.ts +5 -1
- package/dist/tools/websearch/types.js +7 -1
- package/dist/update/index.d.ts +3 -3
- package/dist/update/index.js +2 -2
- package/dist/update/ipc.d.ts +13 -2
- package/dist/update/ipc.js +36 -2
- package/dist/update/scheduler.js +5 -2
- package/dist/update/snapshot.d.ts +18 -3
- package/dist/update/snapshot.js +5 -2
- package/dist/update/updater.d.ts +17 -1
- package/dist/update/updater.js +47 -18
- package/dist/update/version.d.ts +3 -0
- package/dist/update/version.js +9 -3
- package/drizzle/0008_tranquil_lily_hollister.sql +1 -0
- package/drizzle/0010_usage_events_ledger.sql +17 -0
- package/drizzle/0011_slow_slapstick.sql +12 -0
- package/drizzle/0012_chief_timeslip.sql +1 -0
- package/drizzle/0013_swift_zeigeist.sql +1 -0
- package/drizzle/0014_flimsy_legion.sql +1 -0
- package/drizzle/meta/0008_snapshot.json +875 -0
- package/drizzle/meta/0010_snapshot.json +1010 -0
- package/drizzle/meta/0011_snapshot.json +1055 -0
- package/drizzle/meta/0012_snapshot.json +1062 -0
- package/drizzle/meta/0013_snapshot.json +1068 -0
- package/drizzle/meta/0014_snapshot.json +1075 -0
- package/drizzle/meta/_journal.json +42 -0
- package/package.json +42 -42
- package/dist/core/agents/discovery.d.ts +0 -6
- package/dist/core/agents/discovery.js +0 -96
|
@@ -10,8 +10,20 @@
|
|
|
10
10
|
// GET /api/auth/pairing 列出待审批配对
|
|
11
11
|
// POST /api/auth/pairing/approve 审批通过(签发设备 token)
|
|
12
12
|
// POST /api/auth/pairing/deny 拒绝配对
|
|
13
|
+
// GET /api/auth/devices 列出已授权设备
|
|
14
|
+
// DELETE /api/auth/devices/:id 撤销设备(立即生效)
|
|
13
15
|
import { Hono } from 'hono';
|
|
14
16
|
import { apiError } from '../middleware/error.js';
|
|
17
|
+
/** 尽力而为的请求来源:x-forwarded-for 首跳(反代场景),否则视为本地回环。仅展示/软限流。 */
|
|
18
|
+
function requestSource(c) {
|
|
19
|
+
const fwd = c.req.header('x-forwarded-for');
|
|
20
|
+
if (fwd) {
|
|
21
|
+
const first = fwd.split(',')[0]?.trim();
|
|
22
|
+
if (first)
|
|
23
|
+
return first;
|
|
24
|
+
}
|
|
25
|
+
return 'local';
|
|
26
|
+
}
|
|
15
27
|
function createAuthRoute(ctx) {
|
|
16
28
|
const app = new Hono();
|
|
17
29
|
// 首设备注册:凭 bootstrap token(URL ?token=)换发设备 token,bootstrap 随即轮换失效。
|
|
@@ -23,12 +35,24 @@ function createAuthRoute(ctx) {
|
|
|
23
35
|
if (!body.token) {
|
|
24
36
|
return apiError(c, 400, 'BAD_REQUEST', 'token is required');
|
|
25
37
|
}
|
|
26
|
-
const
|
|
27
|
-
if (!
|
|
28
|
-
//
|
|
29
|
-
|
|
38
|
+
const result = await ctx.authManager.registerFirstDevice(body.token, body.deviceName ?? '设备');
|
|
39
|
+
if (!result.ok) {
|
|
40
|
+
// 区分失败原因给正确的恢复指引:链接过期 → 重启 serve 换新链接;
|
|
41
|
+
// 已有设备 → 走配对审批;两者补救动作完全不同,不得混用同一文案。
|
|
42
|
+
if (result.reason === 'ttl_expired') {
|
|
43
|
+
return apiError(c, 403, 'BOOTSTRAP_EXPIRED', '注册链接已过期(超过安全窗口未使用)。请重启 c0de serve——无已注册设备时' +
|
|
44
|
+
'重启会重新生成注册链接,打开启动日志中打印的新 URL 完成首次注册。');
|
|
45
|
+
}
|
|
46
|
+
if (result.reason === 'devices_exist') {
|
|
47
|
+
return apiError(c, 403, 'BOOTSTRAP_CONSUMED', 'bootstrap token 已失效(已有设备注册)。请在新设备发起配对,由已授权设备审批。');
|
|
48
|
+
}
|
|
49
|
+
if (result.reason === 'invalid_bootstrap') {
|
|
50
|
+
return apiError(c, 403, 'BOOTSTRAP_INVALID', 'bootstrap token 无效。');
|
|
51
|
+
}
|
|
52
|
+
return apiError(c, 403, 'STATIC_TOKEN_MODE', '静态 token 模式不支持设备注册。');
|
|
30
53
|
}
|
|
31
|
-
|
|
54
|
+
// P1-3:回传注册成功的设备名,前端展示一次性确认(用户可核对注册的是否自己)。
|
|
55
|
+
return c.json({ deviceToken: result.deviceToken, deviceName: body.deviceName ?? '设备' });
|
|
32
56
|
});
|
|
33
57
|
// 新设备发起配对请求(公开)。
|
|
34
58
|
app.post('/pairing/request', async (c) => {
|
|
@@ -36,11 +60,16 @@ function createAuthRoute(ctx) {
|
|
|
36
60
|
return apiError(c, 400, 'AUTH_DISABLED', '认证未启用');
|
|
37
61
|
}
|
|
38
62
|
const body = (await c.req.json().catch(() => ({})));
|
|
39
|
-
const result = ctx.authManager.requestPairing(body.deviceName ?? '新设备');
|
|
63
|
+
const result = ctx.authManager.requestPairing(body.deviceName ?? '新设备', requestSource(c));
|
|
40
64
|
if (!result) {
|
|
41
65
|
return apiError(c, 429, 'PAIRING_LIMIT', '待审批的配对请求过多,请稍后再试');
|
|
42
66
|
}
|
|
43
|
-
|
|
67
|
+
// L3:零已授权设备时配对审批不可能完成(无人可批准)——前端据此展示
|
|
68
|
+
// 恢复指引(重启 serve 重新生成 bootstrap 注册链接)而非干等审批。
|
|
69
|
+
return c.json({
|
|
70
|
+
...result,
|
|
71
|
+
hasAuthorizedDevices: ctx.authManager.listDevices().length > 0,
|
|
72
|
+
});
|
|
44
73
|
});
|
|
45
74
|
// 新设备轮询配对审批结果(公开)。
|
|
46
75
|
app.get('/pairing/status', (c) => {
|
|
@@ -63,7 +92,8 @@ function createAuthRoute(ctx) {
|
|
|
63
92
|
}
|
|
64
93
|
return c.json({ pairings: ctx.authManager.listPairings() });
|
|
65
94
|
});
|
|
66
|
-
// 审批通过(需认证)。
|
|
95
|
+
// 审批通过(需认证)。P2-9:必须携带审批方输入的 6 位配对码(新设备屏幕显示),
|
|
96
|
+
// 服务端核对匹配才签发——防多请求并存时看错行误批给错设备。
|
|
67
97
|
app.post('/pairing/approve', async (c) => {
|
|
68
98
|
if (!ctx.authManager) {
|
|
69
99
|
return apiError(c, 400, 'AUTH_DISABLED', '认证未启用');
|
|
@@ -71,9 +101,18 @@ function createAuthRoute(ctx) {
|
|
|
71
101
|
const body = (await c.req.json().catch(() => ({})));
|
|
72
102
|
if (!body.pairingId)
|
|
73
103
|
return apiError(c, 400, 'BAD_REQUEST', 'pairingId is required');
|
|
74
|
-
|
|
75
|
-
|
|
104
|
+
if (!body.code)
|
|
105
|
+
return apiError(c, 400, 'BAD_REQUEST', 'code is required');
|
|
106
|
+
const result = ctx.authManager.approvePairing(body.pairingId, body.code);
|
|
107
|
+
if (result === 'code_mismatch') {
|
|
108
|
+
return apiError(c, 400, 'PAIRING_CODE_MISMATCH', '配对码不匹配:请核对新设备屏幕显示的 6 位配对码后重新输入');
|
|
109
|
+
}
|
|
110
|
+
if (result === 'not_found' || result === 'expired') {
|
|
76
111
|
return apiError(c, 404, 'PAIRING_NOT_FOUND', '配对请求不存在或已过期');
|
|
112
|
+
}
|
|
113
|
+
if (result === 'already_handled') {
|
|
114
|
+
return apiError(c, 409, 'PAIRING_ALREADY_HANDLED', '该配对请求已被处理');
|
|
115
|
+
}
|
|
77
116
|
return c.json({ ok: true });
|
|
78
117
|
});
|
|
79
118
|
// 拒绝配对(需认证)。
|
|
@@ -89,6 +128,23 @@ function createAuthRoute(ctx) {
|
|
|
89
128
|
return apiError(c, 404, 'PAIRING_NOT_FOUND', '配对请求不存在或已过期');
|
|
90
129
|
return c.json({ ok: true });
|
|
91
130
|
});
|
|
131
|
+
// 列出已授权设备(需认证;设置页「已授权设备」面板)。
|
|
132
|
+
app.get('/devices', (c) => {
|
|
133
|
+
if (!ctx.authManager) {
|
|
134
|
+
return apiError(c, 400, 'AUTH_DISABLED', '认证未启用');
|
|
135
|
+
}
|
|
136
|
+
return c.json({ devices: ctx.authManager.listDevices() });
|
|
137
|
+
});
|
|
138
|
+
// 撤销设备(需认证)。撤销唯一设备后如需重新注册首设备,请运行 c0de auth reset。
|
|
139
|
+
app.delete('/devices/:id', async (c) => {
|
|
140
|
+
if (!ctx.authManager) {
|
|
141
|
+
return apiError(c, 400, 'AUTH_DISABLED', '认证未启用');
|
|
142
|
+
}
|
|
143
|
+
const ok = ctx.authManager.revokeDevice(c.req.param('id'));
|
|
144
|
+
if (!ok)
|
|
145
|
+
return apiError(c, 404, 'NOT_FOUND', 'Device not found');
|
|
146
|
+
return c.json({ ok: true });
|
|
147
|
+
});
|
|
92
148
|
return app;
|
|
93
149
|
}
|
|
94
150
|
export { createAuthRoute };
|
|
@@ -1,4 +1,7 @@
|
|
|
1
1
|
import { Hono } from 'hono';
|
|
2
|
+
import { type SSEStreamingApi } from 'hono/streaming';
|
|
3
|
+
import type { RegisterChildRun } from '../../core/types.js';
|
|
4
|
+
import type { AgentManager } from '../agent-manager.js';
|
|
2
5
|
import type { ServerContext } from '../types.js';
|
|
3
6
|
/** 按 session.projectId / worktreePath 解析 agent 工作目录:
|
|
4
7
|
* - 有 projectId → 项目 worktree(缺失/目录失效时抛错,由上层转 409)。
|
|
@@ -9,5 +12,23 @@ export declare function resolveAgentCwd(ctx: ServerContext, session: {
|
|
|
9
12
|
projectId: string | null;
|
|
10
13
|
worktreePath?: string | null;
|
|
11
14
|
}): Promise<string>;
|
|
15
|
+
declare const SSE_HEARTBEAT_INTERVAL_MS = 30000;
|
|
16
|
+
/** 启动心跳定时器;返回停止函数(幂等)。流关闭后写入会被吞掉,安全。 */
|
|
17
|
+
declare function startHeartbeat(stream: SSEStreamingApi): () => void;
|
|
18
|
+
export { SSE_HEARTBEAT_INTERVAL_MS, startHeartbeat };
|
|
19
|
+
/**
|
|
20
|
+
* 子 agent run 注册桥接:core 的 registerChildRun → agentManager 槽位。
|
|
21
|
+
* P1:此前子 run(含后台任务)从不注册,暂停/热更新/删除级联/更新影响面
|
|
22
|
+
* 全部绕过它们;core 无 agentManager 引用,桥接由 Web 宿主注入。
|
|
23
|
+
* 返回的注销函数幂等(unregister 对不存在的 key 安全)。
|
|
24
|
+
*/
|
|
25
|
+
export declare function childRunBridge(manager: AgentManager): RegisterChildRun;
|
|
26
|
+
/**
|
|
27
|
+
* 会话「忙」判定统一口径:活跃 run / tryAcquire 占位(starting)/ 工作流运行期
|
|
28
|
+
* (发起会话无主 run,busy 映射承载)。变更型操作(fork/compact/clear 等)在斜杠与
|
|
29
|
+
* REST 双入口共用本判定,防止守卫漂移——REST fork 此前只查 get(),漏 starting
|
|
30
|
+
* 占位窗口与工作流运行期两种态(斜杠守卫早已覆盖)。
|
|
31
|
+
*/
|
|
32
|
+
export declare function hasBusySession(ctx: ServerContext, sessionId: string): 'run' | 'starting' | 'workflow' | null;
|
|
12
33
|
declare function createChatRoute(ctx: ServerContext): Hono;
|
|
13
34
|
export { createChatRoute };
|