c0de-agent 1.0.0 → 1.2.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/dist/cli/deps.d.ts +16 -5
- package/dist/cli/deps.js +18 -5
- package/dist/cli/index.js +8 -2
- package/dist/core/agent.js +5 -0
- package/dist/core/config.js +1 -0
- package/dist/core/index.d.ts +1 -0
- package/dist/core/index.js +1 -0
- package/dist/core/loop.d.ts +10 -0
- package/dist/core/loop.js +559 -295
- package/dist/core/slash.js +3 -4
- package/dist/core/title.js +3 -2
- package/dist/core/types.d.ts +2 -0
- package/dist/core/workflow.d.ts +25 -0
- package/dist/core/workflow.js +98 -0
- package/dist/core/worktree.js +6 -4
- package/dist/dap/session.js +3 -3
- package/dist/llm/provider.js +5 -1
- package/dist/plugins/loader.js +3 -2
- package/dist/server/agent-manager.d.ts +2 -0
- package/dist/server/agent-manager.js +8 -0
- package/dist/server/app.js +3 -0
- package/dist/server/context.js +2 -0
- package/dist/server/dev.d.ts +4 -1
- package/dist/server/dev.js +92 -27
- package/dist/server/permission/store.d.ts +2 -0
- package/dist/server/permission/store.js +9 -0
- package/dist/server/routes/chat.js +44 -1
- package/dist/server/routes/session.js +75 -1
- package/dist/server/routes/terminal.d.ts +5 -0
- package/dist/server/routes/terminal.js +66 -0
- package/dist/server/server.d.ts +14 -1
- package/dist/server/server.js +100 -28
- package/dist/server/terminal/pty-manager.d.ts +53 -0
- package/dist/server/terminal/pty-manager.js +160 -0
- package/dist/server/types.d.ts +3 -0
- package/dist/session/archive.d.ts +1 -1
- package/dist/session/compaction.d.ts +8 -2
- package/dist/session/compaction.js +85 -16
- package/dist/session/shake.d.ts +66 -0
- package/dist/session/shake.js +304 -0
- package/dist/session/types.d.ts +1 -1
- package/dist/shared/types/agent.d.ts +27 -0
- package/dist/shared/types/config.d.ts +10 -0
- package/dist/shared/types/llm.d.ts +1 -0
- package/dist/shared/types/tool.d.ts +3 -0
- package/package.json +11 -3
package/dist/cli/deps.d.ts
CHANGED
|
@@ -3,17 +3,28 @@ import type { DB } from '../db/client.js';
|
|
|
3
3
|
import type { Registry } from '../llm/registry.js';
|
|
4
4
|
import type { Config } from '../shared/types/config.js';
|
|
5
5
|
import type { PermissionChecker } from '../tools/types.js';
|
|
6
|
-
/**
|
|
7
|
-
|
|
6
|
+
/** 权限策略:
|
|
7
|
+
* - 'full-auto':所有工具无条件放行(print/acp 等非交互模式)。
|
|
8
|
+
* - 'safe'(默认):只读工具放行,写/执行工具需确认(chat 等 agent 自主执行场景)。 */
|
|
9
|
+
type PermissionStrategy = 'full-auto' | 'safe';
|
|
10
|
+
/** 真正非交互模式(print/acp):所有工具无条件放行(命令由用户显式触发)。 */
|
|
11
|
+
declare const fullyAutoApproveChecker: PermissionChecker;
|
|
12
|
+
/** 安全策略:只读工具(permission: 'auto',如 read/grep/glob/websearch)自动放行;
|
|
13
|
+
* 写/执行工具(permission: 'ask',如 bash/write/edit)返回 ask 需确认;
|
|
14
|
+
* permission: 'deny' 拒绝。复用 tools 层 autoAllowChecker(按工具自身声明的权限分级)。 */
|
|
15
|
+
declare const readOnlySafeChecker: PermissionChecker;
|
|
8
16
|
/** 把 config.providers 注册到新建的 LLM registry。 */
|
|
9
17
|
declare function buildLLMRegistry(config: Config): Registry;
|
|
10
18
|
type BuildDepsOptions = {
|
|
11
19
|
db: DB;
|
|
12
20
|
cwd: string;
|
|
21
|
+
/** 权限策略:'full-auto' 全部放行;'safe' 只读放行、写操作 ask。不传时按
|
|
22
|
+
* config.permission.defaultMode 决定('auto'→full-auto,'default'→safe)。 */
|
|
23
|
+
permissionStrategy?: PermissionStrategy;
|
|
13
24
|
/** 测试注入 mock chatStream。 */
|
|
14
25
|
chatStream?: LoopDeps['chatStream'];
|
|
15
26
|
};
|
|
16
|
-
/** 组装完整 LoopDeps
|
|
27
|
+
/** 组装完整 LoopDeps(默认 safe 放行 + 默认工具注册表)。 */
|
|
17
28
|
declare function buildAgentDeps(config: Config, opts: BuildDepsOptions): Promise<LoopDeps>;
|
|
18
|
-
export type { BuildDepsOptions };
|
|
19
|
-
export {
|
|
29
|
+
export type { BuildDepsOptions, PermissionStrategy };
|
|
30
|
+
export { buildAgentDeps, buildLLMRegistry, fullyAutoApproveChecker, readOnlySafeChecker };
|
package/dist/cli/deps.js
CHANGED
|
@@ -2,13 +2,18 @@ import { decryptSecret } from '../core/secret.js';
|
|
|
2
2
|
import { createRegistry, registerProvider } from '../llm/index.js';
|
|
3
3
|
import { initPlugins } from '../plugins/index.js';
|
|
4
4
|
import { createDefaultRegistry, createDefaultURLRegistry } from '../tools/index.js';
|
|
5
|
-
|
|
6
|
-
|
|
5
|
+
import { autoAllowChecker } from '../tools/permission.js';
|
|
6
|
+
/** 真正非交互模式(print/acp):所有工具无条件放行(命令由用户显式触发)。 */
|
|
7
|
+
const fullyAutoApproveChecker = {
|
|
7
8
|
check: async (_tool, _input, _ctx) => {
|
|
8
9
|
return { _tag: 'allow' };
|
|
9
10
|
},
|
|
10
11
|
confirm: (_toolCallId, _approved) => { },
|
|
11
12
|
};
|
|
13
|
+
/** 安全策略:只读工具(permission: 'auto',如 read/grep/glob/websearch)自动放行;
|
|
14
|
+
* 写/执行工具(permission: 'ask',如 bash/write/edit)返回 ask 需确认;
|
|
15
|
+
* permission: 'deny' 拒绝。复用 tools 层 autoAllowChecker(按工具自身声明的权限分级)。 */
|
|
16
|
+
const readOnlySafeChecker = autoAllowChecker;
|
|
12
17
|
/** 把 config.providers 注册到新建的 LLM registry。 */
|
|
13
18
|
function buildLLMRegistry(config) {
|
|
14
19
|
const registry = createRegistry();
|
|
@@ -31,7 +36,15 @@ function registerProviderFromConfig(registry, p) {
|
|
|
31
36
|
...(path ? { path } : {}),
|
|
32
37
|
});
|
|
33
38
|
}
|
|
34
|
-
/**
|
|
39
|
+
/** 解析权限 checker:显式策略优先,否则回退到 config.permission.defaultMode。 */
|
|
40
|
+
function resolvePermissionChecker(config, strategy) {
|
|
41
|
+
if (strategy === 'full-auto')
|
|
42
|
+
return fullyAutoApproveChecker;
|
|
43
|
+
if (strategy === 'safe')
|
|
44
|
+
return readOnlySafeChecker;
|
|
45
|
+
return config.permission.defaultMode === 'auto' ? fullyAutoApproveChecker : readOnlySafeChecker;
|
|
46
|
+
}
|
|
47
|
+
/** 组装完整 LoopDeps(默认 safe 放行 + 默认工具注册表)。 */
|
|
35
48
|
async function buildAgentDeps(config, opts) {
|
|
36
49
|
const llmRegistry = buildLLMRegistry(config);
|
|
37
50
|
const toolRegistry = createDefaultRegistry(config);
|
|
@@ -47,11 +60,11 @@ async function buildAgentDeps(config, opts) {
|
|
|
47
60
|
toolRegistry,
|
|
48
61
|
urlRegistry: createDefaultURLRegistry(),
|
|
49
62
|
hookRunner,
|
|
50
|
-
permission:
|
|
63
|
+
permission: resolvePermissionChecker(config, opts.permissionStrategy),
|
|
51
64
|
config,
|
|
52
65
|
cwd: opts.cwd,
|
|
53
66
|
...(opts.chatStream ? { chatStream: opts.chatStream } : {}),
|
|
54
67
|
};
|
|
55
68
|
return deps;
|
|
56
69
|
}
|
|
57
|
-
export {
|
|
70
|
+
export { buildAgentDeps, buildLLMRegistry, fullyAutoApproveChecker, readOnlySafeChecker };
|
package/dist/cli/index.js
CHANGED
|
@@ -89,7 +89,12 @@ async function dispatch(argv, overrides = {}) {
|
|
|
89
89
|
const db = await createDB({ driver: 'pglite' });
|
|
90
90
|
await migrateDB(db);
|
|
91
91
|
try {
|
|
92
|
-
|
|
92
|
+
// --yes / -y 显式放行写操作;否则按 config.permission.defaultMode 决定(默认 safe)。
|
|
93
|
+
const deps = await buildAgentDeps(config, {
|
|
94
|
+
db,
|
|
95
|
+
cwd,
|
|
96
|
+
...(args.options.yes ? { permissionStrategy: 'full-auto' } : {}),
|
|
97
|
+
});
|
|
93
98
|
await runChatCommand({ args, config, deps });
|
|
94
99
|
}
|
|
95
100
|
finally {
|
|
@@ -114,7 +119,8 @@ async function dispatch(argv, overrides = {}) {
|
|
|
114
119
|
const db = await createDB({ driver: 'pglite' });
|
|
115
120
|
await migrateDB(db);
|
|
116
121
|
try {
|
|
117
|
-
|
|
122
|
+
// ACP 非交互:所有工具放行(编辑器侧自行控制执行授权)。
|
|
123
|
+
const deps = await buildAgentDeps(config, { db, cwd, permissionStrategy: 'full-auto' });
|
|
118
124
|
await runAcpCommand({ config, deps });
|
|
119
125
|
}
|
|
120
126
|
finally {
|
package/dist/core/agent.js
CHANGED
|
@@ -32,6 +32,11 @@ async function createAgent(session, config, deps) {
|
|
|
32
32
|
keepRecent: 12_800,
|
|
33
33
|
},
|
|
34
34
|
calibrationFactor: 1.0,
|
|
35
|
+
// 压缩模型覆盖:从全局配置映射到 agent state,compactContext 读取后用于
|
|
36
|
+
// 创建 summarizer。未配置时为 undefined → 回退到会话主模型。
|
|
37
|
+
...(deps.config.compaction.compactionModel
|
|
38
|
+
? { compactionModel: deps.config.compaction.compactionModel }
|
|
39
|
+
: {}),
|
|
35
40
|
};
|
|
36
41
|
}
|
|
37
42
|
async function* runAgent(state, userInput, deps) {
|
package/dist/core/config.js
CHANGED
package/dist/core/index.d.ts
CHANGED
|
@@ -11,3 +11,4 @@ export { clearSteering, drainSteering, injectSteering } from './steering.js';
|
|
|
11
11
|
export type { CollectedToolCall, ToolCallResult } from './tool-exec.js';
|
|
12
12
|
export { executeToolCall, executeToolCalls, partitionByConflict } from './tool-exec.js';
|
|
13
13
|
export type { AgentConfig, AgentDependencies, AgentError, AgentEvent, AgentState, AgentStatus, CommandContext, CommandResult, LLMSegment, PendingToolCall, ProjectInfo, PromptContext, SlashCommand, TokenBudget, } from './types.js';
|
|
14
|
+
export { containsWorkflow, WORKFLOW_NOTICE } from './workflow.js';
|
package/dist/core/index.js
CHANGED
|
@@ -9,3 +9,4 @@ export { buildSystemPrompt } from './prompt.js';
|
|
|
9
9
|
export { builtinCommands, createSlashRegistry, parseSlashInput } from './slash.js';
|
|
10
10
|
export { clearSteering, drainSteering, injectSteering } from './steering.js';
|
|
11
11
|
export { executeToolCall, executeToolCalls, partitionByConflict } from './tool-exec.js';
|
|
12
|
+
export { containsWorkflow, WORKFLOW_NOTICE } from './workflow.js';
|
package/dist/core/loop.d.ts
CHANGED
|
@@ -22,4 +22,14 @@ export type { LoopDeps };
|
|
|
22
22
|
* def.isolated 时在 git worktree 中运行,结束后把 delta 自动 apply 回父仓库(spec §4.6)。
|
|
23
23
|
* request.background 时 fork 异步运行,立即返回 running(spec §4.7)。 */
|
|
24
24
|
export declare function runSubAgent(deps: LoopDeps, parent: AgentState, request: SubAgentRequest): Promise<SubAgentResult>;
|
|
25
|
+
/**
|
|
26
|
+
* 执行会话压缩并刷新 token 预算。
|
|
27
|
+
*
|
|
28
|
+
* 自动压缩(agentLoop 阈值触发)与手动 /compact 共用此逻辑:复用
|
|
29
|
+
* createSummarizer + runCompaction,压缩改写消息历史后标记下一段 trigger='compaction'。
|
|
30
|
+
*
|
|
31
|
+
* 成功时 yield 一条 text_delta 通知:手动 /compact 透传给用户;自动压缩由调用方
|
|
32
|
+
* 静默消费。失败时抛错,由调用方决定是否记录(自动压缩非致命,仅 console.warn)。
|
|
33
|
+
*/
|
|
34
|
+
export declare function compactContext(state: AgentState, deps: LoopDeps): AsyncGenerator<AgentEvent>;
|
|
25
35
|
export declare function agentLoop(state: AgentState, deps: LoopDeps): AsyncGenerator<AgentEvent>;
|