@akagilnc/pi-workflow-roles 0.1.4646 → 0.1.4649

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.
@@ -28713,6 +28713,18 @@ function renderSystemPromptOverride(authority) {
28713
28713
  }
28714
28714
 
28715
28715
  // src/acp-host/role-turn-host.ts
28716
+ var GROK_BUILD_HOST = "grok-build";
28717
+ function acpPromptResultHasUsage(result) {
28718
+ const meta = result._meta;
28719
+ if (typeof meta !== "object" || meta === null || Array.isArray(meta)) return false;
28720
+ return Object.prototype.hasOwnProperty.call(meta, "usage");
28721
+ }
28722
+ function isAcpAutoCompactCompletedNotification(method, params) {
28723
+ if (method !== "_x.ai/session_notification") return false;
28724
+ const update = params.update;
28725
+ if (typeof update !== "object" || update === null || Array.isArray(update)) return false;
28726
+ return update.sessionUpdate === "auto_compact_completed";
28727
+ }
28716
28728
  function acpAgentTextChunk(params) {
28717
28729
  let kind;
28718
28730
  let content;
@@ -28915,9 +28927,13 @@ function createAcpRoleTurnHost(config) {
28915
28927
  const rpc = (method, params) => raceAgainstHostAbort(connection.request(method, params), recordAbort.signal, "host-session-record-failed");
28916
28928
  const agentProseChunks = [];
28917
28929
  let collectAgentProse = false;
28930
+ const ledgerGrokBuildObservability = config.hostName === GROK_BUILD_HOST;
28918
28931
  connection.onNotification?.((method, params) => {
28919
- if (method !== "session/update" || hostSessionRecordFailure !== void 0) return;
28920
- if (collectAgentProse) {
28932
+ if (hostSessionRecordFailure !== void 0) return;
28933
+ const isSessionUpdate = method === "session/update";
28934
+ const isAutoCompact = ledgerGrokBuildObservability && isAcpAutoCompactCompletedNotification(method, params);
28935
+ if (!isSessionUpdate && !isAutoCompact) return;
28936
+ if (isSessionUpdate && collectAgentProse) {
28921
28937
  const chunk = acpAgentTextChunk(params);
28922
28938
  if (chunk !== void 0) agentProseChunks.push(chunk);
28923
28939
  }
@@ -29014,6 +29030,23 @@ function createAcpRoleTurnHost(config) {
29014
29030
  throw error;
29015
29031
  }
29016
29032
  collectAgentProse = false;
29033
+ if (ledgerGrokBuildObservability && acpPromptResultHasUsage(result)) {
29034
+ try {
29035
+ reportHostSessionEvent({
29036
+ host: config.hostName,
29037
+ cwd: request.cwd,
29038
+ sessionParent,
29039
+ source: "acp-host",
29040
+ event: { method: "session/prompt", result }
29041
+ });
29042
+ } catch (error) {
29043
+ noteHostSessionRecordFailure(error);
29044
+ return { status: "terminal", result: hostSessionRecordResult() };
29045
+ }
29046
+ }
29047
+ if (hostSessionRecordFailure !== void 0) {
29048
+ return { status: "terminal", result: hostSessionRecordResult() };
29049
+ }
29017
29050
  if (result.stopReason === "refusal") {
29018
29051
  agentProseChunks.length = 0;
29019
29052
  return {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@akagilnc/pi-workflow-roles",
3
- "version": "0.1.4646",
3
+ "version": "0.1.4649",
4
4
  "description": "Soul-bound workflow roles for Pi",
5
5
  "type": "module",
6
6
  "license": "Apache-2.0",
@@ -20,6 +20,30 @@ import {
20
20
  } from "../prepared-role-turn.ts";
21
21
  import { acpModelId, type AcpHostDescription } from "./description.ts";
22
22
 
23
+ /** #971: authorized host for usage + auto_compact ledgering only. */
24
+ const GROK_BUILD_HOST = "grok-build";
25
+
26
+ /** #971: grok-build prompt result carries host usage under `_meta.usage`. */
27
+ function acpPromptResultHasUsage(result: Readonly<Record<string, unknown>>): boolean {
28
+ const meta = result._meta;
29
+ if (typeof meta !== "object" || meta === null || Array.isArray(meta)) return false;
30
+ return Object.prototype.hasOwnProperty.call(meta, "usage");
31
+ }
32
+
33
+ /**
34
+ * #971: ledger only the authorized vendor compaction notice on grok-build.
35
+ * Other `_x.ai/*` notifications stay out of host-session records.
36
+ */
37
+ function isAcpAutoCompactCompletedNotification(
38
+ method: string,
39
+ params: Readonly<Record<string, unknown>>,
40
+ ): boolean {
41
+ if (method !== "_x.ai/session_notification") return false;
42
+ const update = params.update;
43
+ if (typeof update !== "object" || update === null || Array.isArray(update)) return false;
44
+ return (update as { sessionUpdate?: unknown }).sessionUpdate === "auto_compact_completed";
45
+ }
46
+
23
47
  /**
24
48
  * #959: collect free-form agent text from ACP session/update stream.
25
49
  * Used only when the navigator seat spoke prose without calling the output tool.
@@ -294,9 +318,16 @@ export function createAcpRoleTurnHost(config: AcpRoleTurnHostConfig): RoleTurnHo
294
318
  // (resume / set_model load would otherwise prepend prior turns as "this turn" prose).
295
319
  const agentProseChunks: string[] = [];
296
320
  let collectAgentProse = false;
321
+ // #971: usage + auto_compact are grok-build-only; same ACP adapter serves Hermes too.
322
+ const ledgerGrokBuildObservability = config.hostName === GROK_BUILD_HOST;
297
323
  connection.onNotification?.((method, params) => {
298
- if (method !== "session/update" || hostSessionRecordFailure !== undefined) return;
299
- if (collectAgentProse) {
324
+ if (hostSessionRecordFailure !== undefined) return;
325
+ const isSessionUpdate = method === "session/update";
326
+ const isAutoCompact = ledgerGrokBuildObservability
327
+ && isAcpAutoCompactCompletedNotification(method, params);
328
+ // #971: session/update stays; auto_compact_completed is the only vendor notice.
329
+ if (!isSessionUpdate && !isAutoCompact) return;
330
+ if (isSessionUpdate && collectAgentProse) {
300
331
  const chunk = acpAgentTextChunk(params);
301
332
  if (chunk !== undefined) agentProseChunks.push(chunk);
302
333
  }
@@ -409,6 +440,24 @@ export function createAcpRoleTurnHost(config: AcpRoleTurnHostConfig): RoleTurnHo
409
440
  throw error;
410
441
  }
411
442
  collectAgentProse = false;
443
+ // #971: per-round grok-build usage is on the prompt JSON-RPC result, not a notice.
444
+ if (ledgerGrokBuildObservability && acpPromptResultHasUsage(result)) {
445
+ try {
446
+ reportHostSessionEvent({
447
+ host: config.hostName,
448
+ cwd: request.cwd,
449
+ sessionParent,
450
+ source: "acp-host",
451
+ event: { method: "session/prompt", result },
452
+ });
453
+ } catch (error) {
454
+ noteHostSessionRecordFailure(error);
455
+ return { status: "terminal", result: hostSessionRecordResult() };
456
+ }
457
+ }
458
+ if (hostSessionRecordFailure !== undefined) {
459
+ return { status: "terminal", result: hostSessionRecordResult() };
460
+ }
412
461
  if (result.stopReason === "refusal") {
413
462
  agentProseChunks.length = 0;
414
463
  return {