@cobia/pi-onward 0.3.1 → 0.4.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.
@@ -1,62 +1,42 @@
1
1
  {
2
2
  "$schema": "https://json-schema.org/draft/2020-12/schema",
3
3
  "$id": "https://raw.githubusercontent.com/cobia68/pi-onward/main/onward.schema.json",
4
- "title": "pi-onward 设置",
5
- "description": "~/.pi/agent/onward.json(全局)或 .pi/onward.json(项目级)。顶层的参数是每条规则的默认值,规则里同名的字段覆盖它",
4
+ "title": "pi-onward 阶段恢复策略",
6
5
  "type": "object",
7
6
  "additionalProperties": false,
8
7
  "properties": {
9
8
  "$schema": {
10
- "description": "这份 JSON Schema 的地址,给编辑器用",
11
9
  "type": "string"
12
10
  },
13
11
  "enabled": {
14
- "description": "插件开关",
15
12
  "type": "boolean",
16
13
  "default": true
17
14
  },
18
- "action": {
19
- "description": "怎么续跑。message:发一条看得见的消息再接着跑;resend:静默重发同一个请求;stop:不续跑,只提醒",
20
- "enum": [
21
- "message",
22
- "resend",
23
- "stop"
24
- ],
25
- "default": "message"
26
- },
27
- "prompt": {
28
- "description": "message 发的消息,可含 {attempt} {max} {error} {rule}。仅在 action 为 message 时使用",
29
- "type": "string",
30
- "pattern": "\\S",
31
- "maxLength": 500,
32
- "default": "继续"
15
+ "quietStartup": {
16
+ "type": "boolean",
17
+ "description": "仅允许写在全局;未配置时跟随 Pi"
33
18
  },
34
- "maxRetries": {
35
- "description": "连续失败时最多续跑几次(1–50)。仅在 action 为 message 或 resend 时使用",
19
+ "maxFailures": {
36
20
  "type": "integer",
37
21
  "minimum": 1,
38
- "maximum": 50,
39
- "default": 10
22
+ "maximum": 1000,
23
+ "description": "一次恢复过程最多处理多少次失败;超过后停止",
24
+ "default": 20
40
25
  },
41
- "maxSameError": {
42
- "description": "同一个错误最多续跑几次,再出现就彻底停(1–50)。仅在 action 为 message 或 resend 时使用",
26
+ "maxHandoffs": {
43
27
  "type": "integer",
44
- "minimum": 1,
28
+ "minimum": 0,
45
29
  "maximum": 50,
46
- "default": 10
30
+ "description": "恢复链最多跨会话接管多少次;0 禁止接管",
31
+ "default": 3
47
32
  },
48
- "delay": {
49
- "description": "列表按顺序等,最后一个值重复;起步..封顶按次数增长(5s,10s,30s 或 3s..15s)。仅在 action 为 message 或 resend 时使用",
33
+ "actionTimeout": {
50
34
  "type": "string",
51
- "pattern": "^\\s*(\\d+(\\.\\d+)?(ms|s|m)\\.\\.\\d+(\\.\\d+)?(ms|s|m)|\\d+(\\.\\d+)?(ms|s|m)(\\s*,\\s*\\d+(\\.\\d+)?(ms|s|m))*)\\s*$",
52
- "default": "3s..15s"
53
- },
54
- "quietStartup": {
55
- "description": "启动时的提示(用上了项目级设置、没有可用的规则):true 不显示,false 照常显示,不写时跟着 pi 的 quietStartup;设置有问题时照样警告。只能写在全局设置",
56
- "type": "boolean"
35
+ "pattern": "^\\d+(\\.\\d+)?(ms|s|m)$",
36
+ "description": "单次动作执行时限;超时结果未知,不自动重放",
37
+ "default": "30s"
57
38
  },
58
39
  "rules": {
59
- "description": "按顺序第一条命中的生效;没命中的错误和空回复不处理",
60
40
  "type": "array",
61
41
  "items": {
62
42
  "$ref": "#/$defs/rule"
@@ -65,94 +45,110 @@
65
45
  },
66
46
  "$defs": {
67
47
  "rule": {
68
- "description": "规则需要匹配条件或显式动作;不写 when 或写成 {} 的失败兜底必须显式写 action",
69
48
  "type": "object",
70
49
  "additionalProperties": false,
71
- "anyOf": [
72
- {
73
- "required": [
74
- "action"
75
- ]
76
- },
77
- {
78
- "required": [
79
- "when"
80
- ],
81
- "properties": {
82
- "when": {
83
- "minProperties": 1
84
- }
85
- }
86
- }
50
+ "required": [
51
+ "stages"
87
52
  ],
88
53
  "properties": {
89
54
  "name": {
90
- "description": "规则名,出现在通知里,不能重名;不写时按位置叫 rule-1、rule-2",
91
55
  "type": "string",
92
56
  "pattern": "\\S"
93
57
  },
94
58
  "enabled": {
95
- "description": "false 时保留但跳过",
96
59
  "type": "boolean",
97
60
  "default": true
98
61
  },
99
62
  "when": {
100
63
  "$ref": "#/$defs/when"
101
64
  },
102
- "action": {
103
- "description": "怎么续跑。message:发一条看得见的消息再接着跑;resend:静默重发同一个请求;stop:不续跑,只提醒。覆盖顶层的同名字段",
104
- "enum": [
105
- "message",
106
- "resend",
107
- "stop"
108
- ]
109
- },
110
- "prompt": {
111
- "description": "message 发的消息,可含 {attempt} {max} {error} {rule}。仅在 action 为 message 时使用。覆盖顶层的同名字段",
112
- "type": "string",
113
- "pattern": "\\S",
114
- "maxLength": 500
115
- },
116
- "maxRetries": {
117
- "description": "连续失败时最多续跑几次(1–50)。仅在 action 为 message 或 resend 时使用。覆盖顶层的同名字段",
118
- "type": "integer",
119
- "minimum": 1,
120
- "maximum": 50
121
- },
122
- "maxSameError": {
123
- "description": "同一个错误最多续跑几次,再出现就彻底停(1–50)。仅在 action 为 message 或 resend 时使用。覆盖顶层的同名字段",
124
- "type": "integer",
125
- "minimum": 1,
126
- "maximum": 50
127
- },
128
- "delay": {
129
- "description": "列表按顺序等,最后一个值重复;起步..封顶按次数增长(5s,10s,30s 或 3s..15s)。仅在 action 为 message 或 resend 时使用。覆盖顶层的同名字段",
130
- "type": "string",
131
- "pattern": "^\\s*(\\d+(\\.\\d+)?(ms|s|m)\\.\\.\\d+(\\.\\d+)?(ms|s|m)|\\d+(\\.\\d+)?(ms|s|m)(\\s*,\\s*\\d+(\\.\\d+)?(ms|s|m))*)\\s*$"
65
+ "stages": {
66
+ "type": "array",
67
+ "minItems": 1,
68
+ "description": "minFailures 严格递增;每次失败选择达到下限的最后一个阶段",
69
+ "prefixItems": [
70
+ {
71
+ "allOf": [
72
+ {
73
+ "$ref": "#/$defs/stage"
74
+ },
75
+ {
76
+ "type": "object",
77
+ "properties": {
78
+ "minFailures": {
79
+ "const": 1
80
+ }
81
+ }
82
+ }
83
+ ]
84
+ }
85
+ ],
86
+ "items": {
87
+ "$ref": "#/$defs/stage"
88
+ }
132
89
  }
133
90
  }
134
91
  },
135
92
  "when": {
136
- "description": "命中条件,几项都要满足;不写 failure 就不限制失败类型;不写 when 或写成 {} 时必须显式写 action",
137
93
  "type": "object",
138
94
  "additionalProperties": false,
139
95
  "properties": {
140
96
  "failure": {
141
- "description": "非空正则,大小写不敏感;普通错误匹配原始文案,缺少文案时匹配「未知错误」,空回复匹配空串。^$ 匹配空回复,.+ 匹配普通错误,.* 匹配所有失败",
142
97
  "type": "string",
143
- "minLength": 1
98
+ "minLength": 1,
99
+ "description": "大小写不敏感的正则;空回复用 ^$,所有失败用 .*"
144
100
  },
145
101
  "provider": {
146
- "description": "通配,只有 * 有特殊含义,大小写不敏感,整串匹配",
147
102
  "type": "string",
148
103
  "pattern": "\\S"
149
104
  },
150
105
  "model": {
151
- "description": "通配,只有 * 有特殊含义,大小写不敏感,整串匹配",
152
106
  "type": "string",
153
107
  "pattern": "\\S"
154
108
  }
155
109
  }
110
+ },
111
+ "stage": {
112
+ "type": "object",
113
+ "additionalProperties": false,
114
+ "required": [
115
+ "minFailures",
116
+ "action"
117
+ ],
118
+ "properties": {
119
+ "minFailures": {
120
+ "type": "integer",
121
+ "minimum": 1,
122
+ "maximum": 1000,
123
+ "description": "阶段生效的连续失败次数下限,包含当前失败"
124
+ },
125
+ "delay": {
126
+ "type": "string",
127
+ "pattern": "^\\s*(\\d+(\\.\\d+)?(ms|s|m)\\.\\.\\d+(\\.\\d+)?(ms|s|m)|\\d+(\\.\\d+)?(ms|s|m)(\\s*,\\s*\\d+(\\.\\d+)?(ms|s|m))*)\\s*$",
128
+ "default": "0s",
129
+ "description": "在当前阶段内按失败次数推进;省略时不等待"
130
+ },
131
+ "action": {
132
+ "$ref": "#/$defs/action"
133
+ }
134
+ }
135
+ },
136
+ "action": {
137
+ "type": "object",
138
+ "additionalProperties": false,
139
+ "required": [
140
+ "use"
141
+ ],
142
+ "properties": {
143
+ "use": {
144
+ "type": "string",
145
+ "pattern": "^[a-z][a-z0-9-]*(?:\\.[a-z][a-z0-9-]*)+$"
146
+ },
147
+ "with": {
148
+ "type": "object",
149
+ "description": "由已加载动作提供的 JSON Schema 校验;不执行隐式类型转换"
150
+ }
151
+ }
156
152
  }
157
153
  }
158
154
  }
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "@cobia/pi-onward",
3
- "version": "0.3.1",
4
- "description": "pi 出错或空回停止时,按规则自动续跑",
3
+ "version": "0.4.0",
4
+ "description": "pi 出错或空回复时,按阶段策略恢复并调用扩展命令或具名动作",
5
5
  "keywords": [
6
6
  "pi",
7
7
  "pi-package",
@@ -23,8 +23,12 @@
23
23
  "./src/extension/index.ts"
24
24
  ]
25
25
  },
26
+ "exports": {
27
+ "./actions": "./src/actions/protocol.ts"
28
+ },
26
29
  "files": [
27
30
  "src/",
31
+ "docs/",
28
32
  "example.json",
29
33
  "onward.schema.json"
30
34
  ],
@@ -50,5 +54,8 @@
50
54
  "@types/node": "^22.20.5",
51
55
  "tsx": "^4.23.15",
52
56
  "typescript": "^7.0.2"
57
+ },
58
+ "dependencies": {
59
+ "ajv": "^8.20.0"
53
60
  }
54
61
  }
@@ -0,0 +1,98 @@
1
+ /** Built-ins implement exactly the same contract as external actions. */
2
+ import type { ExtensionAPI } from "@earendil-works/pi-coding-agent";
3
+ import type { ActionDefinition } from "./protocol.ts";
4
+
5
+ export const CUSTOM_TYPE = "pi-onward";
6
+ const modes = ["tui", "rpc", "json", "print"] as const;
7
+ const empty = { type: "object", properties: {}, additionalProperties: false };
8
+ export function builtinActions(pi: Pick<ExtensionAPI, "getCommands" | "sendUserMessage">): ActionDefinition[] {
9
+ return [
10
+ {
11
+ name: "onward.resend",
12
+ description: "从模型上下文省略失败回复,重发请求",
13
+ phase: "boundary",
14
+ modes,
15
+ parameters: empty,
16
+ execute(_params, context) {
17
+ return {
18
+ kind: "continue",
19
+ entries: [{ type: "context_edit", targetId: context.targetId, replacement: null }],
20
+ };
21
+ },
22
+ },
23
+ {
24
+ name: "onward.message",
25
+ description: "发送一条消息续跑",
26
+ phase: "boundary",
27
+ modes,
28
+ parameters: {
29
+ type: "object",
30
+ properties: { prompt: { type: "string", pattern: "\\S", maxLength: 4000, default: "继续" } },
31
+ additionalProperties: false,
32
+ },
33
+ execute(params, context) {
34
+ const prompt = String(params.prompt ?? "继续");
35
+ if (prompt.includes("{taskPrompt}") && !context.taskPrompt?.trim())
36
+ return { kind: "failed", message: "No task prompt is available to expand {taskPrompt}" };
37
+ const vars: Record<string, string> = {
38
+ failures: String(context.failures),
39
+ rule: context.rule,
40
+ error: context.failure.text || "空回复",
41
+ taskPrompt: context.taskPrompt ?? "",
42
+ };
43
+ const content = prompt.replace(/\{(failures|rule|error|taskPrompt)\}/g, (_, key: string) => vars[key]!);
44
+ return {
45
+ kind: "continue",
46
+ entries: [
47
+ {
48
+ type: "custom_message",
49
+ customType: CUSTOM_TYPE,
50
+ content,
51
+ display: true,
52
+ details: { rule: context.rule, failures: context.failures, invocationId: context.invocationId },
53
+ },
54
+ ],
55
+ };
56
+ },
57
+ },
58
+ {
59
+ name: "onward.stop",
60
+ description: "停止本次自动恢复",
61
+ phase: "boundary",
62
+ modes,
63
+ parameters: {
64
+ type: "object",
65
+ properties: { reason: { type: "string", pattern: "\\S" } },
66
+ additionalProperties: false,
67
+ },
68
+ execute(params) {
69
+ return { kind: "stopped", message: String(params.reason ?? "规则要求停止,请处理失败原因后再发消息") };
70
+ },
71
+ },
72
+ {
73
+ name: "onward.command",
74
+ description: "分派已加载的扩展命令;业务结果未知",
75
+ phase: "settled",
76
+ modes,
77
+ parameters: {
78
+ type: "object",
79
+ required: ["name"],
80
+ additionalProperties: false,
81
+ properties: { name: { type: "string", pattern: "^[^/\\s]+$" }, args: { type: "string" } },
82
+ },
83
+ execute(params, context) {
84
+ if (context.signal.aborted) return { kind: "cancelled", message: "命令分派已取消" };
85
+ const name = String(params.name);
86
+ if (name === "onward" || name.startsWith("onward:"))
87
+ return { kind: "failed", message: "Cannot automatically invoke onward's own control commands" };
88
+ if (!pi.getCommands().some((command) => command.source === "extension" && command.name === name))
89
+ return {
90
+ kind: "failed",
91
+ message: `Extension command /${name} is not loaded; no text was sent to the model`,
92
+ };
93
+ pi.sendUserMessage(`/${name}${params.args ? ` ${params.args}` : ""}`, { expandPromptTemplates: true });
94
+ return { kind: "dispatched", message: `已分派 /${name};完成情况由目标插件报告` };
95
+ },
96
+ },
97
+ ];
98
+ }
@@ -0,0 +1,136 @@
1
+ /** Public, in-process action protocol. Registration is synchronous; execution returns a receipt. */
2
+ import type {
3
+ ExtensionAPI,
4
+ ExtensionCommandContext,
5
+ ExtensionContext,
6
+ SessionBoundaryDraft,
7
+ } from "@earendil-works/pi-coding-agent";
8
+
9
+ export type ExtensionMode = ExtensionContext["mode"];
10
+ export const DISCOVER_ACTIONS = "onward:discover-actions";
11
+ export const RESUME_RECOVERY = "onward:resume-recovery";
12
+ export const ACTION_NAME_PATTERN = "^[a-z][a-z0-9-]*(?:\\.[a-z][a-z0-9-]*)+$";
13
+ export type Parameters = Record<string, unknown>;
14
+ export type JsonSchema = Record<string, unknown>;
15
+
16
+ export interface ActionCall {
17
+ use: string;
18
+ with?: Parameters;
19
+ }
20
+
21
+ export interface FailureSnapshot {
22
+ kind: "error" | "empty";
23
+ text: string;
24
+ provider: string;
25
+ model: string;
26
+ }
27
+
28
+ /** Transfer this data through the provider's durable handoff, never through a cached host context. */
29
+ export interface RecoveryChain {
30
+ id: string;
31
+ handoffs: number;
32
+ maxHandoffs: number;
33
+ }
34
+
35
+ interface Execution {
36
+ invocationId: string;
37
+ episodeId: string;
38
+ sessionId: string;
39
+ rule: string;
40
+ failures: number;
41
+ minFailures: number;
42
+ failure: Readonly<FailureSnapshot>;
43
+ /** Task input text, kept stable across automatically generated continuation messages. */
44
+ taskPrompt?: string;
45
+ chain: Readonly<RecoveryChain>;
46
+ signal: AbortSignal;
47
+ }
48
+
49
+ export interface BoundaryActionContext extends Execution {
50
+ phase: "boundary";
51
+ targetId: string;
52
+ }
53
+ export interface SettledActionContext extends Execution {
54
+ phase: "settled";
55
+ /** A fresh command context supplied by Pi after all settled observers have finished. */
56
+ host: ExtensionCommandContext;
57
+ }
58
+ export type ActionContext = BoundaryActionContext | SettledActionContext;
59
+
60
+ export type TerminalResult =
61
+ | { kind: "completed" | "dispatched" | "handoff"; message?: string }
62
+ | { kind: "stopped" | "failed" | "cancelled" | "unknown"; message: string };
63
+ export type BoundaryResult = TerminalResult | { kind: "continue"; entries: SessionBoundaryDraft[] };
64
+ export type ActionResult = BoundaryResult;
65
+
66
+ interface Definition {
67
+ name: string;
68
+ description: string;
69
+ parameters: JsonSchema;
70
+ modes: readonly ExtensionMode[];
71
+ }
72
+ export type ActionDefinition = Definition &
73
+ (
74
+ | {
75
+ phase: "boundary";
76
+ handoff?: never;
77
+ execute(params: Parameters, context: BoundaryActionContext): BoundaryResult | Promise<BoundaryResult>;
78
+ }
79
+ | {
80
+ phase: "settled";
81
+ /** Reserve a cross-process handoff before invoking this action. */
82
+ handoff?: boolean;
83
+ execute(params: Parameters, context: SettledActionContext): TerminalResult | Promise<TerminalResult>;
84
+ }
85
+ );
86
+
87
+ export interface ActionDiscovery {
88
+ add(definition: ActionDefinition): void;
89
+ }
90
+
91
+ /** Call from the extension factory, before session_start; works in either extension load order. */
92
+ export function provideAction(pi: Pick<ExtensionAPI, "events" | "on">, definition: ActionDefinition): () => void {
93
+ let active = true;
94
+ const guard = (): TerminalResult | undefined =>
95
+ !active ? { kind: "cancelled", message: "Action provider has been unloaded" } : undefined;
96
+ const provided: ActionDefinition =
97
+ definition.phase === "boundary"
98
+ ? {
99
+ ...definition,
100
+ execute: (params: Parameters, context: BoundaryActionContext) =>
101
+ guard() ?? definition.execute(params, context),
102
+ }
103
+ : {
104
+ ...definition,
105
+ execute: (params: Parameters, context: SettledActionContext) =>
106
+ guard() ?? definition.execute(params, context),
107
+ };
108
+ const remove = pi.events.on(DISCOVER_ACTIONS, (request: unknown) => {
109
+ if (active && isDiscovery(request)) request.add(provided);
110
+ });
111
+ const dispose = () => {
112
+ active = false;
113
+ remove();
114
+ };
115
+ pi.on("session_shutdown", dispose);
116
+ return dispose;
117
+ }
118
+
119
+ export function isDiscovery(value: unknown): value is ActionDiscovery {
120
+ return !!value && typeof value === "object" && "add" in value && typeof value.add === "function";
121
+ }
122
+
123
+ export function isRecoveryChain(value: unknown): value is RecoveryChain {
124
+ if (!value || typeof value !== "object") return false;
125
+ const chain = value as RecoveryChain;
126
+ return (
127
+ typeof chain.id === "string" &&
128
+ chain.id.length > 0 &&
129
+ chain.id.length <= 128 &&
130
+ Number.isSafeInteger(chain.handoffs) &&
131
+ chain.handoffs >= 0 &&
132
+ Number.isSafeInteger(chain.maxHandoffs) &&
133
+ chain.maxHandoffs >= 0 &&
134
+ chain.handoffs <= chain.maxHandoffs
135
+ );
136
+ }
@@ -0,0 +1,112 @@
1
+ /** Discovers executable actions; configuration is linked only after all extension factories have registered. */
2
+ import type { ExtensionAPI } from "@earendil-works/pi-coding-agent";
3
+ import { Ajv2020, type ValidateFunction } from "ajv/dist/2020.js";
4
+ import type { Config } from "../policy/config.ts";
5
+ import { errorText, isRecord } from "../util.ts";
6
+ import {
7
+ ACTION_NAME_PATTERN,
8
+ type ActionCall,
9
+ type ActionDefinition,
10
+ DISCOVER_ACTIONS,
11
+ type ExtensionMode,
12
+ type Parameters,
13
+ } from "./protocol.ts";
14
+
15
+ export interface RegisteredAction {
16
+ definition: ActionDefinition;
17
+ validate: ValidateFunction;
18
+ }
19
+ export class ActionRegistry {
20
+ private actions = new Map<string, RegisteredAction>();
21
+ private errors: string[] = [];
22
+
23
+ discover(pi: Pick<ExtensionAPI, "events">, builtins: readonly ActionDefinition[]): void {
24
+ this.actions.clear();
25
+ this.errors = [];
26
+ const seen = new Set<string>();
27
+ const ajv = new Ajv2020({ allErrors: true, strict: true, validateFormats: false });
28
+ const add = (candidate: unknown) => {
29
+ try {
30
+ if (!isDefinition(candidate))
31
+ throw new Error("Invalid action definition: expected name, parameter schema, phase, modes, and execute");
32
+ if (seen.has(candidate.name)) {
33
+ this.actions.delete(candidate.name);
34
+ throw new Error("Duplicate action name");
35
+ }
36
+ seen.add(candidate.name);
37
+ const definition = {
38
+ ...candidate,
39
+ modes: [...candidate.modes],
40
+ parameters: structuredClone(candidate.parameters),
41
+ };
42
+ const validate = ajv.compile(definition.parameters);
43
+ if ((validate as ValidateFunction & { $async?: boolean }).$async)
44
+ throw new Error("Parameter schema must validate synchronously");
45
+ this.actions.set(definition.name, { definition, validate });
46
+ } catch (error) {
47
+ const name = isRecord(candidate) && typeof candidate.name === "string" ? candidate.name : "<unnamed>";
48
+ this.errors.push(`Action ${name} registration failed: ${errorText(error)}`);
49
+ }
50
+ };
51
+ for (const definition of builtins) add(definition);
52
+ // Synchronous declarations only. Ignore late callbacks, including asynchronous event handlers.
53
+ let accepting = true;
54
+ pi.events.emit(DISCOVER_ACTIONS, {
55
+ add: (definition: unknown) => {
56
+ if (accepting) add(definition);
57
+ },
58
+ });
59
+ accepting = false;
60
+ }
61
+ clear(): void {
62
+ this.actions.clear();
63
+ this.errors = [];
64
+ }
65
+ list(): ActionDefinition[] {
66
+ return [...this.actions.values()].map((entry) => entry.definition);
67
+ }
68
+ get(name: string): RegisteredAction | undefined {
69
+ return this.actions.get(name);
70
+ }
71
+ /** 注册表诊断独立于配置有效性;未引用的坏动作不能阻断其他动作。 */
72
+ get diagnostics(): readonly string[] {
73
+ return this.errors;
74
+ }
75
+ problems(config: Config): string[] {
76
+ const errors: string[] = [];
77
+ for (const rule of config.rules) {
78
+ if (!rule.enabled) continue;
79
+ for (const stage of rule.stages) {
80
+ const problem = this.check(stage.action);
81
+ if (problem) errors.push(`Rule "${rule.name}", minFailures ${stage.minFailures}: ${problem}`);
82
+ }
83
+ }
84
+ return errors;
85
+ }
86
+ check(call: ActionCall): string | undefined {
87
+ const registered = this.get(call.use);
88
+ if (!registered) return `Action ${call.use} is not loaded or failed to register`;
89
+ if (!registered.validate(call.with ?? {}))
90
+ return `Invalid parameters for ${call.use}: ${registered.validate.errors?.map((error) => `${error.instancePath || "/"} ${error.message}`).join("; ")}`;
91
+ return undefined;
92
+ }
93
+ parameters(call: ActionCall): Parameters {
94
+ return structuredClone(call.with ?? {});
95
+ }
96
+ }
97
+ function isDefinition(value: unknown): value is ActionDefinition {
98
+ if (!isRecord(value)) return false;
99
+ const modes: ExtensionMode[] = ["tui", "rpc", "json", "print"];
100
+ return (
101
+ typeof value.name === "string" &&
102
+ new RegExp(ACTION_NAME_PATTERN).test(value.name) &&
103
+ typeof value.description === "string" &&
104
+ isRecord(value.parameters) &&
105
+ (value.phase === "boundary" || value.phase === "settled") &&
106
+ Array.isArray(value.modes) &&
107
+ value.modes.length > 0 &&
108
+ value.modes.every((mode) => modes.includes(mode)) &&
109
+ (value.handoff === undefined || (value.phase === "settled" && typeof value.handoff === "boolean")) &&
110
+ typeof value.execute === "function"
111
+ );
112
+ }
@@ -1,13 +1,11 @@
1
- /** `/onward` 的参数里按 Tab:补参数,不补文件名。 */
2
1
  import type { AutocompleteProviderFactory } from "@earendil-works/pi-coding-agent";
3
2
  import { COMMAND } from "./text.ts";
4
3
 
5
- /** 光标在 `/onward` 的参数里:和 pi 一样只看第一行,命令名到空格为止。 */
6
4
  export function isArgumentTab(lines: string[], cursorLine: number, cursorCol: number): boolean {
7
5
  return cursorLine === 0 && (lines[0] ?? "").slice(0, cursorCol).trimStart().startsWith(`/${COMMAND} `);
8
6
  }
9
7
 
10
- /** pi 把参数里的 Tab 当成文件补全,紧跟在「/onward 」后面的 Tab 直接丢掉;在 `/onward` 的参数里都改成补参数。 */
8
+ /** Pi 的 Tab 默认补文件且忽略命令后的空参数;此处强制补参数。 */
11
9
  export const argumentTabCompletion: AutocompleteProviderFactory = (current) => ({
12
10
  getSuggestions: (lines, cursorLine, cursorCol, options) =>
13
11
  current.getSuggestions(lines, cursorLine, cursorCol, {