@narumitw/pi-goal 0.54.3 → 0.54.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.
Files changed (39) hide show
  1. package/README.md +117 -190
  2. package/dist/chunks/{chunk-QWIUWKRW.js → chunk-VJ5LR26S.js} +57 -77
  3. package/dist/chunks/chunk-VJ5LR26S.js.map +7 -0
  4. package/dist/chunks/{chunk-UQRRW4CY.js → chunk-WQIA35U2.js} +6 -5
  5. package/dist/chunks/chunk-WQIA35U2.js.map +7 -0
  6. package/dist/chunks/{menu-WEFDREGC.js → menu-JMGWQZIT.js} +7 -22
  7. package/dist/chunks/menu-JMGWQZIT.js.map +7 -0
  8. package/dist/chunks/{settings-ui-MVYTTBHW.js → settings-ui-JG3PFRB5.js} +6 -18
  9. package/dist/chunks/settings-ui-JG3PFRB5.js.map +7 -0
  10. package/dist/index.ts +111 -126
  11. package/dist/index.ts.map +2 -2
  12. package/docs/managing-goals.md +47 -0
  13. package/docs/settings.md +91 -0
  14. package/package.json +55 -58
  15. package/src/accounting.ts +62 -66
  16. package/src/command-registration.ts +104 -102
  17. package/src/command.ts +101 -112
  18. package/src/commands.ts +465 -501
  19. package/src/errors.ts +127 -122
  20. package/src/goal-contract.ts +64 -64
  21. package/src/goal.ts +25 -25
  22. package/src/lifecycle.ts +615 -628
  23. package/src/markers.ts +6 -6
  24. package/src/menu.ts +565 -591
  25. package/src/persistence.ts +177 -192
  26. package/src/prompts.ts +53 -67
  27. package/src/run-protocol.ts +299 -325
  28. package/src/runtime.ts +1422 -1495
  29. package/src/safety.ts +51 -51
  30. package/src/settings-ui.ts +366 -393
  31. package/src/settings.ts +134 -147
  32. package/src/tool-policy.ts +6 -6
  33. package/src/tools.ts +371 -347
  34. package/src/wait.ts +47 -51
  35. package/src/workflow-mutex.ts +68 -68
  36. package/dist/chunks/chunk-QWIUWKRW.js.map +0 -7
  37. package/dist/chunks/chunk-UQRRW4CY.js.map +0 -7
  38. package/dist/chunks/menu-WEFDREGC.js.map +0 -7
  39. package/dist/chunks/settings-ui-MVYTTBHW.js.map +0 -7
package/src/safety.ts CHANGED
@@ -2,77 +2,77 @@ import { createHash } from "node:crypto";
2
2
  import type { ActiveGoal } from "./persistence.js";
3
3
 
4
4
  export interface ToolFreeRepeatState {
5
- toolFreeRepeatCount: number;
6
- lastToolFreeOutputFingerprint?: string;
5
+ toolFreeRepeatCount: number;
6
+ lastToolFreeOutputFingerprint?: string;
7
7
  }
8
8
 
9
9
  export function queueGoalSafetyReset(goal: ActiveGoal): ActiveGoal {
10
- return { ...goal, safetyResetPending: true };
10
+ return { ...goal, safetyResetPending: true };
11
11
  }
12
12
 
13
13
  export function resetGoalSafetyEpoch(goal: ActiveGoal): ActiveGoal {
14
- return {
15
- ...goal,
16
- automaticModelTurns: 0,
17
- toolFreeRepeatCount: 0,
18
- lastToolFreeOutputFingerprint: undefined,
19
- safetyPauseCause: undefined,
20
- safetyResetPending: undefined,
21
- };
14
+ return {
15
+ ...goal,
16
+ automaticModelTurns: 0,
17
+ toolFreeRepeatCount: 0,
18
+ lastToolFreeOutputFingerprint: undefined,
19
+ safetyPauseCause: undefined,
20
+ safetyResetPending: undefined,
21
+ };
22
22
  }
23
23
 
24
24
  export function nextToolFreeRepeatState(
25
- current: ToolFreeRepeatState,
26
- messages: readonly unknown[],
27
- toolAttempted: boolean,
25
+ current: ToolFreeRepeatState,
26
+ messages: readonly unknown[],
27
+ toolAttempted: boolean,
28
28
  ): ToolFreeRepeatState {
29
- if (toolAttempted) return { toolFreeRepeatCount: 0 };
30
- const fingerprint = fingerprintVisibleAssistantOutput(messages);
31
- return {
32
- toolFreeRepeatCount:
33
- fingerprint === current.lastToolFreeOutputFingerprint
34
- ? Math.min(Number.MAX_SAFE_INTEGER, current.toolFreeRepeatCount + 1)
35
- : 1,
36
- lastToolFreeOutputFingerprint: fingerprint,
37
- };
29
+ if (toolAttempted) return { toolFreeRepeatCount: 0 };
30
+ const fingerprint = fingerprintVisibleAssistantOutput(messages);
31
+ return {
32
+ toolFreeRepeatCount:
33
+ fingerprint === current.lastToolFreeOutputFingerprint
34
+ ? Math.min(Number.MAX_SAFE_INTEGER, current.toolFreeRepeatCount + 1)
35
+ : 1,
36
+ lastToolFreeOutputFingerprint: fingerprint,
37
+ };
38
38
  }
39
39
 
40
40
  export function hasAssistantToolCall(messages: readonly unknown[]) {
41
- for (const message of messages) {
42
- if (!isRecord(message) || message.role !== "assistant" || !Array.isArray(message.content)) {
43
- continue;
44
- }
45
- if (message.content.some((block) => isRecord(block) && block.type === "toolCall")) return true;
46
- }
47
- return false;
41
+ for (const message of messages) {
42
+ if (!isRecord(message) || message.role !== "assistant" || !Array.isArray(message.content)) {
43
+ continue;
44
+ }
45
+ if (message.content.some((block) => isRecord(block) && block.type === "toolCall")) return true;
46
+ }
47
+ return false;
48
48
  }
49
49
 
50
50
  export function fingerprintVisibleAssistantOutput(messages: readonly unknown[]) {
51
- const normalized = normalizeVisibleAssistantOutput(messages);
52
- return createHash("sha256").update(normalized, "utf8").digest("hex");
51
+ const normalized = normalizeVisibleAssistantOutput(messages);
52
+ return createHash("sha256").update(normalized, "utf8").digest("hex");
53
53
  }
54
54
 
55
55
  export function normalizeVisibleAssistantOutput(messages: readonly unknown[]) {
56
- const text: string[] = [];
57
- for (const message of messages) {
58
- if (!isRecord(message) || message.role !== "assistant" || !Array.isArray(message.content)) {
59
- continue;
60
- }
61
- for (const block of message.content) {
62
- if (!isRecord(block) || block.type !== "text" || typeof block.text !== "string") continue;
63
- text.push(block.text);
64
- }
65
- }
66
- const normalized = text
67
- .join("\n")
68
- .normalize("NFKC")
69
- .toLowerCase()
70
- .replace(/\s+/gu, " ")
71
- .replace(/[\p{Cc}\p{Cf}]/gu, "")
72
- .trim();
73
- return normalized === "" || /^[\p{P}\s]+$/u.test(normalized) ? "" : normalized;
56
+ const text: string[] = [];
57
+ for (const message of messages) {
58
+ if (!isRecord(message) || message.role !== "assistant" || !Array.isArray(message.content)) {
59
+ continue;
60
+ }
61
+ for (const block of message.content) {
62
+ if (!isRecord(block) || block.type !== "text" || typeof block.text !== "string") continue;
63
+ text.push(block.text);
64
+ }
65
+ }
66
+ const normalized = text
67
+ .join("\n")
68
+ .normalize("NFKC")
69
+ .toLowerCase()
70
+ .replace(/\s+/gu, " ")
71
+ .replace(/[\p{Cc}\p{Cf}]/gu, "")
72
+ .trim();
73
+ return normalized === "" || /^[\p{P}\s]+$/u.test(normalized) ? "" : normalized;
74
74
  }
75
75
 
76
76
  function isRecord(value: unknown): value is Record<string, unknown> {
77
- return typeof value === "object" && value !== null && !Array.isArray(value);
77
+ return typeof value === "object" && value !== null && !Array.isArray(value);
78
78
  }