@promptbook/cli 0.114.0-11 → 0.114.0-13

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 (145) hide show
  1. package/apps/agents-server/src/app/admin/messages/MessagesClient.tsx +8 -1
  2. package/apps/agents-server/src/app/admin/messages/send-email/SendEmailClient.tsx +193 -63
  3. package/apps/agents-server/src/app/admin/messages/send-email/actions.ts +25 -28
  4. package/apps/agents-server/src/app/admin/messages/send-email/emailTesting.ts +153 -0
  5. package/apps/agents-server/src/app/admin/messages/send-email/emailTestingAccess.ts +30 -0
  6. package/apps/agents-server/src/app/admin/messages/send-email/page.tsx +18 -5
  7. package/apps/agents-server/src/app/agents/[agentName]/AgentChatWrapper.tsx +7 -4
  8. package/apps/agents-server/src/app/agents/[agentName]/chat/AgentGoalChatPlannedMessages.tsx +23 -8
  9. package/apps/agents-server/src/app/agents/[agentName]/chat/CanonicalAgentChatSurface.tsx +14 -3
  10. package/apps/agents-server/src/app/agents/[agentName]/chat/page.tsx +2 -20
  11. package/apps/agents-server/src/app/agents/[agentName]/page.tsx +2 -1
  12. package/apps/agents-server/src/app/agents/[agentName]/projectReferenceActions.ts +61 -0
  13. package/apps/agents-server/src/app/api/internal/agent-goal-chat-planned-messages/route.ts +34 -7
  14. package/apps/agents-server/src/components/AgentProjects/resolveLatestCompletedAgentMessageKey.ts +32 -0
  15. package/apps/agents-server/src/components/AgentProjects/useAgentProjectMarkdownReferences.ts +124 -2
  16. package/apps/agents-server/src/languages/ServerTranslationKeys.ts +3 -0
  17. package/apps/agents-server/src/languages/translations/czech.yaml +3 -0
  18. package/apps/agents-server/src/languages/translations/english.yaml +3 -0
  19. package/apps/agents-server/src/message-providers/email/stalwart/StalwartMessageProvider.ts +2 -1
  20. package/apps/agents-server/src/tools/agentGoalChatTimeoutToolFunctions.ts +24 -2
  21. package/apps/agents-server/src/tools/agentGoalChatTimeoutTools.ts +5 -4
  22. package/apps/agents-server/src/utils/agentGoalChat/agentGoalChatPlannedMessageActions.ts +38 -9
  23. package/apps/agents-server/src/utils/agentGoalChat/createAgentGoalChatNoteContent.ts +15 -6
  24. package/apps/agents-server/src/utils/agentProjects/listAgentProjectNames.ts +35 -0
  25. package/apps/agents-server/src/utils/agentProjects/listAgentProjects.ts +6 -23
  26. package/apps/agents-server/src/utils/agentProjects/resolveAgentChatProjectReferences.ts +25 -0
  27. package/apps/agents-server/src/utils/chatMessageChips/createAnsweredMessageChipToolCalls.ts +37 -0
  28. package/apps/agents-server/src/utils/chatMessageChips/createPlannedMessageChipToolCalls.ts +39 -0
  29. package/apps/agents-server/src/utils/chatMessageChips/createTouchedProjectChipToolCalls.ts +75 -0
  30. package/apps/agents-server/src/utils/email/agentEmailAddress.ts +14 -0
  31. package/apps/agents-server/src/utils/email/sendEmailThroughStalwart.ts +2 -1
  32. package/apps/agents-server/src/utils/localChatRunner/applyLocalAgentPlannedMessageCommands.ts +212 -0
  33. package/apps/agents-server/src/utils/localChatRunner/prepareLocalAgentPlannedMessagesSidecar.ts +66 -0
  34. package/apps/agents-server/src/utils/localChatRunner/processLocalUserChatJob.ts +110 -22
  35. package/apps/agents-server/src/utils/userChat/persistUserChatJobTerminalState.ts +5 -0
  36. package/apps/agents-server/src/utils/userChat/userChatJobRunReport.ts +30 -0
  37. package/apps/agents-server/src/utils/userChatTimeout/createTimeoutWakeUpMessage.ts +9 -1
  38. package/apps/agents-server/src/utils/userChatTimeout/userChatTimeoutStore/repeatFiredUserChatTimeout.ts +74 -0
  39. package/apps/agents-server/src/utils/userChatTimeout/userChatTimeoutStore.ts +1 -0
  40. package/apps/agents-server/src/utils/userChatTimeout/userChatTimeoutWorker.ts +63 -54
  41. package/esm/index.es.js +1042 -194
  42. package/esm/index.es.js.map +1 -1
  43. package/esm/scripts/run-agent-messages/messages/buildAgentGoalChatPromptSection.d.ts +22 -4
  44. package/esm/scripts/run-agent-messages/messages/buildAgentMessagePrompt.d.ts +3 -3
  45. package/esm/scripts/run-agent-messages/messages/loadAgentPlannedMessagesSidecar.d.ts +10 -0
  46. package/esm/scripts/run-agent-messages/messages/resolveTouchedAgentProjects.d.ts +15 -0
  47. package/esm/scripts/run-codex-prompts/common/runGoScript/$spawnLoggedBashScript.d.ts +25 -0
  48. package/esm/scripts/run-codex-prompts/common/runGoScript/$terminateLoggedBashProcessTree.d.ts +11 -0
  49. package/esm/scripts/run-codex-prompts/common/runGoScript/scriptExecutionLog.d.ts +4 -0
  50. package/esm/src/book-2.0/agent-source/AgentSourceParseResult.d.ts +5 -0
  51. package/esm/src/book-2.0/agent-source/ParsedUnknownCommitment.d.ts +26 -0
  52. package/esm/src/book-2.0/agent-source/createAgentModelRequirementsWithCommitments.unknown.test.d.ts +1 -0
  53. package/esm/src/book-2.0/agent-source/getBookCommitmentLineType.d.ts +19 -0
  54. package/esm/src/book-2.0/agent-source/parseAgentSourceWithCommitments.unknown.test.d.ts +1 -0
  55. package/esm/src/book-3.0/AgentMessageRunReport.d.ts +28 -0
  56. package/esm/src/book-3.0/AgentPlannedMessagesSidecar.d.ts +94 -0
  57. package/esm/src/book-3.0/AgentPlannedMessagesSidecar.test.d.ts +1 -0
  58. package/esm/src/book-3.0/createAgentMessageSidecarBaseName.d.ts +13 -0
  59. package/esm/src/book-components/BookEditor/createUnknownCommitmentDiagnostics.d.ts +28 -0
  60. package/esm/src/book-components/BookEditor/createUnknownCommitmentDiagnostics.test.d.ts +1 -0
  61. package/esm/src/book-components/Chat/utils/agentProjectToolCall.d.ts +46 -0
  62. package/esm/src/book-components/Chat/utils/timeoutToolCallPresentation.d.ts +24 -0
  63. package/esm/src/cli/cli-commands/common/harness/$checkHarnessInstallation.d.ts +3 -3
  64. package/esm/src/cli/cli-commands/common/harness/$checkHarnessInstallation.test.d.ts +1 -0
  65. package/esm/src/cli/cli-commands/common/harness/$ensureHarnessInstallations.d.ts +3 -3
  66. package/esm/src/cli/cli-commands/common/harness/HarnessInstallationStatus.d.ts +3 -2
  67. package/esm/src/cli/cli-commands/common/harnessUpdateCliOptions.d.ts +29 -0
  68. package/esm/src/cli/cli-commands/common/harnessUpdateCliOptions.test.d.ts +1 -0
  69. package/esm/src/executables/platforms/locateAppOnWindows.d.ts +1 -1
  70. package/esm/src/executables/platforms/locateAppOnWindows.test.d.ts +1 -0
  71. package/esm/src/utils/agent-message-runtime/parseAgentMessageRuntimeLogEvents.d.ts +59 -0
  72. package/esm/src/utils/agent-message-runtime/resolveAgentMessageTouchedProjectNames.d.ts +19 -0
  73. package/esm/src/utils/agent-message-runtime/resolveAgentMessageTouchedProjectNames.test.d.ts +1 -0
  74. package/esm/src/version.d.ts +1 -1
  75. package/package.json +1 -1
  76. package/src/book-2.0/agent-source/AgentSourceParseResult.ts +6 -0
  77. package/src/book-2.0/agent-source/ParsedUnknownCommitment.ts +29 -0
  78. package/src/book-2.0/agent-source/createAgentModelRequirementsWithCommitments/augmentAgentModelRequirementsFromSource.ts +38 -1
  79. package/src/book-2.0/agent-source/getBookCommitmentLineType.ts +36 -0
  80. package/src/book-2.0/agent-source/parseAgentSourceWithCommitments.ts +128 -61
  81. package/src/book-3.0/AgentMessageRunReport.ts +76 -0
  82. package/src/book-3.0/AgentPlannedMessagesSidecar.ts +229 -0
  83. package/src/book-3.0/AgentTeamConversationWorkspace.ts +3 -5
  84. package/src/book-3.0/createAgentMessageSidecarBaseName.ts +20 -0
  85. package/src/book-components/BookEditor/BookEditorMonaco.tsx +6 -1
  86. package/src/book-components/BookEditor/BookEditorMonacoTokenization.ts +3 -1
  87. package/src/book-components/BookEditor/createUnknownCommitmentDiagnostics.ts +50 -0
  88. package/src/book-components/Chat/Chat/Chat.module.css +6 -1
  89. package/src/book-components/Chat/Chat/renderToolCallDetails.tsx +1 -12
  90. package/src/book-components/Chat/utils/agentProjectToolCall.ts +74 -0
  91. package/src/book-components/Chat/utils/getToolCallChipletInfo.ts +28 -0
  92. package/src/book-components/Chat/utils/timeoutToolCallPresentation.ts +23 -3
  93. package/src/cli/cli-commands/coder/boilerplateTemplates.ts +3 -15
  94. package/src/cli/cli-commands/coder/init.ts +11 -2
  95. package/src/cli/cli-commands/coder/ping.ts +11 -1
  96. package/src/cli/cli-commands/coder/run.ts +11 -2
  97. package/src/cli/cli-commands/coder/server.ts +11 -2
  98. package/src/cli/cli-commands/common/harness/$applyHarnessInstallationStatus.ts +5 -0
  99. package/src/cli/cli-commands/common/harness/$checkHarnessInstallation.ts +17 -5
  100. package/src/cli/cli-commands/common/harness/$ensureHarnessInstallations.ts +6 -3
  101. package/src/cli/cli-commands/common/harness/HarnessInstallationStatus.ts +3 -2
  102. package/src/cli/cli-commands/common/harnessUpdateCliOptions.ts +49 -0
  103. package/src/executables/platforms/locateAppOnWindows.ts +12 -9
  104. package/src/other/templates/getTemplatesPipelineCollection.ts +740 -860
  105. package/src/utils/agent-message-runtime/parseAgentMessageRuntimeLogEvents.ts +105 -0
  106. package/src/utils/agent-message-runtime/resolveAgentMessageRuntimeActivity.ts +6 -54
  107. package/src/utils/agent-message-runtime/resolveAgentMessageTouchedProjectNames.ts +147 -0
  108. package/src/version.ts +2 -2
  109. package/src/versions.txt +2 -1
  110. package/umd/index.umd.js +1041 -193
  111. package/umd/index.umd.js.map +1 -1
  112. package/umd/scripts/run-agent-messages/messages/buildAgentGoalChatPromptSection.d.ts +22 -4
  113. package/umd/scripts/run-agent-messages/messages/buildAgentMessagePrompt.d.ts +3 -3
  114. package/umd/scripts/run-agent-messages/messages/loadAgentPlannedMessagesSidecar.d.ts +10 -0
  115. package/umd/scripts/run-agent-messages/messages/resolveTouchedAgentProjects.d.ts +15 -0
  116. package/umd/scripts/run-codex-prompts/common/runGoScript/$spawnLoggedBashScript.d.ts +25 -0
  117. package/umd/scripts/run-codex-prompts/common/runGoScript/$terminateLoggedBashProcessTree.d.ts +11 -0
  118. package/umd/scripts/run-codex-prompts/common/runGoScript/scriptExecutionLog.d.ts +4 -0
  119. package/umd/src/book-2.0/agent-source/AgentSourceParseResult.d.ts +5 -0
  120. package/umd/src/book-2.0/agent-source/ParsedUnknownCommitment.d.ts +26 -0
  121. package/umd/src/book-2.0/agent-source/createAgentModelRequirementsWithCommitments.unknown.test.d.ts +1 -0
  122. package/umd/src/book-2.0/agent-source/getBookCommitmentLineType.d.ts +19 -0
  123. package/umd/src/book-2.0/agent-source/parseAgentSourceWithCommitments.unknown.test.d.ts +1 -0
  124. package/umd/src/book-3.0/AgentMessageRunReport.d.ts +28 -0
  125. package/umd/src/book-3.0/AgentPlannedMessagesSidecar.d.ts +94 -0
  126. package/umd/src/book-3.0/AgentPlannedMessagesSidecar.test.d.ts +1 -0
  127. package/umd/src/book-3.0/createAgentMessageSidecarBaseName.d.ts +13 -0
  128. package/umd/src/book-components/BookEditor/createUnknownCommitmentDiagnostics.d.ts +28 -0
  129. package/umd/src/book-components/BookEditor/createUnknownCommitmentDiagnostics.test.d.ts +1 -0
  130. package/umd/src/book-components/Chat/utils/agentProjectToolCall.d.ts +46 -0
  131. package/umd/src/book-components/Chat/utils/timeoutToolCallPresentation.d.ts +24 -0
  132. package/umd/src/cli/cli-commands/common/harness/$checkHarnessInstallation.d.ts +3 -3
  133. package/umd/src/cli/cli-commands/common/harness/$checkHarnessInstallation.test.d.ts +1 -0
  134. package/umd/src/cli/cli-commands/common/harness/$ensureHarnessInstallations.d.ts +3 -3
  135. package/umd/src/cli/cli-commands/common/harness/HarnessInstallationStatus.d.ts +3 -2
  136. package/umd/src/cli/cli-commands/common/harnessUpdateCliOptions.d.ts +29 -0
  137. package/umd/src/cli/cli-commands/common/harnessUpdateCliOptions.test.d.ts +1 -0
  138. package/umd/src/executables/platforms/locateAppOnWindows.d.ts +1 -1
  139. package/umd/src/executables/platforms/locateAppOnWindows.test.d.ts +1 -0
  140. package/umd/src/utils/agent-message-runtime/parseAgentMessageRuntimeLogEvents.d.ts +59 -0
  141. package/umd/src/utils/agent-message-runtime/resolveAgentMessageTouchedProjectNames.d.ts +19 -0
  142. package/umd/src/utils/agent-message-runtime/resolveAgentMessageTouchedProjectNames.test.d.ts +1 -0
  143. package/umd/src/version.d.ts +1 -1
  144. package/esm/apps/agents-server/src/utils/agentGoalChat/agentGoalChatConstants.d.ts +0 -12
  145. package/umd/apps/agents-server/src/utils/agentGoalChat/agentGoalChatConstants.d.ts +0 -12
@@ -0,0 +1,105 @@
1
+ /**
2
+ * One string-keyed payload of a coding-harness tool invocation.
3
+ *
4
+ * @private internal type of agent-message runtime logs
5
+ */
6
+ type RuntimeLogToolInput = Record<string, unknown>;
7
+
8
+ /**
9
+ * One content block of a Claude Code `stream-json` assistant event.
10
+ *
11
+ * @private internal type of agent-message runtime logs
12
+ */
13
+ export type AgentMessageRuntimeLogContentBlock = {
14
+ readonly type?: string;
15
+ readonly text?: string;
16
+ readonly name?: string;
17
+ readonly input?: RuntimeLogToolInput;
18
+ };
19
+
20
+ /**
21
+ * One file path touched by a Codex `file_change` item.
22
+ *
23
+ * @private internal type of agent-message runtime logs
24
+ */
25
+ export type AgentMessageRuntimeLogFileChange = {
26
+ readonly path?: string;
27
+ };
28
+
29
+ /**
30
+ * Minimal shape of one coding-harness runtime log event.
31
+ *
32
+ * The runtime log mixes two harness formats — Claude Code `stream-json` (`type`/`message`) and
33
+ * Codex JSONL (`type`/`item`) — so both are described by one permissive structure and every
34
+ * consumer reads only the fields it understands.
35
+ *
36
+ * @private internal type of agent-message runtime logs
37
+ */
38
+ export type AgentMessageRuntimeLogEvent = {
39
+ readonly type?: string;
40
+ readonly message?: {
41
+ readonly content?: ReadonlyArray<AgentMessageRuntimeLogContentBlock>;
42
+ };
43
+ readonly item?: {
44
+ readonly type?: string;
45
+ readonly command?: string;
46
+ readonly exit_code?: number | null;
47
+ readonly changes?: ReadonlyArray<AgentMessageRuntimeLogFileChange>;
48
+ };
49
+ };
50
+
51
+ /**
52
+ * Parses every structured event out of one coding-harness runtime log.
53
+ *
54
+ * The local agent runner streams the answering harness output into a live runtime log file, one
55
+ * JSON event per line, optionally prefixed by shell noise. Lines without a usable JSON object are
56
+ * skipped so a partially written or interleaved log never breaks its consumers.
57
+ *
58
+ * @param logText - Raw runtime log content.
59
+ * @returns Structured events in the order they were streamed.
60
+ * @private internal utility of the agent-message runtime
61
+ */
62
+ export function parseAgentMessageRuntimeLogEvents(
63
+ logText: string | null | undefined,
64
+ ): ReadonlyArray<AgentMessageRuntimeLogEvent> {
65
+ if (!logText) {
66
+ return [];
67
+ }
68
+
69
+ const events: Array<AgentMessageRuntimeLogEvent> = [];
70
+
71
+ for (const line of logText.split(/\r?\n/u)) {
72
+ const event = parseAgentMessageRuntimeLogEvent(line);
73
+
74
+ if (event) {
75
+ events.push(event);
76
+ }
77
+ }
78
+
79
+ return events;
80
+ }
81
+
82
+ /**
83
+ * Parses one runtime log line into a structured event when it embeds JSON.
84
+ *
85
+ * @param line - One raw runtime log line.
86
+ * @returns Structured event, or `null` when the line carries no JSON object.
87
+ * @private internal helper of `parseAgentMessageRuntimeLogEvents`
88
+ */
89
+ function parseAgentMessageRuntimeLogEvent(line: string): AgentMessageRuntimeLogEvent | null {
90
+ const jsonStartIndex = line.indexOf('{');
91
+ if (jsonStartIndex === -1) {
92
+ return null;
93
+ }
94
+
95
+ try {
96
+ const parsedEvent = JSON.parse(line.slice(jsonStartIndex).trim()) as unknown;
97
+ if (typeof parsedEvent !== 'object' || parsedEvent === null || Array.isArray(parsedEvent)) {
98
+ return null;
99
+ }
100
+
101
+ return parsedEvent as AgentMessageRuntimeLogEvent;
102
+ } catch {
103
+ return null;
104
+ }
105
+ }
@@ -1,3 +1,6 @@
1
+ import type { AgentMessageRuntimeLogEvent } from './parseAgentMessageRuntimeLogEvents';
2
+ import { parseAgentMessageRuntimeLogEvents } from './parseAgentMessageRuntimeLogEvents';
3
+
1
4
  /**
2
5
  * Maximum length of one user-facing progress activity snippet.
3
6
  *
@@ -71,29 +74,6 @@ const CODEX_COMMAND_ACTIVITIES: ReadonlyArray<CodexCommandActivity> = [
71
74
  },
72
75
  ];
73
76
 
74
- /**
75
- * Minimal shape of one coding-harness `stream-json` event relevant to progress extraction.
76
- *
77
- * Only the natural-language assistant narration is read; every other field is ignored so raw
78
- * tool payloads and technical envelopes never reach the user-facing progress card.
79
- *
80
- * @private internal type of agent-message runtime activity
81
- */
82
- type RuntimeLogEvent = {
83
- readonly type?: string;
84
- readonly message?: {
85
- readonly content?: ReadonlyArray<{
86
- readonly type?: string;
87
- readonly text?: string;
88
- }>;
89
- };
90
- readonly item?: {
91
- readonly type?: string;
92
- readonly command?: string;
93
- readonly exit_code?: number | null;
94
- };
95
- };
96
-
97
77
  /**
98
78
  * Resolves the latest user-friendly activity snippet from a coding-harness runtime log.
99
79
  *
@@ -116,12 +96,7 @@ export function resolveAgentMessageRuntimeActivity(logText: string | null | unde
116
96
 
117
97
  let latestActivity: string | null = null;
118
98
 
119
- for (const line of logText.split(/\r?\n/u)) {
120
- const event = parseRuntimeLogEvent(line);
121
- if (!event) {
122
- continue;
123
- }
124
-
99
+ for (const event of parseAgentMessageRuntimeLogEvents(logText)) {
125
100
  const activity = resolveRuntimeLogEventActivity(event);
126
101
  if (activity) {
127
102
  latestActivity = activity;
@@ -131,35 +106,12 @@ export function resolveAgentMessageRuntimeActivity(logText: string | null | unde
131
106
  return latestActivity === null ? null : truncateRuntimeActivity(latestActivity);
132
107
  }
133
108
 
134
- /**
135
- * Parses one runtime log line into a structured event when it embeds JSON.
136
- *
137
- * @private internal helper of `resolveAgentMessageRuntimeActivity`
138
- */
139
- function parseRuntimeLogEvent(line: string): RuntimeLogEvent | null {
140
- const jsonStartIndex = line.indexOf('{');
141
- if (jsonStartIndex === -1) {
142
- return null;
143
- }
144
-
145
- try {
146
- const parsed = JSON.parse(line.slice(jsonStartIndex).trim()) as unknown;
147
- if (typeof parsed !== 'object' || parsed === null || Array.isArray(parsed)) {
148
- return null;
149
- }
150
-
151
- return parsed as RuntimeLogEvent;
152
- } catch {
153
- return null;
154
- }
155
- }
156
-
157
109
  /**
158
110
  * Resolves the natural-language assistant narration from one complete assistant event.
159
111
  *
160
112
  * @private internal helper of `resolveAgentMessageRuntimeActivity`
161
113
  */
162
- function resolveRuntimeLogEventActivity(event: RuntimeLogEvent): string | null {
114
+ function resolveRuntimeLogEventActivity(event: AgentMessageRuntimeLogEvent): string | null {
163
115
  const codexActivity = resolveCodexRuntimeLogEventActivity(event);
164
116
  if (codexActivity) {
165
117
  return codexActivity;
@@ -190,7 +142,7 @@ function resolveRuntimeLogEventActivity(event: RuntimeLogEvent): string | null {
190
142
  *
191
143
  * @private internal helper of `resolveAgentMessageRuntimeActivity`
192
144
  */
193
- function resolveCodexRuntimeLogEventActivity(event: RuntimeLogEvent): string | null {
145
+ function resolveCodexRuntimeLogEventActivity(event: AgentMessageRuntimeLogEvent): string | null {
194
146
  if (!event.item || !isCodexItemEvent(event.type)) {
195
147
  return null;
196
148
  }
@@ -0,0 +1,147 @@
1
+ import { AGENT_PROJECTS_DIRECTORY_PATH } from '../../book-3.0/agentFolderPaths';
2
+ import type { AgentMessageRuntimeLogEvent } from './parseAgentMessageRuntimeLogEvents';
3
+ import { parseAgentMessageRuntimeLogEvents } from './parseAgentMessageRuntimeLogEvents';
4
+
5
+ /**
6
+ * Matches one project directory name following the agent `projects/` folder in a file path or command.
7
+ *
8
+ * Both path separators are accepted because the local runner answers messages on Unix and Windows,
9
+ * and JSON-encoded payloads escape backslashes.
10
+ *
11
+ * @private internal constant of agent-message touched projects
12
+ */
13
+ const TOUCHED_PROJECT_PATH_REGEX = new RegExp(`${AGENT_PROJECTS_DIRECTORY_PATH}[\\\\/]+([^\\\\/"'\\s,;:]+)`, 'giu');
14
+
15
+ /**
16
+ * Resolves which projects one coding harness touched while answering a single message.
17
+ *
18
+ * The runtime log streams what the harness really did, so a project counts as touched when the
19
+ * harness named it in a tool invocation — reading, searching, running, or editing files inside
20
+ * `projects/<project-name>/`. Only tool payloads are inspected: tool results and assistant
21
+ * narration are ignored so a project merely mentioned in the conversation is never reported.
22
+ *
23
+ * Every candidate is matched against the projects that really exist, which both filters prompt
24
+ * placeholders such as `projects/<project-name>/` and keeps the reported names canonical.
25
+ *
26
+ * @param options - Raw runtime log content and the project directory names of the agent.
27
+ * @returns Touched project names in the canonical spelling, ordered by first appearance.
28
+ * @private internal utility of the agent-message runtime
29
+ */
30
+ export function resolveAgentMessageTouchedProjectNames(options: {
31
+ readonly logText: string | null | undefined;
32
+ readonly knownProjectNames: ReadonlyArray<string>;
33
+ }): ReadonlyArray<string> {
34
+ const canonicalProjectNames = createCanonicalProjectNameLookup(options.knownProjectNames);
35
+ if (canonicalProjectNames.size === 0) {
36
+ return [];
37
+ }
38
+
39
+ const touchedProjectNames = new Set<string>();
40
+
41
+ for (const event of parseAgentMessageRuntimeLogEvents(options.logText)) {
42
+ for (const toolInvocationText of resolveRuntimeLogEventToolInvocationTexts(event)) {
43
+ for (const candidateProjectName of resolveCandidateProjectNames(toolInvocationText)) {
44
+ const canonicalProjectName = canonicalProjectNames.get(candidateProjectName.toLowerCase());
45
+
46
+ if (canonicalProjectName !== undefined) {
47
+ touchedProjectNames.add(canonicalProjectName);
48
+ }
49
+ }
50
+ }
51
+ }
52
+
53
+ return Array.from(touchedProjectNames);
54
+ }
55
+
56
+ /**
57
+ * Indexes the existing project directory names by their lower-cased form.
58
+ *
59
+ * @param knownProjectNames - Project directory names of the agent.
60
+ * @returns Lookup from the lower-cased name to its canonical spelling.
61
+ * @private internal helper of `resolveAgentMessageTouchedProjectNames`
62
+ */
63
+ function createCanonicalProjectNameLookup(knownProjectNames: ReadonlyArray<string>): Map<string, string> {
64
+ const canonicalProjectNames = new Map<string, string>();
65
+
66
+ for (const knownProjectName of knownProjectNames) {
67
+ const normalizedProjectName = knownProjectName.trim();
68
+
69
+ if (normalizedProjectName.length > 0) {
70
+ canonicalProjectNames.set(normalizedProjectName.toLowerCase(), normalizedProjectName);
71
+ }
72
+ }
73
+
74
+ return canonicalProjectNames;
75
+ }
76
+
77
+ /**
78
+ * Collects the texts of every tool invocation described by one runtime log event.
79
+ *
80
+ * Claude Code reports tool invocations as `tool_use` content blocks, while Codex reports executed
81
+ * commands and file changes as items — both carry the paths the harness worked with.
82
+ *
83
+ * @param event - One structured runtime log event.
84
+ * @returns Texts that may contain project paths.
85
+ * @private internal helper of `resolveAgentMessageTouchedProjectNames`
86
+ */
87
+ function resolveRuntimeLogEventToolInvocationTexts(event: AgentMessageRuntimeLogEvent): ReadonlyArray<string> {
88
+ const toolInvocationTexts: Array<string> = [];
89
+
90
+ for (const contentBlock of event.message?.content || []) {
91
+ if (contentBlock.type === 'tool_use' && contentBlock.input) {
92
+ toolInvocationTexts.push(serializeToolInput(contentBlock.input));
93
+ }
94
+ }
95
+
96
+ if (typeof event.item?.command === 'string') {
97
+ toolInvocationTexts.push(event.item.command);
98
+ }
99
+
100
+ for (const fileChange of event.item?.changes || []) {
101
+ if (typeof fileChange.path === 'string') {
102
+ toolInvocationTexts.push(fileChange.path);
103
+ }
104
+ }
105
+
106
+ return toolInvocationTexts;
107
+ }
108
+
109
+ /**
110
+ * Serializes one tool input payload into scannable text.
111
+ *
112
+ * @param toolInput - Tool arguments of one harness tool invocation.
113
+ * @returns Serialized payload, or an empty string when it cannot be serialized.
114
+ * @private internal helper of `resolveAgentMessageTouchedProjectNames`
115
+ */
116
+ function serializeToolInput(toolInput: Record<string, unknown>): string {
117
+ try {
118
+ return JSON.stringify(toolInput);
119
+ } catch {
120
+ return '';
121
+ }
122
+ }
123
+
124
+ /**
125
+ * Extracts every project directory name mentioned right after the agent `projects/` folder.
126
+ *
127
+ * @param toolInvocationText - One tool payload, command, or changed path.
128
+ * @returns Candidate project directory names.
129
+ * @private internal helper of `resolveAgentMessageTouchedProjectNames`
130
+ */
131
+ function resolveCandidateProjectNames(toolInvocationText: string): ReadonlyArray<string> {
132
+ const candidateProjectNames: Array<string> = [];
133
+ const projectPathRegex = new RegExp(TOUCHED_PROJECT_PATH_REGEX.source, TOUCHED_PROJECT_PATH_REGEX.flags);
134
+ let projectPathMatch = projectPathRegex.exec(toolInvocationText);
135
+
136
+ while (projectPathMatch !== null) {
137
+ const candidateProjectName = projectPathMatch[1];
138
+
139
+ if (candidateProjectName) {
140
+ candidateProjectNames.push(candidateProjectName);
141
+ }
142
+
143
+ projectPathMatch = projectPathRegex.exec(toolInvocationText);
144
+ }
145
+
146
+ return candidateProjectNames;
147
+ }
package/src/version.ts CHANGED
@@ -16,11 +16,11 @@ export const BOOK_LANGUAGE_VERSION: string_semantic_version = '2.0.0';
16
16
  * @generated
17
17
  * @see https://github.com/webgptorg/promptbook
18
18
  */
19
- export const PROMPTBOOK_ENGINE_VERSION: string_promptbook_version = '0.114.0-11';
19
+ export const PROMPTBOOK_ENGINE_VERSION: string_promptbook_version = '0.114.0-13';
20
20
 
21
21
  /**
22
22
  * Represents the version string of the Promptbook engine.
23
- * It follows semantic versioning (e.g., `0.114.0-10`).
23
+ * It follows semantic versioning (e.g., `0.114.0-12`).
24
24
  *
25
25
  * @generated
26
26
  */
package/src/versions.txt CHANGED
@@ -1187,4 +1187,5 @@
1187
1187
  0.114.0-8
1188
1188
  0.114.0-9
1189
1189
  0.114.0-10
1190
- 0.114.0-11
1190
+ 0.114.0-12
1191
+ 0.114.0-13