@ai-matrx/coding-sessions 0.1.86 → 0.1.87

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,5 +1,5 @@
1
- import { C as CodingSessionsMethod, a as CodingSessionsApi, b as CodingEvent, c as CodingSessionsEngine, d as CodingSessionsEngineOptions } from '../index-aavbdzSo.cjs';
2
- export { e as CodingSessionsAgentsOptions } from '../index-aavbdzSo.cjs';
1
+ import { C as CodingSessionsMethod, a as CodingSessionsApi, b as CodingEvent, c as CodingSessionsEngine, d as CodingSessionsEngineOptions } from '../index-CDeDKQHe.cjs';
2
+ export { e as CodingSessionsAgentsOptions } from '../index-CDeDKQHe.cjs';
3
3
  import '@ai-matrx/agents/portable';
4
4
  import '@ai-matrx/data';
5
5
  import '@ai-matrx/agents/portable/mcp';
@@ -1,5 +1,5 @@
1
- import { C as CodingSessionsMethod, a as CodingSessionsApi, b as CodingEvent, c as CodingSessionsEngine, d as CodingSessionsEngineOptions } from '../index-aavbdzSo.js';
2
- export { e as CodingSessionsAgentsOptions } from '../index-aavbdzSo.js';
1
+ import { C as CodingSessionsMethod, a as CodingSessionsApi, b as CodingEvent, c as CodingSessionsEngine, d as CodingSessionsEngineOptions } from '../index-CDeDKQHe.js';
2
+ export { e as CodingSessionsAgentsOptions } from '../index-CDeDKQHe.js';
3
3
  import '@ai-matrx/agents/portable';
4
4
  import '@ai-matrx/data';
5
5
  import '@ai-matrx/agents/portable/mcp';
@@ -91,6 +91,7 @@ function stripAgentBlock(text) {
91
91
  // src/engine/agent-attach.ts
92
92
  var AGENT_MCP_SERVER_NAME = "matrx-agent";
93
93
  var AGENT_PLUGIN_NAME = "matrx-agent";
94
+ 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.";
94
95
  function escapeAttr(value) {
95
96
  return value.replace(/&/g, "&amp;").replace(/"/g, "&quot;").replace(/</g, "&lt;");
96
97
  }
@@ -139,9 +140,12 @@ function renderCodexSkillsList(bundle, skillsRoot) {
139
140
  ];
140
141
  return lines.join("\n");
141
142
  }
142
- function renderFallbackBlock(bundle, skillsRoot) {
143
+ function renderFallbackBlock(bundle, skillsRoot, options = {}) {
143
144
  const skills = renderCodexSkillsList(bundle, skillsRoot);
144
- 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.");
145
+ 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.";
146
+ const body = renderAgentInstructions(bundle).trim().replace(/^(<ai_matrx_agent [^>]*>)/, `$1
147
+
148
+ ${lead}`);
145
149
  return skills ? `${body}
146
150
 
147
151
  ${skills}
@@ -210,10 +214,16 @@ async function writeAgentAttachment(dir, bundle, options) {
210
214
  pluginDir,
211
215
  mcpConfigFile,
212
216
  mcpUrl,
213
- // Same order as Claude's: the skills list first, the agent's words last.
214
- codexInstructions: skillsList ? `${skillsList}
217
+ // Same order as Claude's: the skills list first, the agent's words last —
218
+ // then the one sentence that lets a later block replace them. Codex ranks
219
+ // developer instructions above a user message, so without this permission
220
+ // a mid-chat switch or update is ignored (measured live: the v2 block was
221
+ // delivered and Codex kept ending with v1's line).
222
+ codexInstructions: `${skillsList ? `${skillsList}
215
223
 
216
- ${instructions}` : instructions
224
+ ` : ""}${instructions}
225
+ ${CODEX_REPLACEMENT_CLAUSE}
226
+ `
217
227
  };
218
228
  }
219
229
  function agentArgsFor(provider, attachment, options) {
@@ -271,7 +281,7 @@ function sessionAgentRecord(bundle, options) {
271
281
  ...options.variables ? { variables: options.variables } : {}
272
282
  };
273
283
  }
274
- 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";
284
+ 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";
275
285
  async function codexCompactionDroppedAgent(rolloutFile, sinceIso) {
276
286
  const text = await fs2.readFile(rolloutFile, "utf8").catch(() => "");
277
287
  if (!text.includes('"type":"compacted"')) return false;
@@ -603,7 +613,7 @@ function createClaudeNormalizer() {
603
613
  if (typeof content === "string") {
604
614
  if (isSyntheticClaudeUserText(content) || content.trim().length === 0) return [];
605
615
  userCounter += 1;
606
- return [{ kind: "user", id: str(entry.uuid) ?? `user-${userCounter}`, text: content, at }];
616
+ return [{ kind: "user", id: str(entry.uuid) ?? `user-${userCounter}`, text: stripAgentBlock(content), at }];
607
617
  }
608
618
  if (!Array.isArray(content)) return [];
609
619
  const items = [];
@@ -627,7 +637,7 @@ function createClaudeNormalizer() {
627
637
  items.unshift({
628
638
  kind: "user",
629
639
  id: str(entry.uuid) ?? `user-${userCounter}`,
630
- text: typed.join("\n\n"),
640
+ text: stripAgentBlock(typed.join("\n\n")),
631
641
  at
632
642
  });
633
643
  }
@@ -2446,7 +2456,7 @@ async function createCodingSessionsEngine(options = {}) {
2446
2456
  let cliPrompt = prompt;
2447
2457
  let delivered = null;
2448
2458
  if (!session.agent && session.agentRemovedDue) {
2449
- if (provider === "codex") cliPrompt = `${AGENT_REMOVED_BLOCK}${prompt}`;
2459
+ cliPrompt = `${AGENT_REMOVED_BLOCK}${prompt}`;
2450
2460
  delivered = { agentRemovedDue: false };
2451
2461
  }
2452
2462
  if (session.agent) {
@@ -2466,8 +2476,8 @@ async function createCodingSessionsEngine(options = {}) {
2466
2476
  mcpUrl: await agents.mcpUrlFor(session.id)
2467
2477
  });
2468
2478
  agentArgs = agentArgsFor(provider, attachment, { resuming: session.providerSessionId !== null });
2469
- if (provider === "codex" && session.agent.blockDue) {
2470
- cliPrompt = `${renderFallbackBlock(bundle, path9.join(attachment.dir, "skills"))}${prompt}`;
2479
+ if (session.agent.blockDue) {
2480
+ cliPrompt = `${renderFallbackBlock(bundle, path9.join(attachment.dir, "skills"), { replaces: session.agent.replaces })}${prompt}`;
2471
2481
  }
2472
2482
  delivered = { agent: { ...session.agent, blockDue: false, deliveredAt: run.startedAt } };
2473
2483
  }
@@ -2672,7 +2682,8 @@ async function createCodingSessionsEngine(options = {}) {
2672
2682
  variables: selection.variables ?? {}
2673
2683
  }),
2674
2684
  blockDue: options2.blockDue,
2675
- deliveredAt: null
2685
+ deliveredAt: null,
2686
+ replaces: options2.replaces ?? null
2676
2687
  };
2677
2688
  }
2678
2689
  function killGroup(liveRun) {
@@ -2967,11 +2978,14 @@ async function createCodingSessionsEngine(options = {}) {
2967
2978
  const session = index.session(String(sessionId ?? ""));
2968
2979
  if (!session) throw new Error("This session is not in the list anymore.");
2969
2980
  if (!selection) {
2970
- const told = session.provider === "codex" && session.agent?.deliveredAt != null;
2981
+ const told = session.agent?.deliveredAt != null;
2971
2982
  return saveSession({ ...session, agent: null, agentRemovedDue: told });
2972
2983
  }
2984
+ const previous = session.agent && session.agent.deliveredAt != null ? session.agent : null;
2985
+ const started = session.providerSessionId !== null;
2973
2986
  const agent = await attachAgent(session.id, selection, {
2974
- blockDue: session.provider === "codex" && session.providerSessionId !== null
2987
+ blockDue: started,
2988
+ replaces: previous ? `${previous.name}${previous.versionNumber !== null ? ` v${previous.versionNumber}` : ""}` : null
2975
2989
  });
2976
2990
  return saveSession({ ...session, agent, agentRemovedDue: false });
2977
2991
  },