@mortiseai/stem 0.0.29 → 0.0.30

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.
@@ -44,6 +44,29 @@ function createSupervisorAnnounceFile(cwd) {
44
44
  return join(mkdtempSync(join(tmpRoot, 'session-')), 'session.json')
45
45
  }
46
46
 
47
+ /** Replace startup mode flags and remove options unsupported by the target interface. */
48
+ export function rewriteStartModeArgs(argv, mode) {
49
+ if (!['agent', 'coding', 'fde', 'evo'].includes(mode)) throw new Error('invalid startup mode')
50
+ let args = argv.filter(arg => !['--agent', '--coding', '--fde', '--evo'].includes(arg))
51
+ if (args[0] === 'evo' && args[1] === 'attach') args = args.slice(2)
52
+ const result = []
53
+ for (let i = 0; i < args.length; i++) {
54
+ const name = args[i].split('=')[0]
55
+ if (['--evo-view', '--type', '--space'].includes(name)) {
56
+ if (!args[i].includes('=')) i++
57
+ continue
58
+ }
59
+ // Evolve has a separate, strict argument parser. Keep shared startup options only.
60
+ if (mode === 'evo') {
61
+ if (['--tenant', '--user', '--model', '--telemetry-url'].includes(name)) {
62
+ result.push(args[i])
63
+ if (!args[i].includes('=') && i + 1 < args.length) result.push(args[++i])
64
+ }
65
+ } else result.push(args[i])
66
+ }
67
+ return [...result, `--${mode}`]
68
+ }
69
+
47
70
  /** 从 argv 剥离 --resume/-r(supervisor 重启时按通告会话重挂)。 */
48
71
  export function stripResumeFlag(argv) {
49
72
  const out = []
@@ -525,6 +548,8 @@ export async function runSupervisor(distEntry, argv, options = {}) {
525
548
  let crashTimes = []
526
549
  let memoryRestartTimes = []
527
550
  let configurationRestartTimes = []
551
+ let switchedStartMode = null
552
+ let returnFromEvoArgs = null
528
553
  let expectedResumePath = ''
529
554
  let automaticResume = false
530
555
  let evoResumeHandoff = ''
@@ -593,6 +618,8 @@ export async function runSupervisor(distEntry, argv, options = {}) {
593
618
  STEM_RESUME_EXPECTED_PATH: automaticResume ? expectedResumePath : '',
594
619
  STEM_EVO_RESUME_HANDOFF: evoResumeHandoff,
595
620
  STEM_CONFIGURATION_RELOAD: configurationReload ? '1' : '',
621
+ STEM_START_RESUME_ID: switchedStartMode === 'evo' ? (resumeId ?? '') : '',
622
+ STEM_EVO_ROLE: switchedStartMode && switchedStartMode !== 'evo' ? '' : (process.env.STEM_EVO_ROLE ?? ''),
596
623
  }, { command: launchCommand, cwd: launchCwd })
597
624
  evoResumeHandoff = '' // Only the immediately following controlled restart receives the capability.
598
625
  configurationReload = false
@@ -623,12 +650,12 @@ export async function runSupervisor(distEntry, argv, options = {}) {
623
650
  if (code === EXIT_CODE_CONFIGURATION_RESTART) {
624
651
  const t = now()
625
652
  configurationRestartTimes = configurationRestartTimes.filter(x => t - x < CRASH_WINDOW_MS)
626
- configurationRestartTimes.push(t)
627
653
  resetTerminalFn()
628
654
  const announce = readSessionAnnouncement(announceFile)
655
+ if (announce?.startMode === undefined) configurationRestartTimes.push(t)
629
656
  if (!announce || announce.requestState?.pid !== child.pid || announce.requestState?.active !== false ||
630
657
  typeof announce.queuePath !== 'string' || !announce.queuePath ||
631
- configurationRestartTimes.length >= CRASH_GIVE_UP_COUNT) {
658
+ (announce.startMode === undefined && configurationRestartTimes.length >= CRASH_GIVE_UP_COUNT)) {
632
659
  logLine(isZh ? 'stem: 无法安全自动重启,请重新启动 CLI 加载配置。'
633
660
  : 'stem: automatic restart is unavailable; restart the CLI to load configuration.')
634
661
  return EXIT_CODE_CONFIGURATION_RESTART
@@ -656,10 +683,27 @@ export async function runSupervisor(distEntry, argv, options = {}) {
656
683
  automaticResume = true
657
684
  expectedResumePath = (Array.isArray(announce.jsonlPaths) ? announce.jsonlPaths : [])
658
685
  .find(p => typeof p === 'string' && existsSync(p)) ?? ''
659
- // Load model and permission defaults from the new configuration.
660
- baseArgs = stripPermissionModeFlag(stripModelFlag(baseArgs))
661
- permissionModeFromAnnounce = null
662
- modelFromAnnounce = null
686
+ if (announce.startMode !== undefined) {
687
+ const returningFromEvo = switchedStartMode === 'evo' && announce.startMode !== 'evo' && returnFromEvoArgs !== null
688
+ if (announce.startMode === 'evo' && switchedStartMode !== 'evo') {
689
+ returnFromEvoArgs = stripModelFlag(stripPermissionModeFlag(baseArgs))
690
+ if (announce.model) returnFromEvoArgs.push('--model', announce.model)
691
+ if (announce.permissionMode) returnFromEvoArgs.push('--permission-mode', announce.permissionMode)
692
+ }
693
+ try { baseArgs = rewriteStartModeArgs(returningFromEvo ? returnFromEvoArgs : baseArgs, announce.startMode) }
694
+ catch { return EXIT_CODE_CONFIG }
695
+ if (returningFromEvo) returnFromEvoArgs = null
696
+ switchedStartMode = announce.startMode
697
+ // A standalone Evolve window has no chat transcript to resume.
698
+ if (!expectedResumePath) { resumeId = null; automaticResume = false }
699
+ permissionModeFromAnnounce = switchedStartMode === 'evo' || returningFromEvo ? null : (announce.permissionMode || null)
700
+ modelFromAnnounce = returningFromEvo ? null : (announce.model || null)
701
+ } else {
702
+ // Load model and permission defaults from the new configuration.
703
+ baseArgs = stripPermissionModeFlag(stripModelFlag(baseArgs))
704
+ permissionModeFromAnnounce = null
705
+ modelFromAnnounce = null
706
+ }
663
707
  evoResumeHandoff = ''
664
708
  configurationReload = true
665
709
  onCrashCleanupPid(child.pid)