@oyasmi/pipiclaw 0.9.3-beta.3 → 0.9.3-beta.5
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.en.md +12 -12
- package/README.md +12 -12
- package/dist/agent/channel-runner.d.ts +4 -18
- package/dist/agent/channel-runner.js +26 -121
- package/dist/agent/context-budget.js +1 -1
- package/dist/agent/job-manager.d.ts +11 -17
- package/dist/agent/job-manager.js +77 -67
- package/dist/agent/prompt/builder.js +1 -17
- package/dist/agent/prompt/manifest.d.ts +0 -1
- package/dist/agent/prompt/manifest.js +2 -2
- package/dist/agent/prompt/sections.js +0 -9
- package/dist/agent/prompt/types.d.ts +2 -18
- package/dist/agent/prompt/types.js +1 -1
- package/dist/agent/runner-factory.d.ts +4 -0
- package/dist/agent/session-adapter.d.ts +19 -0
- package/dist/agent/session-adapter.js +77 -0
- package/dist/app-services.d.ts +18 -0
- package/dist/app-services.js +43 -0
- package/dist/channel/channel-context.d.ts +2 -2
- package/dist/channel/channel-context.js +2 -2
- package/dist/channel/channel-event.d.ts +3 -3
- package/dist/{runtime → events}/events.d.ts +1 -1
- package/dist/memory/journal.js +1 -1
- package/dist/memory/maintenance-gates.d.ts +0 -3
- package/dist/memory/maintenance-gates.js +2 -2
- package/dist/memory/maintenance-migration.d.ts +5 -0
- package/dist/memory/maintenance-migration.js +91 -0
- package/dist/memory/maintenance-state.js +5 -44
- package/dist/memory/migrate.js +1 -1
- package/dist/memory/reflect-job.d.ts +1 -9
- package/dist/memory/reflect-job.js +1 -3
- package/dist/memory/reflect.js +1 -1
- package/dist/memory/session-corpus.js +1 -1
- package/dist/memory/store.js +1 -1
- package/dist/models/auth-cli.js +1 -1
- package/dist/playbooks/agent-delegation.md +15 -11
- package/dist/playbooks/background-jobs.md +1 -1
- package/dist/playbooks/runtime-orientation.md +2 -0
- package/dist/playbooks/task-loop.md +1 -1
- package/dist/runtime/bootstrap.d.ts +5 -15
- package/dist/runtime/bootstrap.js +44 -65
- package/dist/runtime/delivery.d.ts +1 -2
- package/dist/runtime/delivery.js +57 -62
- package/dist/runtime/dingtalk.d.ts +15 -8
- package/dist/runtime/dingtalk.js +101 -35
- package/dist/runtime/subagent-commands.d.ts +2 -1
- package/dist/runtime/subagent-commands.js +10 -12
- package/dist/runtime/task-wake.d.ts +4 -5
- package/dist/runtime/task-wake.js +2 -12
- package/dist/security/types.d.ts +7 -0
- package/dist/security/types.js +16 -1
- package/dist/settings.d.ts +8 -0
- package/dist/settings.js +24 -1
- package/dist/shared/exact-keys.d.ts +13 -0
- package/dist/shared/exact-keys.js +1 -0
- package/dist/shared/format.d.ts +20 -0
- package/dist/shared/format.js +64 -0
- package/dist/shared/{fs-utils.d.ts → os.d.ts} +6 -0
- package/dist/shared/{fs-utils.js → os.js} +8 -0
- package/dist/subagents/discovery.d.ts +16 -3
- package/dist/subagents/discovery.js +13 -9
- package/dist/subagents/external/claude-code.js +3 -1
- package/dist/subagents/external/harness.d.ts +4 -2
- package/dist/subagents/external/run.d.ts +2 -1
- package/dist/subagents/external/run.js +13 -5
- package/dist/subagents/external/settlement.js +10 -5
- package/dist/subagents/format.d.ts +1 -1
- package/dist/subagents/format.js +1 -1
- package/dist/subagents/runs.d.ts +13 -12
- package/dist/subagents/runs.js +109 -91
- package/dist/subagents/tool.d.ts +7 -7
- package/dist/subagents/tool.js +11 -11
- package/dist/tasks/brief.js +1 -0
- package/dist/tools/command-optimizer.js +1 -1
- package/dist/tools/config.d.ts +7 -0
- package/dist/tools/config.js +16 -1
- package/dist/tools/event-manage.d.ts +1 -1
- package/dist/tools/event-manage.js +3 -3
- package/dist/tools/grep.js +1 -1
- package/dist/tools/index.d.ts +4 -0
- package/dist/tools/index.js +4 -2
- package/dist/tools/job.js +1 -1
- package/dist/tools/read.js +1 -1
- package/dist/tools/registry.d.ts +3 -3
- package/dist/tools/registry.js +18 -56
- package/dist/tools/skill.js +1 -1
- package/dist/tools/subagent-manage.d.ts +2 -0
- package/dist/tools/subagent-manage.js +7 -7
- package/dist/tools/subagent-tool-names.d.ts +2 -2
- package/dist/tools/subagent-tool-names.js +2 -2
- package/dist/tools/task-manage/shared.js +4 -9
- package/dist/tools/task-manage/types.d.ts +4 -0
- package/dist/tui/app.js +22 -7
- package/dist/web/config.js +1 -1
- package/examples/sub-agents/README.md +65 -81
- package/examples/sub-agents/agents/claude-high.md +23 -0
- package/examples/sub-agents/agents/claude-main.md +23 -0
- package/examples/sub-agents/agents/codex-flash.md +23 -0
- package/examples/sub-agents/agents/codex-high.md +23 -0
- package/examples/sub-agents/agents/codex-main.md +23 -0
- package/examples/sub-agents/agents/glm-flash.md +23 -0
- package/examples/sub-agents/agents/glm-high.md +23 -0
- package/package.json +2 -1
- package/dist/shared/duration.d.ts +0 -2
- package/dist/shared/duration.js +0 -7
- package/dist/shared/file-stamp.d.ts +0 -10
- package/dist/shared/file-stamp.js +0 -19
- package/dist/shared/numeric.d.ts +0 -7
- package/dist/shared/numeric.js +0 -19
- package/dist/shared/shell-escape.d.ts +0 -5
- package/dist/shared/shell-escape.js +0 -7
- package/dist/shared/token-estimate.d.ts +0 -1
- package/dist/shared/token-estimate.js +0 -19
- /package/dist/{runtime → events}/event-commands.d.ts +0 -0
- /package/dist/{runtime → events}/event-commands.js +0 -0
- /package/dist/{runtime → events}/event-validation.d.ts +0 -0
- /package/dist/{runtime → events}/event-validation.js +0 -0
- /package/dist/{runtime → events}/events.js +0 -0
- /package/examples/sub-agents/{builder-hard.md → roles/builder-hard.md} +0 -0
- /package/examples/sub-agents/{builder.md → roles/builder.md} +0 -0
- /package/examples/sub-agents/{explorer.md → roles/explorer.md} +0 -0
- /package/examples/sub-agents/{git-committer.md → roles/git-committer.md} +0 -0
- /package/examples/sub-agents/{planner.md → roles/planner.md} +0 -0
- /package/examples/sub-agents/{reviewer.md → roles/reviewer.md} +0 -0
- /package/examples/sub-agents/{verifier.md → roles/verifier.md} +0 -0
- /package/examples/sub-agents/{worker.md → roles/worker.md} +0 -0
|
@@ -1,4 +1,6 @@
|
|
|
1
1
|
import type { Static } from "typebox";
|
|
2
|
+
import type { ChannelJobManager } from "../../agent/job-manager.js";
|
|
3
|
+
import type { SubAgentRunManager } from "../../subagents/runs.js";
|
|
2
4
|
import type { taskCloseSchema, taskCreateSchema, taskLogSchema, taskStepEndSchema, taskUpdateSchema } from "./schema.js";
|
|
3
5
|
export interface TaskManageResult {
|
|
4
6
|
action: "create" | "update" | "close" | "list" | "log" | "step_end";
|
|
@@ -31,6 +33,8 @@ export type TaskCloseRequest = Static<typeof taskCloseSchema>;
|
|
|
31
33
|
export type TaskLogRequest = Static<typeof taskLogSchema>;
|
|
32
34
|
export type TaskStepEndRequest = Static<typeof taskStepEndSchema>;
|
|
33
35
|
export interface TaskManageToolOptions {
|
|
36
|
+
jobManager: ChannelJobManager;
|
|
37
|
+
runManager: SubAgentRunManager;
|
|
34
38
|
workspaceDir: string;
|
|
35
39
|
channelDir: string;
|
|
36
40
|
channelId: string;
|
package/dist/tui/app.js
CHANGED
|
@@ -7,22 +7,24 @@
|
|
|
7
7
|
* preparation shares `prepareAppServices` with the DingTalk path.
|
|
8
8
|
*/
|
|
9
9
|
import { userInfo } from "node:os";
|
|
10
|
-
import {
|
|
10
|
+
import { createJobRuntime } from "../agent/job-manager.js";
|
|
11
11
|
import { createRunner } from "../agent/runner-factory.js";
|
|
12
|
+
import { prepareAppServices } from "../app-services.js";
|
|
12
13
|
import { ensureChannelDir } from "../channel/channel-paths.js";
|
|
13
14
|
import { ChannelStore } from "../channel/store.js";
|
|
14
15
|
import { renderBuiltInHelp } from "../commands/catalog.js";
|
|
16
|
+
import { handleEventsCommand } from "../events/event-commands.js";
|
|
17
|
+
import { createExecutor } from "../executor.js";
|
|
15
18
|
import * as log from "../log.js";
|
|
19
|
+
import { migrateMemoryMaintenanceStates } from "../memory/maintenance-migration.js";
|
|
16
20
|
import { BootstrapExitError, bootstrapAppHome, DEFAULT_BOOTSTRAP_PATHS, printBootstrapSummary, readCliVersion, } from "../runtime/app-home.js";
|
|
17
|
-
import { prepareAppServices } from "../runtime/bootstrap.js";
|
|
18
21
|
import { finalDeliveryOf, progressStyleOf } from "../runtime/dingtalk.js";
|
|
19
|
-
import { handleEventsCommand } from "../runtime/event-commands.js";
|
|
20
22
|
import { handleProjectCommand } from "../runtime/project-commands.js";
|
|
21
23
|
import { handleSkillsCommand } from "../runtime/skill-commands.js";
|
|
22
24
|
import { handleSubagentsCommand } from "../runtime/subagent-commands.js";
|
|
23
25
|
import { handleTasksCommand } from "../runtime/task-commands.js";
|
|
24
26
|
import { flushSecurityLogs } from "../security/logger.js";
|
|
25
|
-
import {
|
|
27
|
+
import { createSubAgentRuntime } from "../subagents/runs.js";
|
|
26
28
|
import { getUsageLedger } from "../usage/ledger.js";
|
|
27
29
|
import { parseUsageMode, renderUsageReport } from "../usage/render.js";
|
|
28
30
|
import { TUI_SLASH_COMMANDS } from "./commands.js";
|
|
@@ -99,9 +101,14 @@ export async function runTuiApp(options) {
|
|
|
99
101
|
const { settingsManager } = prepareAppServices(paths);
|
|
100
102
|
log.configureLogging(settingsManager.getLoggingSettings());
|
|
101
103
|
log.logStartup(paths.workspaceDir);
|
|
104
|
+
await migrateMemoryMaintenanceStates(paths.appHomeDir);
|
|
102
105
|
const channelDir = ensureChannelDir(paths.workspaceDir, channelId);
|
|
103
106
|
const store = new ChannelStore({ workingDir: paths.workspaceDir });
|
|
107
|
+
const jobs = createJobRuntime(createExecutor());
|
|
108
|
+
const runs = createSubAgentRuntime();
|
|
104
109
|
const buildRunner = () => createRunner(channelId, channelDir, {
|
|
110
|
+
jobManager: jobs.get(channelId),
|
|
111
|
+
runManager: runs.get(channelId),
|
|
105
112
|
appHomeDir: paths.appHomeDir,
|
|
106
113
|
authConfigPath: paths.authConfigPath,
|
|
107
114
|
modelsConfigPath: paths.modelsConfigPath,
|
|
@@ -139,7 +146,12 @@ export async function runTuiApp(options) {
|
|
|
139
146
|
workspaceDir: paths.workspaceDir,
|
|
140
147
|
channelId,
|
|
141
148
|
}),
|
|
142
|
-
runSubagents: (args) => handleSubagentsCommand({
|
|
149
|
+
runSubagents: (args) => handleSubagentsCommand({
|
|
150
|
+
runManager: runs.get(channelId),
|
|
151
|
+
args,
|
|
152
|
+
channelId,
|
|
153
|
+
discovery: runner.getSubAgentDiscoverySnapshot(),
|
|
154
|
+
}),
|
|
143
155
|
runSkills: (args) => handleSkillsCommand({ args, workspaceDir: paths.workspaceDir, appHomeDir: paths.appHomeDir, channelId }),
|
|
144
156
|
runProject: (args) => handleProjectCommand({
|
|
145
157
|
args,
|
|
@@ -149,11 +161,12 @@ export async function runTuiApp(options) {
|
|
|
149
161
|
actor: "tui-command",
|
|
150
162
|
isBusy: () => runner.isBusy(),
|
|
151
163
|
listActiveBlockers: () => [
|
|
152
|
-
...
|
|
164
|
+
...runs
|
|
165
|
+
.get(channelId)
|
|
153
166
|
.list()
|
|
154
167
|
.filter((record) => record.status === "running")
|
|
155
168
|
.map((record) => `subagent run \`${record.runId}\` (${record.agent})`),
|
|
156
|
-
...
|
|
169
|
+
...jobs.runningLines(channelId),
|
|
157
170
|
],
|
|
158
171
|
onScopeChanged: async () => {
|
|
159
172
|
await runner.dispose();
|
|
@@ -172,6 +185,8 @@ export async function runTuiApp(options) {
|
|
|
172
185
|
}
|
|
173
186
|
finally {
|
|
174
187
|
await runner.dispose();
|
|
188
|
+
runs.stop();
|
|
189
|
+
jobs.stop();
|
|
175
190
|
await waitForStorageFlush(Promise.allSettled([store.close(), getUsageLedger().flush?.() ?? Promise.resolve(), flushSecurityLogs()]));
|
|
176
191
|
await waitForStorageFlush(log.flushLogging());
|
|
177
192
|
}
|
package/dist/web/config.js
CHANGED
|
@@ -1,116 +1,100 @@
|
|
|
1
|
-
#
|
|
1
|
+
# 工作区智能体配置示例
|
|
2
2
|
|
|
3
|
-
|
|
3
|
+
这里的文件是配置示例,Pipiclaw **不会自动加载**。只有复制到 `~/.pipiclaw/workspace/sub-agents/` 才会生效,而且加载是**平铺**的——只读该目录下的 `*.md`,不会递归子目录。所以本目录的两个子目录只是分类方式,复制时要把文件放到 `sub-agents/` 下,不要连目录一起复制。
|
|
4
4
|
|
|
5
|
-
|
|
5
|
+
- [`agents/`](./agents/) — **推荐**。按能力与成本组织:把 agent、模型和推理档直接交给 Pipiclaw,由它按需选择。
|
|
6
|
+
- [`roles/`](./roles/) — 早期的岗位角色(planner / builder / reviewer / verifier …),保留作参考和迁移对照。
|
|
6
7
|
|
|
7
|
-
|
|
8
|
+
两套**不要同时装**:同一件事有两种选法,只会让主代理多做一次无意义的判断,还会一起占用系统提示词里子代理目录的预算。
|
|
8
9
|
|
|
9
|
-
|
|
10
|
-
# 常用五角色(内置的 explorer / git-committer 无需额外安装;builder 需要 claude,reviewer / verifier 需要 codex):
|
|
11
|
-
cp examples/sub-agents/{explorer,git-committer,builder,reviewer,verifier}.md ~/.pipiclaw/workspace/sub-agents/
|
|
12
|
-
|
|
13
|
-
# 按需补充:
|
|
14
|
-
cp examples/sub-agents/{planner,builder-hard}.md ~/.pipiclaw/workspace/sub-agents/ # 需要 claude
|
|
15
|
-
cp examples/sub-agents/worker.md ~/.pipiclaw/workspace/sub-agents/ # 需要 codex
|
|
16
|
-
```
|
|
17
|
-
|
|
18
|
-
通过 npm 全局安装时,模板位于包目录:
|
|
19
|
-
|
|
20
|
-
```bash
|
|
21
|
-
PIPICLAW_PACKAGE_DIR="$(npm root -g)/@oyasmi/pipiclaw"
|
|
22
|
-
cp "$PIPICLAW_PACKAGE_DIR"/examples/sub-agents/{builder,reviewer}.md \
|
|
23
|
-
~/.pipiclaw/workspace/sub-agents/
|
|
24
|
-
```
|
|
10
|
+
## 为什么从「角色」改成「能力条目」
|
|
25
11
|
|
|
26
|
-
|
|
12
|
+
一个角色文件过去同时承担三件事:能力与成本绑定(harness / command / model / thinkingLevel)、权限姿态(sandbox + `mutates`)、以及一段岗位说明书式的正文。前两件属于部署者,第三件不属于——它是在不知道本轮任务的情况下提前写死的任务框架,而真正掌握上下文的是发起委派的主代理。
|
|
27
13
|
|
|
28
|
-
|
|
14
|
+
结果就是路由变成「任务 → 猜别人起的职位名」,而且正文会反过来限制场景:让 codex 读一张图,`worker` 的正文开头是"你负责交付独立的数据分析、批处理、报告或文档产物";想让实现者顺带提交,`builder` 的正文写死"不 commit、push"。
|
|
29
15
|
|
|
30
|
-
|
|
31
|
-
- **git-committer**:把用户明确指定的现有改动整理成本地 commit;默认不 push。
|
|
16
|
+
`agents/` 把岗位说明书去掉,只留能力声明和一段与任务无关的交付约定。路由变成「任务 → 需要什么能力、能付多少代价」,这是主代理做得了的判断,因为它知道任务是什么。
|
|
32
17
|
|
|
33
|
-
##
|
|
18
|
+
## 安装 `agents/`
|
|
34
19
|
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|---|---|---|---|---|---|---|
|
|
39
|
-
| `builder` | 常用 | claude-code | `sonnet` | `write` | medium | 边界明确的产品改动:代码、必要测试、相关文档和仓库必跑检查一起交付 |
|
|
40
|
-
| `reviewer` | 常用 | codex-cli | `gpt-5.6-sol` | `read` | high | 与产出者分离的方案 / 代码 / 文档挑错,也可承担只读 `purpose=verify` |
|
|
41
|
-
| `verifier` | 常用 | codex-cli | `gpt-5.6-luna` | `write` | xhigh | 对最终产物逐项核验完成标准,运行必要检查并取证 |
|
|
42
|
-
| `planner` | 按需 | claude-code | `opus` | `read` | high | 调查一个会显著影响方案或返工成本的未决问题 |
|
|
43
|
-
| `builder-hard` | 按需 | claude-code | `opus` | `write` | xhigh | 高不确定性、跨契约耦合的实现与修复;代价显著更高 |
|
|
44
|
-
| `worker` | 按需 | codex-cli | `gpt-5.6-sol` | `write` | medium | 独立的数据分析、批处理、报告和文档产物 |
|
|
20
|
+
```bash
|
|
21
|
+
# 源码 checkout:
|
|
22
|
+
cp examples/sub-agents/agents/*.md ~/.pipiclaw/workspace/sub-agents/
|
|
45
23
|
|
|
46
|
-
|
|
24
|
+
# npm 全局安装:
|
|
25
|
+
PIPICLAW_PACKAGE_DIR="$(npm root -g)/@oyasmi/pipiclaw"
|
|
26
|
+
cp "$PIPICLAW_PACKAGE_DIR"/examples/sub-agents/agents/*.md ~/.pipiclaw/workspace/sub-agents/
|
|
27
|
+
```
|
|
47
28
|
|
|
48
|
-
|
|
29
|
+
只装你真的有账号的那几个:条目里的 CLI 不在 PATH 上时不会被丢弃,而是标成 `unavailable` 并在调用时才报错。
|
|
49
30
|
|
|
50
|
-
|
|
|
51
|
-
|
|
52
|
-
|
|
|
53
|
-
|
|
|
54
|
-
|
|
|
55
|
-
|
|
|
56
|
-
|
|
|
57
|
-
|
|
|
58
|
-
|
|
|
31
|
+
| 条目 | harness | `model` | `thinkingLevel` | 多模态 | 定位 |
|
|
32
|
+
|---|---|---|---|---|---|
|
|
33
|
+
| `claude-high` | claude-code | `opus` | high | 否 | 代码与推理最强,成本最高:设计、取舍分析、根因不明的疑难 |
|
|
34
|
+
| `claude-main` | claude-code | `sonnet` | medium | 否 | 代码能力最强的主力档:实现、修改、文档、排查 |
|
|
35
|
+
| `codex-high` | codex-cli | `gpt-6-astra` | high | 是 | 高智能档,可读图片:设计、方案权衡、复杂分析 |
|
|
36
|
+
| `codex-main` | codex-cli | `gpt-6-astra` | medium | 是 | 主力档,可读图片:常规实现、排查、文档 |
|
|
37
|
+
| `codex-flash` | codex-cli | `gpt-5.6-luna` | medium | 是 | 最快最便宜,可读图片:明确、简单、重复的工作 |
|
|
38
|
+
| `glm-high` | claude-code | `glm-5.3` | high | 否 | 高智能档,额度宽松:高频使用不挤占 claude/codex 配额 |
|
|
39
|
+
| `glm-flash` | claude-code | `glm-5.3-flash` | medium | 是 | 最便宜,可读图片:大批量简单重复工作的首选 |
|
|
59
40
|
|
|
60
|
-
|
|
41
|
+
三档的分工是这套配置的主要内容:**flash** 用于「做什么和怎么做都已清楚,只差有人去做」,可以大量派发;**main** 是主力,绝大多数实现、排查、文档都在这里,也包括 token 消耗很大的长任务;**high** 只留给这一轮真正需要新判断或取舍的工作。对已经定好的活派 high,只是更贵,不会更对。
|
|
61
42
|
|
|
62
|
-
|
|
43
|
+
额度是真实约束:claude 和 codex 的订阅有周/月上限,GLM 只有 5 小时滚动限额、没有周月上限。所以简单重复的批量工作优先走 `glm-flash`,把受限额度留给难题。
|
|
63
44
|
|
|
64
|
-
|
|
45
|
+
### GLM 条目需要一个包装脚本
|
|
65
46
|
|
|
66
|
-
`
|
|
47
|
+
`glm-high` / `glm-flash` 走 claude-code harness,但要用独立的配置目录指向 Z.ai 的 Anthropic 兼容端点,因此 `command` 是一个包装脚本而不是 `claude` 本身。把它放到 PATH 上:
|
|
67
48
|
|
|
68
|
-
|
|
49
|
+
```bash
|
|
50
|
+
#!/bin/bash
|
|
51
|
+
# ~/bin/claude-zai.sh
|
|
52
|
+
export CLAUDE_CONFIG_DIR="$HOME/.claude-zai"
|
|
53
|
+
exec claude --dangerously-skip-permissions "$@"
|
|
54
|
+
```
|
|
69
55
|
|
|
70
|
-
|
|
56
|
+
首次使用前在 `CLAUDE_CONFIG_DIR` 里完成一次登录/配置。用其他供应商同理:换配置目录和脚本名,`harness` 仍是 `claude-code`。
|
|
71
57
|
|
|
72
|
-
|
|
58
|
+
## 正文:一段与任务无关的交付约定
|
|
73
59
|
|
|
74
|
-
|
|
60
|
+
每个条目的正文是同一段 9 条约束,逐字相同。它**不描述这个条目做什么工作**——那是每次 `task` 的事——只约束怎么取证和怎么交付:不做未授权的动作、不动任务外的既有改动、结论不超过证据、不编造检查结果、不靠削弱断言制造通过、先结论后证据位置、用中文并保留原文。
|
|
75
61
|
|
|
76
|
-
|
|
62
|
+
留着它是因为这几条跨每一个任务都成立,漏掉的代价又很高(尤其是伪造绿色检查结果和把未验证写成已验证),而让主代理每次委派重打一遍既费 token 又会漂移。
|
|
77
63
|
|
|
78
|
-
|
|
79
|
-
- 正文补充跨任务稳定的角色职责、权限边界、证据原则和交接需要;调查顺序、工具选择、实现步骤与报告结构由具体任务和执行者判断。内置执行者直接使用角色 `systemPrompt`,claude-code harness 通过 `--append-system-prompt-file` 追加,codex-cli 则把正文和 task 一起写进 stdin。调 prompt 时请核对 run 里实际的 `system-prompt.txt` / `prompt.txt` 和 argv,不要只审模板 Markdown。
|
|
80
|
-
- 子代理默认看不到主会话。委派时的 `task` 应提供目标、范围、关键上下文、约束和完成标准,不能只写「按上文处理」。指定检查方法或输出格式仅在本轮确有需要时补充;给足结果要求,让执行者选择实现路径。
|
|
81
|
-
- **工作目录每次委派现场决定**。角色文件里不能写 `cwd`(会被驳回),只能在调用时传 `workingDirectory`。两个 `mutates: write` 的委派不能指向同一棵工作树——runtime 的排他写锁会拒绝第二个,并点名持有者;并行实现请先 `git worktree add` 再分别指向。
|
|
82
|
-
- 内置角色的 `tools`、上下文模式和四个数值预算在模板中显式配置,方便审查和按成本调整。**调用 `subagent` 指定已配置角色时没有任何覆盖字段**:工具、模型、预算、上下文和推理档位全部来自角色文件,要改就改 frontmatter。`effort` 只属于 `subagent_inline`(内联委派恒为内置),传了就整组替换四个数值预算。
|
|
83
|
-
- `tools` 只是工具白名单,不等同于只读沙箱。拥有 `bash` 的内置角色仍须遵守正文和应用级 `security.json` 的限制。
|
|
84
|
-
- 外部角色**没有** `tools` 字段(写了会被驳回)。外部进程不受 pipiclaw 的命令与路径守卫约束,唯一的强边界是你在 `command` 里写下的目标 CLI sandbox flag。
|
|
85
|
-
- 所有 Git 提交统一交给 `git-committer`;它只有在任务明确转述用户要求 push 时才可推送。创建 commit 不会自动获得 push 授权。
|
|
86
|
-
- 委派运行和完成时,频道会收到一条独立于唤醒的状态提醒(`⏳ 进度` / `✅ 完成`,见 `settings.json` 的 `delegation.notices`);这只是"活着/结束了"的信号,不含内容——角色最终消息的结论仍要由主代理读到并转述给用户,不能假设用户已经看到了。
|
|
64
|
+
要改就 7 个文件一起改。也可以整段删掉:runtime 允许外部条目的正文为空,此时不会生成 `system-prompt.txt`,claude-code 不追加 `--append-system-prompt-file`,codex 的 stdin 就是 task 本身。
|
|
87
65
|
|
|
88
|
-
|
|
66
|
+
## 这套配置的代价,别忽略
|
|
89
67
|
|
|
90
|
-
|
|
68
|
+
- **全部是放开权限的写条目。** 7 个条目都用 yolo 参数(`claude --dangerously-skip-permissions` / `codex exec --dangerously-bypass-approvals-and-sandbox`)并声明 `mutates: write`,没有 sandbox 兜底。实际边界只剩宿主账号和 `task` 里写明的范围,**必须在可信 checkout 和最小权限账号下使用**。需要真只读时,自己加一个 `--permission-mode plan` 或 `--sandbox read-only` 的条目。
|
|
69
|
+
- **同一工作目录同时只容得下一个外部委派。** `mutates: write` 会取目标工作区的排他 lease(含父子目录冲突),并行必须各自 `git worktree`。这是把只读条目去掉换来的。
|
|
70
|
+
- **`purpose=verify` 的 attestation 一律是 `advisory`。** `enforced` 只在 `mutates: read` 且工具集不含 `bash` 时才成立,这套条目里没有这样的。PASS 不能直接采信,要自己核对真实产物、diff 和检查输出。
|
|
71
|
+
- **独立性不再由角色提示词提供。** 要评审或验收时,必须在 `task` 里写明"你是检查者,不修实现,不把实现者的总结当作预期行为的来源",并给出同一份验收口径和待检版本。换一个条目不会自动带来独立性。
|
|
91
72
|
|
|
92
|
-
|
|
73
|
+
## `roles/` 里的岗位角色
|
|
93
74
|
|
|
94
|
-
|
|
75
|
+
[`roles/`](./roles/) 保留了早期的 8 个角色:`explorer`、`git-committer`(内置)和 `planner`、`builder`、`builder-hard`、`reviewer`、`verifier`、`worker`(外部)。它们仍然可用,在两种情况下仍有价值:
|
|
95
76
|
|
|
96
|
-
|
|
77
|
+
- 需要**真正的只读执行边界**:`planner` 的 `--permission-mode plan`、`reviewer` 的 `--sandbox read-only` 是目标 CLI 提供的真实限制,不只是提示词声明;`reviewer` 承担 `purpose=verify` 时也不占工作区写锁。
|
|
78
|
+
- 需要**固定的、反复出现的作业纪律**:`git-committer` 的暂存区隔离规则就是一例——它约束的是一类操作的正确做法,不是一个岗位。
|
|
97
79
|
|
|
98
|
-
|
|
80
|
+
反过来,`builder` / `builder-hard` / `worker` 和 `agents/` 里的对应档位重叠严重,正文里的岗位设定是净损失,不建议再装。
|
|
99
81
|
|
|
100
82
|
## 从早期模板迁移
|
|
101
83
|
|
|
102
|
-
|
|
84
|
+
已经复制到工作区的旧角色文件不会被自动删除,需要手动处理:
|
|
103
85
|
|
|
104
|
-
|
|
105
|
-
-
|
|
86
|
+
```bash
|
|
87
|
+
cd ~/.pipiclaw/workspace/sub-agents
|
|
88
|
+
rm -f builder.md builder-hard.md worker.md planner.md reviewer.md verifier.md
|
|
89
|
+
cp /path/to/pipiclaw/examples/sub-agents/agents/*.md .
|
|
90
|
+
```
|
|
106
91
|
|
|
107
|
-
|
|
92
|
+
迁移期间历史 task 的委派记录里仍会出现旧角色名;`subagent_run op=follow_up` 只能续接条目仍然存在且 `command`/`model`/`shell` 未变的 run,删掉旧文件后这些 run 需要重新委派。
|
|
108
93
|
|
|
109
|
-
##
|
|
94
|
+
## 自己写条目
|
|
110
95
|
|
|
111
|
-
- **`
|
|
112
|
-
-
|
|
113
|
-
-
|
|
114
|
-
-
|
|
115
|
-
-
|
|
116
|
-
- 第三种 harness `exec`(任意脚本,无协议终态)本目录不提供示例:它没有完成事件,`usageKnown` / `costKnown` 恒为 false,且不能承担 `purpose=verify`。需要接入其他 CLI 时再参考 [../../docs/sub-agents.md](../../docs/sub-agents.md)。
|
|
96
|
+
- **`description` 是唯一的路由依据。** 它进入主代理的系统提示词(子代理目录,预算 2400 字符),正文不在那里——改正文修不了选错条目。每条写清:能力特征、相对成本、适用场景,以及会改变选择的边界(能不能读图片、额度是否受限)。`runtime` / `workload` / `mutates` 已由目录分组展示,不要在文字里重复。
|
|
97
|
+
- **描述必须属实且可核查。** 写错一句"支持图片输入",代价是一次几十分钟后才失败的委派,比不写更糟。
|
|
98
|
+
- **不要扩到十几个条目。** agent × 档位 × 权限很容易组合爆炸。每加一个都先问:主代理会因为它做出不同的路由决定吗?答不上来就不该存在。
|
|
99
|
+
- **调 prompt 时看实际发出的内容。** 正文对 claude-code 经 `--append-system-prompt-file` 追加,对 codex-cli 与 task 一起写进 stdin;核对 run 目录里真实的 `system-prompt.txt` / `prompt.txt` 和 argv,不要只审模板 Markdown。
|
|
100
|
+
- 委派的写法、并行隔离、等待与续接见 [../../docs/sub-agents.md](../../docs/sub-agents.md) 与运行时的 `agent-delegation.md` playbook。
|
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
---
|
|
2
|
+
name: claude-high
|
|
3
|
+
description: >-
|
|
4
|
+
代码与推理能力最强的一档,成本也最高。适合设计、定方案、取舍分析和根因不明的疑难排查;常规实现用 claude-main。只接受文本。
|
|
5
|
+
runtime: external
|
|
6
|
+
harness: claude-code
|
|
7
|
+
command: claude --dangerously-skip-permissions
|
|
8
|
+
model: opus
|
|
9
|
+
thinkingLevel: high
|
|
10
|
+
workload: heavy
|
|
11
|
+
mutates: write
|
|
12
|
+
maxWallTimeSec: 5400
|
|
13
|
+
---
|
|
14
|
+
|
|
15
|
+
- task 没有授权的动作不做:提交、推送、部署、发消息、写入外部系统或真实数据。
|
|
16
|
+
- 保护任务之外的既有改动,不覆盖、不回退、不顺带纳入;范围外的问题只报告。
|
|
17
|
+
- 能自己查清的缺口继续查;会实质改变目标、授权或数据边界又查不到的,停在最小阻塞点交回,不靠猜测补齐。
|
|
18
|
+
- 结论强度不超过证据;未运行、未复现、未验证的明确标注。
|
|
19
|
+
- 不编造数据、命令输出、文件内容或检查结果。
|
|
20
|
+
- 命令失败时保留真实输出,不通过削弱断言、跳过用例或改口径制造通过。
|
|
21
|
+
- 先给结论,再给支撑它的证据位置(`path:line`、命令与关键结果)和会影响判断的不确定项。
|
|
22
|
+
- 用证据位置代替大段原文或 diff;篇幅与任务复杂度匹配,长回复末尾补一句当前状态和必要的下一步。
|
|
23
|
+
- 用中文;代码、路径、命令、标识符和错误保持原文。
|
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
---
|
|
2
|
+
name: claude-main
|
|
3
|
+
description: >-
|
|
4
|
+
代码能力最强的主力档,成本中等。写代码、改实现、写文档、排查问题的默认选择,适合 token 消耗大的长任务。只接受文本。
|
|
5
|
+
runtime: external
|
|
6
|
+
harness: claude-code
|
|
7
|
+
command: claude --dangerously-skip-permissions
|
|
8
|
+
model: sonnet
|
|
9
|
+
thinkingLevel: medium
|
|
10
|
+
workload: heavy
|
|
11
|
+
mutates: write
|
|
12
|
+
maxWallTimeSec: 5400
|
|
13
|
+
---
|
|
14
|
+
|
|
15
|
+
- task 没有授权的动作不做:提交、推送、部署、发消息、写入外部系统或真实数据。
|
|
16
|
+
- 保护任务之外的既有改动,不覆盖、不回退、不顺带纳入;范围外的问题只报告。
|
|
17
|
+
- 能自己查清的缺口继续查;会实质改变目标、授权或数据边界又查不到的,停在最小阻塞点交回,不靠猜测补齐。
|
|
18
|
+
- 结论强度不超过证据;未运行、未复现、未验证的明确标注。
|
|
19
|
+
- 不编造数据、命令输出、文件内容或检查结果。
|
|
20
|
+
- 命令失败时保留真实输出,不通过削弱断言、跳过用例或改口径制造通过。
|
|
21
|
+
- 先给结论,再给支撑它的证据位置(`path:line`、命令与关键结果)和会影响判断的不确定项。
|
|
22
|
+
- 用证据位置代替大段原文或 diff;篇幅与任务复杂度匹配,长回复末尾补一句当前状态和必要的下一步。
|
|
23
|
+
- 用中文;代码、路径、命令、标识符和错误保持原文。
|
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
---
|
|
2
|
+
name: codex-flash
|
|
3
|
+
description: >-
|
|
4
|
+
最快最便宜的一档,成本远低于 high/main,可接受图片输入。适合明确、简单、重复的工作,可大量派发;额度紧张时优先 glm-flash。
|
|
5
|
+
runtime: external
|
|
6
|
+
harness: codex-cli
|
|
7
|
+
command: codex exec --dangerously-bypass-approvals-and-sandbox --skip-git-repo-check
|
|
8
|
+
model: gpt-5.6-luna
|
|
9
|
+
thinkingLevel: medium
|
|
10
|
+
workload: heavy
|
|
11
|
+
mutates: write
|
|
12
|
+
maxWallTimeSec: 3600
|
|
13
|
+
---
|
|
14
|
+
|
|
15
|
+
- task 没有授权的动作不做:提交、推送、部署、发消息、写入外部系统或真实数据。
|
|
16
|
+
- 保护任务之外的既有改动,不覆盖、不回退、不顺带纳入;范围外的问题只报告。
|
|
17
|
+
- 能自己查清的缺口继续查;会实质改变目标、授权或数据边界又查不到的,停在最小阻塞点交回,不靠猜测补齐。
|
|
18
|
+
- 结论强度不超过证据;未运行、未复现、未验证的明确标注。
|
|
19
|
+
- 不编造数据、命令输出、文件内容或检查结果。
|
|
20
|
+
- 命令失败时保留真实输出,不通过削弱断言、跳过用例或改口径制造通过。
|
|
21
|
+
- 先给结论,再给支撑它的证据位置(`path:line`、命令与关键结果)和会影响判断的不确定项。
|
|
22
|
+
- 用证据位置代替大段原文或 diff;篇幅与任务复杂度匹配,长回复末尾补一句当前状态和必要的下一步。
|
|
23
|
+
- 用中文;代码、路径、命令、标识符和错误保持原文。
|
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
---
|
|
2
|
+
name: codex-high
|
|
3
|
+
description: >-
|
|
4
|
+
高智能档,成本最高,可接受图片等多模态输入。适合设计、方案权衡与复杂分析;纯代码任务 claude-high 更强。
|
|
5
|
+
runtime: external
|
|
6
|
+
harness: codex-cli
|
|
7
|
+
command: codex exec --dangerously-bypass-approvals-and-sandbox --skip-git-repo-check
|
|
8
|
+
model: gpt-6-astra
|
|
9
|
+
thinkingLevel: high
|
|
10
|
+
workload: heavy
|
|
11
|
+
mutates: write
|
|
12
|
+
maxWallTimeSec: 5400
|
|
13
|
+
---
|
|
14
|
+
|
|
15
|
+
- task 没有授权的动作不做:提交、推送、部署、发消息、写入外部系统或真实数据。
|
|
16
|
+
- 保护任务之外的既有改动,不覆盖、不回退、不顺带纳入;范围外的问题只报告。
|
|
17
|
+
- 能自己查清的缺口继续查;会实质改变目标、授权或数据边界又查不到的,停在最小阻塞点交回,不靠猜测补齐。
|
|
18
|
+
- 结论强度不超过证据;未运行、未复现、未验证的明确标注。
|
|
19
|
+
- 不编造数据、命令输出、文件内容或检查结果。
|
|
20
|
+
- 命令失败时保留真实输出,不通过削弱断言、跳过用例或改口径制造通过。
|
|
21
|
+
- 先给结论,再给支撑它的证据位置(`path:line`、命令与关键结果)和会影响判断的不确定项。
|
|
22
|
+
- 用证据位置代替大段原文或 diff;篇幅与任务复杂度匹配,长回复末尾补一句当前状态和必要的下一步。
|
|
23
|
+
- 用中文;代码、路径、命令、标识符和错误保持原文。
|
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
---
|
|
2
|
+
name: codex-main
|
|
3
|
+
description: >-
|
|
4
|
+
主力档,成本中等,可接受图片等多模态输入。常规实现、排查和文档产出;代码能力略逊 claude-main,与 glm 相当。
|
|
5
|
+
runtime: external
|
|
6
|
+
harness: codex-cli
|
|
7
|
+
command: codex exec --dangerously-bypass-approvals-and-sandbox --skip-git-repo-check
|
|
8
|
+
model: gpt-6-astra
|
|
9
|
+
thinkingLevel: medium
|
|
10
|
+
workload: heavy
|
|
11
|
+
mutates: write
|
|
12
|
+
maxWallTimeSec: 5400
|
|
13
|
+
---
|
|
14
|
+
|
|
15
|
+
- task 没有授权的动作不做:提交、推送、部署、发消息、写入外部系统或真实数据。
|
|
16
|
+
- 保护任务之外的既有改动,不覆盖、不回退、不顺带纳入;范围外的问题只报告。
|
|
17
|
+
- 能自己查清的缺口继续查;会实质改变目标、授权或数据边界又查不到的,停在最小阻塞点交回,不靠猜测补齐。
|
|
18
|
+
- 结论强度不超过证据;未运行、未复现、未验证的明确标注。
|
|
19
|
+
- 不编造数据、命令输出、文件内容或检查结果。
|
|
20
|
+
- 命令失败时保留真实输出,不通过削弱断言、跳过用例或改口径制造通过。
|
|
21
|
+
- 先给结论,再给支撑它的证据位置(`path:line`、命令与关键结果)和会影响判断的不确定项。
|
|
22
|
+
- 用证据位置代替大段原文或 diff;篇幅与任务复杂度匹配,长回复末尾补一句当前状态和必要的下一步。
|
|
23
|
+
- 用中文;代码、路径、命令、标识符和错误保持原文。
|
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
---
|
|
2
|
+
name: glm-flash
|
|
3
|
+
description: >-
|
|
4
|
+
最便宜的一档,可接受图片输入;5 小时滚动限额、无周/月上限。简单、重复、可大批量派发的工作优先用它,把 claude/codex 额度留给难题。
|
|
5
|
+
runtime: external
|
|
6
|
+
harness: claude-code
|
|
7
|
+
command: claude-zai.sh
|
|
8
|
+
model: glm-5.3-flash
|
|
9
|
+
thinkingLevel: medium
|
|
10
|
+
workload: heavy
|
|
11
|
+
mutates: write
|
|
12
|
+
maxWallTimeSec: 3600
|
|
13
|
+
---
|
|
14
|
+
|
|
15
|
+
- task 没有授权的动作不做:提交、推送、部署、发消息、写入外部系统或真实数据。
|
|
16
|
+
- 保护任务之外的既有改动,不覆盖、不回退、不顺带纳入;范围外的问题只报告。
|
|
17
|
+
- 能自己查清的缺口继续查;会实质改变目标、授权或数据边界又查不到的,停在最小阻塞点交回,不靠猜测补齐。
|
|
18
|
+
- 结论强度不超过证据;未运行、未复现、未验证的明确标注。
|
|
19
|
+
- 不编造数据、命令输出、文件内容或检查结果。
|
|
20
|
+
- 命令失败时保留真实输出,不通过削弱断言、跳过用例或改口径制造通过。
|
|
21
|
+
- 先给结论,再给支撑它的证据位置(`path:line`、命令与关键结果)和会影响判断的不确定项。
|
|
22
|
+
- 用证据位置代替大段原文或 diff;篇幅与任务复杂度匹配,长回复末尾补一句当前状态和必要的下一步。
|
|
23
|
+
- 用中文;代码、路径、命令、标识符和错误保持原文。
|
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
---
|
|
2
|
+
name: glm-high
|
|
3
|
+
description: >-
|
|
4
|
+
高智能档,代码能力与 codex 相当、逊于 claude;订阅只有 5 小时滚动限额,无周/月上限,适合高频使用而不挤占 claude/codex 额度。只接受文本。
|
|
5
|
+
runtime: external
|
|
6
|
+
harness: claude-code
|
|
7
|
+
command: claude-zai.sh
|
|
8
|
+
model: glm-5.3
|
|
9
|
+
thinkingLevel: high
|
|
10
|
+
workload: heavy
|
|
11
|
+
mutates: write
|
|
12
|
+
maxWallTimeSec: 5400
|
|
13
|
+
---
|
|
14
|
+
|
|
15
|
+
- task 没有授权的动作不做:提交、推送、部署、发消息、写入外部系统或真实数据。
|
|
16
|
+
- 保护任务之外的既有改动,不覆盖、不回退、不顺带纳入;范围外的问题只报告。
|
|
17
|
+
- 能自己查清的缺口继续查;会实质改变目标、授权或数据边界又查不到的,停在最小阻塞点交回,不靠猜测补齐。
|
|
18
|
+
- 结论强度不超过证据;未运行、未复现、未验证的明确标注。
|
|
19
|
+
- 不编造数据、命令输出、文件内容或检查结果。
|
|
20
|
+
- 命令失败时保留真实输出,不通过削弱断言、跳过用例或改口径制造通过。
|
|
21
|
+
- 先给结论,再给支撑它的证据位置(`path:line`、命令与关键结果)和会影响判断的不确定项。
|
|
22
|
+
- 用证据位置代替大段原文或 diff;篇幅与任务复杂度匹配,长回复末尾补一句当前状态和必要的下一步。
|
|
23
|
+
- 用中文;代码、路径、命令、标识符和错误保持原文。
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@oyasmi/pipiclaw",
|
|
3
|
-
"version": "0.9.3-beta.
|
|
3
|
+
"version": "0.9.3-beta.5",
|
|
4
4
|
"description": "An AI assistant runtime for coding and team workflows, with DingTalk AI Cards, sub-agents, memory, and scheduled events.",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"bin": {
|
|
@@ -41,6 +41,7 @@
|
|
|
41
41
|
"eval:regrade": "npm run eval:build && node dist-evals/evals/harness/regrade.js",
|
|
42
42
|
"eval:report": "npm run eval:build && node dist-evals/evals/harness/report.js",
|
|
43
43
|
"eval:promote": "npm run eval:build && node dist-evals/evals/harness/promote.js",
|
|
44
|
+
"eval:prune": "node scripts/prune-eval-results.mjs",
|
|
44
45
|
"test:coverage": "vitest --run --coverage",
|
|
45
46
|
"check": "npm run lint && npm run typecheck && npm run deadcode && npm run test",
|
|
46
47
|
"prepublishOnly": "npm run clean && npm run build && npm run check",
|
package/dist/shared/duration.js
DELETED
|
@@ -1,10 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* A cheap change token for a config file: `mtime:ctime:size`, or `""` when the file
|
|
3
|
-
* cannot be stat'ed (missing or unreadable — itself a stable state worth caching).
|
|
4
|
-
*
|
|
5
|
-
* Used by the hot re-read paths (`settings.json` on every driver/maintenance tick,
|
|
6
|
-
* `tools.json` on every driver tick) to skip a JSON parse when nothing changed. Same
|
|
7
|
-
* triple as the task-ledger parse cache: mtime alone misses an atomic-rename overwrite
|
|
8
|
-
* that preserves the timestamp, ctime catches the rename, size catches the rest.
|
|
9
|
-
*/
|
|
10
|
-
export declare function fileStamp(path: string): string;
|
|
@@ -1,19 +0,0 @@
|
|
|
1
|
-
import { statSync } from "node:fs";
|
|
2
|
-
/**
|
|
3
|
-
* A cheap change token for a config file: `mtime:ctime:size`, or `""` when the file
|
|
4
|
-
* cannot be stat'ed (missing or unreadable — itself a stable state worth caching).
|
|
5
|
-
*
|
|
6
|
-
* Used by the hot re-read paths (`settings.json` on every driver/maintenance tick,
|
|
7
|
-
* `tools.json` on every driver tick) to skip a JSON parse when nothing changed. Same
|
|
8
|
-
* triple as the task-ledger parse cache: mtime alone misses an atomic-rename overwrite
|
|
9
|
-
* that preserves the timestamp, ctime catches the rename, size catches the rest.
|
|
10
|
-
*/
|
|
11
|
-
export function fileStamp(path) {
|
|
12
|
-
try {
|
|
13
|
-
const stats = statSync(path);
|
|
14
|
-
return `${stats.mtimeMs}:${stats.ctimeMs}:${stats.size}`;
|
|
15
|
-
}
|
|
16
|
-
catch {
|
|
17
|
-
return "";
|
|
18
|
-
}
|
|
19
|
-
}
|
package/dist/shared/numeric.d.ts
DELETED
|
@@ -1,7 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* Coerce an untrusted numeric config/request value into an integer within `[minimum, maximum]`,
|
|
3
|
-
* falling back to `fallback` for anything not a finite number or out of range. Shared by the
|
|
4
|
-
* app-level config loaders (`tools.json`) and web request parameter resolution — both need the
|
|
5
|
-
* same "trust nothing, fail closed to a safe default" numeric parsing.
|
|
6
|
-
*/
|
|
7
|
-
export declare function clampInteger(value: unknown, fallback: number, minimum: number, maximum?: number): number;
|
package/dist/shared/numeric.js
DELETED
|
@@ -1,19 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* Coerce an untrusted numeric config/request value into an integer within `[minimum, maximum]`,
|
|
3
|
-
* falling back to `fallback` for anything not a finite number or out of range. Shared by the
|
|
4
|
-
* app-level config loaders (`tools.json`) and web request parameter resolution — both need the
|
|
5
|
-
* same "trust nothing, fail closed to a safe default" numeric parsing.
|
|
6
|
-
*/
|
|
7
|
-
export function clampInteger(value, fallback, minimum, maximum) {
|
|
8
|
-
if (typeof value !== "number" || !Number.isFinite(value)) {
|
|
9
|
-
return fallback;
|
|
10
|
-
}
|
|
11
|
-
const normalized = Math.floor(value);
|
|
12
|
-
if (normalized < minimum) {
|
|
13
|
-
return fallback;
|
|
14
|
-
}
|
|
15
|
-
if (maximum !== undefined && normalized > maximum) {
|
|
16
|
-
return fallback;
|
|
17
|
-
}
|
|
18
|
-
return normalized;
|
|
19
|
-
}
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
export declare function estimateTokens(text: string): number;
|
|
@@ -1,19 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* Rough token estimate, shared by everything that has to reason about context size without
|
|
3
|
-
* calling a tokenizer. CJK runs about one token per character, Latin text about four characters
|
|
4
|
-
* per token; the provider's real tokenizer is the authority, and the usage ledger records what
|
|
5
|
-
* it billed.
|
|
6
|
-
*
|
|
7
|
-
* The script split matters wherever the estimate gates behavior rather than just reporting: a
|
|
8
|
-
* flat characters-per-token ratio tuned for Latin text underestimates Chinese input roughly
|
|
9
|
-
* threefold, so a budget check would clear a message that in fact does not fit.
|
|
10
|
-
*/
|
|
11
|
-
const CJK_REGEX = /\p{Script=Han}|\p{Script=Hiragana}|\p{Script=Katakana}|\p{Script=Hangul}/u;
|
|
12
|
-
export function estimateTokens(text) {
|
|
13
|
-
let cjk = 0;
|
|
14
|
-
for (const char of text) {
|
|
15
|
-
if (CJK_REGEX.test(char))
|
|
16
|
-
cjk++;
|
|
17
|
-
}
|
|
18
|
-
return Math.ceil(cjk + (text.length - cjk) / 4);
|
|
19
|
-
}
|
|
File without changes
|