@narumitw/pi-plan-mode 0.57.0 → 0.57.1

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.
package/dist/index.ts CHANGED
@@ -17,12 +17,10 @@ import {
17
17
  configuredPlanExportPath,
18
18
  configuredPlanModeToggleShortcut,
19
19
  configuredThinkingLevel,
20
- createImplementationPreferenceChange,
21
20
  createImplementationRetentionCoordinator,
22
21
  exportStoredPlan,
23
22
  findBlockedCommandSegment,
24
23
  findBlockedPowerShellCommandSegment,
25
- hasImplementationPreferences,
26
24
  implementationRetentionPreview,
27
25
  invalidPlanMessage,
28
26
  latestAssistantStopReason,
@@ -30,24 +28,19 @@ import {
30
28
  messageTextContent,
31
29
  normalizePlanModeCompletion,
32
30
  normalizePlanModeQuestionParams,
33
- normalizePlanModeSettings,
34
- observeImplementationModelSelections,
35
31
  parseProposedPlan,
36
32
  planExportDestination,
37
33
  planFromCompletionDetails,
38
34
  planModeCompleted,
39
35
  planModeQuestionCancelled,
40
36
  planModeSettingsPath,
41
- preferenceError,
42
- preflightImplementationPreferences,
43
37
  readCommand,
44
38
  readPlanModeSettings,
45
39
  renderPlanModeCompletion,
46
- sameModel,
47
40
  snapshotPlanModeSelectedNames,
48
41
  toolPolicyLabel,
49
42
  updatePlanModeSettings
50
- } from "./chunks/chunk-YUFPCQVG.js";
43
+ } from "./chunks/chunk-57OBPS7P.js";
51
44
 
52
45
  // src/plan-mode.ts
53
46
  import { randomUUID as randomUUID2 } from "node:crypto";
@@ -127,65 +120,6 @@ function createFinalizationRequestCoordinator() {
127
120
  // src/fresh-implementation.ts
128
121
  import { randomUUID } from "node:crypto";
129
122
 
130
- // src/fresh-implementation-preferences.ts
131
- var FRESH_PREFERENCES_ENTRY = "plan-mode:fresh-preferences:v1";
132
- async function applyFreshImplementationPreferences(pi, ctx, isCurrent, selectionSnapshot) {
133
- if (!isCurrent() || !ctx.isIdle()) return;
134
- const entry = latestPreferenceEntry(ctx);
135
- if (entry?.type !== "custom" || !entry.data || typeof entry.data !== "object") return;
136
- const request = entry.data;
137
- if (request.status !== "pending" || typeof request.id !== "string") return;
138
- const preferences = normalizePlanModeSettings(request.preferences);
139
- pi.appendEntry(FRESH_PREFERENCES_ENTRY, { id: request.id, status: "failed" });
140
- if (!preferences || !hasImplementationPreferences(preferences)) return;
141
- const change = createImplementationPreferenceChange(
142
- pi,
143
- ctx,
144
- isCurrent,
145
- void 0,
146
- selectionSnapshot
147
- );
148
- try {
149
- const originalModel = ctx.model;
150
- const originalThinking = pi.getThinkingLevel();
151
- const current = () => isCurrent() && ctx.isIdle();
152
- const model = await preflightImplementationPreferences(
153
- ctx,
154
- preferences,
155
- () => current() && sameModel(ctx.model, originalModel) && pi.getThinkingLevel() === originalThinking
156
- );
157
- if (!model || !current()) return;
158
- if (!await change.apply(model, preferences, current) || !current()) {
159
- await change.rollback();
160
- return;
161
- }
162
- pi.appendEntry(FRESH_PREFERENCES_ENTRY, {
163
- id: request.id,
164
- status: "applied",
165
- model: { provider: ctx.model?.provider, id: ctx.model?.id },
166
- thinking: pi.getThinkingLevel()
167
- });
168
- } catch (error) {
169
- if (!isCurrent()) return;
170
- await change.rollback().catch(() => void 0);
171
- if (!isCurrent()) return;
172
- pi.appendEntry(FRESH_PREFERENCES_ENTRY, {
173
- id: request.id,
174
- status: "failed",
175
- error: preferenceError(error)
176
- });
177
- }
178
- }
179
- function latestPreferenceEntry(ctx) {
180
- return ctx.sessionManager.getBranch().slice().reverse().find((entry) => entry.type === "custom" && entry.customType === FRESH_PREFERENCES_ENTRY);
181
- }
182
- function freshPreferencesApplied(ctx, id) {
183
- const entry = latestPreferenceEntry(ctx);
184
- if (entry?.type !== "custom" || !entry.data || typeof entry.data !== "object") return false;
185
- const result = entry.data;
186
- return result.id === id && result.status === "applied" && sameModel(ctx.model, result.model) && ctx.thinkingLevel === result.thinking;
187
- }
188
-
189
123
  // src/prompt.ts
190
124
  var PLAN_CONTEXT_MARKER = "[CODEX-LIKE PLAN MODE ACTIVE]";
191
125
  function buildPlanModePrompt() {
@@ -361,7 +295,6 @@ async function startFreshImplementationFromState(ctx, options) {
361
295
  return startFreshImplementationSession(ctx, {
362
296
  plan,
363
297
  source,
364
- preferences: options.preferences,
365
298
  retention: options.retention,
366
299
  stateEntryType: options.stateEntryType,
367
300
  isCurrent
@@ -373,22 +306,8 @@ async function startFreshImplementationSession(ctx, request) {
373
306
  }
374
307
  await ctx.waitForIdle();
375
308
  if (!request.isCurrent()) return { kind: "stale" };
376
- const preferences = request.preferences ?? {};
377
- const originalModel = ctx.model;
378
- const originalThinking = ctx.thinkingLevel;
379
- const preflightCurrent = () => request.isCurrent() && sameModel(ctx.model, originalModel) && ctx.thinkingLevel === originalThinking;
380
- const preferencesId = hasImplementationPreferences(preferences) ? randomUUID() : void 0;
381
- if (preferencesId) {
382
- try {
383
- if (!await preflightImplementationPreferences(ctx, preferences, preflightCurrent))
384
- return { kind: "stale" };
385
- } catch (error) {
386
- if (preflightCurrent())
387
- safeNotify(ctx, `Unable to implement the plan: ${safeErrorDetail(error)}`, "error");
388
- return { kind: "rejected" };
389
- }
390
- } else if (!await preflightModel(ctx, preflightCurrent)) return { kind: "rejected" };
391
- if (!preflightCurrent() || !ctx.isIdle()) return { kind: "stale" };
309
+ if (!await preflightModel(ctx, request.isCurrent)) return { kind: "rejected" };
310
+ if (!request.isCurrent()) return { kind: "stale" };
392
311
  const usesConversationHistory = request.retention === "clear-on-start";
393
312
  const destinationState = usesConversationHistory ? void 0 : {
394
313
  enabled: false,
@@ -412,12 +331,6 @@ async function startFreshImplementationSession(ctx, request) {
412
331
  ...parentSession ? { parentSession } : {},
413
332
  setup: async (sessionManager) => {
414
333
  try {
415
- if (preferencesId)
416
- sessionManager.appendCustomEntry(FRESH_PREFERENCES_ENTRY, {
417
- id: preferencesId,
418
- status: "pending",
419
- preferences
420
- });
421
334
  const contract = createModeContractMessage("normal");
422
335
  sessionManager.appendCustomMessageEntry(
423
336
  contract.customType,
@@ -433,9 +346,6 @@ async function startFreshImplementationSession(ctx, request) {
433
346
  }
434
347
  },
435
348
  withSession: async (replacementCtx) => {
436
- if (!setupError && preferencesId && !freshPreferencesApplied(replacementCtx, preferencesId)) {
437
- setupError = "Implementation model/thinking could not be applied or changed before kickoff";
438
- }
439
349
  if (setupError) {
440
350
  recoverSetupFailure(replacementCtx, handoff, setupError);
441
351
  return;
@@ -532,15 +442,7 @@ function safeErrorDetail(error) {
532
442
 
533
443
  // src/plan-action-controller.ts
534
444
  function createPlanActionController(options) {
535
- const implementationActions = (ctx, lifecycle) => ({
536
- implementationPreferences: options.getImplementationPreferences?.(),
537
- implementHere: (preferences, signal) => options.implementHere(
538
- ctx,
539
- preferences,
540
- () => lifecycle.isCurrent() && !lifecycle.signal.aborted && !signal?.aborted
541
- ),
542
- implementFresh: (signal, preferences) => options.implementFresh(ctx, () => lifecycle.isCurrent() && !signal.aborted, preferences)
543
- });
445
+ const freshAction = (ctx, lifecycle, signal) => options.implementFresh(ctx, () => lifecycle.isCurrent() && !signal.aborted);
544
446
  return {
545
447
  async showSaved(ctx) {
546
448
  const lifecycle = options.captureLifecycle();
@@ -554,7 +456,8 @@ function createPlanActionController(options) {
554
456
  signal: lifecycle.signal,
555
457
  isCurrent: lifecycle.isCurrent,
556
458
  show: () => options.show(ctx),
557
- ...implementationActions(ctx, lifecycle),
459
+ implementHere: () => options.implementHere(ctx),
460
+ implementFresh: (signal) => freshAction(ctx, lifecycle, signal),
558
461
  exportPlan: (path, signal) => options.exportPlan(ctx, path, signal, lifecycle.isCurrent),
559
462
  settings: (signal) => options.settings(ctx, signal, lifecycle.isCurrent),
560
463
  clear: () => options.clearSaved(ctx)
@@ -577,7 +480,8 @@ function createPlanActionController(options) {
577
480
  ...lifecycle,
578
481
  show: () => options.show(ctx),
579
482
  finalize: () => options.finalize(ctx),
580
- ...implementationActions(ctx, lifecycle),
483
+ implementHere: () => options.implementHere(ctx),
484
+ implementFresh: (signal) => freshAction(ctx, lifecycle, signal),
581
485
  exportPlan: (path, signal) => options.exportPlan(ctx, path, signal, lifecycle.isCurrent),
582
486
  save: () => options.save(ctx),
583
487
  stay: () => options.stay(ctx),
@@ -593,7 +497,8 @@ function createPlanActionController(options) {
593
497
  ...lifecycle,
594
498
  implementationOutcome: options.implementationOutcome,
595
499
  getExportDestination: () => options.getExportDestination(ctx),
596
- ...implementationActions(ctx, lifecycle),
500
+ implementHere: () => options.implementHere(ctx),
501
+ implementFresh: (signal) => freshAction(ctx, lifecycle, signal),
597
502
  exportPlan: (path, signal) => options.exportPlan(ctx, path, signal, lifecycle.isCurrent),
598
503
  save: () => options.save(ctx),
599
504
  stay: () => void 0,
@@ -961,7 +866,6 @@ var PROPOSED_PLAN_MESSAGE_TYPE = "proposed-plan";
961
866
  var BLOCKED_MUTATING_TOOLS = /* @__PURE__ */ new Set(["edit", "write", "update_plan"]);
962
867
  var DEFAULT_TOOLS = ["read", "bash", "edit", "write"];
963
868
  function planMode(pi, dependencies = {}) {
964
- const selectionSnapshot = observeImplementationModelSelections(pi);
965
869
  const workflowMutex = new WorkflowMutex(pi);
966
870
  let workflowOwner;
967
871
  let currentSession;
@@ -970,7 +874,7 @@ function planMode(pi, dependencies = {}) {
970
874
  const loadInteractiveUi = () => {
971
875
  if (dependencies.loadInteractiveUi) return dependencies.loadInteractiveUi();
972
876
  if (!interactiveUiPromise) {
973
- interactiveUiPromise = import("./chunks/interactive-ui-M3GEZN4M.js").catch((error) => {
877
+ interactiveUiPromise = import("./chunks/interactive-ui-N2ZKBVNE.js").catch((error) => {
974
878
  interactiveUiPromise = void 0;
975
879
  throw error;
976
880
  });
@@ -991,8 +895,6 @@ function planMode(pi, dependencies = {}) {
991
895
  let latestCommandContext;
992
896
  let nextReadyPresentationNonce = 0;
993
897
  let menuGeneration = 0;
994
- let implementationInFlight = false;
995
- let applyingImplementationPreferences = false;
996
898
  let workflowGeneration = 0;
997
899
  let refreshStateBeforeFirstAgentStart = false;
998
900
  let menuController = new AbortController();
@@ -1017,10 +919,6 @@ function planMode(pi, dependencies = {}) {
1017
919
  getExportDestination: (ctx) => planExports.getDestination(ctx),
1018
920
  show: (ctx) => showStoredPlan(pi, ctx, state),
1019
921
  finalize: requestFinalPlan,
1020
- getImplementationPreferences: () => ({
1021
- implementationModel: settings.implementationModel,
1022
- implementationThinkingLevel: settings.implementationThinkingLevel
1023
- }),
1024
922
  implementHere: startImplementation,
1025
923
  implementFresh: startFreshImplementation,
1026
924
  exportPlan,
@@ -1282,13 +1180,6 @@ function planMode(pi, dependencies = {}) {
1282
1180
  if (!installRestoredState(restoredState, ctx)) return;
1283
1181
  implementationRetention.restore(state.activeImplementation);
1284
1182
  updateUi(ctx);
1285
- if (event.reason === "new")
1286
- await applyFreshImplementationPreferences(
1287
- pi,
1288
- ctx,
1289
- () => generation === menuGeneration && !menuController.signal.aborted,
1290
- selectionSnapshot
1291
- );
1292
1183
  });
1293
1184
  pi.on("session_before_tree", (event, ctx) => {
1294
1185
  const target = ctx.sessionManager.getEntry(event.preparation.targetId);
@@ -1320,7 +1211,7 @@ function planMode(pi, dependencies = {}) {
1320
1211
  updateUi(ctx);
1321
1212
  });
1322
1213
  pi.on("thinking_level_select", (event) => {
1323
- if (applyingImplementationPreferences || !state.enabled || !state.appliedThinkingLevel) return;
1214
+ if (!state.enabled || !state.appliedThinkingLevel) return;
1324
1215
  if (event.level !== state.appliedThinkingLevel) {
1325
1216
  state = {
1326
1217
  ...state,
@@ -1731,73 +1622,15 @@ ${intent.plan}`,
1731
1622
  releaseWorkflowOwner();
1732
1623
  ctx.ui.notify("Plan saved for later. Plan mode disabled.", "info");
1733
1624
  }
1734
- async function startFreshImplementation(ctx, menuIsCurrent, preferences = settings) {
1625
+ async function startFreshImplementation(ctx, menuIsCurrent) {
1735
1626
  await startFreshImplementationFromState(ctx, {
1736
- preferences,
1737
1627
  getState: () => state,
1738
1628
  menuIsCurrent,
1739
1629
  retention: configuredImplementationPlanRetention(settings),
1740
1630
  stateEntryType: STATE_ENTRY_TYPE
1741
1631
  });
1742
1632
  }
1743
- async function startImplementation(ctx, preferences = settings, menuIsCurrent = () => true) {
1744
- if (implementationInFlight || !menuIsCurrent()) return;
1745
- if (!hasImplementationPreferences(preferences)) {
1746
- await startImplementationCore(ctx);
1747
- return;
1748
- }
1749
- if (!allowModeTransition(ctx, "start plan implementation")) return;
1750
- if (ctx.mode === "print" || ctx.mode === "json")
1751
- throw new Error("Implementation model options require TUI or RPC mode.");
1752
- const previousState = state;
1753
- if (!(state.enabled ? state.latestPlan : state.savedPlan?.plan)) return;
1754
- const generation = menuGeneration;
1755
- const workflow = workflowGeneration;
1756
- const original = { model: ctx.model, thinking: pi.getThinkingLevel() };
1757
- const sessionCurrent = () => generation === menuGeneration && !menuController.signal.aborted;
1758
- let expectedState = state;
1759
- const current = () => sessionCurrent() && workflow === workflowGeneration && state === expectedState && menuIsCurrent() && ctx.isIdle();
1760
- const change = createImplementationPreferenceChange(
1761
- pi,
1762
- ctx,
1763
- sessionCurrent,
1764
- original,
1765
- selectionSnapshot
1766
- );
1767
- implementationInFlight = true;
1768
- let started = false;
1769
- try {
1770
- const model = await preflightImplementationPreferences(
1771
- ctx,
1772
- preferences,
1773
- () => current() && sameModel(ctx.model, original.model) && pi.getThinkingLevel() === original.thinking
1774
- );
1775
- if (!model || !current()) return;
1776
- applyingImplementationPreferences = true;
1777
- if (state.enabled) restoreThinkingLevel();
1778
- expectedState = state;
1779
- if (!await change.apply(model, preferences, current) || !current()) return;
1780
- started = await startImplementationCore(ctx, true) === true;
1781
- } catch (error) {
1782
- if (sessionCurrent())
1783
- ctx.ui.notify(`Unable to start implementation: ${preferenceError(error)}`, "error");
1784
- } finally {
1785
- if (!started && sessionCurrent()) {
1786
- await change.rollback().catch((error) => {
1787
- if (sessionCurrent()) ctx.ui.notify(preferenceError(error), "error");
1788
- });
1789
- if (sessionCurrent() && state === expectedState) {
1790
- state = previousState;
1791
- captureManualThinkingLevel();
1792
- persistState();
1793
- updateUi(ctx);
1794
- }
1795
- }
1796
- applyingImplementationPreferences = false;
1797
- implementationInFlight = false;
1798
- }
1799
- }
1800
- async function startImplementationCore(ctx, preferencesApplied = false) {
1633
+ async function startImplementation(ctx) {
1801
1634
  const savedPlan = state.enabled ? void 0 : state.savedPlan;
1802
1635
  const initialPlan = (state.enabled ? state.latestPlan : savedPlan?.plan)?.trim();
1803
1636
  if (!initialPlan) {
@@ -1805,7 +1638,7 @@ ${intent.plan}`,
1805
1638
  return;
1806
1639
  }
1807
1640
  if (!allowModeTransition(ctx, "start plan implementation")) return;
1808
- if (savedPlan && !preferencesApplied) {
1641
+ if (savedPlan) {
1809
1642
  const sessionGeneration = menuGeneration;
1810
1643
  const planWorkflowGeneration = workflowGeneration;
1811
1644
  const isCurrent = () => sessionGeneration === menuGeneration && planWorkflowGeneration === workflowGeneration && !menuController.signal.aborted && !state.enabled && state.savedPlan === savedPlan;
@@ -1841,7 +1674,7 @@ ${intent.plan}`,
1841
1674
  workflowToolPolicy: void 0,
1842
1675
  manualThinkingLevel: void 0
1843
1676
  };
1844
- if (wasEnabled && !preferencesApplied) {
1677
+ if (wasEnabled) {
1845
1678
  restoreThinkingLevel();
1846
1679
  state = { ...state, manualThinkingLevel: void 0 };
1847
1680
  }
@@ -1855,14 +1688,13 @@ ${intent.plan}`,
1855
1688
  if (wasEnabled) {
1856
1689
  restoreWorkflowToolPolicy(state.workflowToolPolicy);
1857
1690
  publishModeContract("plan", ctx);
1858
- if (!preferencesApplied) applyPlanThinkingLevel();
1691
+ applyPlanThinkingLevel();
1859
1692
  }
1860
1693
  persistState();
1861
1694
  updateUi(ctx);
1862
1695
  return;
1863
1696
  }
1864
1697
  if (wasEnabled) releaseWorkflowOwner();
1865
- return true;
1866
1698
  }
1867
1699
  function clearActiveImplementation(id, ctx) {
1868
1700
  if (state.activeImplementation?.id !== id) return false;