@reasontrail/cli 0.1.4 → 0.1.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.
@@ -0,0 +1 @@
1
+ 03073358141704852517d933e17cda384d5a9c358d92e13b12584741df9c0804 reasontrail-runtime.mjs
@@ -74,6 +74,25 @@ that transcript source as unavailable and request the binding or access needed.
74
74
  A summary-only project update may still follow the normal governance policy,
75
75
  but it is not evidence that any Conversation messages were synchronized.
76
76
 
77
+ When the user says **"update my brain"** or explicitly asks for the **full
78
+ conversation**, the intended result is that the complete visible conversation
79
+ through the current checkpoint exists in ReasonTrail, not merely a summary or
80
+ the latest exchange. First inspect the native source and compare it with the
81
+ durable ReasonTrail cursor. Preserve the same native session and Conversation
82
+ identity; send only missing visible user/assistant turns after the cursor, so
83
+ earlier turns remain part of the complete transcript without being duplicated.
84
+ For Codex Desktop, use the authorized Codex app transcript reader when exposed
85
+ and page until the source reports no more turns. Include original visible
86
+ messages and stable source ids; exclude hidden reasoning and tool internals.
87
+ If the source exposes more turns than one MCP call accepts, use the supported
88
+ delta/chunk workflow under that same identity. Do not split one session into
89
+ new synthetic conversations or use `save_conversation` fragments to evade a
90
+ limit. Do not fall back to a summary when the native transcript is readable.
91
+ If identity, cursor, or coverage cannot be reconciled, stop the transcript
92
+ write, report the exact blocker, and keep any separately authorized project
93
+ summary clearly labeled as summary-only. Report measured source coverage and
94
+ persisted counts; never claim COMPLETE from a successful tool response alone.
95
+
77
96
  ## Context
78
97
 
79
98
  For substantive work on an associated repository—implementation, debugging,
@@ -99,6 +118,7 @@ Treat **"update my brain"** as the primary request to synchronize the current
99
118
  session. Equivalent phrases include:
100
119
 
101
120
  - "update ReasonTrail"
121
+ - "update to ReasonTrail"
102
122
  - "sync this session"
103
123
  - "save what we've done"
104
124
  - "update project memory"
@@ -108,6 +128,21 @@ For this intent:
108
128
  1. Resolve the actual host-native session identity through the authorized
109
129
  capture adapter, then inspect only that mapped session. Never guess the
110
130
  identity or derive the transcript from the current model context.
131
+ Transcript-bearing MCP calls are fail-closed: if a call includes `userRequest`,
132
+ `turns` or complete `messages`, set `captureMode`. Use `MANUAL` only when the
133
+ user explicitly requested a sync, and `AUTOMATIC` only after the policy check
134
+ below. For ordinary task tracking, omit transcript fields and use metadata only.
135
+ Respect the user's per-project capture choice. Manual-only capture requires
136
+ an explicit sync command; automatic capture requires the project-managed
137
+ service to be enabled and verified. An MCP connection alone is not consent
138
+ or proof that automatic capture is active. A manual command never turns on
139
+ background capture.
140
+ Before an automatic adapter reads or sends native transcript turns, call
141
+ `get_conversation_capture_policy` with the exact project slug. Continue only
142
+ when the current member's project setting returns `automaticEnabled: true`,
143
+ and mark previews and writes as `captureMode: "AUTOMATIC"`. If the tool is
144
+ unavailable or the preference is off, do not inspect or send the transcript;
145
+ an explicit user-requested sync remains `captureMode: "MANUAL"`.
111
146
  2. Determine the original visible user/assistant delta since the last
112
147
  successful ReasonTrail sync. Use the last returned sync cursor when
113
148
  available. Never include hidden reasoning.
@@ -0,0 +1 @@
1
+ {"sourceRevision":"94fcd4782ad73dd42e232665da7f1b9d2e4d6350"}
package/src/cli.mjs CHANGED
@@ -631,10 +631,21 @@ async function getStatus(target) {
631
631
  }
632
632
  const hooksInstalled = await claudeHooksInstalled(target.profile);
633
633
  const codexSyncState = await readSyncState(target.paths.dir);
634
- const codexSessions = await discoverAndMapCodexSessions({
635
- codexHome: defaultCodexHome(),
636
- bindings: target.cfg.bindings || {},
637
- }).catch(() => []);
634
+ let capturePolicy = { automaticEnabled: false, status: "unavailable" };
635
+ if (projectBound && binding?.projectSlug && hasTool(tools, "get_conversation_capture_policy")) {
636
+ try {
637
+ const policy = await client.call("get_conversation_capture_policy", { projectSlug: binding.projectSlug });
638
+ capturePolicy = { automaticEnabled: policy?.automaticEnabled === true, status: "available" };
639
+ } catch (error) {
640
+ capturePolicy = { automaticEnabled: false, status: "error", error: String(error?.message || error).slice(0, 200) };
641
+ }
642
+ }
643
+ const codexSessions = capturePolicy.automaticEnabled
644
+ ? await discoverAndMapCodexSessions({
645
+ codexHome: defaultCodexHome(),
646
+ bindings: target.cfg.bindings || {},
647
+ }).catch(() => [])
648
+ : [];
638
649
  const codexMapped = codexSessions.filter((s) => s.mapped);
639
650
  const codexPending = codexMapped.filter((s) => {
640
651
  const prev = codexSyncState.sessions?.[s.threadId];
@@ -663,14 +674,19 @@ async function getStatus(target) {
663
674
  conversation_connector: projectBound
664
675
  ? (hooksInstalled ? "Claude Code Hooks; Codex Local Session Sync" : "Codex Local Session Sync")
665
676
  : "none",
666
- automatic_transcript_sync: managedCapture.active ? "active_managed_capture" : "inactive",
677
+ automatic_transcript_sync: !capturePolicy.automaticEnabled
678
+ ? capturePolicy.status === "available" ? "disabled_by_project_preference" : `policy_${capturePolicy.status}`
679
+ : managedCapture.active ? "active_managed_capture" : "preference_enabled_service_inactive",
680
+ conversation_capture_policy: capturePolicy,
667
681
  managed_capture_service: managedCapture,
668
682
  codex_desktop: {
669
683
  brain_access: codexMcp ? "connected" : "not_configured",
670
684
  workspace: root,
671
685
  repository: normalizedRepositoryUrl(gitRemote(root)),
672
686
  project: projectBound ? binding.projectSlug : null,
673
- capture_mechanism: managedCapture.active ? "managed capture service" : "inactive; explicit sync remains available",
687
+ capture_mechanism: !capturePolicy.automaticEnabled
688
+ ? "automatic capture off for project; explicit sync remains available"
689
+ : managedCapture.active ? "managed capture service" : "preference enabled; managed service inactive",
674
690
  session_store: join(defaultCodexHome(), "sessions"),
675
691
  mcp_configured: codexMcp,
676
692
  skill_installed: codexSkill,
@@ -1189,14 +1205,37 @@ async function syncCommand(argv) {
1189
1205
  return client.call(tool, { ...(project ? { projectSlug: project } : {}), syncMode: "MANUAL" });
1190
1206
  }
1191
1207
  if (sub === "managed") {
1192
- const codex = await syncCodex(client, tools, target.paths.dir, target.cfg, {
1193
- dryRun: !apply,
1194
- managed: true,
1195
- since: opts.since || null,
1196
- project,
1197
- session: opts.session || null,
1198
- force: Boolean(opts.force),
1199
- });
1208
+ let capturePolicy = { automaticEnabled: false, status: "unavailable" };
1209
+ if (project && hasTool(tools, "get_conversation_capture_policy")) {
1210
+ try {
1211
+ const policy = await client.call("get_conversation_capture_policy", { projectSlug: project });
1212
+ capturePolicy = { automaticEnabled: policy?.automaticEnabled === true, status: "available" };
1213
+ } catch (error) {
1214
+ capturePolicy = { automaticEnabled: false, status: "error", error: String(error?.message || error).slice(0, 200) };
1215
+ }
1216
+ }
1217
+ const codex = capturePolicy.automaticEnabled
1218
+ ? await syncCodex(client, tools, target.paths.dir, target.cfg, {
1219
+ dryRun: !apply,
1220
+ managed: true,
1221
+ since: opts.since || null,
1222
+ project,
1223
+ session: opts.session || null,
1224
+ force: Boolean(opts.force),
1225
+ captureMode: "AUTOMATIC",
1226
+ })
1227
+ : {
1228
+ synchronized: false,
1229
+ dry_run: !apply,
1230
+ automatic_capture: "disabled",
1231
+ skipped_reason: capturePolicy.status === "available"
1232
+ ? "automatic_capture_disabled_for_project"
1233
+ : `capture_policy_${capturePolicy.status}`,
1234
+ error: capturePolicy.error || null,
1235
+ sessions_discovered: 0,
1236
+ sessions_mapped: 0,
1237
+ eligible_for_import: 0,
1238
+ };
1200
1239
  let docs = null;
1201
1240
  const docsTool = apply ? "sync_docs" : "preview_docs_reconciliation";
1202
1241
  if (hasTool(tools, docsTool)) {
@@ -1211,7 +1250,7 @@ async function syncCommand(argv) {
1211
1250
  throw new Error(`Repository Resource synchronization was partial: ${detail}`);
1212
1251
  }
1213
1252
  }
1214
- const result = { synchronized: apply, dry_run: !apply, codex, docs };
1253
+ const result = { synchronized: apply, dry_run: !apply, conversation_capture_policy: capturePolicy, codex, docs };
1215
1254
  if (apply) {
1216
1255
  await recordManagedHeartbeat(target, project, {
1217
1256
  service: managedServiceIdentity(target, project).service,
@@ -1221,6 +1260,7 @@ async function syncCommand(argv) {
1221
1260
  lastSuccessAt: new Date().toISOString(),
1222
1261
  lastError: null,
1223
1262
  codex,
1263
+ conversationCapturePolicy: capturePolicy,
1224
1264
  docs,
1225
1265
  });
1226
1266
  }
@@ -1543,10 +1583,13 @@ async function claudeHookCommandUnsafe(argv) {
1543
1583
  if (!eventCwd) throw new CliError("WORKSPACE UNBOUND: Claude hook payload did not include cwd; automatic capture is disabled.", 2, { kind: "workspace_unbound" });
1544
1584
  const { root, binding } = await bindingFor(target, eventCwd);
1545
1585
  if (!binding?.projectSlug) throw new CliError(`WORKSPACE UNBOUND: ${root}`, 2, { kind: "workspace_unbound" });
1586
+ const { client, tools } = await connected(target);
1587
+ if (!hasTool(tools, "get_conversation_capture_policy")) return;
1588
+ const capturePolicy = await client.call("get_conversation_capture_policy", { projectSlug: binding.projectSlug });
1589
+ if (capturePolicy?.automaticEnabled !== true) return;
1546
1590
  const stateDir = join(target.paths.connectors, "claude");
1547
1591
  const stateFile = join(stateDir, `${createHash("sha256").update(session).digest("hex")}.json`);
1548
1592
  const state = await readJson(stateFile, { session, clientConversationId: `claude:${session}`, turns: [], started: false, completed: false });
1549
- const { client, tools } = await connected(target);
1550
1593
  const project = { projectSlug: binding.projectSlug };
1551
1594
  const now = new Date().toISOString();
1552
1595
  const text = (value) => typeof value === "string" ? value.trim() : "";
@@ -1555,12 +1598,12 @@ async function claudeHookCommandUnsafe(argv) {
1555
1598
  client.turnId = eventId;
1556
1599
  async function sync(turns) {
1557
1600
  if (!turns.length || !hasTool(tools, "sync_conversation_delta")) return;
1558
- const result = await client.call("sync_conversation_delta", { clientConversationId: state.clientConversationId, turns, ...project });
1601
+ const result = await client.call("sync_conversation_delta", { clientConversationId: state.clientConversationId, captureMode: "AUTOMATIC", turns, ...project });
1559
1602
  state.lastSyncAt = now; state.cursor = result?.lastSyncedMessageId || result?.lastSyncedMessageId === null ? result.lastSyncedMessageId : state.cursor;
1560
1603
  await saveJson(stateFile, state);
1561
1604
  }
1562
1605
  if (name === "SessionStart" && !state.started) {
1563
- await client.call("begin_task", { taskTitle: text(event.task_title || event.prompt || "Claude Code session") || "Claude Code session", userRequest: text(event.prompt), messageId: `${eventId}:start`, clientConversationId: state.clientConversationId, timestamp: now, ...project });
1606
+ await client.call("begin_task", { taskTitle: text(event.task_title || event.prompt || "Claude Code session") || "Claude Code session", userRequest: text(event.prompt), messageId: `${eventId}:start`, clientConversationId: state.clientConversationId, timestamp: now, captureMode: "AUTOMATIC", ...project });
1564
1607
  state.started = true; await saveJson(stateFile, state);
1565
1608
  } else if (name === "UserPromptSubmit") {
1566
1609
  const content = text(event.prompt || event.user_prompt || event.message);
@@ -609,6 +609,7 @@ export async function syncCodex(client, tools, configDir, config, options = {})
609
609
  sourceSessionId: session.threadId,
610
610
  sourceCheckpoint: session.sourceCheckpoint,
611
611
  turns,
612
+ captureMode: options.captureMode === "AUTOMATIC" ? "AUTOMATIC" : "MANUAL",
612
613
  projectSlug: session.projectSlug,
613
614
  }));
614
615
  }
@@ -737,6 +738,7 @@ export async function syncCodex(client, tools, configDir, config, options = {})
737
738
  taskTitle: s.title,
738
739
  ...(firstUser ? { userRequest: firstUser.content, messageId: firstUser.messageId } : {}),
739
740
  timestamp: s.startedAt || s.updatedAt || now,
741
+ captureMode: options.captureMode === "AUTOMATIC" ? "AUTOMATIC" : "MANUAL",
740
742
  ...project,
741
743
  });
742
744
 
@@ -755,6 +757,7 @@ export async function syncCodex(client, tools, configDir, config, options = {})
755
757
  sourceCheckpoint: s.sourceCheckpoint,
756
758
  sourceEligibleTurns: s.turns.length,
757
759
  sourceAvailability: "AVAILABLE",
760
+ captureMode: options.captureMode === "AUTOMATIC" ? "AUTOMATIC" : "MANUAL",
758
761
  turns,
759
762
  sourceStatus: s.interrupted ? "INTERRUPTED" : "ACTIVE",
760
763
  sourceStatusReason: s.interruptionReason,