@akagilnc/pi-workflow-roles 0.1.5949 → 0.1.5955

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/CLAUDE.md CHANGED
@@ -57,7 +57,7 @@
57
57
 
58
58
  ## 起居录位置(#1092)
59
59
 
60
- 本票记录在 `~/.ak-roles/books/<簿>/<票号>/`,没有票号的在 `~/.ak-roles/books/<簿>/unbound/`。各腿的记录在其下 `runs/<runId>@<席>/`。角色凭已知票号自行定位与读取;代码不计算、不冻结、不向提示或附件递送本票指针。
60
+ 本票记录在 `~/.ak-roles/books/<簿>/<票号>/`,没有票号的在 `~/.ak-roles/books/<簿>/unbound/`。各腿的记录在其下 `runs/<runId>@<席>/`。角色凭已知票号自行定位与读取;代码不计算、不冻结、不向提示或附件递送本票指针。要读会话卷里谁说了什么,可以用 `ak-role dialogue <会话卷>`(用法见 `ak-role help dialogue`)。
61
61
 
62
62
  ## 锚定宪法
63
63
 
@@ -5081,20 +5081,20 @@ function isCodexOwnerResponseItemUser(message) {
5081
5081
  if (kinds === void 0) return false;
5082
5082
  return kinds.some((kind) => kind.startsWith("user."));
5083
5083
  }
5084
- function fromQueueEvent(row) {
5085
- if (row.type !== "queue-operation" || row.operation !== "enqueue") return [];
5086
- const content = row.content;
5087
- if (typeof content !== "string" || content === "") return [];
5088
- const id = nativeEventId(row);
5089
- return [{ speaker: "owner", text: content, ...id === void 0 ? {} : { id } }];
5090
- }
5091
5084
  function hasFixedOpenTagPrefix(content, tag) {
5092
5085
  if (!content.startsWith(tag)) return false;
5093
5086
  const next = content.charAt(tag.length);
5094
5087
  return next === "" || next === ">" || next === " " || next === " " || next === "\n" || next === "\r";
5095
5088
  }
5096
- function isFixedNonOwnerEnqueueShape(content) {
5097
- return hasFixedOpenTagPrefix(content, TASK_NOTIFICATION_OPEN_TAG);
5089
+ function fromQueuedCommandAttachment(row) {
5090
+ if (!isRecord(row.attachment) || row.attachment.type !== "queued_command") return [];
5091
+ const kind = materializationOriginKind(row.attachment);
5092
+ if (isNonOwnerOriginKind(kind)) return [];
5093
+ const text = textParts(row.attachment.prompt).join("");
5094
+ if (text === "") return [];
5095
+ if (kind === void 0 && hasFixedOpenTagPrefix(text, TASK_NOTIFICATION_OPEN_TAG)) return [];
5096
+ const id = nativeEventId(row);
5097
+ return [{ speaker: "owner", text, ...id === void 0 ? {} : { id } }];
5098
5098
  }
5099
5099
  function materializationOriginKind(row) {
5100
5100
  if (!isRecord(row.origin)) return void 0;
@@ -5124,13 +5124,10 @@ function fromMessageEvent(row) {
5124
5124
  function adaptSessionDialogue(rows) {
5125
5125
  return rows.map((row) => {
5126
5126
  if (row === void 0) return [];
5127
+ if (row.type === "queue-operation" || row.type === "api-request-blob") return [];
5128
+ if (row.type === "attachment") return fromQueuedCommandAttachment(row);
5127
5129
  const originKind = materializationOriginKind(row);
5128
5130
  if (isNonOwnerOriginKind(originKind)) return [];
5129
- if (row.type === "queue-operation" && row.operation === "enqueue" && typeof row.content === "string" && isFixedNonOwnerEnqueueShape(row.content)) {
5130
- return [];
5131
- }
5132
- const queued = fromQueueEvent(row);
5133
- if (queued.length > 0) return queued;
5134
5131
  return fromMessageEvent(row);
5135
5132
  });
5136
5133
  }
@@ -6402,20 +6402,20 @@ function isCodexOwnerResponseItemUser(message) {
6402
6402
  if (kinds === void 0) return false;
6403
6403
  return kinds.some((kind) => kind.startsWith("user."));
6404
6404
  }
6405
- function fromQueueEvent(row) {
6406
- if (row.type !== "queue-operation" || row.operation !== "enqueue") return [];
6407
- const content = row.content;
6408
- if (typeof content !== "string" || content === "") return [];
6409
- const id = nativeEventId(row);
6410
- return [{ speaker: "owner", text: content, ...id === void 0 ? {} : { id } }];
6411
- }
6412
6405
  function hasFixedOpenTagPrefix(content, tag) {
6413
6406
  if (!content.startsWith(tag)) return false;
6414
6407
  const next = content.charAt(tag.length);
6415
6408
  return next === "" || next === ">" || next === " " || next === " " || next === "\n" || next === "\r";
6416
6409
  }
6417
- function isFixedNonOwnerEnqueueShape(content) {
6418
- return hasFixedOpenTagPrefix(content, TASK_NOTIFICATION_OPEN_TAG);
6410
+ function fromQueuedCommandAttachment(row) {
6411
+ if (!isRecord(row.attachment) || row.attachment.type !== "queued_command") return [];
6412
+ const kind = materializationOriginKind(row.attachment);
6413
+ if (isNonOwnerOriginKind(kind)) return [];
6414
+ const text = textParts(row.attachment.prompt).join("");
6415
+ if (text === "") return [];
6416
+ if (kind === void 0 && hasFixedOpenTagPrefix(text, TASK_NOTIFICATION_OPEN_TAG)) return [];
6417
+ const id = nativeEventId(row);
6418
+ return [{ speaker: "owner", text, ...id === void 0 ? {} : { id } }];
6419
6419
  }
6420
6420
  function materializationOriginKind(row) {
6421
6421
  if (!isRecord(row.origin)) return void 0;
@@ -6445,13 +6445,10 @@ function fromMessageEvent(row) {
6445
6445
  function adaptSessionDialogue(rows) {
6446
6446
  return rows.map((row) => {
6447
6447
  if (row === void 0) return [];
6448
+ if (row.type === "queue-operation" || row.type === "api-request-blob") return [];
6449
+ if (row.type === "attachment") return fromQueuedCommandAttachment(row);
6448
6450
  const originKind = materializationOriginKind(row);
6449
6451
  if (isNonOwnerOriginKind(originKind)) return [];
6450
- if (row.type === "queue-operation" && row.operation === "enqueue" && typeof row.content === "string" && isFixedNonOwnerEnqueueShape(row.content)) {
6451
- return [];
6452
- }
6453
- const queued = fromQueueEvent(row);
6454
- if (queued.length > 0) return queued;
6455
6452
  return fromMessageEvent(row);
6456
6453
  });
6457
6454
  }
@@ -13530,20 +13530,20 @@ function isCodexOwnerResponseItemUser(message) {
13530
13530
  if (kinds === void 0) return false;
13531
13531
  return kinds.some((kind) => kind.startsWith("user."));
13532
13532
  }
13533
- function fromQueueEvent(row) {
13534
- if (row.type !== "queue-operation" || row.operation !== "enqueue") return [];
13535
- const content = row.content;
13536
- if (typeof content !== "string" || content === "") return [];
13537
- const id = nativeEventId(row);
13538
- return [{ speaker: "owner", text: content, ...id === void 0 ? {} : { id } }];
13539
- }
13540
13533
  function hasFixedOpenTagPrefix(content, tag) {
13541
13534
  if (!content.startsWith(tag)) return false;
13542
13535
  const next = content.charAt(tag.length);
13543
13536
  return next === "" || next === ">" || next === " " || next === " " || next === "\n" || next === "\r";
13544
13537
  }
13545
- function isFixedNonOwnerEnqueueShape(content) {
13546
- return hasFixedOpenTagPrefix(content, TASK_NOTIFICATION_OPEN_TAG);
13538
+ function fromQueuedCommandAttachment(row) {
13539
+ if (!isRecord(row.attachment) || row.attachment.type !== "queued_command") return [];
13540
+ const kind = materializationOriginKind(row.attachment);
13541
+ if (isNonOwnerOriginKind(kind)) return [];
13542
+ const text = textParts(row.attachment.prompt).join("");
13543
+ if (text === "") return [];
13544
+ if (kind === void 0 && hasFixedOpenTagPrefix(text, TASK_NOTIFICATION_OPEN_TAG)) return [];
13545
+ const id = nativeEventId(row);
13546
+ return [{ speaker: "owner", text, ...id === void 0 ? {} : { id } }];
13547
13547
  }
13548
13548
  function materializationOriginKind(row) {
13549
13549
  if (!isRecord(row.origin)) return void 0;
@@ -13573,13 +13573,10 @@ function fromMessageEvent(row) {
13573
13573
  function adaptSessionDialogue(rows) {
13574
13574
  return rows.map((row) => {
13575
13575
  if (row === void 0) return [];
13576
+ if (row.type === "queue-operation" || row.type === "api-request-blob") return [];
13577
+ if (row.type === "attachment") return fromQueuedCommandAttachment(row);
13576
13578
  const originKind = materializationOriginKind(row);
13577
13579
  if (isNonOwnerOriginKind(originKind)) return [];
13578
- if (row.type === "queue-operation" && row.operation === "enqueue" && typeof row.content === "string" && isFixedNonOwnerEnqueueShape(row.content)) {
13579
- return [];
13580
- }
13581
- const queued = fromQueueEvent(row);
13582
- if (queued.length > 0) return queued;
13583
13580
  return fromMessageEvent(row);
13584
13581
  });
13585
13582
  }
@@ -89,26 +89,12 @@ function isCodexOwnerResponseItemUser(message) {
89
89
  return false;
90
90
  return kinds.some((kind) => kind.startsWith("user."));
91
91
  }
92
- /**
93
- * 入队事件适配:人类这次输入经队列的来源。
94
- * 被吸收的插话靠入队事件入录(无独立消息记录,#901 用户故事 11)。
95
- * 机器入队由整卷适配层排除(#918);本函数不读正文、不自判机器。
96
- */
97
- function fromQueueEvent(row) {
98
- if (row.type !== "queue-operation" || row.operation !== "enqueue")
99
- return [];
100
- const content = row.content;
101
- if (typeof content !== "string" || content === "")
102
- return [];
103
- const id = nativeEventId(row);
104
- return [{ speaker: "owner", text: content, ...(id === undefined ? {} : { id }) }];
105
- }
106
92
  /**
107
93
  * 票面 #918 准许的唯一固定起始形状:`<task-notification`。
108
94
  * 其它标签不在御裁射程内——不得扩表,不得伪造 decision key / 「陛下拍定」。
109
95
  * 开标签后可直接 `>`(无属性)、EOF 或空白再接属性;其它字符不成立。
110
96
  *
111
- * 机器 enqueue 的完整判据=结构化来源(origin.kind)/本固定形状/真实因果与位置;
97
+ * 无 origin 的 `queued_command` 只靠本固定形状排除;不得扩表。
112
98
  * 用可变载荷正文(全等或子串)做 identity join 仍为锚定宪法所禁。
113
99
  */
114
100
  const TASK_NOTIFICATION_OPEN_TAG = "<task-notification";
@@ -123,9 +109,24 @@ function hasFixedOpenTagPrefix(content, tag) {
123
109
  next === "\n" ||
124
110
  next === "\r");
125
111
  }
126
- /** enqueue.content 是否以票面准许的 `<task-notification` 固定开标签起头。 */
127
- function isFixedNonOwnerEnqueueShape(content) {
128
- return hasFixedOpenTagPrefix(content, TASK_NOTIFICATION_OPEN_TAG);
112
+ /**
113
+ * 被吸收的中途插话取 `queued_command` 附件原文(#1260)。
114
+ * 来源按附件 `origin.kind` 判;缺 origin 就当真人,只排除固定开头。
115
+ * 入队行不再是来源,本函数不读入队行、不做正文比对。
116
+ */
117
+ function fromQueuedCommandAttachment(row) {
118
+ if (!isRecord(row.attachment) || row.attachment.type !== "queued_command")
119
+ return [];
120
+ const kind = materializationOriginKind(row.attachment);
121
+ if (isNonOwnerOriginKind(kind))
122
+ return [];
123
+ const text = textParts(row.attachment.prompt).join("");
124
+ if (text === "")
125
+ return [];
126
+ if (kind === undefined && hasFixedOpenTagPrefix(text, TASK_NOTIFICATION_OPEN_TAG))
127
+ return [];
128
+ const id = nativeEventId(row);
129
+ return [{ speaker: "owner", text, ...(id === undefined ? {} : { id }) }];
129
130
  }
130
131
  /**
131
132
  * 物化 user 行上的结构化来源 kind(CC top-level `origin.kind`)。不读正文。
@@ -149,7 +150,7 @@ function isNonOwnerOriginKind(kind) {
149
150
  return kind !== "human";
150
151
  }
151
152
  /**
152
- * 消息事件适配:助手回话,以及未经入队事件记录的人类输入。
153
+ * 消息事件适配:助手回话,以及 `type=user` 的人类输入。
153
154
  * 思考块、工具调用块、工具结果块按块排除;同消息的说话人 text 保留
154
155
  * (#901 排除按来源不按正文;混合块不得整条丢弃)。
155
156
  * Codex response_item user:仅 `content_item_kinds` 含 `user.*` 时入录。
@@ -181,26 +182,21 @@ function fromMessageEvent(row) {
181
182
  /**
182
183
  * 整卷适配:返回与入参行等长的对话事实数组(该行不是对话则为空数组)。
183
184
  *
185
+ * 说话来源只取 `type=user` 行与 `queued_command` 附件。入队行与 `api-request-blob`
186
+ * 不投。有原生 id 则带上,不另编。不做正文比对或 id 去重。
184
187
  * 物化 user 只消费自身的 typed `origin.kind`:human 保留,具名非 human 排除。
185
- * enqueue 没有与物化 user 的 typed 关联,故不得以位置把某个 user 来源反扣给它;
186
- * 仅票面准许的 `<task-notification` 固定形状可直接排除,其余维持既有投影。
187
188
  */
188
189
  export function adaptSessionDialogue(rows) {
189
190
  return rows.map((row) => {
190
191
  if (row === undefined)
191
192
  return [];
193
+ if (row.type === "queue-operation" || row.type === "api-request-blob")
194
+ return [];
195
+ if (row.type === "attachment")
196
+ return fromQueuedCommandAttachment(row);
192
197
  const originKind = materializationOriginKind(row);
193
198
  if (isNonOwnerOriginKind(originKind))
194
199
  return [];
195
- if (row.type === "queue-operation" &&
196
- row.operation === "enqueue" &&
197
- typeof row.content === "string" &&
198
- isFixedNonOwnerEnqueueShape(row.content)) {
199
- return [];
200
- }
201
- const queued = fromQueueEvent(row);
202
- if (queued.length > 0)
203
- return queued;
204
200
  return fromMessageEvent(row);
205
201
  });
206
202
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@akagilnc/pi-workflow-roles",
3
- "version": "0.1.5949",
3
+ "version": "0.1.5955",
4
4
  "description": "Soul-bound workflow roles for Pi",
5
5
  "type": "module",
6
6
  "license": "Apache-2.0",
@@ -6,7 +6,8 @@ import { isRecord } from "./unknown-value.ts";
6
6
  * 排除按来源、不按正文:说话人自己写下的文字一律原样保留,其中引用了 ADR 段落
7
7
  * 或工具结果也不删(#901 Out of Scope「不做正文过滤」)。
8
8
  *
9
- * 不入录的是工具结果载荷、附件记录与注入块——它们是独立的机器事件,不是谁说的话。
9
+ * 不入录的是工具结果载荷、入队行、请求快照与注入块。附件记录同样不入录,
10
+ * 只有 `queued_command` 例外:它是被吸收插话的带 uuid 说话记录(#1260)。
10
11
  *
11
12
  * 适配规则按宿主并列,不硬套某一宿主的类型名;一行产出 0..n 条对话事实。
12
13
  */
@@ -107,25 +108,12 @@ function isCodexOwnerResponseItemUser(message: Record<string, unknown>): boolean
107
108
  return kinds.some((kind) => kind.startsWith("user."));
108
109
  }
109
110
 
110
- /**
111
- * 入队事件适配:人类这次输入经队列的来源。
112
- * 被吸收的插话靠入队事件入录(无独立消息记录,#901 用户故事 11)。
113
- * 机器入队由整卷适配层排除(#918);本函数不读正文、不自判机器。
114
- */
115
- function fromQueueEvent(row: Record<string, unknown>): DialogueEvent[] {
116
- if (row.type !== "queue-operation" || row.operation !== "enqueue") return [];
117
- const content = row.content;
118
- if (typeof content !== "string" || content === "") return [];
119
- const id = nativeEventId(row);
120
- return [{ speaker: "owner", text: content, ...(id === undefined ? {} : { id }) }];
121
- }
122
-
123
111
  /**
124
112
  * 票面 #918 准许的唯一固定起始形状:`<task-notification`。
125
113
  * 其它标签不在御裁射程内——不得扩表,不得伪造 decision key / 「陛下拍定」。
126
114
  * 开标签后可直接 `>`(无属性)、EOF 或空白再接属性;其它字符不成立。
127
115
  *
128
- * 机器 enqueue 的完整判据=结构化来源(origin.kind)/本固定形状/真实因果与位置;
116
+ * 无 origin 的 `queued_command` 只靠本固定形状排除;不得扩表。
129
117
  * 用可变载荷正文(全等或子串)做 identity join 仍为锚定宪法所禁。
130
118
  */
131
119
  const TASK_NOTIFICATION_OPEN_TAG = "<task-notification";
@@ -143,9 +131,20 @@ function hasFixedOpenTagPrefix(content: string, tag: string): boolean {
143
131
  );
144
132
  }
145
133
 
146
- /** enqueue.content 是否以票面准许的 `<task-notification` 固定开标签起头。 */
147
- function isFixedNonOwnerEnqueueShape(content: string): boolean {
148
- return hasFixedOpenTagPrefix(content, TASK_NOTIFICATION_OPEN_TAG);
134
+ /**
135
+ * 被吸收的中途插话取 `queued_command` 附件原文(#1260)。
136
+ * 来源按附件 `origin.kind` 判;缺 origin 就当真人,只排除固定开头。
137
+ * 入队行不再是来源,本函数不读入队行、不做正文比对。
138
+ */
139
+ function fromQueuedCommandAttachment(row: Record<string, unknown>): DialogueEvent[] {
140
+ if (!isRecord(row.attachment) || row.attachment.type !== "queued_command") return [];
141
+ const kind = materializationOriginKind(row.attachment);
142
+ if (isNonOwnerOriginKind(kind)) return [];
143
+ const text = textParts(row.attachment.prompt).join("");
144
+ if (text === "") return [];
145
+ if (kind === undefined && hasFixedOpenTagPrefix(text, TASK_NOTIFICATION_OPEN_TAG)) return [];
146
+ const id = nativeEventId(row);
147
+ return [{ speaker: "owner", text, ...(id === undefined ? {} : { id }) }];
149
148
  }
150
149
 
151
150
  /**
@@ -172,7 +171,7 @@ function isNonOwnerOriginKind(kind: string | undefined): boolean {
172
171
  }
173
172
 
174
173
  /**
175
- * 消息事件适配:助手回话,以及未经入队事件记录的人类输入。
174
+ * 消息事件适配:助手回话,以及 `type=user` 的人类输入。
176
175
  * 思考块、工具调用块、工具结果块按块排除;同消息的说话人 text 保留
177
176
  * (#901 排除按来源不按正文;混合块不得整条丢弃)。
178
177
  * Codex response_item user:仅 `content_item_kinds` 含 `user.*` 时入录。
@@ -199,27 +198,19 @@ function fromMessageEvent(row: Record<string, unknown>): DialogueEvent[] {
199
198
  /**
200
199
  * 整卷适配:返回与入参行等长的对话事实数组(该行不是对话则为空数组)。
201
200
  *
201
+ * 说话来源只取 `type=user` 行与 `queued_command` 附件。入队行与 `api-request-blob`
202
+ * 不投。有原生 id 则带上,不另编。不做正文比对或 id 去重。
202
203
  * 物化 user 只消费自身的 typed `origin.kind`:human 保留,具名非 human 排除。
203
- * enqueue 没有与物化 user 的 typed 关联,故不得以位置把某个 user 来源反扣给它;
204
- * 仅票面准许的 `<task-notification` 固定形状可直接排除,其余维持既有投影。
205
204
  */
206
205
  export function adaptSessionDialogue(
207
206
  rows: readonly (Record<string, unknown> | undefined)[],
208
207
  ): DialogueEvent[][] {
209
208
  return rows.map((row) => {
210
209
  if (row === undefined) return [];
210
+ if (row.type === "queue-operation" || row.type === "api-request-blob") return [];
211
+ if (row.type === "attachment") return fromQueuedCommandAttachment(row);
211
212
  const originKind = materializationOriginKind(row);
212
213
  if (isNonOwnerOriginKind(originKind)) return [];
213
- if (
214
- row.type === "queue-operation" &&
215
- row.operation === "enqueue" &&
216
- typeof row.content === "string" &&
217
- isFixedNonOwnerEnqueueShape(row.content)
218
- ) {
219
- return [];
220
- }
221
- const queued = fromQueueEvent(row);
222
- if (queued.length > 0) return queued;
223
214
  return fromMessageEvent(row);
224
215
  });
225
216
  }