@epoch-agent/protocol 0.1.0 → 0.3.1
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 +38 -34
- package/dist/index.d.ts +3610 -152
- package/dist/index.js +551 -105
- package/package.json +4 -2
package/dist/index.js
CHANGED
|
@@ -5,7 +5,6 @@ var ToolExposure = /* @__PURE__ */ ((ToolExposure2) => {
|
|
|
5
5
|
ToolExposure2["Hidden"] = "hidden";
|
|
6
6
|
return ToolExposure2;
|
|
7
7
|
})(ToolExposure || {});
|
|
8
|
-
|
|
9
8
|
// src/diagnostics.ts
|
|
10
9
|
function hasFailure(list) {
|
|
11
10
|
return list.some((d) => d.status === "failed");
|
|
@@ -19,30 +18,18 @@ var DiagnosticSink = class {
|
|
|
19
18
|
const render = typeof detail === "string" ? () => detail : detail;
|
|
20
19
|
this.list.push({ module, status, detail: render, ...code ? { code } : {} });
|
|
21
20
|
}
|
|
22
|
-
/** 正常。`detail` 缺省是 `OK`(与改造前的字符串一致) */
|
|
23
21
|
ok(module, detail = "OK") {
|
|
24
22
|
this.add(module, "ok", detail);
|
|
25
23
|
}
|
|
26
|
-
/** 能用,但用户该知道(降级、回退到默认值、缺可选依赖) */
|
|
27
24
|
warn(module, detail, code) {
|
|
28
25
|
this.add(module, "warn", detail, code);
|
|
29
26
|
}
|
|
30
|
-
/** 起不来。**注意这会让 `epoch doctor` 退非 0** */
|
|
31
27
|
failed(module, detail, code) {
|
|
32
28
|
this.add(module, "failed", detail, code);
|
|
33
29
|
}
|
|
34
|
-
/** 没配所以没起。既不是成功也不是失败 —— 伪装成任何一种都是在骗人 */
|
|
35
30
|
skipped(module, detail) {
|
|
36
31
|
this.add(module, "skipped", detail);
|
|
37
32
|
}
|
|
38
|
-
/**
|
|
39
|
-
* 结构化的那一份(宿主用)。
|
|
40
|
-
*
|
|
41
|
-
* @param lang 用哪个语言渲染 `detail`。**不给 = 进程语言**,也就是这一轮之前的
|
|
42
|
-
* 全部行为(CLI / `epoch doctor` / 没带 `?lang=` 的请求走的都是这条)。
|
|
43
|
-
* ⚠️ **只换 `detail`** —— `module` / `code` / `status` 是契约,
|
|
44
|
-
* 跟着语言变等于让宿主的去重和分支按语言分叉(见文件头)
|
|
45
|
-
*/
|
|
46
33
|
toList(lang) {
|
|
47
34
|
return this.list.map((d) => ({
|
|
48
35
|
module: d.module,
|
|
@@ -51,7 +38,6 @@ var DiagnosticSink = class {
|
|
|
51
38
|
...d.code ? { code: d.code } : {}
|
|
52
39
|
}));
|
|
53
40
|
}
|
|
54
|
-
/** 字符串那一份(CLI / TUI 用)。**派生**,不是另一份状态 */
|
|
55
41
|
toStrings() {
|
|
56
42
|
return this.toList().map(diagnosticToLine);
|
|
57
43
|
}
|
|
@@ -59,14 +45,12 @@ var DiagnosticSink = class {
|
|
|
59
45
|
return this.list.length;
|
|
60
46
|
}
|
|
61
47
|
};
|
|
62
|
-
|
|
63
48
|
// src/agent-role.ts
|
|
64
49
|
var DEFAULT_AGENT_ROLE = "general";
|
|
65
50
|
var AGENT_ROLE_NAME_PATTERN = /^[a-z0-9][a-z0-9-]*$/;
|
|
66
51
|
function isValidAgentRoleName(name) {
|
|
67
52
|
return AGENT_ROLE_NAME_PATTERN.test(name);
|
|
68
53
|
}
|
|
69
|
-
|
|
70
54
|
// src/commands.ts
|
|
71
55
|
var RESERVED_COMMAND_NAMES = [
|
|
72
56
|
"help",
|
|
@@ -88,9 +72,6 @@ var RESERVED_COMMAND_NAMES = [
|
|
|
88
72
|
"exit",
|
|
89
73
|
"quit",
|
|
90
74
|
"q",
|
|
91
|
-
// 方案 25 PR-4 补的九条。**登记的是全集,不是「这次注册了的」** ——
|
|
92
|
-
// 一条命令因为宿主缺能力而没注册,不代表自定义命令就可以占它的名字:
|
|
93
|
-
// 那样升个版、或者换个宿主,同一个文件就突然撞名了
|
|
94
75
|
"cost",
|
|
95
76
|
"export",
|
|
96
77
|
"skills",
|
|
@@ -104,29 +85,20 @@ var RESERVED_COMMAND_NAMES = [
|
|
|
104
85
|
"resume",
|
|
105
86
|
"permissions",
|
|
106
87
|
"perms",
|
|
107
|
-
// 方案 27 PR-3。它和 `/clear` 属于同一类「逃生通道」:被一个坏掉的自定义命令
|
|
108
|
-
// 顶掉之后,用户失去的是**把工作区退回去**的那条路 —— 而他会在最需要它的
|
|
109
|
-
// 那一刻才发现
|
|
110
88
|
"rewind",
|
|
111
|
-
// 方案 32。同样是逃生通道,而且是这一条名单里唯一**能自我修复**的那个:
|
|
112
|
-
// 一个插件把界面搞砸之后,`/plugin` 是用户不重启就能停用它的唯一入口 ——
|
|
113
|
-
// 让插件自己占掉这个名字等于把灭火器锁在着火的屋里
|
|
114
89
|
"plugin",
|
|
115
90
|
"plugins",
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
"goal"
|
|
91
|
+
"goal",
|
|
92
|
+
"keybindings",
|
|
93
|
+
"keys",
|
|
94
|
+
"terminal-setup"
|
|
121
95
|
];
|
|
122
96
|
var COMMAND_NAME_PATTERN = /^[a-z0-9_]+(?:[-:][a-z0-9_]+)*$/;
|
|
123
97
|
function isValidCommandName(name) {
|
|
124
98
|
return COMMAND_NAME_PATTERN.test(name);
|
|
125
99
|
}
|
|
126
|
-
|
|
127
100
|
// src/keybindings.ts
|
|
128
101
|
var KEY_ACTIONS = [
|
|
129
|
-
// ── global:App 那一层的 useInput ────────────────────────────────
|
|
130
102
|
"interrupt",
|
|
131
103
|
"rewind",
|
|
132
104
|
"clear-screen",
|
|
@@ -134,7 +106,6 @@ var KEY_ACTIONS = [
|
|
|
134
106
|
"transcript-search",
|
|
135
107
|
"exit",
|
|
136
108
|
"exit-if-empty",
|
|
137
|
-
// ── input:输入框(没有补全面板时)───────────────────────────────
|
|
138
109
|
"submit",
|
|
139
110
|
"newline",
|
|
140
111
|
"history-prev",
|
|
@@ -149,7 +120,6 @@ var KEY_ACTIONS = [
|
|
|
149
120
|
"delete-char-left",
|
|
150
121
|
"delete-char-right",
|
|
151
122
|
"paste-image",
|
|
152
|
-
// ── dialog:补全面板开着时 ───────────────────────────────────────
|
|
153
123
|
"complete",
|
|
154
124
|
"complete-prev",
|
|
155
125
|
"complete-next"
|
|
@@ -184,6 +154,7 @@ var ACTION_CONTEXTS = {
|
|
|
184
154
|
"complete-prev": ["dialog"],
|
|
185
155
|
"complete-next": ["dialog"]
|
|
186
156
|
};
|
|
157
|
+
var SEQUENCE_CONTEXTS = ["global", "input"];
|
|
187
158
|
var RESERVED_CHORDS = ["ctrl+c", "ctrl+d"];
|
|
188
159
|
var KEY_NAMES = {
|
|
189
160
|
esc: "escape",
|
|
@@ -245,10 +216,34 @@ function parseChord(text) {
|
|
|
245
216
|
}
|
|
246
217
|
return chord;
|
|
247
218
|
}
|
|
219
|
+
function sequenceId(sequence) {
|
|
220
|
+
return sequence.map(chordId).join(" ");
|
|
221
|
+
}
|
|
222
|
+
function parseSequence(text) {
|
|
223
|
+
const parts = text.trim().split(/\s+/);
|
|
224
|
+
const first = parts[0];
|
|
225
|
+
if (first === void 0 || first.length === 0) return void 0;
|
|
226
|
+
const head = parseChord(first);
|
|
227
|
+
if (!head) return void 0;
|
|
228
|
+
const rest = [];
|
|
229
|
+
for (const part of parts.slice(1)) {
|
|
230
|
+
const chord = parseChord(part);
|
|
231
|
+
if (!chord) return void 0;
|
|
232
|
+
rest.push(chord);
|
|
233
|
+
}
|
|
234
|
+
return [head, ...rest];
|
|
235
|
+
}
|
|
248
236
|
function isKeyAction(value) {
|
|
249
237
|
return KEY_ACTIONS.includes(value);
|
|
250
238
|
}
|
|
251
|
-
|
|
239
|
+
function perAction(make) {
|
|
240
|
+
const out = {};
|
|
241
|
+
for (const action of KEY_ACTIONS) out[action] = make(action);
|
|
242
|
+
return out;
|
|
243
|
+
}
|
|
244
|
+
function tableOf(bindings) {
|
|
245
|
+
return perAction((action) => bindings[action].map((b) => b.keys));
|
|
246
|
+
}
|
|
252
247
|
// src/config.ts
|
|
253
248
|
var SHELL_KINDS = ["cmd", "powershell", "pwsh"];
|
|
254
249
|
var PROVIDER_INFOS = [
|
|
@@ -273,10 +268,10 @@ var PROVIDER_INFOS = [
|
|
|
273
268
|
{ type: "xai", label: "xAI / Grok", apiKeyEnv: "XAI_API_KEY", interactive: true },
|
|
274
269
|
{ type: "perplexity", label: "Perplexity", apiKeyEnv: "PERPLEXITY_API_KEY", interactive: true },
|
|
275
270
|
{ type: "togetherai", label: "Together AI", apiKeyEnv: "TOGETHER_API_KEY", interactive: true },
|
|
276
|
-
{ type: "ollama", label: "Ollama
|
|
271
|
+
{ type: "ollama", label: "Ollama", apiKeyEnv: null, interactive: true },
|
|
277
272
|
{
|
|
278
273
|
type: "openai-compatible",
|
|
279
|
-
label: "OpenAI Compatible
|
|
274
|
+
label: "OpenAI Compatible",
|
|
280
275
|
apiKeyEnv: "OPENAI_API_KEY",
|
|
281
276
|
interactive: true
|
|
282
277
|
},
|
|
@@ -310,7 +305,6 @@ var SEARCH_API_KEY_ENV = {
|
|
|
310
305
|
brave: "BRAVE_SEARCH_API_KEY",
|
|
311
306
|
searxng: null
|
|
312
307
|
};
|
|
313
|
-
|
|
314
308
|
// src/model-ref.ts
|
|
315
309
|
function parseModelRef(raw) {
|
|
316
310
|
const value = raw.trim();
|
|
@@ -323,7 +317,6 @@ function parseModelRef(raw) {
|
|
|
323
317
|
}
|
|
324
318
|
return { model: value };
|
|
325
319
|
}
|
|
326
|
-
|
|
327
320
|
// src/telemetry.ts
|
|
328
321
|
var GEN_AI = {
|
|
329
322
|
OPERATION_NAME: "gen_ai.operation.name",
|
|
@@ -342,18 +335,10 @@ var METRIC = {
|
|
|
342
335
|
TOOL_APPROVAL: "epoch.tool.approval.count",
|
|
343
336
|
LLM_CALL_LATENCY: "epoch.llm.call.latency",
|
|
344
337
|
PROVIDER_FALLBACK: "epoch.provider.fallback.count",
|
|
345
|
-
/**
|
|
346
|
-
* 换模型的次数(方案 26 #13)。属性 `origin` 分辨谁换的
|
|
347
|
-
* (`user-switch` / `command-frontmatter` / `fallback`)。
|
|
348
|
-
*
|
|
349
|
-
* 和 {@link METRIC.MODEL_FALLBACK} 分成两个名字而不是靠一个属性区分,
|
|
350
|
-
* 是因为看板上「用户主动换了几次」和「引擎被迫降了几次」是两条完全不同的
|
|
351
|
-
* 曲线:前者高说明默认模型选得不好,后者高说明 provider 在抖。
|
|
352
|
-
*/
|
|
353
338
|
MODEL_SWITCH: "epoch.model.switch.count",
|
|
354
|
-
/** 同一 provider 内模型级降级的次数(方案 26 #10/#11),属性带 from/to */
|
|
355
339
|
MODEL_FALLBACK: "epoch.model.fallback.count",
|
|
356
340
|
CONTEXT_COMPACTION: "epoch.context.compaction.count",
|
|
341
|
+
COMPLIANCE_HIT: "epoch.compliance.hit.count",
|
|
357
342
|
STARTUP_DURATION: "epoch.startup.duration"
|
|
358
343
|
};
|
|
359
344
|
var NOOP_SPAN = {
|
|
@@ -371,7 +356,6 @@ var NOOP_TELEMETRY = {
|
|
|
371
356
|
histogram: () => {
|
|
372
357
|
}
|
|
373
358
|
};
|
|
374
|
-
|
|
375
359
|
// src/permission.ts
|
|
376
360
|
var PERMISSION_LEVELS = [
|
|
377
361
|
"default",
|
|
@@ -411,19 +395,11 @@ function isApprovalOutcome(value) {
|
|
|
411
395
|
function normalizeApproval(reply) {
|
|
412
396
|
return typeof reply === "string" ? { outcome: reply } : reply;
|
|
413
397
|
}
|
|
414
|
-
|
|
415
398
|
// src/plan.ts
|
|
416
399
|
var PLAN_OUTCOMES = ["plan-execute", "plan-readonly", "plan-revise"];
|
|
417
400
|
function isPlanOutcome(value) {
|
|
418
401
|
return PLAN_OUTCOMES.includes(value);
|
|
419
402
|
}
|
|
420
|
-
var PLAN_OUTCOME_LABELS = {
|
|
421
|
-
"plan-execute": "\u6279\u51C6\u5E76\u6267\u884C",
|
|
422
|
-
"plan-readonly": "\u6279\u51C6\uFF0C\u4F46\u4FDD\u6301\u53EA\u8BFB",
|
|
423
|
-
"plan-revise": "\u8BA9\u6211\u6539\u4E00\u4E0B",
|
|
424
|
-
deny: "\u62D2\u7EDD"
|
|
425
|
-
};
|
|
426
|
-
|
|
427
403
|
// src/schedule.ts
|
|
428
404
|
var SCHEDULE_INTERVAL_MINUTES = [
|
|
429
405
|
5,
|
|
@@ -449,7 +425,101 @@ var SCHEDULE_RUN_STATUSES = [
|
|
|
449
425
|
"skipped-window",
|
|
450
426
|
"missed"
|
|
451
427
|
];
|
|
452
|
-
|
|
428
|
+
// src/schedule-templates.ts
|
|
429
|
+
var REPORTS = "file_write(./reports/**)";
|
|
430
|
+
var SCHEDULE_TEMPLATES = [
|
|
431
|
+
{
|
|
432
|
+
id: "repo-sweep",
|
|
433
|
+
trigger: { kind: "cron", cycle: "daily", at: "09:00" },
|
|
434
|
+
permission: "default",
|
|
435
|
+
allowOperations: ["file_read"],
|
|
436
|
+
allowRules: [
|
|
437
|
+
"terminal(git status:*)",
|
|
438
|
+
"terminal(git branch:*)",
|
|
439
|
+
"terminal(git log:*)",
|
|
440
|
+
REPORTS
|
|
441
|
+
]
|
|
442
|
+
},
|
|
443
|
+
{
|
|
444
|
+
id: "todo-digest",
|
|
445
|
+
trigger: { kind: "cron", cycle: "daily", at: "08:30" },
|
|
446
|
+
permission: "plan",
|
|
447
|
+
allowTools: ["todo"],
|
|
448
|
+
allowOperations: ["file_read"],
|
|
449
|
+
allowRules: [REPORTS]
|
|
450
|
+
},
|
|
451
|
+
{
|
|
452
|
+
id: "weekly-digest",
|
|
453
|
+
trigger: { kind: "cron", cycle: "weekly", at: "18:00", weekdays: [5] },
|
|
454
|
+
permission: "default",
|
|
455
|
+
allowOperations: ["file_read"],
|
|
456
|
+
allowRules: ["terminal(gh pr list:*)", "terminal(gh issue list:*)", "mcp__github__*", REPORTS]
|
|
457
|
+
},
|
|
458
|
+
{
|
|
459
|
+
id: "dep-checkup",
|
|
460
|
+
trigger: { kind: "cron", cycle: "weekly", at: "10:00", weekdays: [1] },
|
|
461
|
+
permission: "default",
|
|
462
|
+
allowOperations: ["file_read"],
|
|
463
|
+
allowRules: ["terminal(pnpm outdated:*)", "terminal(pnpm audit:*)", REPORTS]
|
|
464
|
+
},
|
|
465
|
+
{
|
|
466
|
+
id: "stale-docs",
|
|
467
|
+
trigger: { kind: "cron", cycle: "monthly", at: "07:30", days: [1] },
|
|
468
|
+
permission: "plan",
|
|
469
|
+
allowOperations: ["file_read"],
|
|
470
|
+
allowRules: [REPORTS]
|
|
471
|
+
},
|
|
472
|
+
{
|
|
473
|
+
id: "test-flake",
|
|
474
|
+
trigger: { kind: "cron", cycle: "weekly", at: "20:00", weekdays: [3] },
|
|
475
|
+
permission: "default",
|
|
476
|
+
allowOperations: ["file_read"],
|
|
477
|
+
allowRules: ["terminal(pnpm test:*)", "terminal(pnpm vitest:*)", REPORTS],
|
|
478
|
+
timeoutMs: 40 * 6e4
|
|
479
|
+
}
|
|
480
|
+
];
|
|
481
|
+
// src/schedule-pending.ts
|
|
482
|
+
function unfixedRules(allowRules, approvals) {
|
|
483
|
+
const seen = new Set(allowRules);
|
|
484
|
+
const out = [];
|
|
485
|
+
for (const item of approvals) {
|
|
486
|
+
if (item.suggestedRule === void 0 || seen.has(item.suggestedRule)) continue;
|
|
487
|
+
seen.add(item.suggestedRule);
|
|
488
|
+
out.push(item.suggestedRule);
|
|
489
|
+
}
|
|
490
|
+
return out;
|
|
491
|
+
}
|
|
492
|
+
function unfixedApprovals(allowRules, approvals) {
|
|
493
|
+
const rules = new Set(unfixedRules(allowRules, approvals));
|
|
494
|
+
const out = [];
|
|
495
|
+
for (const item of approvals) {
|
|
496
|
+
if (item.suggestedRule === void 0 || !rules.has(item.suggestedRule)) continue;
|
|
497
|
+
rules.delete(item.suggestedRule);
|
|
498
|
+
out.push({ ...item, suggestedRule: item.suggestedRule });
|
|
499
|
+
}
|
|
500
|
+
return out;
|
|
501
|
+
}
|
|
502
|
+
function collectPendingApprovals(defs, runs) {
|
|
503
|
+
const byId = new Map(defs.map((def) => [def.id, def]));
|
|
504
|
+
const items = [];
|
|
505
|
+
const taken = /* @__PURE__ */ new Set();
|
|
506
|
+
for (const run of runs) {
|
|
507
|
+
if (taken.has(run.scheduleId)) continue;
|
|
508
|
+
const def = byId.get(run.scheduleId);
|
|
509
|
+
if (!def) continue;
|
|
510
|
+
const approvals = unfixedApprovals(def.allowRules, run.pendingApprovals);
|
|
511
|
+
if (approvals.length === 0) continue;
|
|
512
|
+
taken.add(run.scheduleId);
|
|
513
|
+
items.push({
|
|
514
|
+
scheduleId: def.id,
|
|
515
|
+
scheduleName: def.name,
|
|
516
|
+
runId: run.id,
|
|
517
|
+
at: run.startedAt,
|
|
518
|
+
approvals
|
|
519
|
+
});
|
|
520
|
+
}
|
|
521
|
+
return items.sort((a, b) => a.at - b.at || (a.scheduleId < b.scheduleId ? -1 : 1));
|
|
522
|
+
}
|
|
453
523
|
// src/question.ts
|
|
454
524
|
var MAX_QUESTIONS = 4;
|
|
455
525
|
var MIN_OPTIONS = 2;
|
|
@@ -461,8 +531,14 @@ function isQuestionAnswerMap(value) {
|
|
|
461
531
|
(v) => typeof v === "string" || Array.isArray(v) && v.every((x) => typeof x === "string")
|
|
462
532
|
);
|
|
463
533
|
}
|
|
464
|
-
|
|
465
534
|
// src/message.ts
|
|
535
|
+
var SESSION_REFERENCE_ERROR_CODES = Object.freeze([
|
|
536
|
+
"invalid-reference",
|
|
537
|
+
"self-reference",
|
|
538
|
+
"too-many",
|
|
539
|
+
"not-authorized",
|
|
540
|
+
"budget-exceeded"
|
|
541
|
+
]);
|
|
466
542
|
var OMIT_LABEL = {
|
|
467
543
|
binary: "\u4E8C\u8FDB\u5236\u6587\u4EF6\uFF0C\u672A\u9644\u5185\u5BB9",
|
|
468
544
|
denied: "\u6743\u9650\u672A\u653E\u884C\uFF0C\u672A\u9644\u5185\u5BB9",
|
|
@@ -475,31 +551,180 @@ function filePartSummary(part) {
|
|
|
475
551
|
const truncated = part.truncatedTo === void 0 ? "" : `\uFF0C\u5DF2\u622A\u65AD\u5230 ${part.truncatedTo} \u5B57\u8282`;
|
|
476
552
|
return `[\u6587\u4EF6 ${part.path}${truncated}]`;
|
|
477
553
|
}
|
|
478
|
-
function
|
|
554
|
+
function sessionPartSummary(part) {
|
|
555
|
+
const name = part.title ?? part.sessionId ?? part.ref;
|
|
556
|
+
const head = `[referenced session "${name}"`;
|
|
557
|
+
if (part.omitted) return `${head} \u2014 not attached: ${part.omitted}]`;
|
|
558
|
+
const counted = part.messageCount === void 0 ? "" : ` \u2014 ${part.messageCount} active message(s)${part.totalMessages === void 0 ? "" : ` of ${part.totalMessages} total`}`;
|
|
559
|
+
const truncated = part.truncatedTo === void 0 ? "" : `, truncated to ${part.truncatedTo} bytes`;
|
|
560
|
+
return `${head}${counted}${truncated}]`;
|
|
561
|
+
}
|
|
562
|
+
function contentToText(content, opts = {}) {
|
|
479
563
|
if (typeof content === "string") return content;
|
|
480
564
|
return content.map((p) => {
|
|
481
565
|
if (p.type === "text") return p.text;
|
|
482
566
|
if (p.type === "file") return filePartSummary(p);
|
|
483
|
-
|
|
484
|
-
|
|
567
|
+
if (p.type === "session") return sessionPartSummary(p);
|
|
568
|
+
if (p.type === "image") {
|
|
569
|
+
return opts.imagesCarriedAsParts ? void 0 : `[\u56FE\u7247 ${p.mediaType ?? "\u672A\u77E5\u7C7B\u578B"}]`;
|
|
570
|
+
}
|
|
571
|
+
return assertNeverPart(p);
|
|
572
|
+
}).filter((line) => line !== void 0).join("\n");
|
|
573
|
+
}
|
|
574
|
+
var TURN_DIGEST_MAX_TOOLS = 8;
|
|
575
|
+
function turnDigest(results) {
|
|
576
|
+
if (results.length === 0) return "";
|
|
577
|
+
const counts = /* @__PURE__ */ new Map();
|
|
578
|
+
for (const r of results) counts.set(r.toolName, (counts.get(r.toolName) ?? 0) + 1);
|
|
579
|
+
const named = [...counts.entries()].slice(0, TURN_DIGEST_MAX_TOOLS);
|
|
580
|
+
const parts = named.map(([name, n]) => n > 1 ? `${name}\xD7${n}` : name);
|
|
581
|
+
const rest = counts.size - named.length;
|
|
582
|
+
if (rest > 0) parts.push(`\u7B49 ${rest} \u79CD`);
|
|
583
|
+
return `[\u672C\u8F6E\u8C03\u7528\u8FC7\u7684\u5DE5\u5177\uFF1A${parts.join(" \xB7 ")}]`;
|
|
485
584
|
}
|
|
585
|
+
function assistantTurnText(text, results) {
|
|
586
|
+
const digest = turnDigest(results);
|
|
587
|
+
if (!digest) return text;
|
|
588
|
+
return text ? `${text}
|
|
486
589
|
|
|
590
|
+
${digest}` : digest;
|
|
591
|
+
}
|
|
592
|
+
function assertNeverPart(part) {
|
|
593
|
+
throw new Error(`unhandled content part: ${JSON.stringify(part)}`);
|
|
594
|
+
}
|
|
487
595
|
// src/mentions.ts
|
|
488
596
|
var CJK_PUNCT = "\uFF0C\u3002\uFF1B\uFF1A\uFF01\uFF1F\u3001\uFF09\u3011\u300B\u300D\u300F\uFF08\u3010\u300A\u300C\u300E";
|
|
489
597
|
var MENTION_RE = new RegExp(String.raw`(^|\s)@([^\s${CJK_PUNCT}]+)`, "gu");
|
|
490
|
-
|
|
491
|
-
|
|
492
|
-
const
|
|
598
|
+
var SESSION_MENTION_PREFIX = ":";
|
|
599
|
+
function extractAllMentions(text) {
|
|
600
|
+
const files = [];
|
|
601
|
+
const sessions = [];
|
|
602
|
+
const seenFiles = /* @__PURE__ */ new Set();
|
|
603
|
+
const seenSessions = /* @__PURE__ */ new Set();
|
|
493
604
|
for (const match of text.matchAll(MENTION_RE)) {
|
|
494
605
|
const raw = (match[2] ?? "").split("\\").join("/");
|
|
495
|
-
const
|
|
496
|
-
if (!
|
|
497
|
-
|
|
498
|
-
|
|
606
|
+
const body = raw.replace(/[,.;:!?)\]}]+$/u, "");
|
|
607
|
+
if (!body) continue;
|
|
608
|
+
if (body.startsWith(SESSION_MENTION_PREFIX)) {
|
|
609
|
+
const ref = body.slice(SESSION_MENTION_PREFIX.length);
|
|
610
|
+
if (!ref || seenSessions.has(ref)) continue;
|
|
611
|
+
seenSessions.add(ref);
|
|
612
|
+
sessions.push(ref);
|
|
613
|
+
continue;
|
|
614
|
+
}
|
|
615
|
+
if (seenFiles.has(body)) continue;
|
|
616
|
+
seenFiles.add(body);
|
|
617
|
+
files.push(body);
|
|
499
618
|
}
|
|
500
|
-
return
|
|
619
|
+
return { files, sessions };
|
|
620
|
+
}
|
|
621
|
+
function extractMentions(text) {
|
|
622
|
+
return extractAllMentions(text).files;
|
|
623
|
+
}
|
|
624
|
+
function extractSessionMentions(text) {
|
|
625
|
+
return extractAllMentions(text).sessions;
|
|
626
|
+
}
|
|
627
|
+
function isMentionableFilePath(path) {
|
|
628
|
+
if (!path) return false;
|
|
629
|
+
const { files } = extractAllMentions(`@${path}`);
|
|
630
|
+
return files.length === 1 && files[0] === path;
|
|
631
|
+
}
|
|
632
|
+
var MAX_ATTACH_BYTES = 100 * 1024;
|
|
633
|
+
var MAX_ATTACH_FILES = 20;
|
|
634
|
+
var MAX_ATTACH_TOTAL_BYTES = 200 * 1024;
|
|
635
|
+
var MAX_SESSION_ATTACH_BYTES = 50 * 1024;
|
|
636
|
+
var MAX_SESSION_REFS = 2;
|
|
637
|
+
function attachSessionSurface(ref, surface, usedBytes) {
|
|
638
|
+
const head = {
|
|
639
|
+
type: "session",
|
|
640
|
+
ref,
|
|
641
|
+
sessionId: surface.sessionId,
|
|
642
|
+
title: surface.title,
|
|
643
|
+
...surface.cwd ? { cwd: surface.cwd } : {},
|
|
644
|
+
messageCount: surface.messages.length,
|
|
645
|
+
totalMessages: surface.totalMessages
|
|
646
|
+
};
|
|
647
|
+
const surfaced = surface.messages.length;
|
|
648
|
+
const remaining = MAX_ATTACH_TOTAL_BYTES - usedBytes;
|
|
649
|
+
if (remaining <= 0) {
|
|
650
|
+
return {
|
|
651
|
+
part: { ...head, omitted: "budget-exceeded" },
|
|
652
|
+
kind: "budget-exceeded",
|
|
653
|
+
kept: 0,
|
|
654
|
+
surfaced,
|
|
655
|
+
budget: 0,
|
|
656
|
+
bytes: 0
|
|
657
|
+
};
|
|
658
|
+
}
|
|
659
|
+
if (surfaced === 0) {
|
|
660
|
+
return { part: { ...head, text: "" }, kind: "empty", kept: 0, surfaced, budget: 0, bytes: 0 };
|
|
661
|
+
}
|
|
662
|
+
const budget = Math.min(MAX_SESSION_ATTACH_BYTES, remaining);
|
|
663
|
+
const packed = packSessionSurface(surface.messages, budget);
|
|
664
|
+
const bytes = utf8ByteLength(packed.text);
|
|
665
|
+
if (packed.dropped === 0) {
|
|
666
|
+
return {
|
|
667
|
+
part: { ...head, text: packed.text },
|
|
668
|
+
kind: "full",
|
|
669
|
+
kept: surfaced,
|
|
670
|
+
surfaced,
|
|
671
|
+
budget,
|
|
672
|
+
bytes
|
|
673
|
+
};
|
|
674
|
+
}
|
|
675
|
+
return {
|
|
676
|
+
part: { ...head, text: packed.text, truncatedTo: bytes },
|
|
677
|
+
kind: "truncated",
|
|
678
|
+
kept: surfaced - packed.dropped,
|
|
679
|
+
surfaced,
|
|
680
|
+
budget,
|
|
681
|
+
bytes
|
|
682
|
+
};
|
|
683
|
+
}
|
|
684
|
+
function utf8ByteLength(text) {
|
|
685
|
+
return new TextEncoder().encode(text).length;
|
|
686
|
+
}
|
|
687
|
+
function renderSurfaceMessage(message) {
|
|
688
|
+
const label = message.toolName ? `${message.role}:${message.toolName}` : message.role;
|
|
689
|
+
return `[${label}] ${message.content}`;
|
|
690
|
+
}
|
|
691
|
+
function packSessionSurface(messages, budget) {
|
|
692
|
+
const blocks = messages.map(renderSurfaceMessage);
|
|
693
|
+
const sizes = blocks.map((b) => utf8ByteLength(b) + 1);
|
|
694
|
+
const total = sizes.reduce((a, b) => a + b, 0);
|
|
695
|
+
if (total <= budget) return { text: blocks.join("\n"), dropped: 0 };
|
|
696
|
+
const headBudget = Math.floor(budget / 2);
|
|
697
|
+
let used = 0;
|
|
698
|
+
let headCount = 0;
|
|
699
|
+
for (const size of sizes) {
|
|
700
|
+
if (used + size > headBudget) break;
|
|
701
|
+
used += size;
|
|
702
|
+
headCount++;
|
|
703
|
+
}
|
|
704
|
+
let tailCount = 0;
|
|
705
|
+
for (let i = sizes.length - 1; i >= headCount; i--) {
|
|
706
|
+
const size = sizes[i] ?? 0;
|
|
707
|
+
if (used + size > budget) break;
|
|
708
|
+
used += size;
|
|
709
|
+
tailCount++;
|
|
710
|
+
}
|
|
711
|
+
const dropped = blocks.length - headCount - tailCount;
|
|
712
|
+
if (headCount === 0 && tailCount === 0) {
|
|
713
|
+
const only = blocks[blocks.length - 1] ?? "";
|
|
714
|
+
return {
|
|
715
|
+
text: new TextDecoder().decode(new TextEncoder().encode(only).slice(0, budget)),
|
|
716
|
+
dropped: blocks.length - 1
|
|
717
|
+
};
|
|
718
|
+
}
|
|
719
|
+
return {
|
|
720
|
+
text: [
|
|
721
|
+
...blocks.slice(0, headCount),
|
|
722
|
+
`\u2026 ${dropped} message(s) omitted here (over the ${Math.round(budget / 1024)}KB reference budget; use session_search for the full record) \u2026`,
|
|
723
|
+
...blocks.slice(blocks.length - tailCount)
|
|
724
|
+
].join("\n"),
|
|
725
|
+
dropped
|
|
726
|
+
};
|
|
501
727
|
}
|
|
502
|
-
|
|
503
728
|
// src/system-note.ts
|
|
504
729
|
var SYSTEM_NOTE_PREFIX = "[\u7CFB\u7EDF] ";
|
|
505
730
|
function systemNote(body) {
|
|
@@ -509,7 +734,6 @@ function stripSystemNote(text) {
|
|
|
509
734
|
if (!text.startsWith(SYSTEM_NOTE_PREFIX)) return void 0;
|
|
510
735
|
return text.slice(SYSTEM_NOTE_PREFIX.length);
|
|
511
736
|
}
|
|
512
|
-
|
|
513
737
|
// src/usage.ts
|
|
514
738
|
function promptTokens(usage) {
|
|
515
739
|
return usage.inputTokens + (usage.cacheHitTokens ?? 0) + (usage.cacheWriteTokens ?? 0);
|
|
@@ -523,7 +747,6 @@ function isContextNearlyFull(prompt, contextLength, threshold) {
|
|
|
523
747
|
function totalUsageTokens(usage) {
|
|
524
748
|
return usage.totalTokens ?? promptTokens(usage) + usage.outputTokens;
|
|
525
749
|
}
|
|
526
|
-
|
|
527
750
|
// src/wire.ts
|
|
528
751
|
var HUB_EVENT_TYPES = /* @__PURE__ */ new Set([
|
|
529
752
|
"connected",
|
|
@@ -539,7 +762,6 @@ function isWireHubEvent(event) {
|
|
|
539
762
|
var WIRE_AUTH_COOKIE = "epoch_web_token";
|
|
540
763
|
var WIRE_AUTH_TOKEN_PARAM = "token";
|
|
541
764
|
var WIRE_AUTH_COOKIE_ATTRS = "HttpOnly; SameSite=Strict; Path=/";
|
|
542
|
-
|
|
543
765
|
// src/headless-wire.ts
|
|
544
766
|
var HEADLESS_PROTOCOL_VERSION = 1;
|
|
545
767
|
var HEADLESS_OUTPUT_FORMATS = ["text", "json", "stream-json"];
|
|
@@ -564,7 +786,6 @@ var HEADLESS_INPUT_EVENT_TYPES = /* @__PURE__ */ new Set([
|
|
|
564
786
|
"abort",
|
|
565
787
|
"close"
|
|
566
788
|
]);
|
|
567
|
-
|
|
568
789
|
// src/wire-rest.ts
|
|
569
790
|
function wireFields() {
|
|
570
791
|
return (spec) => Object.keys(spec);
|
|
@@ -601,7 +822,6 @@ var WIRE_ABOUT_FIELDS = wireFields()({
|
|
|
601
822
|
platform: true,
|
|
602
823
|
homeDir: true,
|
|
603
824
|
dbPath: true
|
|
604
|
-
// ⚠️ `profile` 是可选键,故意不在这张表上(同 `WIRE_CONFIG_FIELDS` 那条 ⚠️)
|
|
605
825
|
});
|
|
606
826
|
var WIRE_CONFIG_FIELDS = wireFields()({
|
|
607
827
|
sessionId: true,
|
|
@@ -615,11 +835,8 @@ var WIRE_CONFIG_FIELDS = wireFields()({
|
|
|
615
835
|
tools: true,
|
|
616
836
|
diagnostics: true,
|
|
617
837
|
about: true,
|
|
618
|
-
lanExposed: true
|
|
619
|
-
|
|
620
|
-
// 写进来编译不过(见 `wireFields` 那条 ⚠️)。这份清单是 `conformsToWire()`
|
|
621
|
-
// 的运行时判据,可选键一旦进来,「宿主没配所以没这个键」就会被判成不合契约,
|
|
622
|
-
// 而那恰恰是这两个字段的**正常形态**
|
|
838
|
+
lanExposed: true,
|
|
839
|
+
nativeDirPicker: true
|
|
623
840
|
});
|
|
624
841
|
var WIRE_SESSION_SUMMARY_FIELDS = wireFields()({
|
|
625
842
|
id: true,
|
|
@@ -671,14 +888,19 @@ var WIRE_MESSAGE_LIST_FIELDS = wireFields()({
|
|
|
671
888
|
});
|
|
672
889
|
var WIRE_SEND_MESSAGE_FIELDS = wireFields()({
|
|
673
890
|
message: true
|
|
674
|
-
|
|
675
|
-
|
|
891
|
+
});
|
|
892
|
+
var WIRE_SESSION_REFERENCE_FIELDS = wireFields()({
|
|
893
|
+
ref: true
|
|
894
|
+
});
|
|
895
|
+
var WIRE_FILE_REFERENCE_FIELDS = wireFields()({
|
|
896
|
+
path: true
|
|
897
|
+
});
|
|
898
|
+
var WIRE_IMAGE_REFERENCE_FIELDS = wireFields()({
|
|
899
|
+
image: true
|
|
676
900
|
});
|
|
677
901
|
var WIRE_SEND_MESSAGE_RESPONSE_FIELDS = wireFields()({
|
|
678
902
|
accepted: true,
|
|
679
903
|
queued: true
|
|
680
|
-
// `command` 是可选的,所以**不在**清单里 —— 见 `wireFields` 的那条警告。
|
|
681
|
-
// 绝大多数消息不是命令,把它写进来等于让正常路径判成不合契约
|
|
682
904
|
});
|
|
683
905
|
var WIRE_ABORT_FIELDS = wireFields()({
|
|
684
906
|
aborted: true
|
|
@@ -835,21 +1057,31 @@ var WIRE_CREATE_WORKSPACE_FIELDS = wireFields()({
|
|
|
835
1057
|
var WIRE_CREATE_WORKSPACE_RESPONSE_FIELDS = wireFields()({
|
|
836
1058
|
entry: true
|
|
837
1059
|
});
|
|
838
|
-
|
|
1060
|
+
var WIRE_CONTEXT_FIELDS = wireFields()({
|
|
1061
|
+
breakdown: true
|
|
1062
|
+
});
|
|
1063
|
+
var WIRE_COMPACT_FIELDS = wireFields()({
|
|
1064
|
+
ran: true,
|
|
1065
|
+
before: true,
|
|
1066
|
+
after: true
|
|
1067
|
+
});
|
|
839
1068
|
// src/wire-capability.ts
|
|
840
1069
|
var WIRE_AGENT_ROLE_FIELDS = wireFields()({
|
|
841
1070
|
name: true,
|
|
842
1071
|
description: true,
|
|
843
1072
|
source: true,
|
|
844
1073
|
tools: true,
|
|
1074
|
+
skills: true,
|
|
845
1075
|
maxTurns: true,
|
|
846
|
-
toolsCut: true
|
|
1076
|
+
toolsCut: true,
|
|
1077
|
+
skillsCut: true
|
|
847
1078
|
});
|
|
848
1079
|
var WIRE_SKILL_FIELDS = wireFields()({
|
|
849
1080
|
name: true,
|
|
850
1081
|
category: true,
|
|
851
1082
|
description: true,
|
|
852
1083
|
tokens: true,
|
|
1084
|
+
residency: true,
|
|
853
1085
|
scope: true,
|
|
854
1086
|
type: true
|
|
855
1087
|
});
|
|
@@ -910,7 +1142,13 @@ var WIRE_SKILL_IMPORT_FIELDS = wireFields()({
|
|
|
910
1142
|
detail: true,
|
|
911
1143
|
reason: true
|
|
912
1144
|
});
|
|
913
|
-
|
|
1145
|
+
var WIRE_SKILL_REMOVE_FIELDS = wireFields()({
|
|
1146
|
+
ok: true,
|
|
1147
|
+
name: true,
|
|
1148
|
+
path: true,
|
|
1149
|
+
detail: true,
|
|
1150
|
+
reason: true
|
|
1151
|
+
});
|
|
914
1152
|
// src/wire-agent-role.ts
|
|
915
1153
|
var WIRE_ROLE_ADD_FIELDS = wireFields()({
|
|
916
1154
|
name: true,
|
|
@@ -920,7 +1158,36 @@ var WIRE_ROLE_ADD_RESPONSE_FIELDS = wireFields()({
|
|
|
920
1158
|
role: true,
|
|
921
1159
|
path: true
|
|
922
1160
|
});
|
|
923
|
-
|
|
1161
|
+
// src/wire-plugin.ts
|
|
1162
|
+
var WIRE_PLUGINS_FIELDS = wireFields()({
|
|
1163
|
+
installed: true,
|
|
1164
|
+
hits: true,
|
|
1165
|
+
pendingRestart: true
|
|
1166
|
+
});
|
|
1167
|
+
var WIRE_PLUGIN_PREVIEW_FIELDS = wireFields()({ ref: true });
|
|
1168
|
+
var WIRE_PLUGIN_INSTALL_FIELDS = wireFields()({
|
|
1169
|
+
ref: true,
|
|
1170
|
+
token: true
|
|
1171
|
+
});
|
|
1172
|
+
var WIRE_PLUGIN_NAME_FIELDS = wireFields()({ name: true });
|
|
1173
|
+
var WIRE_PLUGIN_UPDATE_FIELDS = wireFields()({
|
|
1174
|
+
name: true,
|
|
1175
|
+
token: true
|
|
1176
|
+
});
|
|
1177
|
+
var WIRE_PLUGIN_PREVIEW_RESPONSE_FIELDS = wireFields()({
|
|
1178
|
+
ok: true,
|
|
1179
|
+
preview: true,
|
|
1180
|
+
token: true,
|
|
1181
|
+
reason: true,
|
|
1182
|
+
detail: true
|
|
1183
|
+
});
|
|
1184
|
+
var WIRE_PLUGIN_ACTION_FIELDS = wireFields()({
|
|
1185
|
+
ok: true,
|
|
1186
|
+
entry: true,
|
|
1187
|
+
pendingRestart: true,
|
|
1188
|
+
detail: true,
|
|
1189
|
+
reason: true
|
|
1190
|
+
});
|
|
924
1191
|
// src/wire-mcp-config.ts
|
|
925
1192
|
var WIRE_MCP_CONFIG_ISSUE_FIELDS = wireFields()({
|
|
926
1193
|
path: true,
|
|
@@ -955,7 +1222,6 @@ var WIRE_MCP_APPLY_RESPONSE_FIELDS = wireFields()({
|
|
|
955
1222
|
issues: true,
|
|
956
1223
|
changes: true
|
|
957
1224
|
});
|
|
958
|
-
|
|
959
1225
|
// src/wire-security.ts
|
|
960
1226
|
var WIRE_SANDBOX_STATUS_FIELDS = wireFields()({
|
|
961
1227
|
level: true,
|
|
@@ -987,7 +1253,8 @@ var WIRE_PERMISSION_STATUS_FIELDS = wireFields()({
|
|
|
987
1253
|
configuredLayer: true,
|
|
988
1254
|
rules: true,
|
|
989
1255
|
shadows: true,
|
|
990
|
-
managed: true
|
|
1256
|
+
managed: true,
|
|
1257
|
+
cached: true
|
|
991
1258
|
});
|
|
992
1259
|
var WIRE_SECURITY_WORKSPACE_FIELDS = wireFields()({
|
|
993
1260
|
root: true,
|
|
@@ -1036,7 +1303,22 @@ var WIRE_SECURITY_FIELDS = wireFields()({
|
|
|
1036
1303
|
policy: true,
|
|
1037
1304
|
audit: true
|
|
1038
1305
|
});
|
|
1039
|
-
|
|
1306
|
+
// src/wire-approval-cache.ts
|
|
1307
|
+
var WIRE_CACHED_APPROVAL_FIELDS = wireFields()({
|
|
1308
|
+
id: true,
|
|
1309
|
+
toolName: true,
|
|
1310
|
+
target: true,
|
|
1311
|
+
scope: true,
|
|
1312
|
+
decision: true,
|
|
1313
|
+
at: true
|
|
1314
|
+
});
|
|
1315
|
+
var WIRE_APPROVAL_CACHE_REVOKE_REQUEST_FIELDS = wireFields()({
|
|
1316
|
+
id: true
|
|
1317
|
+
});
|
|
1318
|
+
var WIRE_APPROVAL_CACHE_REVOKE_RESPONSE_FIELDS = wireFields()({
|
|
1319
|
+
revoked: true,
|
|
1320
|
+
cached: true
|
|
1321
|
+
});
|
|
1040
1322
|
// src/wire-permission.ts
|
|
1041
1323
|
var WIRE_BLOCKED_LEVEL_FIELDS = wireFields()({
|
|
1042
1324
|
level: true,
|
|
@@ -1056,7 +1338,6 @@ var WIRE_PERMISSION_SET_RESPONSE_FIELDS = wireFields()({
|
|
|
1056
1338
|
changed: true,
|
|
1057
1339
|
state: true
|
|
1058
1340
|
});
|
|
1059
|
-
|
|
1060
1341
|
// src/wire-settings.ts
|
|
1061
1342
|
var WIRE_SETTING_WRITE_LAYERS = ["user", "projectLocal"];
|
|
1062
1343
|
function isWireSettingWriteLayer(value) {
|
|
@@ -1092,7 +1373,6 @@ var WIRE_SETTINGS_WRITE_FIELDS = wireFields()({
|
|
|
1092
1373
|
value: true,
|
|
1093
1374
|
apply: true
|
|
1094
1375
|
});
|
|
1095
|
-
|
|
1096
1376
|
// src/wire-model.ts
|
|
1097
1377
|
var WIRE_MODEL_SELECTION_FIELDS = wireFields()({
|
|
1098
1378
|
provider: true,
|
|
@@ -1106,13 +1386,13 @@ var WIRE_MODEL_FIELDS = wireFields()({
|
|
|
1106
1386
|
var WIRE_MODEL_SET_FIELDS = wireFields()({
|
|
1107
1387
|
model: true
|
|
1108
1388
|
});
|
|
1109
|
-
|
|
1110
1389
|
// src/wire-provider.ts
|
|
1111
1390
|
var WIRE_PROVIDER_OPTION_FIELDS = wireFields()({
|
|
1112
1391
|
type: true,
|
|
1113
1392
|
label: true,
|
|
1114
1393
|
envVar: true,
|
|
1115
|
-
hasKey: true
|
|
1394
|
+
hasKey: true,
|
|
1395
|
+
keyHint: true
|
|
1116
1396
|
});
|
|
1117
1397
|
var WIRE_PROVIDERS_FIELDS = wireFields()({
|
|
1118
1398
|
providers: true
|
|
@@ -1126,14 +1406,19 @@ var WIRE_MODEL_SUGGESTIONS_FIELDS = wireFields()({
|
|
|
1126
1406
|
var WIRE_PROVIDER_MODELS_FIELDS = wireFields()({
|
|
1127
1407
|
suggestions: true
|
|
1128
1408
|
});
|
|
1129
|
-
|
|
1409
|
+
var WIRE_PROVIDER_KEY_FIELDS = wireFields()({
|
|
1410
|
+
provider: true,
|
|
1411
|
+
hasKey: true,
|
|
1412
|
+
keyHint: true,
|
|
1413
|
+
backend: true,
|
|
1414
|
+
encrypted: true,
|
|
1415
|
+
envPath: true
|
|
1416
|
+
});
|
|
1130
1417
|
// src/wire-tools.ts
|
|
1131
1418
|
var WIRE_TOOL_GATE_FIELDS = wireFields()({
|
|
1132
1419
|
verdict: true,
|
|
1133
1420
|
by: true,
|
|
1134
1421
|
conditional: true
|
|
1135
|
-
// ⚠️ `rule` / `layer` 是可选键,**故意不在这张表上**(同 `WIRE_CONFIG_FIELDS`
|
|
1136
|
-
// 那条 ⚠️):没命中规则、或者反查不到层,正是它们的正常形态
|
|
1137
1422
|
});
|
|
1138
1423
|
var WIRE_TOOL_ROW_FIELDS = wireFields()({
|
|
1139
1424
|
name: true,
|
|
@@ -1141,13 +1426,11 @@ var WIRE_TOOL_ROW_FIELDS = wireFields()({
|
|
|
1141
1426
|
source: true,
|
|
1142
1427
|
type: true,
|
|
1143
1428
|
calls: true
|
|
1144
|
-
// ⚠️ `gate` 是可选键,理由同上面那条
|
|
1145
1429
|
});
|
|
1146
1430
|
var WIRE_TOOLS_FIELDS = wireFields()({
|
|
1147
1431
|
tools: true,
|
|
1148
1432
|
level: true
|
|
1149
1433
|
});
|
|
1150
|
-
|
|
1151
1434
|
// src/wire-artifacts.ts
|
|
1152
1435
|
var WIRE_FILE_CHANGE_FIELDS = wireFields()({
|
|
1153
1436
|
path: true,
|
|
@@ -1159,7 +1442,34 @@ var WIRE_ARTIFACTS_FIELDS = wireFields()({
|
|
|
1159
1442
|
changes: true,
|
|
1160
1443
|
root: true
|
|
1161
1444
|
});
|
|
1162
|
-
|
|
1445
|
+
// src/wire-file-view.ts
|
|
1446
|
+
var WIRE_FILE_STAT_MAX = 32;
|
|
1447
|
+
var WIRE_FILE_STAT_OK_FIELDS = wireFields()({
|
|
1448
|
+
path: true,
|
|
1449
|
+
ok: true,
|
|
1450
|
+
kind: true,
|
|
1451
|
+
bytes: true,
|
|
1452
|
+
mtimeMs: true,
|
|
1453
|
+
openable: true
|
|
1454
|
+
});
|
|
1455
|
+
var WIRE_FILE_STAT_REFUSED_FIELDS = wireFields()({
|
|
1456
|
+
path: true,
|
|
1457
|
+
ok: true,
|
|
1458
|
+
refusal: true
|
|
1459
|
+
});
|
|
1460
|
+
var WIRE_FILE_STAT_RESPONSE_FIELDS = wireFields()({
|
|
1461
|
+
files: true,
|
|
1462
|
+
overLimit: true,
|
|
1463
|
+
root: true
|
|
1464
|
+
});
|
|
1465
|
+
var WIRE_FILE_TEXT_RESPONSE_FIELDS = wireFields()({
|
|
1466
|
+
path: true,
|
|
1467
|
+
text: true,
|
|
1468
|
+
bytes: true
|
|
1469
|
+
});
|
|
1470
|
+
var WIRE_FILE_OPEN_RESPONSE_FIELDS = wireFields()({
|
|
1471
|
+
ok: true
|
|
1472
|
+
});
|
|
1163
1473
|
// src/wire-schedule.ts
|
|
1164
1474
|
var WIRE_SCHEDULE_ISSUE_CODES = [
|
|
1165
1475
|
"name-empty",
|
|
@@ -1238,11 +1548,114 @@ var WIRE_SCHEDULE_RECORDING_FIELDS = wireFields()({
|
|
|
1238
1548
|
missing: true,
|
|
1239
1549
|
truncated: true
|
|
1240
1550
|
});
|
|
1241
|
-
|
|
1551
|
+
var WIRE_SCHEDULE_PENDING_FIELDS = wireFields()({
|
|
1552
|
+
items: true
|
|
1553
|
+
});
|
|
1554
|
+
// src/wire-goal.ts
|
|
1555
|
+
var WIRE_GOAL_PHASES = [
|
|
1556
|
+
"active",
|
|
1557
|
+
"paused",
|
|
1558
|
+
"blocked",
|
|
1559
|
+
"complete"
|
|
1560
|
+
];
|
|
1561
|
+
function isWireGoalPhase(value) {
|
|
1562
|
+
return WIRE_GOAL_PHASES.includes(value);
|
|
1563
|
+
}
|
|
1564
|
+
var WIRE_GOAL_BLOCK_FIELDS = wireFields()({
|
|
1565
|
+
code: true,
|
|
1566
|
+
message: true
|
|
1567
|
+
});
|
|
1568
|
+
var WIRE_GOAL_FIELDS = wireFields()({
|
|
1569
|
+
objective: true,
|
|
1570
|
+
phase: true,
|
|
1571
|
+
maxRounds: true,
|
|
1572
|
+
roundsUsed: true,
|
|
1573
|
+
createdAt: true,
|
|
1574
|
+
updatedAt: true
|
|
1575
|
+
});
|
|
1576
|
+
var WIRE_GOAL_LIMITS_FIELDS = wireFields()({
|
|
1577
|
+
defaultMaxRounds: true,
|
|
1578
|
+
maxRounds: true,
|
|
1579
|
+
maxObjectiveChars: true,
|
|
1580
|
+
maxReasonChars: true
|
|
1581
|
+
});
|
|
1582
|
+
var WIRE_GOAL_RESPONSE_FIELDS = wireFields()({
|
|
1583
|
+
goal: true,
|
|
1584
|
+
limits: true
|
|
1585
|
+
});
|
|
1586
|
+
var WIRE_GOAL_CREATE_FIELDS = wireFields()({
|
|
1587
|
+
objective: true
|
|
1588
|
+
});
|
|
1589
|
+
var WIRE_GOAL_ACTIONS = [
|
|
1590
|
+
"edit",
|
|
1591
|
+
"budget",
|
|
1592
|
+
"pause",
|
|
1593
|
+
"resume",
|
|
1594
|
+
"complete"
|
|
1595
|
+
];
|
|
1596
|
+
var WIRE_GOAL_REFUSALS = [
|
|
1597
|
+
"busy",
|
|
1598
|
+
"no-goal",
|
|
1599
|
+
"empty-objective",
|
|
1600
|
+
"objective-too-long",
|
|
1601
|
+
"bad-budget",
|
|
1602
|
+
"bad-block-code",
|
|
1603
|
+
"empty-block-message",
|
|
1604
|
+
"empty-evidence",
|
|
1605
|
+
"wrong-phase",
|
|
1606
|
+
"unavailable"
|
|
1607
|
+
];
|
|
1608
|
+
var WIRE_GOAL_WRITE_FIELDS = wireFields()({
|
|
1609
|
+
ok: true,
|
|
1610
|
+
goal: true
|
|
1611
|
+
});
|
|
1612
|
+
var WIRE_GOAL_CLEAR_FIELDS = wireFields()({
|
|
1613
|
+
ok: true,
|
|
1614
|
+
cleared: true
|
|
1615
|
+
});
|
|
1616
|
+
var WIRE_BLOCKED_GOAL_FIELDS = wireFields()({
|
|
1617
|
+
sessionId: true,
|
|
1618
|
+
sessionTitle: true,
|
|
1619
|
+
goal: true
|
|
1620
|
+
});
|
|
1621
|
+
var WIRE_BLOCKED_GOALS_FIELDS = wireFields()({
|
|
1622
|
+
items: true
|
|
1623
|
+
});
|
|
1624
|
+
// src/wire-mention.ts
|
|
1625
|
+
var WIRE_SESSION_CANDIDATE_FIELDS = wireFields()({
|
|
1626
|
+
sessionId: true,
|
|
1627
|
+
title: true,
|
|
1628
|
+
updatedAt: true,
|
|
1629
|
+
messageCount: true,
|
|
1630
|
+
sameWorkspace: true
|
|
1631
|
+
});
|
|
1632
|
+
var WIRE_SESSION_CANDIDATES_FIELDS = wireFields()({
|
|
1633
|
+
candidates: true
|
|
1634
|
+
});
|
|
1635
|
+
var WIRE_FILE_CANDIDATE_FIELDS = wireFields()({
|
|
1636
|
+
path: true
|
|
1637
|
+
});
|
|
1638
|
+
var WIRE_FILE_CANDIDATES_FIELDS = wireFields()({
|
|
1639
|
+
candidates: true,
|
|
1640
|
+
unmentionable: true,
|
|
1641
|
+
truncated: true
|
|
1642
|
+
});
|
|
1643
|
+
// src/sidebar-menu.ts
|
|
1644
|
+
var SIDEBAR_MENU_MESSAGE_TYPE = "epoch:sidebar-menu";
|
|
1645
|
+
// src/compliance.ts
|
|
1646
|
+
var COMPLIANCE_CATEGORIES = [
|
|
1647
|
+
"sexual",
|
|
1648
|
+
"political",
|
|
1649
|
+
"hate",
|
|
1650
|
+
"violence",
|
|
1651
|
+
"illegal",
|
|
1652
|
+
"self_harm",
|
|
1653
|
+
"privacy"
|
|
1654
|
+
];
|
|
1655
|
+
var COMPLIANCE_ACTIONS = ["block", "mask", "warn", "off"];
|
|
1242
1656
|
// src/secret.ts
|
|
1243
1657
|
var SECRET_SERVICE = "epoch-agent";
|
|
1244
1658
|
var MCP_DATA_KEY_NAME = "mcp-auth-data-key";
|
|
1245
|
-
|
|
1246
1659
|
// src/i18n.ts
|
|
1247
1660
|
var LANGS = ["zh", "en"];
|
|
1248
1661
|
var DEFAULT_LANG = "zh";
|
|
@@ -1250,5 +1663,38 @@ function isLang(value) {
|
|
|
1250
1663
|
return LANGS.includes(value);
|
|
1251
1664
|
}
|
|
1252
1665
|
var WIRE_LANG_PARAM = "lang";
|
|
1666
|
+
var PLACEHOLDER = /\{(\w+)\}/g;
|
|
1667
|
+
function placeholdersOf(text) {
|
|
1668
|
+
const found = [];
|
|
1669
|
+
for (const match of text.matchAll(PLACEHOLDER)) {
|
|
1670
|
+
const name = match[1];
|
|
1671
|
+
if (name && !found.includes(name)) found.push(name);
|
|
1672
|
+
}
|
|
1673
|
+
return found;
|
|
1674
|
+
}
|
|
1675
|
+
function flattenCatalog(value, prefix = "", out = {}) {
|
|
1676
|
+
if (!value || typeof value !== "object" || Array.isArray(value)) return out;
|
|
1677
|
+
for (const [key, child] of Object.entries(value)) {
|
|
1678
|
+
const path = prefix ? `${prefix}.${key}` : key;
|
|
1679
|
+
if (typeof child === "string") out[path] = child;
|
|
1680
|
+
else flattenCatalog(child, path, out);
|
|
1681
|
+
}
|
|
1682
|
+
return out;
|
|
1683
|
+
}
|
|
1684
|
+
function makeTranslate(catalogs) {
|
|
1685
|
+
const catalogOf = (lang) => catalogs[lang] ?? {};
|
|
1686
|
+
return (lang, key, vars) => {
|
|
1687
|
+
const text = catalogOf(lang)[key] ?? catalogOf(DEFAULT_LANG)[key] ?? key;
|
|
1688
|
+
if (!vars) return text;
|
|
1689
|
+
return text.replace(PLACEHOLDER, (whole, name) => {
|
|
1690
|
+
const value = vars[name];
|
|
1691
|
+
return value === void 0 ? whole : String(value);
|
|
1692
|
+
});
|
|
1693
|
+
};
|
|
1694
|
+
}
|
|
1695
|
+
function translatorFor(catalogs, lang) {
|
|
1696
|
+
const translate = makeTranslate(catalogs);
|
|
1697
|
+
return (key, vars) => translate(lang, key, vars);
|
|
1698
|
+
}
|
|
1253
1699
|
|
|
1254
|
-
export { ACTION_CONTEXTS, AGENT_ROLE_NAME_PATTERN, API_KEY_ENV_VARS, APPROVAL_OUTCOMES, COMMAND_NAME_PATTERN, DEFAULT_AGENT_ROLE, DEFAULT_LANG, DiagnosticSink, GEN_AI, HEADLESS_INPUT_EVENT_TYPES, HEADLESS_INPUT_FORMATS, HEADLESS_OUTPUT_FORMATS, HEADLESS_PROTOCOL_VERSION, KEY_ACTIONS, LANGS, MAX_HEADER_CHARS, MAX_OPTIONS, MAX_QUESTIONS, MCP_DATA_KEY_NAME, METRIC, MIN_OPTIONS, NOOP_TELEMETRY, OPERATION_TYPES, PERMISSION_LEVELS, PLAN_OUTCOMES,
|
|
1700
|
+
export { ACTION_CONTEXTS, AGENT_ROLE_NAME_PATTERN, API_KEY_ENV_VARS, APPROVAL_OUTCOMES, COMMAND_NAME_PATTERN, COMPLIANCE_ACTIONS, COMPLIANCE_CATEGORIES, DEFAULT_AGENT_ROLE, DEFAULT_LANG, DiagnosticSink, GEN_AI, HEADLESS_INPUT_EVENT_TYPES, HEADLESS_INPUT_FORMATS, HEADLESS_OUTPUT_FORMATS, HEADLESS_PROTOCOL_VERSION, KEY_ACTIONS, LANGS, MAX_ATTACH_BYTES, MAX_ATTACH_FILES, MAX_ATTACH_TOTAL_BYTES, MAX_HEADER_CHARS, MAX_OPTIONS, MAX_QUESTIONS, MAX_SESSION_ATTACH_BYTES, MAX_SESSION_REFS, MCP_DATA_KEY_NAME, METRIC, MIN_OPTIONS, NOOP_TELEMETRY, OPERATION_TYPES, PERMISSION_LEVELS, PLAN_OUTCOMES, PROVIDER_INFOS, PROVIDER_TYPES, RESERVED_CHORDS, RESERVED_COMMAND_NAMES, SCHEDULE_INTERVAL_MINUTES, SCHEDULE_RUN_STATUSES, SCHEDULE_TEMPLATES, SEARCH_API_KEY_ENV, SEARCH_PROVIDER_TYPES, SECRET_SERVICE, SEQUENCE_CONTEXTS, SESSION_MENTION_PREFIX, SESSION_REFERENCE_ERROR_CODES, SHELL_KINDS, SIDEBAR_MENU_MESSAGE_TYPE, SIMULTANEOUS_CONTEXTS, SYSTEM_NOTE_PREFIX, ToolExposure, WIRE_ABORT_FIELDS, WIRE_ABOUT_FIELDS, WIRE_AGENT_ROLE_FIELDS, WIRE_APPROVAL_CACHE_REVOKE_REQUEST_FIELDS, WIRE_APPROVAL_CACHE_REVOKE_RESPONSE_FIELDS, WIRE_APPROVAL_LIST_FIELDS, WIRE_APPROVAL_ROW_FIELDS, WIRE_ARTIFACTS_FIELDS, WIRE_AUDIT_LOG_FIELDS, WIRE_AUDIT_ROW_FIELDS, WIRE_AUTH_COOKIE, WIRE_AUTH_COOKIE_ATTRS, WIRE_AUTH_TOKEN_PARAM, WIRE_BACKGROUND_TASK_FIELDS, WIRE_BLOCKED_GOALS_FIELDS, WIRE_BLOCKED_GOAL_FIELDS, WIRE_BLOCKED_LEVEL_FIELDS, WIRE_BUILTIN_CONNECTOR_FIELDS, WIRE_CACHED_APPROVAL_FIELDS, WIRE_CAPABILITIES_FIELDS, WIRE_CAPABILITY_PROJECT_FIELDS, WIRE_CHECKPOINT_LIST_FIELDS, WIRE_CHECKPOINT_SUMMARY_FIELDS, WIRE_COMMANDS_FIELDS, WIRE_COMMAND_EXPANSION_FIELDS, WIRE_COMPACT_FIELDS, WIRE_COMPRESSION_LINE_FIELDS, WIRE_CONFIG_FIELDS, WIRE_CONTEXT_FIELDS, WIRE_CREATE_SESSION_FIELDS, WIRE_CREATE_WORKSPACE_FIELDS, WIRE_CREATE_WORKSPACE_RESPONSE_FIELDS, WIRE_CUSTOM_COMMAND_FIELDS, WIRE_DELETE_SESSION_FIELDS, WIRE_DIFF_FILE_FIELDS, WIRE_ERROR_FIELDS, WIRE_FILE_CANDIDATES_FIELDS, WIRE_FILE_CANDIDATE_FIELDS, WIRE_FILE_CHANGE_FIELDS, WIRE_FILE_OPEN_RESPONSE_FIELDS, WIRE_FILE_REFERENCE_FIELDS, WIRE_FILE_STAT_MAX, WIRE_FILE_STAT_OK_FIELDS, WIRE_FILE_STAT_REFUSED_FIELDS, WIRE_FILE_STAT_RESPONSE_FIELDS, WIRE_FILE_TEXT_RESPONSE_FIELDS, WIRE_GOAL_ACTIONS, WIRE_GOAL_BLOCK_FIELDS, WIRE_GOAL_CLEAR_FIELDS, WIRE_GOAL_CREATE_FIELDS, WIRE_GOAL_FIELDS, WIRE_GOAL_LIMITS_FIELDS, WIRE_GOAL_PHASES, WIRE_GOAL_REFUSALS, WIRE_GOAL_RESPONSE_FIELDS, WIRE_GOAL_WRITE_FIELDS, WIRE_HEALTH_FIELDS, WIRE_IMAGE_REFERENCE_FIELDS, WIRE_KNOWN_WORKSPACE_FIELDS, WIRE_LANG_PARAM, WIRE_MANAGED_LOCK_FIELDS, WIRE_MCP_ADD_FIELDS, WIRE_MCP_ADD_RESPONSE_FIELDS, WIRE_MCP_APPLY_ENTRY_FIELDS, WIRE_MCP_APPLY_RESPONSE_FIELDS, WIRE_MCP_CONFIG_APPLY_FIELDS, WIRE_MCP_CONFIG_FIELDS, WIRE_MCP_CONFIG_ISSUE_FIELDS, WIRE_MCP_CONFIG_SAVE_FIELDS, WIRE_MCP_CONFIG_SAVE_RESPONSE_FIELDS, WIRE_MCP_CONNECTOR_FIELDS, WIRE_MCP_RECONNECT_FIELDS, WIRE_MESSAGE_LIST_FIELDS, WIRE_MODEL_FIELDS, WIRE_MODEL_SELECTION_FIELDS, WIRE_MODEL_SET_FIELDS, WIRE_MODEL_SUGGESTIONS_FIELDS, WIRE_PATCH_SESSION_FIELDS, WIRE_PATCH_SESSION_RESPONSE_FIELDS, WIRE_PERMISSION_RULE_FIELDS, WIRE_PERMISSION_SET_REQUEST_FIELDS, WIRE_PERMISSION_SET_RESPONSE_FIELDS, WIRE_PERMISSION_SHADOW_FIELDS, WIRE_PERMISSION_STATE_FIELDS, WIRE_PERMISSION_STATUS_FIELDS, WIRE_PLAN_ACTIONS, WIRE_PLAN_FIELDS, WIRE_PLAN_MODE_REQUEST_FIELDS, WIRE_PLAN_MODE_RESPONSE_FIELDS, WIRE_PLAN_MODE_STATE_FIELDS, WIRE_PLUGINS_FIELDS, WIRE_PLUGIN_ACTION_FIELDS, WIRE_PLUGIN_INSTALL_FIELDS, WIRE_PLUGIN_NAME_FIELDS, WIRE_PLUGIN_PREVIEW_FIELDS, WIRE_PLUGIN_PREVIEW_RESPONSE_FIELDS, WIRE_PLUGIN_UPDATE_FIELDS, WIRE_POLICY_DIR_FIELDS, WIRE_POLICY_STATUS_FIELDS, WIRE_PROVIDERS_FIELDS, WIRE_PROVIDER_KEY_FIELDS, WIRE_PROVIDER_MODELS_FIELDS, WIRE_PROVIDER_OPTION_FIELDS, WIRE_QUESTION_LIST_FIELDS, WIRE_QUESTION_ROW_FIELDS, WIRE_RESPOND_APPROVAL_FIELDS, WIRE_RESPOND_APPROVAL_RESPONSE_FIELDS, WIRE_RESPOND_QUESTION_FIELDS, WIRE_RESPOND_QUESTION_RESPONSE_FIELDS, WIRE_REWIND_FILE_PLAN_FIELDS, WIRE_REWIND_OUTCOME_FIELDS, WIRE_REWIND_PREVIEW_FIELDS, WIRE_REWIND_REQUEST_FIELDS, WIRE_REWIND_RESPONSE_FIELDS, WIRE_REWIND_SCOPES, WIRE_ROLE_ADD_FIELDS, WIRE_ROLE_ADD_RESPONSE_FIELDS, WIRE_SANDBOX_STATUS_FIELDS, WIRE_SCHEDULE_CAPABILITY_FIELDS, WIRE_SCHEDULE_CREATE_FIELDS, WIRE_SCHEDULE_DEFAULTS_FIELDS, WIRE_SCHEDULE_DELETE_FIELDS, WIRE_SCHEDULE_FIELDS, WIRE_SCHEDULE_FIX_FIELDS, WIRE_SCHEDULE_FIX_REQUEST_FIELDS, WIRE_SCHEDULE_ISSUE_CODES, WIRE_SCHEDULE_LIST_FIELDS, WIRE_SCHEDULE_PENDING_FIELDS, WIRE_SCHEDULE_RECORDING_FIELDS, WIRE_SCHEDULE_ROW_FIELDS, WIRE_SCHEDULE_RUNS_FIELDS, WIRE_SCHEDULE_RUN_FIELDS, WIRE_SCHEDULE_SAVE_FIELDS, WIRE_SECURITY_FIELDS, WIRE_SECURITY_WORKSPACE_FIELDS, WIRE_SEND_MESSAGE_FIELDS, WIRE_SEND_MESSAGE_RESPONSE_FIELDS, WIRE_SESSION_CANDIDATES_FIELDS, WIRE_SESSION_CANDIDATE_FIELDS, WIRE_SESSION_FINISH_FIELDS, WIRE_SESSION_LIST_FIELDS, WIRE_SESSION_REFERENCE_FIELDS, WIRE_SESSION_RESPONSE_FIELDS, WIRE_SESSION_SUMMARY_FIELDS, WIRE_SESSION_WORKSPACE_FIELDS, WIRE_SESSION_WORKSPACE_RESPONSE_FIELDS, WIRE_SETTINGS_FIELDS, WIRE_SETTINGS_WRITE_FIELDS, WIRE_SETTINGS_WRITE_REQUEST_FIELDS, WIRE_SETTING_ROW_FIELDS, WIRE_SETTING_STEP_FIELDS, WIRE_SETTING_WRITE_FIELDS, WIRE_SETTING_WRITE_LAYERS, WIRE_SKILL_BODY_FIELDS, WIRE_SKILL_FIELDS, WIRE_SKILL_IMPORT_FIELDS, WIRE_SKILL_IMPORT_PREVIEW_FIELDS, WIRE_SKILL_REMOVE_FIELDS, WIRE_TASKS_FIELDS, WIRE_TOOLS_FIELDS, WIRE_TOOL_GATE_FIELDS, WIRE_TOOL_ROW_FIELDS, WIRE_WORKSPACE_DIFF_FIELDS, WIRE_WORKSPACE_DIRS_FIELDS, WIRE_WORKSPACE_DIR_ENTRY_FIELDS, WIRE_WORKSPACE_REF_FIELDS, apiKeyEnvVar, assertNeverPart, assistantTurnText, attachSessionSurface, chordId, collectPendingApprovals, compressionThresholdTokens, conformsToWire, contentToText, diagnosticToLine, extractAllMentions, extractMentions, extractSessionMentions, filePartSummary, flattenCatalog, getProviderInfo, hasFailure, isApprovalOutcome, isContextNearlyFull, isHeadlessInputFormat, isHeadlessLifecycleEvent, isHeadlessOutputFormat, isKeyAction, isLang, isMentionableFilePath, isOperationType, isPermissionLevel, isPlanOutcome, isProviderType, isQuestionAnswerMap, isSearchProviderType, isValidAgentRoleName, isValidCommandName, isWireGoalPhase, isWireHubEvent, isWirePlanAction, isWireRewindScope, isWireSettingWriteLayer, makeTranslate, normalizeApproval, packSessionSurface, parseChord, parseModelRef, parseSequence, perAction, placeholdersOf, promptTokens, sequenceId, sessionPartSummary, stripSystemNote, systemNote, tableOf, totalUsageTokens, translatorFor, turnDigest, unfixedRules, utf8ByteLength, wireFields };
|