instar 1.3.914 → 1.3.916

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 +1 @@
1
- {"version":3,"file":"server.d.ts","sourceRoot":"","sources":["../../src/commands/server.ts"],"names":[],"mappings":"AAAA;;;;;;;;GAQG;AA4EH,OAAO,EAAE,cAAc,EAAE,MAAM,2BAA2B,CAAC;AAU3D,OAAO,EAAE,eAAe,EAAiC,MAAM,iCAAiC,CAAC;AA0BjG,OAAO,EAAE,WAAW,EAAE,MAAM,0BAA0B,CAAC;AAGvD,OAAO,EAAE,YAAY,EAAE,MAAM,+BAA+B,CAAC;AA8H7D,OAAO,KAAK,EAAW,oBAAoB,EAAe,YAAY,EAAE,MAAM,kBAAkB,CAAC;AACjG,OAAO,EAAE,WAAW,EAAE,MAAM,yBAAyB,CAAC;AAgFtD;;;;;;;;;;;;;;;;;GAiBG;AACH,wBAAgB,yBAAyB,CACvC,IAAI,EAAE,MAAM,EACZ,OAAO,EAAE,MAAM,EACf,gBAAgB,EAAE,MAAM,GAAG,IAAI,GAAG,SAAS,GAC1C,OAAO,CAUT;AAyID,UAAU,YAAY;IACpB,UAAU,CAAC,EAAE,OAAO,CAAC;IACrB,GAAG,CAAC,EAAE,MAAM,CAAC;IACb;2DACuD;IACvD,QAAQ,CAAC,EAAE,OAAO,CAAC;CACpB;AA+rDD;;;;;;;;GAQG;AACH,wBAAgB,wBAAwB,CACtC,MAAM,EAAE,YAAY,EACpB,YAAY,EAAE,oBAAoB,GAAG,IAAI,GACxC;IACD,YAAY,EAAE,oBAAoB,GAAG,IAAI,CAAC;IAC1C,OAAO,EAAE,OAAO,CAAC;IACjB,MAAM,EAAE,OAAO,CAAC;IAChB,aAAa,EAAE,MAAM,CAAC;IACtB,SAAS,EAAE,MAAM,CAAC;IAClB,YAAY,EAAE,MAAM,CAAC;IACrB,SAAS,EAAE,MAAM,GAAG,UAAU,GAAG,SAAS,CAAC;IAC3C,QAA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AY,CAAC,EAAE,YAAY,EAC3B,WAAW,CAAC,EAAE,WAAW,EACzB,WAAW,CAAC,EAAE,WAAW,EACzB,iBAAiB,CAAC,EAAE,CAAC,OAAO,EAAE,MAAM,EAAE,IAAI,EAAE,MAAM,KAAK,OAAO,CAAC,OAAO,CAAC,EAGvE,UAAU,CAAC,EAAE,MAAM,OAAO,8BAA8B,EAAE,WAAW,GAAG,IAAI,EAK5E,qBAAqB,CAAC,EAAE,MAAM,OAAO,gCAAgC,EAAE,kBAAkB,GAAG,IAAI,EAKhG,mBAAmB,CAAC,EAAE,MAAM,MAAM,GAAG,IAAI,GAAG,SAAS,EAQrD,oBAAoB,CAAC,EAAE,MAAM;IAC3B,YAAY,EAAE,OAAO,kBAAkB,EAAE,oBAAoB,GAAG,IAAI,CAAC;IACrE,OAAO,EAAE,OAAO,CAAC;IACjB,MAAM,EAAE,OAAO,CAAC;IAChB,aAAa,EAAE,MAAM,CAAC;IACtB,SAAS,EAAE,MAAM,CAAC;IAClB,YAAY,EAAE,MAAM,CAAC;IACrB,SAAS,EAAE,MAAM,GAAG,UAAU,GAAG,SAAS,CAAC;IAC3C,QAAQ,EAAE,MAAM,CAAC;CAClB,GAAG,IAAI,GACP,IAAI,CAwtBN;AAgmBD,wBAAsB,WAAW,CAAC,OAAO,EAAE,YAAY,GAAG,OAAO,CAAC,IAAI,CAAC,CAi4pBtE;AAED,wBAAsB,UAAU,CAAC,OAAO,EAAE;IAAE,GAAG,CAAC,EAAE,MAAM,CAAA;CAAE,GAAG,OAAO,CAAC,IAAI,CAAC,CAsDzE;AAED;;;;;;;;;;;GAWG;AACH,wBAAsB,aAAa,CAAC,OAAO,EAAE;IAAE,GAAG,CAAC,EAAE,MAAM,CAAA;CAAE,GAAG,OAAO,CAAC,IAAI,CAAC,CAuD5E"}
@@ -11658,6 +11658,53 @@ export async function startServer(options) {
11658
11658
  console.log(pc.green(' RateLimitSentinel enabled (server-throttle backoff + check-ins)'));
11659
11659
  }
11660
11660
  console.log(pc.green(' CompactionSentinel enabled (verified recovery lifecycle)'));
11661
+ // ── Proactive autonomous compaction ───────────────────────────────
11662
+ // Explicit opt-in, dry-run first. Claude already exposes a grounded
11663
+ // percentage in its live pane ("Context left until auto-compact: N%").
11664
+ // At >=85% used, ask for /compact only when the canonical async work-state
11665
+ // probe says IDLE. Working and indeterminate sessions are never touched.
11666
+ const proactiveCompactionCfg = config.monitoring?.proactiveAutonomousCompaction;
11667
+ if (proactiveCompactionCfg?.enabled === true) {
11668
+ const { ProactiveCompactionSentinel } = await import('../monitoring/ProactiveCompactionSentinel.js');
11669
+ const parseContextRemaining = (pane) => {
11670
+ const match = pane?.match(/Context left until auto-compact:\s*([0-9]+)%/i);
11671
+ if (!match)
11672
+ return null;
11673
+ const value = Number(match[1]);
11674
+ return Number.isFinite(value) ? Math.min(100, Math.max(0, value)) : null;
11675
+ };
11676
+ const proactiveCompaction = new ProactiveCompactionSentinel({
11677
+ listCandidates: async () => Promise.all(sessionManager.listRunningSessions().map(async (session) => {
11678
+ const topic = telegram?.getTopicForSession(session.tmuxSession);
11679
+ let autonomous = false;
11680
+ if (topic != null) {
11681
+ try {
11682
+ autonomous = fs.existsSync(path.join(config.stateDir, 'autonomous', `${topic}.local.md`));
11683
+ }
11684
+ catch {
11685
+ // Fail closed: an unreadable registration never grants actuation.
11686
+ autonomous = false;
11687
+ }
11688
+ }
11689
+ return {
11690
+ sessionName: session.tmuxSession,
11691
+ autonomous,
11692
+ framework: session.framework,
11693
+ contextRemainingPercent: parseContextRemaining(sessionManager.captureOutput(session.tmuxSession, 30)),
11694
+ workState: await sessionManager.checkSessionWorkState(session.tmuxSession),
11695
+ };
11696
+ })),
11697
+ triggerCompact: (sessionName) => sessionManager.injectInternalMessage(sessionName, '/compact', 'proactive-autonomous-compaction'),
11698
+ audit: (event) => {
11699
+ console.log(`[ProactiveCompaction] ${event.kind} "${event.sessionName}" ` +
11700
+ `at ${event.usedPercent}% used (threshold ${event.thresholdUsedPercent}%)`);
11701
+ },
11702
+ }, proactiveCompactionCfg);
11703
+ const proactiveCompactionTimer = setInterval(() => { void proactiveCompaction.tick(); }, Math.max(10_000, proactiveCompactionCfg.tickIntervalMs ?? 60_000));
11704
+ proactiveCompactionTimer.unref?.();
11705
+ void proactiveCompaction.tick();
11706
+ console.log(pc.green(` Proactive autonomous compaction enabled (${proactiveCompactionCfg.dryRun === false ? 'live' : 'dry-run'})`));
11707
+ }
11661
11708
  // ── Silently-stopped trio: SocketDisconnectSentinel + ActiveWorkSilenceSentinel ──
11662
11709
  // Wire-up post-2026-05-22 incident. Every transition (detect/nudge/recover)
11663
11710
  // lands in the audit log (server logs + JSONL) — the user never sees it.
@@ -22632,6 +22679,7 @@ export async function startServer(options) {
22632
22679
  const stageMod = await import('../core/StageAdvancer.js');
22633
22680
  const guardMod = await import('../config/stageWriteGuard.js');
22634
22681
  const crypto = await import('node:crypto');
22682
+ const failoverCheckMod = await import('../core/sessionPoolFailoverCheck.js');
22635
22683
  // HMAC over the agent's authToken — tamper-evident without a separate keystore.
22636
22684
  const hmacKey = String(config.authToken ?? 'instar-session-pool-e2e');
22637
22685
  const hmac = (c) => crypto.createHmac('sha256', hmacKey).update(c).digest('hex');
@@ -22648,27 +22696,60 @@ export async function startServer(options) {
22648
22696
  }
22649
22697
  },
22650
22698
  });
22651
- // Boot-cache the running commit SHA once (env first, else git HEAD, else
22652
- // 'unknown'). StageAdvancer scopes an E2E red/green to the CURRENT build via
22653
- // this, so a stale result from another commit can't trigger a revert/advance.
22699
+ // Resolve the checkout the failover subprocess will actually exercise.
22700
+ // Boot-pin it so the proof target and its build identity cannot drift
22701
+ // independently during a run.
22702
+ const failoverSourceCandidates = [
22703
+ process.env.INSTAR_SOURCE_ROOT,
22704
+ path.resolve(__dirname, '..', '..'),
22705
+ process.cwd(),
22706
+ ].filter((c) => typeof c === 'string' && c.length > 0);
22707
+ let sessionPoolFailoverSourceRoot = null;
22708
+ for (const candidate of failoverSourceCandidates) {
22709
+ try {
22710
+ if (fs.existsSync(path.join(candidate, 'node_modules', '.bin', 'vitest'))
22711
+ && fs.existsSync(path.join(candidate, failoverCheckMod.DEFAULT_FAILOVER_E2E_PATH))) {
22712
+ sessionPoolFailoverSourceRoot = candidate;
22713
+ break;
22714
+ }
22715
+ }
22716
+ catch { /* @silent-fallback-ok — probe the next bounded candidate */ }
22717
+ }
22718
+ // Boot-cache one build identity (env SHA first, else the exact runner
22719
+ // checkout's git HEAD, else cwd git HEAD, installed package version, then
22720
+ // 'unknown'). Producer and StageAdvancer share this exact closure.
22654
22721
  const gitMod = await import('../core/SafeGitExecutor.js');
22655
22722
  let bootCommitSha = process.env.INSTAR_COMMIT_SHA ?? process.env.GITHUB_SHA ?? '';
22656
- if (!bootCommitSha) {
22723
+ const gitIdentityCandidates = [
22724
+ sessionPoolFailoverSourceRoot,
22725
+ process.cwd(),
22726
+ ].filter((c, index, all) => typeof c === 'string' && c.length > 0 && all.indexOf(c) === index);
22727
+ for (const candidate of gitIdentityCandidates) {
22728
+ if (bootCommitSha)
22729
+ break;
22657
22730
  try {
22658
22731
  bootCommitSha = gitMod.SafeGitExecutor.readSync(['rev-parse', 'HEAD'], {
22659
- cwd: process.cwd(), encoding: 'utf-8', stdio: 'pipe', operation: 'server.ts:rollout-commit-sha',
22732
+ cwd: candidate, encoding: 'utf-8', stdio: 'pipe', operation: 'server.ts:rollout-commit-sha',
22660
22733
  }).trim();
22661
22734
  }
22662
22735
  catch {
22663
- bootCommitSha = ''; /* @silent-fallback-ok — git unreadable → 'unknown' */
22736
+ bootCommitSha = ''; /* @silent-fallback-ok — git unreadable → package identity below */
22664
22737
  }
22665
22738
  }
22739
+ if (!bootCommitSha && startupVersion && startupVersion !== '0.0.0') {
22740
+ bootCommitSha = `package:${startupVersion}`;
22741
+ }
22742
+ const currentSessionPoolBuildIdentity = () => bootCommitSha || 'unknown';
22743
+ // ONE authoritative stage read for the rollout gate and its proof producer.
22744
+ // Splitting these previously let the runner stamp every green as stage 0
22745
+ // while StageAdvancer was already waiting for a green at stage 2.
22746
+ const readSessionPoolStage = () => liveConfig.get('multiMachine.sessionPool.stage', 'dark');
22666
22747
  // StageAdvancer: the sole stage writer. Held for the rollout job/route to drive;
22667
22748
  // constructed here so the write path (liveConfig + token) is wired in one place.
22668
22749
  const stageAdvancer = new stageMod.StageAdvancer({
22669
22750
  resultStore: sessionPoolE2EResultStore,
22670
- currentCommitSha: () => bootCommitSha || 'unknown',
22671
- readStage: () => liveConfig.get('multiMachine.sessionPool.stage', 'dark'),
22751
+ currentCommitSha: currentSessionPoolBuildIdentity,
22752
+ readStage: readSessionPoolStage,
22672
22753
  writeStageConfig: (s) => liveConfig.set(guardMod.STAGE_CONFIG_PATH, s, { stageWriteToken: guardMod.STAGE_WRITE_TOKEN }),
22673
22754
  audit: (event, detail) => console.log(pc.dim(` [stage-advancer] ${event} ${JSON.stringify(detail)}`)),
22674
22755
  });
@@ -22737,24 +22818,7 @@ export async function startServer(options) {
22737
22818
  const cp = await import('node:child_process');
22738
22819
  const failoverLogPath = path.join(config.stateDir, 'logs', 'session-pool-failover-runner.log');
22739
22820
  const runProcess = (args) => new Promise((resolve) => {
22740
- // Candidate source roots, most-specific first: an explicit env override,
22741
- // then this build's package root (dist/../..), then cwd. The first that
22742
- // carries BOTH node_modules/.bin/vitest AND the test file wins.
22743
- const candidates = [
22744
- process.env.INSTAR_SOURCE_ROOT,
22745
- path.resolve(__dirname, '..', '..'),
22746
- process.cwd(),
22747
- ].filter((c) => typeof c === 'string' && c.length > 0);
22748
- let sourceRoot = null;
22749
- for (const c of candidates) {
22750
- try {
22751
- if (fs.existsSync(path.join(c, 'node_modules', '.bin', 'vitest')) && fs.existsSync(path.join(c, args.testPath))) {
22752
- sourceRoot = c;
22753
- break;
22754
- }
22755
- }
22756
- catch { /* @silent-fallback-ok — probe next candidate */ }
22757
- }
22821
+ const sourceRoot = sessionPoolFailoverSourceRoot;
22758
22822
  if (!sourceRoot) {
22759
22823
  // No source/vitest resolvable → NOT a failover verdict; the check
22760
22824
  // contract makes this THROW so the runner records nothing.
@@ -22813,10 +22877,10 @@ export async function startServer(options) {
22813
22877
  resultStore: sessionPoolE2EResultStore,
22814
22878
  dryRunResultStore: failoverDryRunStore,
22815
22879
  runProcess,
22816
- currentCommitSha: () => bootCommitSha || 'unknown',
22817
- // The shadow→live-transfer failover is proven at the 'shadow' stage index
22818
- // (0), which StageAdvancer.advanceTo('live-transfer') reads.
22819
- provenStage: () => 0,
22880
+ currentCommitSha: currentSessionPoolBuildIdentity,
22881
+ // Credit the proof to the stage that is actually running. The next
22882
+ // promotion reads this same current-stage index as its prior-stage gate.
22883
+ provenStage: () => stageMod.stageIndex(readSessionPoolStage()),
22820
22884
  audit: (event, detail) => console.log(pc.dim(` [failover-runner] ${event} ${JSON.stringify(detail)}`)),
22821
22885
  });
22822
22886
  if (_sessionPoolFailoverRunnerDriver) {