@karmaniverous/stan-cli 0.10.1 → 0.10.2

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/cli/stan.js CHANGED
@@ -19581,9 +19581,14 @@ const cleanupPatchDirAfterArchive = async (cwd, stanPath) => {
19581
19581
  };
19582
19582
 
19583
19583
  /** src/stan/prompt/resolve.ts
19584
- * Resolve the packaged core prompt path with a robust fallback.
19585
- * Primary: \@karmaniverous/stan-core.getPackagedSystemPromptPath()
19586
- * Fallback: locate core's package root via createRequire() and join dist/stan.system.md.
19584
+ * Resolve the packaged core prompt path with robust fallbacks.
19585
+ * Order:
19586
+ * 1) \@karmaniverous/stan-core.getPackagedSystemPromptPath()
19587
+ * 2) createRequire(import.meta.url).resolve('\@karmaniverous/stan-core') → walk up to module root → dist/stan.system.md
19588
+ * 3) createRequire(import.meta.url).resolve('\@karmaniverous/stan-core/dist/stan.system.md')
19589
+ *
19590
+ * Note: CLI fallback (dist/stan.system.md within this package) is handled upstream as kind='path'
19591
+ * via getCliPackagedSystemPromptPath() and should not be returned from this resolver.
19587
19592
  */
19588
19593
  /** Resolve the absolute path to core's packaged stan.system.md, or null if unavailable. */
19589
19594
  const resolveCorePromptPath = () => {
@@ -19594,19 +19599,66 @@ const resolveCorePromptPath = () => {
19594
19599
  return p;
19595
19600
  }
19596
19601
  catch {
19597
- /* fall through */
19602
+ /* ignore */
19598
19603
  }
19599
- // Fallback: anchor at core's package root resolved relative to this module.
19604
+ // Fallback A: resolve core's main entry, walk up to the module root "stan-core", then join dist/stan.system.md
19600
19605
  try {
19601
19606
  const req = createRequire(import.meta.url);
19602
- const pkgJson = req.resolve('@karmaniverous/stan-core/package.json');
19603
- const root = path.dirname(pkgJson);
19604
- const candidate = path.join(root, 'dist', 'stan.system.md');
19605
- return existsSync(candidate) ? candidate : null;
19607
+ const mainEntry = req.resolve('@karmaniverous/stan-core');
19608
+ let dir = path.dirname(mainEntry);
19609
+ for (let i = 0; i < 10; i += 1) {
19610
+ const base = path.basename(dir);
19611
+ if (base === 'stan-core') {
19612
+ const candidate = path.join(dir, 'dist', 'stan.system.md');
19613
+ if (existsSync(candidate))
19614
+ return candidate;
19615
+ break;
19616
+ }
19617
+ const parent = path.dirname(dir);
19618
+ if (parent === dir)
19619
+ break;
19620
+ dir = parent;
19621
+ }
19606
19622
  }
19607
19623
  catch {
19608
- return null;
19624
+ /* ignore */
19625
+ }
19626
+ // Fallback B: subpath resolution when exports permit
19627
+ try {
19628
+ const req = createRequire(import.meta.url);
19629
+ const candidate = req.resolve('@karmaniverous/stan-core/dist/stan.system.md');
19630
+ if (candidate && existsSync(candidate))
19631
+ return candidate;
19609
19632
  }
19633
+ catch {
19634
+ /* ignore */
19635
+ }
19636
+ return null;
19637
+ };
19638
+ /**
19639
+ * Resolve the CLI-packaged prompt path (this package's dist/stan.system.md), or null if absent.
19640
+ * This is intended as a last-resort "path" fallback when the core package cannot be located.
19641
+ */
19642
+ const getCliPackagedSystemPromptPath = () => {
19643
+ try {
19644
+ const here = fileURLToPath(import.meta.url);
19645
+ let dir = path.dirname(here);
19646
+ // Walk upward to find a "dist/stan.system.md" near the package root.
19647
+ for (let i = 0; i < 8; i += 1) {
19648
+ const distDir = path.join(dir, 'dist');
19649
+ const candidate = path.join(distDir, 'stan.system.md');
19650
+ if (existsSync(candidate))
19651
+ return candidate;
19652
+ const parent = path.dirname(dir);
19653
+ if (parent === dir)
19654
+ break;
19655
+ dir = parent;
19656
+ }
19657
+ }
19658
+ catch {
19659
+ /* ignore */
19660
+ }
19661
+ return null;
19610
19662
  };
19611
19663
 
19612
19664
  /* src/stan/run/prompt.ts
@@ -19662,6 +19714,20 @@ const resolvePromptSource = (cwd, stanPath, choice) => {
19662
19714
  kind: 'core',
19663
19715
  };
19664
19716
  }
19717
+ // Last-ditch: use CLI's packaged prompt (treated as a plain 'path' source).
19718
+ try {
19719
+ const cliAbs = getCliPackagedSystemPromptPath();
19720
+ if (cliAbs && existsSync(cliAbs)) {
19721
+ return {
19722
+ abs: cliAbs,
19723
+ display: `${cliAbs.replace(/\\/g, '/')}`,
19724
+ kind: 'path',
19725
+ };
19726
+ }
19727
+ }
19728
+ catch {
19729
+ /* ignore */
19730
+ }
19665
19731
  throw new Error('unable to resolve system prompt (auto: local and core unavailable)');
19666
19732
  }
19667
19733
  // treat any other string as a path (absolute or repo-relative)
@@ -20057,7 +20123,7 @@ const resolvePromptOrThrow = (cwd, stanPath, promptChoice) => {
20057
20123
  const choice = (promptChoice ?? 'auto').trim();
20058
20124
  const resolved = resolvePromptSource(cwd, stanPath, choice);
20059
20125
  const display = choice === 'auto' ? `auto → ${resolved.display}` : resolved.display;
20060
- return { display, abs: resolved.abs };
20126
+ return { display, abs: resolved.abs, kind: resolved.kind };
20061
20127
  };
20062
20128
  /** Print the plan with a prompt: line injected (TTY-agnostic). */
20063
20129
  const printPlanWithPrompt = (cwd, args) => {
@@ -20913,8 +20979,7 @@ const runScriptsPhase = async (args) => {
20913
20979
  return created;
20914
20980
  };
20915
20981
 
20916
- // src/stan/run/session/index.ts
20917
- /**
20982
+ /* src/stan/run/session/index.ts
20918
20983
  * One-shot run session (single attempt).
20919
20984
  * Orchestrates: plan print, UI wiring, cancellation/restart, scripts, archives.
20920
20985
  */
@@ -20938,6 +21003,20 @@ const runSessionOnce = async (args) => {
20938
21003
  const rp = resolvePromptOrThrow(cwd, config.stanPath, promptChoice);
20939
21004
  resolvedPromptDisplay = rp.display;
20940
21005
  resolvedPromptAbs = rp.abs;
21006
+ // Minimal, non-noisy diagnostics: exactly one line under STAN_DEBUG=1.
21007
+ try {
21008
+ if (process.env.STAN_DEBUG === '1') {
21009
+ // Prefer the kind returned by resolver; normalize slashes in the path for readability.
21010
+ const srcKind = rp.kind ??
21011
+ 'path';
21012
+ const p = String(resolvedPromptAbs ?? '').replace(/\\/g, '/');
21013
+ // stderr only; do not change normal output
21014
+ console.error(`stan: debug: prompt: ${srcKind} ${p}`);
21015
+ }
21016
+ }
21017
+ catch {
21018
+ /* ignore */
21019
+ }
20941
21020
  }
20942
21021
  catch (e) {
20943
21022
  const msg = e instanceof Error ? e.message : typeof e === 'string' ? e : String(e);
@@ -29014,9 +29093,10 @@ class LoggerUI {
29014
29093
  * @param selection - Explicit list of script keys (or `null` to run all).
29015
29094
  * @param mode - Execution mode (`concurrent` by default).
29016
29095
  * @param behaviorMaybe - Archive/combine/keep flags.
29096
+ * @param promptChoice - System prompt choice (auto|local|core|<path>) to honor during the run.
29017
29097
  * @returns Absolute paths to created artifacts (script outputs and/or archives).
29018
29098
  */
29019
- const runSelected = async (cwd, config, selection = null, mode = 'concurrent', behaviorMaybe) => {
29099
+ const runSelected = async (cwd, config, selection = null, mode = 'concurrent', behaviorMaybe, promptChoice) => {
29020
29100
  const behavior = behaviorMaybe ?? {};
29021
29101
  // Ensure workspace (also manages archive.prev when keep=false)
29022
29102
  await Xc(cwd, config.stanPath, Boolean(behavior.keep));
@@ -29050,6 +29130,8 @@ const runSelected = async (cwd, config, selection = null, mode = 'concurrent', b
29050
29130
  planBody,
29051
29131
  printPlan: !printedPlan && behavior.plan !== false,
29052
29132
  ui,
29133
+ // Honor CLI/system choice for prompt resolution within the session.
29134
+ promptChoice,
29053
29135
  });
29054
29136
  printedPlan = true;
29055
29137
  if (restartRequested) {
@@ -29490,7 +29572,12 @@ const registerRunAction = (cmd, getFlagPresence) => {
29490
29572
  printPlan = false;
29491
29573
  }
29492
29574
  derived.behavior.plan = printPlan;
29493
- await runSelected(runCwd, runnerConfig, derived.selection, derived.mode, derived.behavior);
29575
+ await runSelected(runCwd, runnerConfig, derived.selection, derived.mode, derived.behavior,
29576
+ // Ensure the session honors the user/config prompt choice:
29577
+ // - 'auto' (default) or an explicit 'local'|'core'|<path>
29578
+ // - The session will print a single debug line under STAN_DEBUG=1
29579
+ // identifying the chosen source/path.
29580
+ derived.promptChoice);
29494
29581
  });
29495
29582
  };
29496
29583