@iaforged/context-code 1.2.8 → 1.2.10

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 (172) hide show
  1. package/README.md +119 -119
  2. package/context-bootstrap.js +26 -26
  3. package/dist/src/QueryEngine.js +394 -327
  4. package/dist/src/bridge/bridgeUI.js +1 -1
  5. package/dist/src/buddy/prompt.js +4 -4
  6. package/dist/src/cli/handlers/auth.js +126 -9
  7. package/dist/src/cli/print.js +35 -1
  8. package/dist/src/commands/agent/agent.js +28 -2
  9. package/dist/src/commands/agent/agentStore.js +8 -1
  10. package/dist/src/commands/agent/index.js +1 -1
  11. package/dist/src/commands/bridge-kick.js +9 -9
  12. package/dist/src/commands/commit.js +34 -34
  13. package/dist/src/commands/init-verifiers.js +3 -3
  14. package/dist/src/commands/init.js +88 -88
  15. package/dist/src/commands/insights.js +787 -787
  16. package/dist/src/commands/install.js +19 -19
  17. package/dist/src/commands/login/login.js +21 -12
  18. package/dist/src/commands/logout/logout.js +9 -0
  19. package/dist/src/commands/model/model.js +9 -4
  20. package/dist/src/commands/orchestrate/SwarmUI.js +50 -0
  21. package/dist/src/commands/orchestrate/index.js +2 -2
  22. package/dist/src/commands/orchestrate/orchestrate.js +708 -12
  23. package/dist/src/commands/pr_comments/index.js +33 -33
  24. package/dist/src/commands/profile/index.js +1 -1
  25. package/dist/src/commands/profile/profile.js +52 -3
  26. package/dist/src/commands/provider/index.js +1 -1
  27. package/dist/src/commands/provider/provider.js +117 -45
  28. package/dist/src/commands/resumen/index.js +9 -0
  29. package/dist/src/commands/resumen/resumen.js +29 -0
  30. package/dist/src/commands/security-review.js +190 -190
  31. package/dist/src/commands/swarm-auto/index.js +9 -0
  32. package/dist/src/commands/swarm-auto/swarmAuto.js +111 -0
  33. package/dist/src/commands/swarm-init/index.js +9 -0
  34. package/dist/src/commands/swarm-init/swarmInit.js +72 -0
  35. package/dist/src/commands/team/team.js +39 -6
  36. package/dist/src/commands.js +14 -0
  37. package/dist/src/components/LogoV2/CondensedLogo.js +2 -2
  38. package/dist/src/components/PromptInput/PromptInputQueuedCommands.js +3 -3
  39. package/dist/src/components/agents/agentFileUtils.js +6 -6
  40. package/dist/src/components/permissions/hooks.js +5 -5
  41. package/dist/src/constants/outputStyles.js +83 -83
  42. package/dist/src/core/agents/blueprints.js +58 -0
  43. package/dist/src/core/agents/cliAdapter.js +61 -0
  44. package/dist/src/core/agents/registry.js +93 -0
  45. package/dist/src/core/agents/runtime.js +4 -0
  46. package/dist/src/core/agents/runtime.smoke.js +42 -0
  47. package/dist/src/core/agents/swarm.smoke.js +48 -0
  48. package/dist/src/core/agents/swarmTools.js +38 -0
  49. package/dist/src/core/auth/index.js +2 -0
  50. package/dist/src/core/auth/loginCliAdapter.js +24 -0
  51. package/dist/src/core/auth/loginCore.js +67 -0
  52. package/dist/src/core/auth/logoutCliAdapter.js +34 -0
  53. package/dist/src/core/auth/logoutCore.js +52 -0
  54. package/dist/src/core/auth/preflight.smoke.js +151 -0
  55. package/dist/src/core/index.js +21 -0
  56. package/dist/src/core/mcp/blueprints.js +27 -0
  57. package/dist/src/core/mcp/common.js +14 -0
  58. package/dist/src/core/mcp/runtime.js +67 -0
  59. package/dist/src/core/mcp/runtime.smoke.js +50 -0
  60. package/dist/src/core/mcp/swarmClient.js +40 -0
  61. package/dist/src/core/mcp/swarmSetup.js +43 -0
  62. package/dist/src/core/providers/cliAdapter.js +39 -0
  63. package/dist/src/core/providers/contracts.js +1 -0
  64. package/dist/src/core/providers/index.js +3 -0
  65. package/dist/src/core/providers/llmCore.js +123 -0
  66. package/dist/src/core/providers/providerCore.js +141 -0
  67. package/dist/src/core/providers/providerModelCompatibility.js +98 -0
  68. package/dist/src/core/providers/providerParitySmoke.js +83 -0
  69. package/dist/src/core/providers/providerProfileModelSmoke.js +80 -0
  70. package/dist/src/core/query/contracts.js +1 -0
  71. package/dist/src/core/query/runtime.js +117 -0
  72. package/dist/src/core/query/runtime.smoke.js +39 -0
  73. package/dist/src/core/query/timelineThinking.smoke.js +25 -0
  74. package/dist/src/core/query/wiring.smoke.js +76 -0
  75. package/dist/src/core/skills/cliAdapter.js +38 -0
  76. package/dist/src/core/skills/index.js +52 -0
  77. package/dist/src/core/skills/runtime.smoke.js +53 -0
  78. package/dist/src/core/tasks/runtime.js +205 -0
  79. package/dist/src/core/tasks/runtime.smoke.js +63 -0
  80. package/dist/src/core/tasks/sdkAdapter.js +4 -0
  81. package/dist/src/core/tools/contracts.js +3 -0
  82. package/dist/src/core/tools/fileResolution.js +112 -0
  83. package/dist/src/core/tools/fileResolution.smoke.js +33 -0
  84. package/dist/src/core/tools/filesCore.js +51 -0
  85. package/dist/src/core/tools/filesCore.smoke.js +108 -0
  86. package/dist/src/core/tools/gitCore.js +20 -0
  87. package/dist/src/core/tools/imageParity.smoke.js +36 -0
  88. package/dist/src/core/tools/notebookParity.smoke.js +68 -0
  89. package/dist/src/core/tools/registry.js +22 -0
  90. package/dist/src/core/tools/runtime.smoke.js +32 -0
  91. package/dist/src/core/tools/shellCore.js +60 -0
  92. package/dist/src/core/types/agentContext.js +9 -0
  93. package/dist/src/core/types/auth.js +3 -0
  94. package/dist/src/core/types/command.js +13 -0
  95. package/dist/src/core/types/provider.js +3 -0
  96. package/dist/src/core/types/sdkEvent.js +10 -0
  97. package/dist/src/core/types/swarm.js +1 -0
  98. package/dist/src/cost-tracker.js +3 -3
  99. package/dist/src/hooks/useAwaySummary.js +22 -9
  100. package/dist/src/main.js +32 -2
  101. package/dist/src/screens/REPL.js +9 -0
  102. package/dist/src/services/AgentSummary/agentSummary.js +10 -10
  103. package/dist/src/services/autoDream/autoDream.js +5 -5
  104. package/dist/src/services/autoDream/consolidationPrompt.js +49 -49
  105. package/dist/src/services/compact/prompt.js +238 -238
  106. package/dist/src/services/limits/sessionCounter.js +17 -17
  107. package/dist/src/services/mcp/client.js +27 -1
  108. package/dist/src/services/orchestration/execution/AgentTaskExecutor.js +39 -20
  109. package/dist/src/services/orchestration/execution/OrchestrationExecutionRuntime.js +65 -58
  110. package/dist/src/skills/bundled/loop.js +57 -57
  111. package/dist/src/skills/bundled/remember.js +53 -53
  112. package/dist/src/skills/bundled/simplify.js +49 -49
  113. package/dist/src/skills/bundled/skillify.js +2 -2
  114. package/dist/src/state/onChangeAppState.js +6 -0
  115. package/dist/src/tasks/LocalAgentTask/LocalAgentTask.js +5 -5
  116. package/dist/src/tasks/LocalMainSessionTask.js +5 -5
  117. package/dist/src/tasks/LocalShellTask/LocalShellTask.js +13 -13
  118. package/dist/src/tools/AgentTool/forkSubagent.js +25 -25
  119. package/dist/src/tools/AskUserQuestionTool/prompt.js +29 -29
  120. package/dist/src/tools/BashTool/BashTool.js +27 -2
  121. package/dist/src/tools/BriefTool/prompt.js +14 -14
  122. package/dist/src/tools/EnterPlanModeTool/EnterPlanModeTool.js +12 -12
  123. package/dist/src/tools/EnterPlanModeTool/prompt.js +140 -140
  124. package/dist/src/tools/ExitPlanModeTool/ExitPlanModeV2Tool.js +18 -18
  125. package/dist/src/tools/ExitPlanModeTool/prompt.js +23 -23
  126. package/dist/src/tools/ExitWorktreeTool/prompt.js +29 -29
  127. package/dist/src/tools/FileEditTool/prompt.js +7 -7
  128. package/dist/src/tools/FileReadTool/FileReadTool.js +18 -1
  129. package/dist/src/tools/FileWriteTool/prompt.js +6 -6
  130. package/dist/src/tools/GlobTool/prompt.js +4 -4
  131. package/dist/src/tools/GrepTool/prompt.js +10 -10
  132. package/dist/src/tools/LSPTool/prompt.js +18 -18
  133. package/dist/src/tools/ListMcpResourcesTool/prompt.js +15 -15
  134. package/dist/src/tools/PowerShellTool/PowerShellTool.js +25 -2
  135. package/dist/src/tools/ReadMcpResourceTool/prompt.js +13 -13
  136. package/dist/src/tools/SendMessageTool/prompt.js +36 -36
  137. package/dist/src/tools/SkillTool/prompt.js +21 -21
  138. package/dist/src/tools/SleepTool/prompt.js +10 -10
  139. package/dist/src/tools/TaskCreateTool/prompt.js +41 -41
  140. package/dist/src/tools/TaskGetTool/prompt.js +21 -21
  141. package/dist/src/tools/TaskListTool/prompt.js +30 -30
  142. package/dist/src/tools/TaskOutputTool/TaskOutputTool.js +8 -8
  143. package/dist/src/tools/TaskStopTool/prompt.js +5 -5
  144. package/dist/src/tools/TaskUpdateTool/prompt.js +74 -74
  145. package/dist/src/tools/TodoWriteTool/prompt.js +178 -178
  146. package/dist/src/tools/ToolSearchTool/prompt.js +9 -9
  147. package/dist/src/tools/WebFetchTool/WebFetchTool.js +9 -9
  148. package/dist/src/tools/WebFetchTool/prompt.js +31 -31
  149. package/dist/src/tools/WebSearchTool/prompt.js +26 -26
  150. package/dist/src/utils/agentContext.js +2 -0
  151. package/dist/src/utils/agenticSessionSearch.js +38 -38
  152. package/dist/src/utils/config.js +2 -0
  153. package/dist/src/utils/genericProcessUtils.js +21 -21
  154. package/dist/src/utils/heapDumpService.js +4 -4
  155. package/dist/src/utils/mcpValidation.js +2 -2
  156. package/dist/src/utils/model/modelStrings.js +1 -1
  157. package/dist/src/utils/model/providers.js +5 -0
  158. package/dist/src/utils/orchestration/store/providerAgentStore.js +22 -22
  159. package/dist/src/utils/orchestration/store/providerWorkspaceStore.js +10 -10
  160. package/dist/src/utils/orchestration/store/runStore.js +68 -68
  161. package/dist/src/utils/orchestration/store/teamStore.js +28 -28
  162. package/dist/src/utils/permissions/permissionExplainer.js +6 -6
  163. package/dist/src/utils/permissions/permissionsDb.js +43 -43
  164. package/dist/src/utils/sdkEventQueue.js +2 -0
  165. package/dist/src/utils/secureStorage/sqliteStorage.js +12 -12
  166. package/dist/src/utils/standardMcp/common.js +15 -0
  167. package/dist/src/utils/standardMcp/setup.js +52 -0
  168. package/dist/src/utils/swarm/teammatePromptAddendum.js +10 -10
  169. package/dist/src/utils/task/framework.js +6 -6
  170. package/package.json +1 -1
  171. package/dist/src/commands/usage/index.js +0 -7
  172. package/dist/src/commands/usage/usage.js +0 -5
@@ -1,10 +1,10 @@
1
1
  import { feature } from '../recovery/bunBundleShim.js';
2
2
  import { useEffect, useRef } from 'react';
3
+ import { useAppState } from '../state/AppState.js';
3
4
  import { getTerminalFocusState, subscribeTerminalFocus, } from '../ink/terminal-focus-state.js';
4
5
  import { getFeatureValue_CACHED_MAY_BE_STALE } from '../services/analytics/growthbook.js';
5
6
  import { generateAwaySummary } from '../services/awaySummary.js';
6
7
  import { createAwaySummaryMessage } from '../utils/messages.js';
7
- const BLUR_DELAY_MS = 5 * 60_000;
8
8
  function hasSummarySinceLastUserTurn(messages) {
9
9
  for (let i = messages.length - 1; i >= 0; i--) {
10
10
  const m = messages[i];
@@ -27,10 +27,14 @@ export function useAwaySummary(messages, setMessages, isLoading) {
27
27
  const abortRef = useRef(null);
28
28
  const messagesRef = useRef(messages);
29
29
  const isLoadingRef = useRef(isLoading);
30
+ const orchestrationActivity = useAppState(s => s.orchestrationActivity);
31
+ const isOrchestrationActive = !!orchestrationActivity;
32
+ const isOrchestrationActiveRef = useRef(isOrchestrationActive);
30
33
  const pendingRef = useRef(false);
31
34
  const generateRef = useRef(null);
32
35
  messagesRef.current = messages;
33
36
  isLoadingRef.current = isLoading;
37
+ isOrchestrationActiveRef.current = !!orchestrationActivity;
34
38
  // 3P default: false
35
39
  const gbEnabled = getFeatureValue_CACHED_MAY_BE_STALE('tengu_sedge_lantern', false);
36
40
  useEffect(() => {
@@ -62,24 +66,33 @@ export function useAwaySummary(messages, setMessages, isLoading) {
62
66
  }
63
67
  function onBlurTimerFire() {
64
68
  timerRef.current = null;
65
- if (isLoadingRef.current) {
69
+ // Do not trigger summary if a turn is in progress or background orchestration is active
70
+ if (isLoadingRef.current || isOrchestrationActiveRef.current) {
71
+ logForDebugging(`Suppressing away summary: isLoading=${isLoadingRef.current}, orchestrationActive=${isOrchestrationActiveRef.current}`);
66
72
  pendingRef.current = true;
67
73
  return;
68
74
  }
75
+ logForDebugging('Generating away summary');
69
76
  void generate();
70
77
  }
71
78
  function onFocusChange() {
72
79
  const state = getTerminalFocusState();
73
80
  if (state === 'blurred') {
74
81
  clearTimer();
75
- timerRef.current = setTimeout(onBlurTimerFire, BLUR_DELAY_MS);
82
+ const delay = getGlobalConfig().awaySummaryBlurDelayMs;
83
+ logForDebugging(`Terminal blurred, setting away summary timer for ${delay}ms`);
84
+ timerRef.current = setTimeout(onBlurTimerFire, delay);
76
85
  }
77
86
  else if (state === 'focused') {
78
87
  clearTimer();
79
- abortInFlight();
80
- pendingRef.current = false;
88
+ if (pendingRef.current) {
89
+ logForDebugging('Terminal focused, pending summary exists. Checking if still needed.');
90
+ // If we had a pending summary that was suppressed, check if we can show it now
91
+ if (!isLoadingRef.current && !isOrchestrationActiveRef.current) {
92
+ void generate();
93
+ }
94
+ }
81
95
  }
82
- // 'unknown' → no-op
83
96
  }
84
97
  const unsubscribe = subscribeTerminalFocus(onFocusChange);
85
98
  // Handle the case where we're already blurred when the effect mounts
@@ -92,14 +105,14 @@ export function useAwaySummary(messages, setMessages, isLoading) {
92
105
  generateRef.current = null;
93
106
  };
94
107
  }, [gbEnabled, setMessages]);
95
- // Timer fired mid-turn → fire when turn ends (if still blurred)
108
+ // Timer fired mid-turn or during orchestration → fire when both end (if still blurred)
96
109
  useEffect(() => {
97
- if (isLoading)
110
+ if (isLoading || isOrchestrationActive)
98
111
  return;
99
112
  if (!pendingRef.current)
100
113
  return;
101
114
  if (getTerminalFocusState() !== 'blurred')
102
115
  return;
103
116
  void generateRef.current?.();
104
- }, [isLoading]);
117
+ }, [isLoading, isOrchestrationActive]);
105
118
  }
package/dist/src/main.js CHANGED
@@ -3729,13 +3729,14 @@ async function run() {
3729
3729
  }
3730
3730
  // context auth
3731
3731
  const auth = program.command('auth').description('Gestionar autenticación').configureHelp(createSortedHelpConfig());
3732
- auth.command('login').description('Iniciar sesión en tu cuenta de Anthropic').option('--email <email>', 'Pre-completar la dirección de correo en la página de inicio de sesión').option('--sso', 'Forzar el flujo de inicio de sesión SSO').option('--console', 'Usar Anthropic Console (facturación por uso de API) en lugar de la suscripción de Claude').option('--claudeai', 'Usar suscripción de Claude (por defecto)').action(async ({ email, sso, console: useConsole, claudeai }) => {
3732
+ auth.command('login').description('Iniciar sesión por OAuth (Anthropic/OpenAI/Google según provider)').option('--email <email>', 'Pre-completar la dirección de correo en la página de inicio de sesión').option('--sso', 'Forzar el flujo de inicio de sesión SSO').option('--console', 'Usar Anthropic Console (facturación por uso de API) en lugar de la suscripción de Claude').option('--claudeai', 'Usar suscripción de Claude (por defecto)').option('--provider <id>', 'Provider OAuth: claude, openai, gemini-google').action(async ({ email, sso, console: useConsole, claudeai, provider }) => {
3733
3733
  const { authLogin } = await import('./cli/handlers/auth.js');
3734
3734
  await authLogin({
3735
3735
  email,
3736
3736
  sso,
3737
3737
  console: useConsole,
3738
- claudeai
3738
+ claudeai,
3739
+ provider
3739
3740
  });
3740
3741
  });
3741
3742
  auth.command('status').description('Show authentication status').option('--json', 'Output as JSON (default)').option('--text', 'Output as human-readable text').action(async (opts) => {
@@ -3746,6 +3747,35 @@ async function run() {
3746
3747
  const { authLogout } = await import('./cli/handlers/auth.js');
3747
3748
  await authLogout();
3748
3749
  });
3750
+ auth.command('provider-api-key').description('Guardar API key para un provider compatible').requiredOption('--provider <id>', 'ID de provider (openrouter, minimax, zai, gemini-api, nvidia, ollama-cloud)').requiredOption('--api-key <key>', 'API key del provider').option('--profile <name>', 'Perfil del provider').action(async (opts) => {
3751
+ const { authProviderApiKey } = await import('./cli/handlers/auth.js');
3752
+ await authProviderApiKey({
3753
+ provider: opts.provider,
3754
+ apiKey: opts.apiKey,
3755
+ profile: opts.profile
3756
+ });
3757
+ });
3758
+ auth.command('provider-base-url').description('Guardar base URL para un provider compatible').requiredOption('--provider <id>', 'ID de provider (ollama, ollama-cloud, openrouter, gemini-google, zai, minimax, nvidia)').requiredOption('--base-url <url>', 'Base URL del provider').option('--profile <name>', 'Perfil del provider').action(async (opts) => {
3759
+ const { authProviderBaseUrl } = await import('./cli/handlers/auth.js');
3760
+ await authProviderBaseUrl({
3761
+ provider: opts.provider,
3762
+ baseUrl: opts.baseUrl,
3763
+ profile: opts.profile
3764
+ });
3765
+ });
3766
+ auth.command('set-provider').description('Establecer provider activo para flujos de auth').requiredOption('--provider <id>', 'ID de provider (claude, openai, gemini-google, ...)').action(async (opts) => {
3767
+ const { authSetProviderPreference } = await import('./cli/handlers/auth.js');
3768
+ await authSetProviderPreference({
3769
+ provider: opts.provider
3770
+ });
3771
+ });
3772
+ auth.command('provider-remove').description('Eliminar provider/perfil y limpiar sus credenciales').requiredOption('--provider <id>', 'ID de provider (claude, openai, minimax, ollama, ...)').option('--profile <name>', 'Perfil del provider (si aplica)').action(async (opts) => {
3773
+ const { authProviderRemove } = await import('./cli/handlers/auth.js');
3774
+ await authProviderRemove({
3775
+ provider: opts.provider,
3776
+ profile: opts.profile
3777
+ });
3778
+ });
3749
3779
  // context provider
3750
3780
  const provider = program.command('provider').description('Cambiar entre proveedores y configurar endpoints').configureHelp(createSortedHelpConfig());
3751
3781
  provider.command('list').description('Listar proveedores y perfiles configurados').action(async () => {
@@ -860,6 +860,12 @@ export function REPL({ commands: initialCommands, debug, initialTools, initialMe
860
860
  // 3. In the onDone callback, use `setToolJSX({ jsx: null, shouldHidePromptInput: false, clearLocalJSX: true })`
861
861
  // to explicitly clear the overlay when the user dismisses it
862
862
  const setToolJSX = useCallback((args) => {
863
+ logForDebugging(`setToolJSX called with: ${JSON.stringify({
864
+ hasJsx: !!args?.jsx,
865
+ shouldHidePromptInput: args?.shouldHidePromptInput,
866
+ isLocalJSXCommand: args?.isLocalJSXCommand,
867
+ clearLocalJSX: args?.clearLocalJSX
868
+ })}`);
863
869
  // If setting a local JSX command, store it in the ref
864
870
  if (args?.isLocalJSXCommand) {
865
871
  const { clearLocalJSX: _, ...rest } = args;
@@ -874,15 +880,18 @@ export function REPL({ commands: initialCommands, debug, initialTools, initialMe
874
880
  if (localJSXCommandRef.current) {
875
881
  // Allow clearing only if explicitly requested (from onDone callbacks)
876
882
  if (args?.clearLocalJSX) {
883
+ logForDebugging('Clearing local JSX command as requested');
877
884
  localJSXCommandRef.current = null;
878
885
  setToolJSXInternal(null);
879
886
  return;
880
887
  }
881
888
  // Otherwise, keep the local JSX command visible - ignore tool updates
889
+ logForDebugging('Ignoring setToolJSX update because a local JSX command is active');
882
890
  return;
883
891
  }
884
892
  // No active local JSX command, allow any update
885
893
  if (args?.clearLocalJSX) {
894
+ logForDebugging('Clearing tool JSX (no local command active)');
886
895
  setToolJSXInternal(null);
887
896
  return;
888
897
  }
@@ -21,16 +21,16 @@ function buildSummaryPrompt(previousSummary) {
21
21
  const prevLine = previousSummary
22
22
  ? `\nPrevious: "${previousSummary}" — say something NEW.\n`
23
23
  : '';
24
- return `Describe your most recent action in 3-5 words using present tense (-ing). Name the file or function, not the branch. Do not use tools.
25
- ${prevLine}
26
- Good: "Reading runAgent.ts"
27
- Good: "Fixing null check in validate.ts"
28
- Good: "Running auth module tests"
29
- Good: "Adding retry logic to fetchUser"
30
-
31
- Bad (past tense): "Analyzed the branch diff"
32
- Bad (too vague): "Investigating the issue"
33
- Bad (too long): "Reviewing full branch diff and AgentTool.tsx integration"
24
+ return `Describe your most recent action in 3-5 words using present tense (-ing). Name the file or function, not the branch. Do not use tools.
25
+ ${prevLine}
26
+ Good: "Reading runAgent.ts"
27
+ Good: "Fixing null check in validate.ts"
28
+ Good: "Running auth module tests"
29
+ Good: "Adding retry logic to fetchUser"
30
+
31
+ Bad (past tense): "Analyzed the branch diff"
32
+ Bad (too vague): "Investigating the issue"
33
+ Bad (too long): "Reviewing full branch diff and AgentTool.tsx integration"
34
34
  Bad (branch name): "Analyzed adam/background-summary branch diff"`;
35
35
  }
36
36
  export function startAgentSummarization(taskId, agentId, cacheSafeParams, setAppState) {
@@ -151,11 +151,11 @@ export function initAutoDream() {
151
151
  // Tool constraints note goes in `extra`, not the shared prompt body —
152
152
  // manual /dream runs in the main loop with normal permissions and this
153
153
  // would be misleading there.
154
- const extra = `
155
-
156
- **Tool constraints for this run:** Bash is restricted to read-only commands (\`ls\`, \`find\`, \`grep\`, \`cat\`, \`stat\`, \`wc\`, \`head\`, \`tail\`, and similar). Anything that writes, redirects to a file, or modifies state will be denied. Plan your exploration with this in mind — no need to probe.
157
-
158
- Sessions since last consolidation (${sessionIds.length}):
154
+ const extra = `
155
+
156
+ **Tool constraints for this run:** Bash is restricted to read-only commands (\`ls\`, \`find\`, \`grep\`, \`cat\`, \`stat\`, \`wc\`, \`head\`, \`tail\`, and similar). Anything that writes, redirects to a file, or modifies state will be denied. Plan your exploration with this in mind — no need to probe.
157
+
158
+ Sessions since last consolidation (${sessionIds.length}):
159
159
  ${sessionIds.map(id => `- ${id}`).join('\n')}`;
160
160
  const prompt = buildConsolidationPrompt(memoryRoot, transcriptDir, extra);
161
161
  const result = await runForkedAgent({
@@ -3,54 +3,54 @@ import { feature } from '../../recovery/bunBundleShim.js';
3
3
  // feature flags (dream.ts is behind a feature()-gated require).
4
4
  import { DIR_EXISTS_GUIDANCE, ENTRYPOINT_NAME, MAX_ENTRYPOINT_LINES, } from '../../memdir/memdir.js';
5
5
  export function buildConsolidationPrompt(memoryRoot, transcriptDir, extra) {
6
- return `# Dream: Memory Consolidation
7
-
8
- You are performing a dream — a reflective pass over your memory files. Synthesize what you've learned recently into durable, well-organized memories so that future sessions can orient quickly.
9
-
10
- Memory directory: \`${memoryRoot}\`
11
- ${DIR_EXISTS_GUIDANCE}
12
-
13
- Session transcripts: \`${transcriptDir}\` (large JSONL files — grep narrowly, don't read whole files)
14
-
15
- ---
16
-
17
- ## Phase 1 — Orient
18
-
19
- - \`ls\` the memory directory to see what already exists
20
- - Read \`${ENTRYPOINT_NAME}\` to understand the current index
21
- - Skim existing topic files so you improve them rather than creating duplicates
22
- - If \`logs/\` or \`sessions/\` subdirectories exist (assistant-mode layout), review recent entries there
23
-
24
- ## Phase 2 — Gather recent signal
25
-
26
- Look for new information worth persisting. Sources in rough priority order:
27
-
28
- 1. **Daily logs** (\`logs/YYYY/MM/YYYY-MM-DD.md\`) if present — these are the append-only stream
29
- 2. **Existing memories that drifted** — facts that contradict something you see in the codebase now
30
- 3. **Transcript search** — if you need specific context (e.g., "what was the error message from yesterday's build failure?"), grep the JSONL transcripts for narrow terms:
31
- \`grep -rn "<narrow term>" ${transcriptDir}/ --include="*.jsonl" | tail -50\`
32
-
33
- Don't exhaustively read transcripts. Look only for things you already suspect matter.
34
-
35
- ## Phase 3 — Consolidate
36
-
37
- For each thing worth remembering, write or update a memory file at the top level of the memory directory. Use the memory file format and type conventions from your system prompt's auto-memory section — it's the source of truth for what to save, how to structure it, and what NOT to save.
38
-
39
- Focus on:
40
- - Merging new signal into existing topic files rather than creating near-duplicates
41
- - Converting relative dates ("yesterday", "last week") to absolute dates so they remain interpretable after time passes
42
- - Deleting contradicted facts — if today's investigation disproves an old memory, fix it at the source
43
-
44
- ## Phase 4 — Prune and index
45
-
46
- Update \`${ENTRYPOINT_NAME}\` so it stays under ${MAX_ENTRYPOINT_LINES} lines AND under ~25KB. It's an **index**, not a dump — each entry should be one line under ~150 characters: \`- [Title](file.md) — one-line hook\`. Never write memory content directly into it.
47
-
48
- - Remove pointers to memories that are now stale, wrong, or superseded
49
- - Demote verbose entries: if an index line is over ~200 chars, it's carrying content that belongs in the topic file — shorten the line, move the detail
50
- - Add pointers to newly important memories
51
- - Resolve contradictions — if two files disagree, fix the wrong one
52
-
53
- ---
54
-
6
+ return `# Dream: Memory Consolidation
7
+
8
+ You are performing a dream — a reflective pass over your memory files. Synthesize what you've learned recently into durable, well-organized memories so that future sessions can orient quickly.
9
+
10
+ Memory directory: \`${memoryRoot}\`
11
+ ${DIR_EXISTS_GUIDANCE}
12
+
13
+ Session transcripts: \`${transcriptDir}\` (large JSONL files — grep narrowly, don't read whole files)
14
+
15
+ ---
16
+
17
+ ## Phase 1 — Orient
18
+
19
+ - \`ls\` the memory directory to see what already exists
20
+ - Read \`${ENTRYPOINT_NAME}\` to understand the current index
21
+ - Skim existing topic files so you improve them rather than creating duplicates
22
+ - If \`logs/\` or \`sessions/\` subdirectories exist (assistant-mode layout), review recent entries there
23
+
24
+ ## Phase 2 — Gather recent signal
25
+
26
+ Look for new information worth persisting. Sources in rough priority order:
27
+
28
+ 1. **Daily logs** (\`logs/YYYY/MM/YYYY-MM-DD.md\`) if present — these are the append-only stream
29
+ 2. **Existing memories that drifted** — facts that contradict something you see in the codebase now
30
+ 3. **Transcript search** — if you need specific context (e.g., "what was the error message from yesterday's build failure?"), grep the JSONL transcripts for narrow terms:
31
+ \`grep -rn "<narrow term>" ${transcriptDir}/ --include="*.jsonl" | tail -50\`
32
+
33
+ Don't exhaustively read transcripts. Look only for things you already suspect matter.
34
+
35
+ ## Phase 3 — Consolidate
36
+
37
+ For each thing worth remembering, write or update a memory file at the top level of the memory directory. Use the memory file format and type conventions from your system prompt's auto-memory section — it's the source of truth for what to save, how to structure it, and what NOT to save.
38
+
39
+ Focus on:
40
+ - Merging new signal into existing topic files rather than creating near-duplicates
41
+ - Converting relative dates ("yesterday", "last week") to absolute dates so they remain interpretable after time passes
42
+ - Deleting contradicted facts — if today's investigation disproves an old memory, fix it at the source
43
+
44
+ ## Phase 4 — Prune and index
45
+
46
+ Update \`${ENTRYPOINT_NAME}\` so it stays under ${MAX_ENTRYPOINT_LINES} lines AND under ~25KB. It's an **index**, not a dump — each entry should be one line under ~150 characters: \`- [Title](file.md) — one-line hook\`. Never write memory content directly into it.
47
+
48
+ - Remove pointers to memories that are now stale, wrong, or superseded
49
+ - Demote verbose entries: if an index line is over ~200 chars, it's carrying content that belongs in the topic file — shorten the line, move the detail
50
+ - Add pointers to newly important memories
51
+ - Resolve contradictions — if two files disagree, fix the wrong one
52
+
53
+ ---
54
+
55
55
  Return a brief summary of what you consolidated, updated, or pruned. If nothing changed (memories are already tight), say so.${extra ? `\n\n## Additional context\n\n${extra}` : ''}`;
56
56
  }