@ai-matrx/coding-sessions 0.1.86 → 0.1.88

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.
@@ -1,4 +1,4 @@
1
- export { e as CodingSessionsAgentsOptions, c as CodingSessionsEngine, d as CodingSessionsEngineOptions, D as DEFAULT_SERVER_URL, f as DEFAULT_SUPABASE_URL, E as EFFORT_LEVELS, P as PreferenceStore, g as ProviderHomes, R as RAW_TRANSCRIPT_MAX_BYTES, h as RawBackupPolicy, i as RawBackupSink, j as RunStatus, k as buildCleanEnv, l as claudeDefaults, m as codexDefaults, n as createAiMatrxRawBackupSink, o as createCodingSessionsEngine, p as createRawBackupScheduler, q as defaultProviderHomes, r as describeActivity, s as describeProviderStatus, t as discoverLocalSessions, u as endsWithOpenToolCall, v as findDrivingProcess, w as findSessionFile, x as isAllowedEnvName, y as listProcesses, z as readSessionFile, A as searchLocalChats, B as sessionActivity, F as snippetAround } from '../index-aavbdzSo.cjs';
1
+ export { e as CodingSessionsAgentsOptions, c as CodingSessionsEngine, d as CodingSessionsEngineOptions, D as DEFAULT_SERVER_URL, f as DEFAULT_SUPABASE_URL, E as EFFORT_LEVELS, P as PreferenceStore, g as ProviderHomes, R as RAW_TRANSCRIPT_MAX_BYTES, h as RawBackupPolicy, i as RawBackupSink, j as RunStatus, k as buildCleanEnv, l as claudeDefaults, m as codexDefaults, n as createAiMatrxRawBackupSink, o as createCodingSessionsEngine, p as createRawBackupScheduler, q as defaultProviderHomes, r as describeActivity, s as describeProviderStatus, t as discoverLocalSessions, u as endsWithOpenToolCall, v as findDrivingProcess, w as findSessionFile, x as isAllowedEnvName, y as listProcesses, z as readSessionFile, A as searchLocalChats, B as sessionActivity, F as snippetAround } from '../index-CDeDKQHe.cjs';
2
2
  import '@ai-matrx/agents/portable/mcp';
3
3
  import '@ai-matrx/agents/portable';
4
4
  import '@ai-matrx/data';
@@ -1,4 +1,4 @@
1
- export { e as CodingSessionsAgentsOptions, c as CodingSessionsEngine, d as CodingSessionsEngineOptions, D as DEFAULT_SERVER_URL, f as DEFAULT_SUPABASE_URL, E as EFFORT_LEVELS, P as PreferenceStore, g as ProviderHomes, R as RAW_TRANSCRIPT_MAX_BYTES, h as RawBackupPolicy, i as RawBackupSink, j as RunStatus, k as buildCleanEnv, l as claudeDefaults, m as codexDefaults, n as createAiMatrxRawBackupSink, o as createCodingSessionsEngine, p as createRawBackupScheduler, q as defaultProviderHomes, r as describeActivity, s as describeProviderStatus, t as discoverLocalSessions, u as endsWithOpenToolCall, v as findDrivingProcess, w as findSessionFile, x as isAllowedEnvName, y as listProcesses, z as readSessionFile, A as searchLocalChats, B as sessionActivity, F as snippetAround } from '../index-aavbdzSo.js';
1
+ export { e as CodingSessionsAgentsOptions, c as CodingSessionsEngine, d as CodingSessionsEngineOptions, D as DEFAULT_SERVER_URL, f as DEFAULT_SUPABASE_URL, E as EFFORT_LEVELS, P as PreferenceStore, g as ProviderHomes, R as RAW_TRANSCRIPT_MAX_BYTES, h as RawBackupPolicy, i as RawBackupSink, j as RunStatus, k as buildCleanEnv, l as claudeDefaults, m as codexDefaults, n as createAiMatrxRawBackupSink, o as createCodingSessionsEngine, p as createRawBackupScheduler, q as defaultProviderHomes, r as describeActivity, s as describeProviderStatus, t as discoverLocalSessions, u as endsWithOpenToolCall, v as findDrivingProcess, w as findSessionFile, x as isAllowedEnvName, y as listProcesses, z as readSessionFile, A as searchLocalChats, B as sessionActivity, F as snippetAround } from '../index-CDeDKQHe.js';
2
2
  import '@ai-matrx/agents/portable/mcp';
3
3
  import '@ai-matrx/agents/portable';
4
4
  import '@ai-matrx/data';
@@ -119,6 +119,7 @@ function stripAgentBlock(text) {
119
119
  // src/engine/agent-attach.ts
120
120
  var AGENT_MCP_SERVER_NAME = "matrx-agent";
121
121
  var AGENT_PLUGIN_NAME = "matrx-agent";
122
+ var CODEX_REPLACEMENT_CLAUSE = "If a later message in this chat begins with an <ai_matrx_agent> block, that block replaces these AI Matrx agent instructions from then on; an <ai_matrx_agent_removed> block withdraws them.";
122
123
  function escapeAttr(value) {
123
124
  return value.replace(/&/g, "&amp;").replace(/"/g, "&quot;").replace(/</g, "&lt;");
124
125
  }
@@ -167,9 +168,12 @@ function renderCodexSkillsList(bundle, skillsRoot) {
167
168
  ];
168
169
  return lines.join("\n");
169
170
  }
170
- function renderFallbackBlock(bundle, skillsRoot) {
171
+ function renderFallbackBlock(bundle, skillsRoot, options = {}) {
171
172
  const skills = renderCodexSkillsList(bundle, skillsRoot);
172
- const body = renderAgentInstructions(bundle).trim().replace(/^(<ai_matrx_agent [^>]*>)/, "$1\n\nThe instructions below are your AI Matrx agent for this chat from now on; they replace any AI Matrx agent instructions given earlier.");
173
+ const lead = options.replaces ? `These instructions REPLACE the earlier AI Matrx agent "${options.replaces}" from this message on. Where they differ from anything said before \u2014 including how earlier replies ended \u2014 follow these.` : "The instructions below are your AI Matrx agent for this chat from now on; they replace any AI Matrx agent instructions given earlier.";
174
+ const body = renderAgentInstructions(bundle).trim().replace(/^(<ai_matrx_agent [^>]*>)/, `$1
175
+
176
+ ${lead}`);
173
177
  return skills ? `${body}
174
178
 
175
179
  ${skills}
@@ -238,10 +242,16 @@ async function writeAgentAttachment(dir, bundle, options) {
238
242
  pluginDir,
239
243
  mcpConfigFile,
240
244
  mcpUrl,
241
- // Same order as Claude's: the skills list first, the agent's words last.
242
- codexInstructions: skillsList ? `${skillsList}
245
+ // Same order as Claude's: the skills list first, the agent's words last —
246
+ // then the one sentence that lets a later block replace them. Codex ranks
247
+ // developer instructions above a user message, so without this permission
248
+ // a mid-chat switch or update is ignored (measured live: the v2 block was
249
+ // delivered and Codex kept ending with v1's line).
250
+ codexInstructions: `${skillsList ? `${skillsList}
243
251
 
244
- ${instructions}` : instructions
252
+ ` : ""}${instructions}
253
+ ${CODEX_REPLACEMENT_CLAUSE}
254
+ `
245
255
  };
246
256
  }
247
257
  function agentArgsFor(provider, attachment, options) {
@@ -299,7 +309,7 @@ function sessionAgentRecord(bundle, options) {
299
309
  ...options.variables ? { variables: options.variables } : {}
300
310
  };
301
311
  }
302
- var AGENT_REMOVED_BLOCK = "<ai_matrx_agent_removed>The AI Matrx agent instructions given earlier in this chat no longer apply.</ai_matrx_agent_removed>\n\n";
312
+ var AGENT_REMOVED_BLOCK = "<ai_matrx_agent_removed>The AI Matrx agent instructions given earlier in this chat no longer apply \u2014 including any rule about how replies end. Answer normally from this message on.</ai_matrx_agent_removed>\n\n";
303
313
  async function codexCompactionDroppedAgent(rolloutFile, sinceIso) {
304
314
  const text = await fs2.readFile(rolloutFile, "utf8").catch(() => "");
305
315
  if (!text.includes('"type":"compacted"')) return false;
@@ -631,7 +641,7 @@ function createClaudeNormalizer() {
631
641
  if (typeof content === "string") {
632
642
  if (isSyntheticClaudeUserText(content) || content.trim().length === 0) return [];
633
643
  userCounter += 1;
634
- return [{ kind: "user", id: str(entry.uuid) ?? `user-${userCounter}`, text: content, at }];
644
+ return [{ kind: "user", id: str(entry.uuid) ?? `user-${userCounter}`, text: stripAgentBlock(content), at }];
635
645
  }
636
646
  if (!Array.isArray(content)) return [];
637
647
  const items = [];
@@ -655,7 +665,7 @@ function createClaudeNormalizer() {
655
665
  items.unshift({
656
666
  kind: "user",
657
667
  id: str(entry.uuid) ?? `user-${userCounter}`,
658
- text: typed.join("\n\n"),
668
+ text: stripAgentBlock(typed.join("\n\n")),
659
669
  at
660
670
  });
661
671
  }
@@ -2474,7 +2484,7 @@ async function createCodingSessionsEngine(options = {}) {
2474
2484
  let cliPrompt = prompt;
2475
2485
  let delivered = null;
2476
2486
  if (!session.agent && session.agentRemovedDue) {
2477
- if (provider === "codex") cliPrompt = `${AGENT_REMOVED_BLOCK}${prompt}`;
2487
+ cliPrompt = `${AGENT_REMOVED_BLOCK}${prompt}`;
2478
2488
  delivered = { agentRemovedDue: false };
2479
2489
  }
2480
2490
  if (session.agent) {
@@ -2494,8 +2504,8 @@ async function createCodingSessionsEngine(options = {}) {
2494
2504
  mcpUrl: await agents.mcpUrlFor(session.id)
2495
2505
  });
2496
2506
  agentArgs = agentArgsFor(provider, attachment, { resuming: session.providerSessionId !== null });
2497
- if (provider === "codex" && session.agent.blockDue) {
2498
- cliPrompt = `${renderFallbackBlock(bundle, path9.join(attachment.dir, "skills"))}${prompt}`;
2507
+ if (session.agent.blockDue) {
2508
+ cliPrompt = `${renderFallbackBlock(bundle, path9.join(attachment.dir, "skills"), { replaces: session.agent.replaces })}${prompt}`;
2499
2509
  }
2500
2510
  delivered = { agent: { ...session.agent, blockDue: false, deliveredAt: run.startedAt } };
2501
2511
  }
@@ -2700,7 +2710,8 @@ async function createCodingSessionsEngine(options = {}) {
2700
2710
  variables: selection.variables ?? {}
2701
2711
  }),
2702
2712
  blockDue: options2.blockDue,
2703
- deliveredAt: null
2713
+ deliveredAt: null,
2714
+ replaces: options2.replaces ?? null
2704
2715
  };
2705
2716
  }
2706
2717
  function killGroup(liveRun) {
@@ -2995,11 +3006,14 @@ async function createCodingSessionsEngine(options = {}) {
2995
3006
  const session = index.session(String(sessionId ?? ""));
2996
3007
  if (!session) throw new Error("This session is not in the list anymore.");
2997
3008
  if (!selection) {
2998
- const told = session.provider === "codex" && session.agent?.deliveredAt != null;
3009
+ const told = session.agent?.deliveredAt != null;
2999
3010
  return saveSession({ ...session, agent: null, agentRemovedDue: told });
3000
3011
  }
3012
+ const previous = session.agent && session.agent.deliveredAt != null ? session.agent : null;
3013
+ const started = session.providerSessionId !== null;
3001
3014
  const agent = await attachAgent(session.id, selection, {
3002
- blockDue: session.provider === "codex" && session.providerSessionId !== null
3015
+ blockDue: started,
3016
+ replaces: previous ? `${previous.name}${previous.versionNumber !== null ? ` v${previous.versionNumber}` : ""}` : null
3003
3017
  });
3004
3018
  return saveSession({ ...session, agent, agentRemovedDue: false });
3005
3019
  },