ostacky 0.10.2 → 0.11.0

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.js CHANGED
@@ -205,7 +205,19 @@ function verifyChecksum(content, expectedHash, label) {
205
205
  recibido: ${actual}`);
206
206
  }
207
207
  }
208
- var init_security = () => {};
208
+ var SENSITIVE_DEFAULT;
209
+ var init_security = __esm(() => {
210
+ SENSITIVE_DEFAULT = [
211
+ "**/.env*",
212
+ "**/.secrets/**",
213
+ "**/*.pem",
214
+ "**/*.key",
215
+ "**/.aws/**",
216
+ "**/.ssh/**",
217
+ "**/credentials.json",
218
+ "**/.npmrc"
219
+ ];
220
+ });
209
221
 
210
222
  // src/fs.ts
211
223
  import {
@@ -263,17 +275,14 @@ function initGitRepo(dir) {
263
275
  execFileSync("git", ["init"], { cwd: dir, stdio: "pipe" });
264
276
  }
265
277
  function getGlobalOpenCodeDir(opts) {
266
- const platform = opts?.platform ?? process.platform;
267
278
  const env = opts?.env ?? process.env;
268
279
  const home = opts?.home ?? homedir();
280
+ const explicit = env.OPENCODE_CONFIG_DIR?.trim();
281
+ if (explicit)
282
+ return explicit;
269
283
  const xdg = env.XDG_CONFIG_HOME?.trim();
270
284
  if (xdg)
271
285
  return join(xdg, "opencode");
272
- if (platform === "win32") {
273
- const appdata = env.APPDATA?.trim();
274
- if (appdata)
275
- return join(appdata, "opencode");
276
- }
277
286
  return join(home, ".config", "opencode");
278
287
  }
279
288
  function getOpenCodeDirForScope(scope, cwd = process.cwd()) {
@@ -641,31 +650,31 @@ var init_fs = __esm(() => {
641
650
  var manifest_default;
642
651
  var init_manifest = __esm(() => {
643
652
  manifest_default = {
644
- version: "0.10.2",
653
+ version: "0.11.0",
645
654
  repo: "JaimeHoracio/Ostacky",
646
- tag: "v0.10.2",
655
+ tag: "v0.11.0",
647
656
  agents: [
648
657
  {
649
658
  name: "ostacky",
650
659
  file: "assets/agents/ostacky.md",
651
- description: "Orquestador con recuperación automática (nunca se congela), ruteo por nivel de impacto, controller MCP con SDK oficial, edición segura con fallback inline, y delegación en OpenSpec + Superpowers. v0.10.2: prune de skills obsoletas, lastHandoff, getAvailableTransitions, consecutiveFailures real, mem_session_summary automático al cierre.",
652
- version: "0.10.2",
653
- sha256: "b3db2a27d7b8249b4552d4f63353d893ec1b8c2abda44f375de65cd1d4364419"
660
+ description: "Orquestador con recuperación automática (nunca se congela), ruteo por nivel de impacto, controller MCP con SDK oficial, edición segura con fallback inline, y delegación en OpenSpec + Superpowers. v0.11.0: prune de skills obsoletas, lastHandoff, getAvailableTransitions, consecutiveFailures real, mem_session_summary automático al cierre.",
661
+ version: "0.11.0",
662
+ sha256: "6b1b19ce2b2ce174394281cb40e39f74db9db17e78ad8dd3c6eb5dc24dbb7812"
654
663
  }
655
664
  ],
656
665
  commands: [
657
666
  {
658
667
  name: "install-stack",
659
668
  file: "assets/commands/install-stack.md",
660
- description: "Instala el stack tecnológico del proyecto (CodeGraph, skills, OpenSpec, Engram, controller plugin). v0.10.2: controller plugin como alma hard-gate, Context7 removido del stack.",
661
- version: "0.10.2",
662
- sha256: "b4845d7b6306b1a8c4914a4cf5a4390a4d3e79f1226de72b0ef2e95157c1f58e"
669
+ description: "Instala el stack tecnológico del proyecto (CodeGraph, skills, OpenSpec, Engram, controller plugin). v0.11.0: controller plugin como alma hard-gate, Context7 removido del stack.",
670
+ version: "0.11.0",
671
+ sha256: "87c9908455a1c976b616ac0da257cae98e20e5b8c631c6d6e4770a2f3c87ed4f"
663
672
  },
664
673
  {
665
674
  name: "opsx-sync",
666
675
  file: "assets/commands/opsx-sync.md",
667
676
  description: "Sincroniza delta specs del change activo sin inicializar CodeGraph si ya existe índice",
668
- version: "0.10.2",
677
+ version: "0.11.0",
669
678
  sha256: "f883f9ad96f7d75778631d5cc13d8a1a9c3e6ec41396bbce8ce13cff2e66fca2"
670
679
  }
671
680
  ],
@@ -673,16 +682,18 @@ var init_manifest = __esm(() => {
673
682
  {
674
683
  name: "ostacky-controller",
675
684
  file: "assets/mcp/ostacky-controller/",
676
- description: "Máquina de estados persistida con @modelcontextprotocol/server SDK. v0.10.2: 22 tools (incluye set_handoff, get_handoff, clear_handoff, get_available_transitions funcional). Bugfixes: consecutiveFailures real, lastHandoff state, defaultChoice persistido. Robustez: degraded mode automático tras 3 fallos, persistence condicional para Nivel 0, prune de skills obsoletas.",
677
- version: "0.10.2",
678
- sha256: "c78d2a8f7ce87d373cbac9135235ef1c90f45380fafc4135fe22c2b55c4423b6"
685
+ description: "Máquina de estados persistida con @modelcontextprotocol/server SDK. v0.11.0: 22 tools (incluye set_handoff, get_handoff, clear_handoff, get_available_transitions funcional). Bugfixes: consecutiveFailures real, lastHandoff state, defaultChoice persistido. Robustez: degraded mode automático tras 3 fallos, persistence condicional para Nivel 0, prune de skills obsoletas.",
686
+ version: "0.11.0",
687
+ sha256: "8a013be07c8751f044c25860bf8846bbda12bd470d1ebf0d68b354c73117d53f",
688
+ sourceSha256: "330c85c8c9ed3a6c8733e1fe7287bf61b9256138675b0b95949635e89697c975"
679
689
  },
680
690
  {
681
691
  name: "openspec",
682
692
  file: "assets/mcp/openspec/",
683
693
  description: "MCP server local para OpenSpec - proposal, apply, archive, sync de cambios",
684
- version: "0.10.2",
685
- sha256: "bdb283fe8ec2dfcba2ec4f38191f4039e58cd7ae12e44e66310783b42c827638"
694
+ version: "0.11.0",
695
+ sha256: "038ef43eaa1816251626610522f874a6c932528c00237f94f5354f18ed59ef53",
696
+ sourceSha256: "bdb283fe8ec2dfcba2ec4f38191f4039e58cd7ae12e44e66310783b42c827638"
686
697
  }
687
698
  ],
688
699
  skills: [
@@ -690,105 +701,105 @@ var init_manifest = __esm(() => {
690
701
  name: "brainstorming",
691
702
  file: "assets/skills/brainstorming/SKILL.md",
692
703
  description: "Skill unificado de pensamiento con dos modos: creative-design (producción de diseño → transición a implementación directa o openspec-propose) y open-exploration (exploración libre)",
693
- version: "0.10.2",
704
+ version: "0.11.0",
694
705
  sha256: "ba76eff6fb5bea08d3b26622089ea4739b7b542b3677a46071b2576f3f2001c7"
695
706
  },
696
707
  {
697
708
  name: "execution-mode-evaluation",
698
709
  file: "assets/skills/execution-mode-evaluation/SKILL.md",
699
710
  description: "Skill de análisis de modo de ejecución — output reconciliado con controller snapshot contract (recommendation field)",
700
- version: "0.10.2",
711
+ version: "0.11.0",
701
712
  sha256: "9090132ccfe31dcf34b6d5f399c1135dcb1044c504d4beb026e0c7d9e09e7c0d"
702
713
  },
703
714
  {
704
715
  name: "tdd",
705
716
  file: "assets/skills/tdd/SKILL.md",
706
717
  description: "Skill de test-driven development (Superpowers)",
707
- version: "0.10.2",
718
+ version: "0.11.0",
708
719
  sha256: "cce54e81cce46ba973066f9b43e74994a7dbf21aa756146c27689241cf62704d"
709
720
  },
710
721
  {
711
722
  name: "subagent-driven-development",
712
723
  file: "assets/skills/subagent-driven-development/SKILL.md",
713
724
  description: "Skill de ejecución con subagentes (Superpowers) — ejecuta solo después de confirmación del coordinador Ostacky",
714
- version: "0.10.2",
725
+ version: "0.11.0",
715
726
  sha256: "1a42d714a9a13faf05f0bf7b580e8d837c2e77a5633839542ccce603023419e8"
716
727
  },
717
728
  {
718
729
  name: "dispatching-parallel-agents",
719
730
  file: "assets/skills/dispatching-parallel-agents/SKILL.md",
720
731
  description: "Skill de dispatch paralelo de agentes (Superpowers)",
721
- version: "0.10.2",
732
+ version: "0.11.0",
722
733
  sha256: "7e7b712ef742d5631e302e6a71583e2bbbd33094da9281abfb84b43505fc3ef1"
723
734
  },
724
735
  {
725
736
  name: "review",
726
737
  file: "assets/skills/review/SKILL.md",
727
738
  description: "Skill de revisión de código (Superpowers)",
728
- version: "0.10.2",
739
+ version: "0.11.0",
729
740
  sha256: "b19650ed4d1d4d9857a4dd5b7e08e91328a1a1fc9c45bcc2fb600fa9d0213279"
730
741
  },
731
742
  {
732
743
  name: "receiving-code-review",
733
744
  file: "assets/skills/receiving-code-review/SKILL.md",
734
745
  description: "Skill de recibir y procesar feedback de code review",
735
- version: "0.10.2",
746
+ version: "0.11.0",
736
747
  sha256: "d761e884e71d8d3476ac734d287cae403a4024506a7d12e7361a448217c0a831"
737
748
  },
738
749
  {
739
750
  name: "openspec-propose",
740
751
  file: "assets/skills/openspec-propose/SKILL.md",
741
752
  description: "Skill de generación de proposal (OpenSpec)",
742
- version: "0.10.2",
753
+ version: "0.11.0",
743
754
  sha256: "9049b944cea88a5428fd5d77b411a0ed32d169ad68acda911b68365fac08f38f"
744
755
  },
745
756
  {
746
757
  name: "openspec-apply-change",
747
758
  file: "assets/skills/openspec-apply-change/SKILL.md",
748
759
  description: "Skill de aplicación de change (OpenSpec)",
749
- version: "0.10.2",
760
+ version: "0.11.0",
750
761
  sha256: "dfc823bf89fc7505e91ab6dee9c1f004be38a410bd3d88fb67b211b1b6cbb1d0"
751
762
  },
752
763
  {
753
764
  name: "openspec-archive-change",
754
765
  file: "assets/skills/openspec-archive-change/SKILL.md",
755
766
  description: "Skill de archivo de change (OpenSpec)",
756
- version: "0.10.2",
767
+ version: "0.11.0",
757
768
  sha256: "16e4b561de7747283663fed602e506abf502452c49a8d4b86d7a5539c40f0195"
758
769
  },
759
770
  {
760
771
  name: "openspec-explore",
761
772
  file: "assets/skills/openspec-explore/SKILL.md",
762
773
  description: "Modo explore para OpenSpec — thinking partner para explorar ideas, investigar problemas y clarificar requisitos antes/durante un cambio",
763
- version: "0.10.2",
774
+ version: "0.11.0",
764
775
  sha256: "9eafc3a8c693b8d9916867ef764d49e5222da717fde501c957bb3f6c312d2415"
765
776
  },
766
777
  {
767
778
  name: "using-git-worktrees",
768
779
  file: "assets/skills/using-git-worktrees/SKILL.md",
769
780
  description: "Skill de uso de git worktrees para aislamiento de trabajo",
770
- version: "0.10.2",
781
+ version: "0.11.0",
771
782
  sha256: "93341bc1b7c053618a8b6dc07e3615b77990d7b549a0201f5835d95fef67ce13"
772
783
  },
773
784
  {
774
785
  name: "using-superpowers",
775
786
  file: "assets/skills/using-superpowers/SKILL.md",
776
787
  description: "Skill de orquestación de Superpowers skills",
777
- version: "0.10.2",
788
+ version: "0.11.0",
778
789
  sha256: "7e54536f96d2a379185a10bfc1e970850caa2561b6d8aca7080f0defea0381a4"
779
790
  },
780
791
  {
781
792
  name: "writing-skills",
782
793
  file: "assets/skills/writing-skills/SKILL.md",
783
794
  description: "Skill de creación y edición de skills",
784
- version: "0.10.2",
795
+ version: "0.11.0",
785
796
  sha256: "3d76b906cee518a2b809febb70db95697a35b9f368986bb504b4120c3bfb437a"
786
797
  },
787
798
  {
788
799
  name: "graceful-degradation",
789
800
  file: "assets/skills/graceful-degradation/SKILL.md",
790
801
  description: "Skill de degradación graceful cuando múltiples tools están indisponibles",
791
- version: "0.10.2",
802
+ version: "0.11.0",
792
803
  sha256: "363449bd9e6f800a0a3168667cf78f767fb105d86e4a4adadcc649d418139303"
793
804
  }
794
805
  ]
@@ -840,9 +851,11 @@ function getBundledMcpPath(name) {
840
851
  validateFilePath(name);
841
852
  return join3(BUNDLED_MCP_DIR, name);
842
853
  }
843
- function getBundledExpectedHash(category, name) {
854
+ function getBundledExpectedHash(category, name, field = "sha256") {
844
855
  const items = manifest_default[category] ?? [];
845
- return items.find((item) => item.name === name)?.sha256 ?? null;
856
+ const found = items.find((item) => item.name === name);
857
+ const value = found?.[field];
858
+ return typeof value === "string" ? value : null;
846
859
  }
847
860
  function getRawUrl(repo, tag, path) {
848
861
  return `${GITHUB_RAW}/${repo}/${tag}/${path}`;
@@ -1213,7 +1226,7 @@ function copyOstackyControllerPlugin(projectRoot) {
1213
1226
  throw new Error(`Plugin bundleado de OstackyController no encontrado: ${packageSource}`);
1214
1227
  }
1215
1228
  mkdirSync4(packageDest, { recursive: true });
1216
- for (const f of ["index.ts", "controller-core.ts", "security.ts", "tiered.ts"]) {
1229
+ for (const f of ["index.ts", "controller-core.ts", "security.ts", "tiered.ts", "session-slots.ts", "session-store.ts", "compaction-threshold.ts"]) {
1217
1230
  const src = join7(packageSource, f);
1218
1231
  if (existsSync6(src))
1219
1232
  copyFileSync3(src, join7(packageDest, f));
@@ -1576,24 +1589,290 @@ var init_stack = __esm(() => {
1576
1589
  init_github();
1577
1590
  });
1578
1591
 
1592
+ // src/session-slots.ts
1593
+ function parsePoolConfig(env = process.env) {
1594
+ const num = (raw, fallback) => {
1595
+ const n = Number(raw);
1596
+ return Number.isFinite(n) && n > 0 ? n : fallback;
1597
+ };
1598
+ return {
1599
+ poolMax: Math.floor(num(env.OSTACKY_SESSION_POOL_MAX, POOL_DEFAULTS.poolMax)),
1600
+ overflowMax: Math.floor(num(env.OSTACKY_SESSION_OVERFLOW_MAX, POOL_DEFAULTS.overflowMax)),
1601
+ activeMs: num(env.OSTACKY_SESSION_ACTIVE_MIN, POOL_DEFAULTS.activeMinutes) * 60000,
1602
+ recycleMs: num(env.OSTACKY_SESSION_RECYCLE_DAYS, POOL_DEFAULTS.recycleDays) * 86400000
1603
+ };
1604
+ }
1605
+ function isActiveSlot(s, now, cfg) {
1606
+ if (!s.sessionId || !s.requestId || s.quarantined)
1607
+ return false;
1608
+ if (s.state && TERMINAL_REQUEST_STATES.includes(s.state))
1609
+ return false;
1610
+ return s.ownerHeartbeat > 0 && now - s.ownerHeartbeat <= cfg.activeMs;
1611
+ }
1612
+ var TERMINAL_REQUEST_STATES, POOL_DEFAULTS;
1613
+ var init_session_slots = __esm(() => {
1614
+ TERMINAL_REQUEST_STATES = ["DONE", "ABANDONED"];
1615
+ POOL_DEFAULTS = {
1616
+ poolMax: 10,
1617
+ overflowMax: 5,
1618
+ activeMinutes: 15,
1619
+ recycleDays: 7
1620
+ };
1621
+ });
1622
+
1623
+ // src/compaction-threshold.ts
1624
+ function num(raw, fallback) {
1625
+ const n = Number(raw);
1626
+ return Number.isFinite(n) && n > 0 ? n : fallback;
1627
+ }
1628
+ function parseCompactConfig(env = process.env) {
1629
+ const enabledRaw = env.OSTACKY_COMPACT_ENABLED;
1630
+ const enabled = enabledRaw === undefined ? COMPACT_DEFAULTS.enabled : enabledRaw.trim().toLowerCase() !== "false";
1631
+ const modeRaw = (env.OSTACKY_COMPACT_MODE ?? COMPACT_DEFAULTS.mode).trim().toLowerCase();
1632
+ const mode = modeRaw === "off" || modeRaw === "warn" || modeRaw === "auto" ? modeRaw : COMPACT_DEFAULTS.mode;
1633
+ const threshold = Math.floor(num(env.OSTACKY_COMPACT_THRESHOLD, DEFAULT_THRESHOLD));
1634
+ const model = env.OSTACKY_COMPACT_MODEL?.trim() || undefined;
1635
+ return { enabled, mode: enabled ? mode : "off", threshold, model };
1636
+ }
1637
+ var COMPACT_DEFAULTS, DEFAULT_THRESHOLD, WARN_AT_FOR_DEFAULT;
1638
+ var init_compaction_threshold = __esm(() => {
1639
+ COMPACT_DEFAULTS = {
1640
+ enabled: true,
1641
+ mode: "warn",
1642
+ threshold: 120000,
1643
+ warnAt: 1e5,
1644
+ model: undefined,
1645
+ cooldownMs: 10 * 60 * 1000
1646
+ };
1647
+ DEFAULT_THRESHOLD = COMPACT_DEFAULTS.threshold;
1648
+ WARN_AT_FOR_DEFAULT = COMPACT_DEFAULTS.warnAt;
1649
+ });
1650
+
1651
+ // src/controller-core.ts
1652
+ var MAX_SNAPSHOT_JSON_LENGTH, MAX_STATE_FILE_SIZE, STATES, TERMINAL_STATES, DEFAULT_STATE;
1653
+ var init_controller_core = __esm(() => {
1654
+ init_security();
1655
+ MAX_SNAPSHOT_JSON_LENGTH = 50 * 1024;
1656
+ MAX_STATE_FILE_SIZE = 2 * 1024 * 1024;
1657
+ STATES = Object.freeze({
1658
+ INTERPRETATION_PENDING: "INTERPRETATION_PENDING",
1659
+ CLARIFICATION_PENDING: "CLARIFICATION_PENDING",
1660
+ DISCOVERY: "DISCOVERY",
1661
+ ROUTE_DECISION_PENDING: "ROUTE_DECISION_PENDING",
1662
+ SPECIFICATION: "SPECIFICATION",
1663
+ EXECUTION_ANALYSIS: "EXECUTION_ANALYSIS",
1664
+ EXECUTION_DECISION_PENDING: "EXECUTION_DECISION_PENDING",
1665
+ EXECUTING_INLINE: "EXECUTING_INLINE",
1666
+ EXECUTING_SUBAGENTS: "EXECUTING_SUBAGENTS",
1667
+ SYNC: "SYNC",
1668
+ DONE: "DONE",
1669
+ BLOCKED: "BLOCKED"
1670
+ });
1671
+ TERMINAL_STATES = Object.freeze([
1672
+ STATES.INTERPRETATION_PENDING,
1673
+ STATES.CLARIFICATION_PENDING,
1674
+ STATES.BLOCKED,
1675
+ STATES.DONE
1676
+ ]);
1677
+ DEFAULT_STATE = {
1678
+ state: STATES.INTERPRETATION_PENDING,
1679
+ revision: 0,
1680
+ requestId: null,
1681
+ changeId: null,
1682
+ routeDecisionId: null,
1683
+ routeChoice: null,
1684
+ level: null,
1685
+ executionDecisionId: null,
1686
+ executionMode: null,
1687
+ snapshots: { codegraph: null, execution: null },
1688
+ tasks: {},
1689
+ fileFingerprints: {},
1690
+ error: null,
1691
+ lastHandoff: null,
1692
+ expectedTasks: null,
1693
+ expectedTaskCount: null,
1694
+ taskVerifications: null,
1695
+ taskVerificationResults: {},
1696
+ auditSeq: 0,
1697
+ degraded: false,
1698
+ schemaVersion: 2,
1699
+ stateOversizedCount: 0,
1700
+ codegraphBypassCount: 0,
1701
+ degradedEditsCount: 0,
1702
+ cacheHitCount: 0,
1703
+ cacheMissCount: 0,
1704
+ tokenSavingEstimate: 0,
1705
+ discoveryCacheHitCount: 0,
1706
+ redundantCallCount: 0,
1707
+ cacheMissWithoutPutCount: 0,
1708
+ stateCheckCount: 0,
1709
+ toolCallCount: 0,
1710
+ lastProposal: null,
1711
+ allowedFiles: {},
1712
+ deniedFiles: {},
1713
+ sensitivePatterns: [...SENSITIVE_DEFAULT],
1714
+ sensitiveAccess: { allowed: 0, denied: 0, blockedAttempts: 0 },
1715
+ staleContentAttempts: 0,
1716
+ completeWithoutValidateCount: 0,
1717
+ toolTimeoutCount: 0,
1718
+ lastToolDurationMs: 0,
1719
+ stateDurationMs: 0,
1720
+ subagentFailedCount: 0,
1721
+ lastValidated: null,
1722
+ pendingFileAccess: {},
1723
+ lastHeartbeat: 0,
1724
+ watchdogEnabled: true,
1725
+ ownerSessionId: null,
1726
+ ownerHeartbeat: 0,
1727
+ ts: Date.now(),
1728
+ specNotInSync: false,
1729
+ engramBypassCount: 0
1730
+ };
1731
+ });
1732
+
1733
+ // src/session-store.ts
1734
+ import { existsSync as existsSync8, mkdirSync as mkdirSync5, readFileSync as readFileSync6, renameSync as renameSync3, rmSync as rmSync5, statSync as statSync3, writeFileSync as writeFileSync6 } from "node:fs";
1735
+ import { join as join10 } from "node:path";
1736
+ function sessionsDir(opencodeDir) {
1737
+ return join10(opencodeDir, "sessions");
1738
+ }
1739
+ function indexPath(opencodeDir) {
1740
+ return join10(sessionsDir(opencodeDir), "index.json");
1741
+ }
1742
+ function emptyIndex() {
1743
+ return { version: 1, revision: 0, migrated: false, slots: {} };
1744
+ }
1745
+ function readIndex(opencodeDir) {
1746
+ try {
1747
+ const parsed = JSON.parse(readFileSync6(indexPath(opencodeDir), "utf-8"));
1748
+ if (parsed && typeof parsed === "object" && parsed.slots && typeof parsed.slots === "object")
1749
+ return parsed;
1750
+ } catch {}
1751
+ return emptyIndex();
1752
+ }
1753
+ function toInfo(slot, r) {
1754
+ return {
1755
+ slot,
1756
+ overflow: r.overflow,
1757
+ quarantined: r.quarantined,
1758
+ sessionId: r.sessionId,
1759
+ requestId: r.requestId,
1760
+ state: r.state,
1761
+ ownerHeartbeat: r.ownerHeartbeat,
1762
+ lastUsedAt: r.lastUsedAt
1763
+ };
1764
+ }
1765
+ function poolReport(opencodeDir, now, cfg) {
1766
+ const idx = readIndex(opencodeDir);
1767
+ const entries = Object.entries(idx.slots);
1768
+ const infos = entries.map(([s, r]) => toInfo(s, r));
1769
+ const active = infos.filter((i) => i.sessionId && i.requestId && i.ownerHeartbeat > 0 && now - i.ownerHeartbeat <= cfg.activeMs && !["DONE", "ABANDONED"].includes(i.state ?? "")).length;
1770
+ return {
1771
+ base: entries.filter(([, r]) => !r.overflow).length,
1772
+ overflow: entries.filter(([, r]) => r.overflow).length,
1773
+ active,
1774
+ quarantined: entries.filter(([, r]) => r.quarantined).map(([s, r]) => `${s}: ${r.quarantineReason ?? "motivo desconocido"}`),
1775
+ occupied: infos.filter((i) => i.sessionId).sort((a, b) => a.lastUsedAt - b.lastUsedAt).map((i) => ({ ...i, sessionName: idx.slots[i.slot].sessionName, active: isActiveSlot(i, now, cfg) }))
1776
+ };
1777
+ }
1778
+ var FILE_ACTIVITY_RETENTION_MS;
1779
+ var init_session_store = __esm(() => {
1780
+ init_controller_core();
1781
+ init_session_slots();
1782
+ FILE_ACTIVITY_RETENTION_MS = 24 * 60 * 60 * 1000;
1783
+ });
1784
+
1579
1785
  // src/doctor-v2.ts
1580
- import { existsSync as existsSync8, readFileSync as readFileSync6, readdirSync as readdirSync3 } from "fs";
1581
- import { join as join10, delimiter, isAbsolute } from "path";
1786
+ import { existsSync as existsSync9, readFileSync as readFileSync7, readdirSync as readdirSync3 } from "fs";
1787
+ import { join as join11, delimiter, isAbsolute } from "path";
1788
+ function globalOstackyArtifacts(globalDir = getGlobalOpenCodeDir()) {
1789
+ const found = [];
1790
+ const candidates = [
1791
+ join11(globalDir, "agent", "ostacky.md"),
1792
+ join11(globalDir, "plugins", "ostacky-controller", "index.ts"),
1793
+ join11(globalDir, "plugin", "ostacky-controller", "index.ts"),
1794
+ join11(globalDir, "command", "ostacky.md")
1795
+ ];
1796
+ for (const p of candidates) {
1797
+ try {
1798
+ if (existsSync9(p))
1799
+ found.push(p);
1800
+ } catch {}
1801
+ }
1802
+ for (const cfgName of ["opencode.json", "opencode.jsonc"]) {
1803
+ const cfg = join11(globalDir, cfgName);
1804
+ try {
1805
+ if (!existsSync9(cfg))
1806
+ continue;
1807
+ const raw = readFileSync7(cfg, "utf-8");
1808
+ const json = JSON.parse(raw.replace(/\/\/.*$/gm, "").replace(/\/\*[\s\S]*?\*\//g, ""));
1809
+ const servers = json?.mcp?.servers ?? json?.mcp ?? {};
1810
+ if (servers && servers["ostacky-controller"])
1811
+ found.push(cfg);
1812
+ } catch {}
1813
+ }
1814
+ return found;
1815
+ }
1816
+ function globalPluginScopeAware(globalDir = getGlobalOpenCodeDir()) {
1817
+ const candidates = [
1818
+ join11(globalDir, "plugins", "ostacky-controller", "index.ts"),
1819
+ join11(globalDir, "plugin", "ostacky-controller", "index.ts"),
1820
+ join11(globalDir, "plugins", "ostacky-controller", "index.js"),
1821
+ join11(globalDir, "plugin", "ostacky-controller", "index.js")
1822
+ ];
1823
+ for (const p of candidates) {
1824
+ try {
1825
+ if (!existsSync9(p))
1826
+ continue;
1827
+ return readFileSync7(p, "utf-8").includes("ostacky-controller-global");
1828
+ } catch {}
1829
+ }
1830
+ return null;
1831
+ }
1582
1832
  function checkDoctorV2(projectRoot) {
1583
1833
  const lines = [];
1834
+ try {
1835
+ const cfg = parseCompactConfig(process.env);
1836
+ lines.push(`ℹ️ compactación: enabled=${cfg.enabled}, mode=${cfg.mode}, threshold=${cfg.threshold}${cfg.model ? `, model=${cfg.model}` : ""}`);
1837
+ } catch (err) {
1838
+ lines.push(`⚠️ compactación: no se pudo leer config (${String(err?.message ?? err)})`);
1839
+ }
1840
+ try {
1841
+ const opencodeDir = join11(projectRoot, ".opencode");
1842
+ if (existsSync9(join11(opencodeDir, "sessions", "index.json"))) {
1843
+ const cfg = parsePoolConfig(process.env);
1844
+ const rep = poolReport(opencodeDir, Date.now(), cfg);
1845
+ lines.push(`ℹ️ sesiones: base ${rep.base}/${cfg.poolMax}, extensión ${rep.overflow}/${cfg.overflowMax}, activas ${rep.active}`);
1846
+ for (const q of rep.quarantined)
1847
+ lines.push(`⚠️ sesiones: slot en cuarentena — ${q}`);
1848
+ for (const o of rep.occupied.filter((x) => !x.active && x.state && !["DONE", "ABANDONED"].includes(x.state))) {
1849
+ lines.push(`ℹ️ sesiones: ${o.slot} "${o.sessionName || o.requestId || "sin nombre"}" con request no terminal (${o.state}) sin actividad reciente`);
1850
+ }
1851
+ }
1852
+ } catch (err) {
1853
+ lines.push(`⚠️ sesiones: no se pudo leer el pool (${String(err?.message ?? err)})`);
1854
+ }
1855
+ const globalArtifacts = globalOstackyArtifacts();
1856
+ if (globalArtifacts.length > 0) {
1857
+ if (globalPluginScopeAware() === false) {
1858
+ lines.push(`⚠️ plugin global legacy (id compartido): OpenCode V2 conserva la copia global y deshabilita la local ("Duplicate plugin ID: ostacky-controller") — los gates los aplica el plugin global, no el local. Actualizá el global (npx ostacky install --scope global) o limpiá con: npx ostacky uninstall --scope global`);
1859
+ } else {
1860
+ lines.push(`⚠️ Instalación global convive con la local: ${globalArtifacts.join(", ")}. El plugin global cede la precedencia al local (ids distintos, sin colisión); el resto de los artefactos globales queda como residuo si no los usás. Limpiá con: npx ostacky uninstall --scope global`);
1861
+ }
1862
+ }
1584
1863
  const cwd = projectRoot;
1585
- const opencodeDir = findOpenCodeDir(cwd) || join10(cwd, ".opencode");
1864
+ const opencodeDir = findOpenCodeDir(cwd) || join11(cwd, ".opencode");
1586
1865
  const pluginPaths = [
1587
- join10(opencodeDir, "plugins", "ostacky-controller", "index.ts"),
1588
- join10(cwd, ".opencode", "plugins", "ostacky-controller", "index.ts"),
1589
- join10(opencodeDir, "plugins", "ostacky-plugin.ts"),
1590
- join10(cwd, ".opencode", "plugins", "ostacky-plugin.ts"),
1591
- join10(cwd, "assets", "plugins", "ostacky-plugin.ts")
1866
+ join11(opencodeDir, "plugins", "ostacky-controller", "index.ts"),
1867
+ join11(cwd, ".opencode", "plugins", "ostacky-controller", "index.ts"),
1868
+ join11(opencodeDir, "plugins", "ostacky-plugin.ts"),
1869
+ join11(cwd, ".opencode", "plugins", "ostacky-plugin.ts"),
1870
+ join11(cwd, "assets", "plugins", "ostacky-plugin.ts")
1592
1871
  ];
1593
- const found = pluginPaths.find((p) => existsSync8(p));
1872
+ const found = pluginPaths.find((p) => existsSync9(p));
1594
1873
  if (found) {
1595
1874
  try {
1596
- const src = readFileSync6(found, "utf-8");
1875
+ const src = readFileSync7(found, "utf-8");
1597
1876
  const hasDefault = /export\s+default/.test(src);
1598
1877
  const hasLegacyPkg = src.includes("@opencode-ai/");
1599
1878
  if (hasDefault && !hasLegacyPkg)
@@ -1604,18 +1883,18 @@ function checkDoctorV2(projectRoot) {
1604
1883
  lines.push(`⚠️ controller: no se pudo leer ${found}`);
1605
1884
  }
1606
1885
  }
1607
- const pluginsDir = join10(opencodeDir, "plugins");
1886
+ const pluginsDir = join11(opencodeDir, "plugins");
1608
1887
  for (const f of ["controller-core.ts", "security.ts", "tiered.ts"]) {
1609
1888
  try {
1610
- const p = join10(pluginsDir, f);
1611
- if (existsSync8(p) && !readFileSync6(p, "utf-8").includes("export default")) {
1889
+ const p = join11(pluginsDir, f);
1890
+ if (existsSync9(p) && !readFileSync7(p, "utf-8").includes("export default")) {
1612
1891
  lines.push(`⚠️ plugins/${f} suelto sin default — el server lo carga como plugin y falla; mové a plugins/ostacky-controller/ o re-corré install (doctor no lo modifica)`);
1613
1892
  }
1614
1893
  } catch {}
1615
1894
  }
1616
1895
  try {
1617
1896
  const home = process.env.HOME || process.env.USERPROFILE || "";
1618
- const globalPlugins = home ? join10(home, ".config", "opencode", "plugins") : "";
1897
+ const globalPlugins = home ? join11(home, ".config", "opencode", "plugins") : "";
1619
1898
  if (globalPlugins) {
1620
1899
  let entries = [];
1621
1900
  try {
@@ -1623,7 +1902,7 @@ function checkDoctorV2(projectRoot) {
1623
1902
  } catch {}
1624
1903
  for (const e of entries) {
1625
1904
  try {
1626
- const src = readFileSync6(join10(globalPlugins, e), "utf-8");
1905
+ const src = readFileSync7(join11(globalPlugins, e), "utf-8");
1627
1906
  if (src.includes("@opencode-ai/") || !src.includes("export default")) {
1628
1907
  lines.push(`⚠️ global ${e} con formato V1 (@opencode-ai/* o sin default) — no corre en server V2; actualizalo o borralo a mano (doctor no lo modifica)`);
1629
1908
  }
@@ -1693,7 +1972,7 @@ function checkDoctorV2(projectRoot) {
1693
1972
  lines.push(`⚠️ mcp.servers.${name} local sin command array — V2 requiere command: [bin, ...args]`);
1694
1973
  } else {
1695
1974
  const bin = cmd[0];
1696
- const ok = isAbsolute(bin) ? existsSync8(bin) : lookupOnPath(bin) !== null;
1975
+ const ok = isAbsolute(bin) ? existsSync9(bin) : lookupOnPath(bin) !== null;
1697
1976
  if (!ok)
1698
1977
  lines.push(`⚠️ mcp.servers.${name} command no existe (${bin}) — ¿proyecto movido? re-corré install`);
1699
1978
  }
@@ -1722,23 +2001,26 @@ function lookupOnPath(name) {
1722
2001
  if (!dir)
1723
2002
  continue;
1724
2003
  try {
1725
- if (existsSync8(join10(dir, name + suffix)))
1726
- return join10(dir, name + suffix);
1727
- if (suffix && existsSync8(join10(dir, name)))
1728
- return join10(dir, name);
2004
+ if (existsSync9(join11(dir, name + suffix)))
2005
+ return join11(dir, name + suffix);
2006
+ if (suffix && existsSync9(join11(dir, name)))
2007
+ return join11(dir, name);
1729
2008
  } catch {}
1730
2009
  }
1731
2010
  } catch {}
1732
2011
  return null;
1733
2012
  }
1734
2013
  var init_doctor_v2 = __esm(() => {
2014
+ init_session_slots();
2015
+ init_compaction_threshold();
2016
+ init_session_store();
1735
2017
  init_config();
1736
2018
  init_fs();
1737
2019
  });
1738
2020
  // package.json
1739
2021
  var package_default = {
1740
2022
  name: "ostacky",
1741
- version: "0.10.2",
2023
+ version: "0.11.0",
1742
2024
  description: "Instalador interactivo de agentes y comandos para OpenCode",
1743
2025
  type: "module",
1744
2026
  bin: {
@@ -1747,15 +2029,17 @@ var package_default = {
1747
2029
  scripts: {
1748
2030
  prebuild: "bun run scripts/sync-version.ts && bun run scripts/sync-controller-core.ts",
1749
2031
  dev: "bun run src/cli.ts",
1750
- build: "bun build src/cli.ts --target=node --format=esm --outfile dist/cli.js && bun scripts/add-shebang.ts",
2032
+ "build:cli": "bun build src/cli.ts --target=node --format=esm --outfile dist/cli.js && bun scripts/add-shebang.ts",
2033
+ "build:mcp": "bun run scripts/build-mcp-bundles.ts",
2034
+ build: "bun run build:cli && bun run build:mcp && tsc --noEmit",
1751
2035
  start: "node dist/cli.js",
1752
2036
  test: "bun test --isolate",
1753
2037
  "test:safe": "bun run scripts/run-tests-isolated.ts",
1754
2038
  "check:skills": "bun run scripts/check-skill-sync.ts",
1755
2039
  "hash:check": "bun run scripts/update-manifest-hashes.ts --check",
1756
- "hash:update": "bun run scripts/update-manifest-hashes.ts",
1757
- prepublishOnly: "bun run build",
1758
- update: "bun run scripts/check-skill-sync.ts && bun run scripts/sync-controller-core.ts && bun run scripts/update-manifest-hashes.ts"
2040
+ "hash:update": "bun run build:mcp && bun run scripts/update-manifest-hashes.ts",
2041
+ prepublishOnly: "bun run build && bun run hash:update",
2042
+ update: "bun run scripts/check-skill-sync.ts && bun run scripts/sync-controller-core.ts && bun run hash:update"
1759
2043
  },
1760
2044
  files: [
1761
2045
  "dist/",
@@ -1776,7 +2060,8 @@ var package_default = {
1776
2060
  devDependencies: {
1777
2061
  "@types/bun": "latest",
1778
2062
  openspec: "^0.0.0",
1779
- typescript: "^5.0.0"
2063
+ typescript: "^5.9.3",
2064
+ "vite-plugin-checker": "^1.0.0"
1780
2065
  },
1781
2066
  publishConfig: {
1782
2067
  access: "public"
@@ -2918,7 +3203,7 @@ async function probeMcpServer(nodeExecutable, serverPath, cwd, statePath, option
2918
3203
  params: {
2919
3204
  protocolVersion: "2025-03-26",
2920
3205
  capabilities: {},
2921
- clientInfo: { name: "ostacky-installer", version: "0.10.2" }
3206
+ clientInfo: { name: "ostacky-installer", version: "0.11.0" }
2922
3207
  }
2923
3208
  });
2924
3209
  });
@@ -2991,8 +3276,8 @@ function upsertLockfile(paths, type, item, manifest, contentHash) {
2991
3276
  existing.lockedAt = new Date().toISOString();
2992
3277
  writeLockfile(paths.root, existing);
2993
3278
  }
2994
- function assertBundledTreeHash(category, name, actualHash) {
2995
- const expected = getBundledExpectedHash(category, name);
3279
+ function assertBundledTreeHash(category, name, actualHash, field = "sha256") {
3280
+ const expected = getBundledExpectedHash(category, name, field);
2996
3281
  if (expected && actualHash !== expected) {
2997
3282
  const labels = {
2998
3283
  skills: "skill",
@@ -3000,7 +3285,7 @@ function assertBundledTreeHash(category, name, actualHash) {
3000
3285
  agents: "agente",
3001
3286
  commands: "command"
3002
3287
  };
3003
- throw new Error(`Tree hash inválido para ${labels[category] ?? category} "${name}"
3288
+ throw new Error(`Hash inválido para ${labels[category] ?? category} "${name}" (${field})
3004
3289
  esperado: ${expected}
3005
3290
  recibido: ${actualHash}`);
3006
3291
  }
@@ -3011,6 +3296,13 @@ function readBundledAsset(relativePath) {
3011
3296
  return null;
3012
3297
  return readFileSync5(fullPath, "utf-8");
3013
3298
  }
3299
+ function mcpArtifactHash(name, packageRoot = PACKAGE_ROOT) {
3300
+ const bundlePath = join6(packageRoot, "dist", "mcp", name, "index.js");
3301
+ if (existsSync5(bundlePath)) {
3302
+ return { field: "sha256", actual: sha256(readFileSync5(bundlePath, "utf-8")) };
3303
+ }
3304
+ return { field: "sourceSha256", actual: computeTreeHash(join6(packageRoot, "assets", "mcp", name)) };
3305
+ }
3014
3306
  async function installAgent(item, manifest, paths) {
3015
3307
  let content;
3016
3308
  try {
@@ -3081,8 +3373,10 @@ async function installMcpServer(item, manifest, paths) {
3081
3373
  if (!existsSync5(src)) {
3082
3374
  throw new Error(`MCP server bundleado no encontrado: ${src}. ` + `¿Falta el directorio assets/mcp/${item.name}/?`);
3083
3375
  }
3084
- const treeHash = computeTreeHash(src);
3085
- assertBundledTreeHash("mcpServers", item.name, treeHash);
3376
+ const bundlePath = join6(PACKAGE_ROOT, "dist", "mcp", item.name, "index.js");
3377
+ const hasBundle = existsSync5(bundlePath);
3378
+ const { field, actual: artifactHash } = mcpArtifactHash(item.name);
3379
+ assertBundledTreeHash("mcpServers", item.name, artifactHash, field);
3086
3380
  const nodeExecutable = getVerifiedNodeExecutable();
3087
3381
  await Promise.resolve().then(() => init_fs());
3088
3382
  const projectRoot = paths.root === getGlobalOpenCodeDir() ? paths.root : dirname4(paths.root);
@@ -3091,9 +3385,8 @@ async function installMcpServer(item, manifest, paths) {
3091
3385
  const statePath = item.name === "ostacky-controller" ? join6(paths.root, "ostacky-state.json") : undefined;
3092
3386
  try {
3093
3387
  mkdirSync3(staging, { recursive: true });
3094
- const bundledPath = join6(PACKAGE_ROOT, "dist", "mcp", item.name, "index.js");
3095
- if (existsSync5(bundledPath)) {
3096
- copyFileSync2(bundledPath, join6(staging, "index.js"));
3388
+ if (hasBundle) {
3389
+ copyFileSync2(bundlePath, join6(staging, "index.js"));
3097
3390
  writeFileSync5(join6(staging, "package.json"), JSON.stringify({ type: "module" }) + `
3098
3391
  `, "utf-8");
3099
3392
  } else {
@@ -3129,7 +3422,7 @@ async function installMcpServer(item, manifest, paths) {
3129
3422
  const promotion = promoteStagedDirectory(staging, dest);
3130
3423
  try {
3131
3424
  setMcpEntryAtProjectRoot(projectRoot, item.name, createMcpConfigEntry(item.name, nodeExecutable, join6(dest, "index.js"), statePath));
3132
- upsertLockfile(paths, "mcpServers", item, manifest, treeHash);
3425
+ upsertLockfile(paths, "mcpServers", item, manifest, artifactHash);
3133
3426
  promotion.commit();
3134
3427
  } catch (error) {
3135
3428
  try {
@@ -3255,7 +3548,10 @@ function uninstallAll(paths) {
3255
3548
  "ostacky-controller.ts",
3256
3549
  "controller-core.ts",
3257
3550
  "security.ts",
3258
- "tiered.ts"
3551
+ "tiered.ts",
3552
+ "session-slots.ts",
3553
+ "session-store.ts",
3554
+ "compaction-threshold.ts"
3259
3555
  ];
3260
3556
  for (const file of ostackyPlugins) {
3261
3557
  const fp = join6(paths.plugins, file);
@@ -4612,10 +4908,11 @@ async function runUninstallMcpCommand(name, scope) {
4612
4908
  }
4613
4909
 
4614
4910
  // src/cli.ts
4615
- import { existsSync as existsSync9, statSync as statSync3, readFileSync as readFileSync7, readdirSync as readdirSync4 } from "node:fs";
4616
- import { join as join11, dirname as dirname8 } from "node:path";
4911
+ import { existsSync as existsSync10, statSync as statSync4, readFileSync as readFileSync8, readdirSync as readdirSync4 } from "node:fs";
4912
+ import { join as join12, dirname as dirname8 } from "node:path";
4617
4913
  import { spawnSync } from "node:child_process";
4618
4914
  init_fs();
4915
+ init_github();
4619
4916
 
4620
4917
  // src/version-check.ts
4621
4918
  function parseMajor(version) {
@@ -4773,8 +5070,8 @@ var noStack = process.argv.includes("--no-stack");
4773
5070
  var [, , cmd, subcmd] = argvNoScope;
4774
5071
  async function runDoctorCommand() {
4775
5072
  const cwd = process.cwd();
4776
- const opencodeDir = findOpenCodeDir(cwd) || join11(cwd, ".opencode");
4777
- const statePath = join11(opencodeDir, "ostacky-state.json");
5073
+ const opencodeDir = findOpenCodeDir(cwd) || join12(cwd, ".opencode");
5074
+ const statePath = join12(opencodeDir, "ostacky-state.json");
4778
5075
  let hasError = false;
4779
5076
  let hasWarn = false;
4780
5077
  const check = (label, ok, warn = false) => {
@@ -4789,26 +5086,26 @@ async function runDoctorCommand() {
4789
5086
  }
4790
5087
  };
4791
5088
  const pluginPaths = [
4792
- join11(cwd, "assets", "plugins", "ostacky-controller", "index.ts"),
4793
- join11(opencodeDir, "plugins", "ostacky-controller", "index.ts"),
4794
- join11(cwd, ".opencode", "plugins", "ostacky-controller", "index.ts"),
4795
- join11(cwd, "assets", "plugins", "ostacky-plugin.ts"),
4796
- join11(opencodeDir, "plugins", "ostacky-plugin.ts"),
4797
- join11(cwd, ".opencode", "plugins", "ostacky-plugin.ts"),
4798
- join11(cwd, "assets", "plugins", "ostacky-controller.ts"),
4799
- join11(opencodeDir, "plugins", "ostacky-controller.ts"),
4800
- join11(cwd, ".opencode", "plugins", "ostacky-controller.ts")
5089
+ join12(cwd, "assets", "plugins", "ostacky-controller", "index.ts"),
5090
+ join12(opencodeDir, "plugins", "ostacky-controller", "index.ts"),
5091
+ join12(cwd, ".opencode", "plugins", "ostacky-controller", "index.ts"),
5092
+ join12(cwd, "assets", "plugins", "ostacky-plugin.ts"),
5093
+ join12(opencodeDir, "plugins", "ostacky-plugin.ts"),
5094
+ join12(cwd, ".opencode", "plugins", "ostacky-plugin.ts"),
5095
+ join12(cwd, "assets", "plugins", "ostacky-controller.ts"),
5096
+ join12(opencodeDir, "plugins", "ostacky-controller.ts"),
5097
+ join12(cwd, ".opencode", "plugins", "ostacky-controller.ts")
4801
5098
  ];
4802
- const pluginActive = pluginPaths.some((p) => existsSync9(p));
5099
+ const pluginActive = pluginPaths.some((p) => existsSync10(p));
4803
5100
  try {
4804
- if (!existsSync9(statePath)) {
5101
+ if (!existsSync10(statePath)) {
4805
5102
  if (pluginActive)
4806
5103
  console.log(`✅ controller: plugin active (no state yet)`);
4807
5104
  else
4808
5105
  check("controller: state file missing", false, true);
4809
5106
  } else {
4810
- const stat = statSync3(statePath);
4811
- const raw = readFileSync7(statePath, "utf-8");
5107
+ const stat = statSync4(statePath);
5108
+ const raw = readFileSync8(statePath, "utf-8");
4812
5109
  const parsed = JSON.parse(raw);
4813
5110
  if (pluginActive) {
4814
5111
  console.log(`✅ controller: plugin active (rev ${parsed.revision || 0} state ${parsed.state || "unknown"})`);
@@ -4872,15 +5169,15 @@ async function runDoctorCommand() {
4872
5169
  check(`controller: ${e.message}`, false);
4873
5170
  }
4874
5171
  try {
4875
- const lockPid = join11(opencodeDir, "ostacky-state.json.lock.pid");
4876
- const lockTs = join11(opencodeDir, "ostacky-state.json.lock.timestamp");
4877
- if (existsSync9(lockPid) || existsSync9(lockTs)) {
5172
+ const lockPid = join12(opencodeDir, "ostacky-state.json.lock.pid");
5173
+ const lockTs = join12(opencodeDir, "ostacky-state.json.lock.timestamp");
5174
+ if (existsSync10(lockPid) || existsSync10(lockTs)) {
4878
5175
  let ageStr = "";
4879
5176
  try {
4880
- const ts = parseInt(readFileSync7(lockTs, "utf-8"), 10);
5177
+ const ts = parseInt(readFileSync8(lockTs, "utf-8"), 10);
4881
5178
  const age = Date.now() - ts;
4882
5179
  ageStr = `${Math.floor(age / 1000)}s`;
4883
- const pid = readFileSync7(lockPid, "utf-8").trim();
5180
+ const pid = readFileSync8(lockPid, "utf-8").trim();
4884
5181
  let alive = false;
4885
5182
  try {
4886
5183
  process.kill(parseInt(pid, 10), 0);
@@ -4898,21 +5195,23 @@ async function runDoctorCommand() {
4898
5195
  }
4899
5196
  const tools = ["codegraph", "engram"];
4900
5197
  for (const t of tools) {
4901
- const p = join11(opencodeDir, "tools", t, "bin", t);
5198
+ const p = join12(opencodeDir, "tools", t, "bin", t);
4902
5199
  const pExe = p + ".exe";
4903
- check(`tool ${t}: ${existsSync9(p) || existsSync9(pExe) ? "found" : "missing"}`, existsSync9(p) || existsSync9(pExe), true);
5200
+ check(`tool ${t}: ${existsSync10(p) || existsSync10(pExe) ? "found" : "missing"}`, existsSync10(p) || existsSync10(pExe), true);
4904
5201
  }
4905
5202
  try {
4906
- const manifest = JSON.parse(readFileSync7(join11(cwd, "manifest.json"), "utf-8"));
4907
- const expected = manifest.mcpServers?.find((x) => x.name === "ostacky-controller")?.sha256;
5203
+ const name = "ostacky-controller";
5204
+ const { field, actual } = mcpArtifactHash(name);
5205
+ const expected = getBundledExpectedHash("mcpServers", name, field);
4908
5206
  if (expected) {
4909
- const actual = computeTreeHash(join11(cwd, "assets", "mcp", "ostacky-controller"));
4910
- check(`manifest hash: ${expected.slice(0, 8)} vs actual ${actual.slice(0, 8)}`, expected === actual);
5207
+ check(`manifest ${field}: ${expected.slice(0, 8)} vs actual ${actual.slice(0, 8)}`, expected === actual);
4911
5208
  if (expected !== actual)
4912
5209
  console.log(" Run: bun run hash:update");
5210
+ } else {
5211
+ check(`manifest ${field}: sin entrada para ${name}`, false, true);
4913
5212
  }
4914
5213
  } catch {
4915
- check("manifest: not found", false, true);
5214
+ check("manifest: no se pudo verificar", false, true);
4916
5215
  }
4917
5216
  try {
4918
5217
  await Promise.resolve().then(() => init_doctor_v2());
@@ -4924,22 +5223,22 @@ async function runDoctorCommand() {
4924
5223
  } catch {
4925
5224
  check("doctor-v2: check failed", false, true);
4926
5225
  }
4927
- if (existsSync9(statePath)) {
5226
+ if (existsSync10(statePath)) {
4928
5227
  try {
4929
- const s = JSON.parse(readFileSync7(statePath, "utf-8"));
5228
+ const s = JSON.parse(readFileSync8(statePath, "utf-8"));
4930
5229
  if (s.allowedFiles || s.deniedFiles) {}
4931
5230
  } catch {}
4932
5231
  }
4933
5232
  try {
4934
- const cacheDir = join11(opencodeDir, "cache", "codegraph");
4935
- if (!existsSync9(cacheDir)) {
5233
+ const cacheDir = join12(opencodeDir, "cache", "codegraph");
5234
+ if (!existsSync10(cacheDir)) {
4936
5235
  console.log("ℹ️ cache: no cache dir yet (ok)");
4937
5236
  } else {
4938
5237
  const files = readdirSync4(cacheDir);
4939
5238
  let total = 0;
4940
5239
  for (const f of files) {
4941
5240
  try {
4942
- total += statSync3(join11(cacheDir, f)).size;
5241
+ total += statSync4(join12(cacheDir, f)).size;
4943
5242
  } catch {}
4944
5243
  }
4945
5244
  const totalMB = (total / 1048576).toFixed(2);
@@ -4950,7 +5249,7 @@ async function runDoctorCommand() {
4950
5249
  console.log(`✅ cache: OK (${files.length} files, ${totalMB}MB)`);
4951
5250
  }
4952
5251
  try {
4953
- const s = JSON.parse(readFileSync7(statePath, "utf-8"));
5252
+ const s = JSON.parse(readFileSync8(statePath, "utf-8"));
4954
5253
  if (s.cacheHitCount !== undefined) {
4955
5254
  console.log(`ℹ️ cacheHitCount=${s.cacheHitCount} cacheMissCount=${s.cacheMissCount || 0} tokenSavingEstimate=${s.tokenSavingEstimate || 0}`);
4956
5255
  }
@@ -4960,29 +5259,29 @@ async function runDoctorCommand() {
4960
5259
  console.log(`⚠️ cache: check failed ${e.message}`);
4961
5260
  }
4962
5261
  try {
4963
- const coreSrc = join11(cwd, "src", "controller-core.ts");
4964
- const coreMcp = join11(cwd, "assets", "mcp", "ostacky-controller", "controller-core.js");
4965
- const corePlugin = join11(cwd, "assets", "plugins", "controller-core.ts");
4966
- const coreSync = existsSync9(coreSrc) && existsSync9(coreMcp) && existsSync9(corePlugin);
5262
+ const coreSrc = join12(cwd, "src", "controller-core.ts");
5263
+ const coreMcp = join12(cwd, "assets", "mcp", "ostacky-controller", "controller-core.js");
5264
+ const corePlugin = join12(cwd, "assets", "plugins", "controller-core.ts");
5265
+ const coreSync = existsSync10(coreSrc) && existsSync10(coreMcp) && existsSync10(corePlugin);
4967
5266
  if (coreSync) {
4968
- const srcHash = readFileSync7(coreSrc, "utf-8").slice(0, 100);
4969
- const mcpHash = readFileSync7(coreMcp, "utf-8").slice(0, 100);
4970
- const ok = readFileSync7(coreMcp, "utf-8").includes("STATES") && readFileSync7(corePlugin, "utf-8").includes("STATES");
5267
+ const srcHash = readFileSync8(coreSrc, "utf-8").slice(0, 100);
5268
+ const mcpHash = readFileSync8(coreMcp, "utf-8").slice(0, 100);
5269
+ const ok = readFileSync8(coreMcp, "utf-8").includes("STATES") && readFileSync8(corePlugin, "utf-8").includes("STATES");
4971
5270
  check(`controller-core: synced (${ok ? "STATES present" : "mismatch"})`, ok);
4972
5271
  if (!ok)
4973
5272
  console.log(" Run: bun run scripts/sync-controller-core.ts (if exists) or copy src/controller-core.ts");
4974
5273
  } else {
4975
5274
  check("controller-core: synced", false, true);
4976
5275
  }
4977
- const auditPath = join11(opencodeDir, "ostacky-audit.jsonl");
4978
- if (existsSync9(auditPath)) {
4979
- const sz = statSync3(auditPath).size;
4980
- const lines = readFileSync7(auditPath, "utf-8").split(`
5276
+ const auditPath = join12(opencodeDir, "ostacky-audit.jsonl");
5277
+ if (existsSync10(auditPath)) {
5278
+ const sz = statSync4(auditPath).size;
5279
+ const lines = readFileSync8(auditPath, "utf-8").split(`
4981
5280
  `).filter(Boolean).length;
4982
5281
  check(`audit: jsonl ${lines} entries, ${(sz / 1024).toFixed(1)}KB`, sz < 512000);
4983
- if (existsSync9(statePath)) {
4984
- const s = JSON.parse(readFileSync7(statePath, "utf-8"));
4985
- const stateSize = statSync3(statePath).size;
5282
+ if (existsSync10(statePath)) {
5283
+ const s = JSON.parse(readFileSync8(statePath, "utf-8"));
5284
+ const stateSize = statSync4(statePath).size;
4986
5285
  check(`state size <50KB (${(stateSize / 1024).toFixed(1)}KB)`, stateSize < 51200);
4987
5286
  if (s.audit && s.audit.length > 20)
4988
5287
  console.log(`⚠️ state.audit large: ${s.audit.length} (should be tail only, full in jsonl)`);
@@ -4992,16 +5291,16 @@ async function runDoctorCommand() {
4992
5291
  } else {
4993
5292
  console.log("ℹ️ audit: jsonl not yet created (will be created on next audit)");
4994
5293
  }
4995
- const ostackyMd = readFileSync7(join11(cwd, "assets", "agents", "ostacky.md"), "utf-8");
5294
+ const ostackyMd = readFileSync8(join12(cwd, "assets", "agents", "ostacky.md"), "utf-8");
4996
5295
  const hasLevels = ostackyMd.includes("LEVEL_THRESHOLDS") || ostackyMd.includes("classifyLevel");
4997
5296
  check("levels: unified via tiered.ts", hasLevels, true);
4998
5297
  const hasHonesty = ostackyMd.includes("Principios de honestidad");
4999
5298
  check("honesty: 7 SHALL", hasHonesty);
5000
5299
  if (!hasHonesty)
5001
5300
  console.log(" Expected: ## Principios de honestidad (SHALL) in ostacky.md");
5002
- const pluginPath = join11(cwd, "assets", "plugins", "ostacky-controller", "index.ts");
5003
- if (existsSync9(pluginPath)) {
5004
- const plugin = readFileSync7(pluginPath, "utf-8");
5301
+ const pluginPath = join12(cwd, "assets", "plugins", "ostacky-controller", "index.ts");
5302
+ if (existsSync10(pluginPath)) {
5303
+ const plugin = readFileSync8(pluginPath, "utf-8");
5005
5304
  const hasNoOverwrite = plugin.includes("shouldBlockCodeRead") && plugin.includes("isCodeReadGated") && plugin.includes("isTaskTracked") && plugin.includes("isShellPathExempt");
5006
5305
  check("spec/tracked read-guard (shouldBlockCodeRead + exemptions)", hasNoOverwrite, true);
5007
5306
  }
@@ -5011,12 +5310,12 @@ async function runDoctorCommand() {
5011
5310
  console.log(`⚠️ honesty/spec checks failed: ${e.message}`);
5012
5311
  }
5013
5312
  try {
5014
- const giPath = join11(cwd, ".gitignore");
5015
- if (!existsSync9(giPath)) {
5313
+ const giPath = join12(cwd, ".gitignore");
5314
+ if (!existsSync10(giPath)) {
5016
5315
  console.log("⚠️ .gitignore: missing (run npx ostacky install --scope local to create)");
5017
5316
  hasWarn = true;
5018
5317
  } else {
5019
- const gi = readFileSync7(giPath, "utf-8");
5318
+ const gi = readFileSync8(giPath, "utf-8");
5020
5319
  const needed = [
5021
5320
  ".opencode/tools/",
5022
5321
  ".opencode/cache/",
@@ -5036,12 +5335,12 @@ async function runDoctorCommand() {
5036
5335
  }
5037
5336
  } catch {}
5038
5337
  try {
5039
- const secPath = join11(cwd, "src", "security.ts");
5040
- if (!existsSync9(secPath)) {
5338
+ const secPath = join12(cwd, "src", "security.ts");
5339
+ if (!existsSync10(secPath)) {
5041
5340
  console.log("⚠️ src/security.ts: missing (source-of-truth)");
5042
5341
  hasWarn = true;
5043
5342
  } else {
5044
- const sec = readFileSync7(secPath, "utf-8");
5343
+ const sec = readFileSync8(secPath, "utf-8");
5045
5344
  const hasSensitiveDefault = sec.includes("SENSITIVE_DEFAULT");
5046
5345
  const hasBashRe = sec.includes("BASH_SENSITIVE_RE");
5047
5346
  const hasIsSensitive = sec.includes("function isSensitive");
@@ -5055,7 +5354,7 @@ async function runDoctorCommand() {
5055
5354
  }
5056
5355
  } catch {}
5057
5356
  try {
5058
- const s = JSON.parse(readFileSync7(statePath, "utf-8"));
5357
+ const s = JSON.parse(readFileSync8(statePath, "utf-8"));
5059
5358
  if (s.sensitiveAccess?.blockedAttempts > 0) {
5060
5359
  console.log(`ℹ️ sensitiveAccess: blockedAttempts includes bash (${s.sensitiveAccess.blockedAttempts})`);
5061
5360
  }
@@ -5068,14 +5367,14 @@ async function runDoctorCommand() {
5068
5367
  async function runStatusCommand(args) {
5069
5368
  const isJson = args.includes("--json");
5070
5369
  const cwd = process.cwd();
5071
- const opencodeDir = findOpenCodeDir(cwd) || join11(cwd, ".opencode");
5072
- const statePath = join11(opencodeDir, "ostacky-state.json");
5073
- if (!existsSync9(statePath)) {
5370
+ const opencodeDir = findOpenCodeDir(cwd) || join12(cwd, ".opencode");
5371
+ const statePath = join12(opencodeDir, "ostacky-state.json");
5372
+ if (!existsSync10(statePath)) {
5074
5373
  console.log(isJson ? JSON.stringify({ error: "no state" }) : "No state file");
5075
5374
  return;
5076
5375
  }
5077
5376
  try {
5078
- const parsed = JSON.parse(readFileSync7(statePath, "utf-8"));
5377
+ const parsed = JSON.parse(readFileSync8(statePath, "utf-8"));
5079
5378
  const completed = Object.values(parsed.tasks || {}).filter((t) => t.status === "COMPLETED").length;
5080
5379
  const expected = parsed.expectedTaskCount ?? parsed.expectedTasks?.length ?? Object.keys(parsed.tasks || {}).length;
5081
5380
  const degraded = parsed.degraded ? " degraded" : "";
@@ -5103,9 +5402,15 @@ async function main() {
5103
5402
  await ensureOpencodeInstalled();
5104
5403
  }
5105
5404
  switch (cmd) {
5106
- case "install":
5405
+ case "install": {
5406
+ await Promise.resolve().then(() => init_doctor_v2());
5407
+ const globalArtifacts = globalOstackyArtifacts();
5408
+ if (scope !== "global" && globalArtifacts.length > 0) {
5409
+ console.error(`Aviso: hay artefactos de Ostacky en la instalación global (${globalArtifacts.join(", ")}). ` + `Podés limpiarlos con: npx ostacky uninstall --scope global`);
5410
+ }
5107
5411
  await runInstallCommand(scope, { noStack });
5108
5412
  break;
5413
+ }
5109
5414
  case "install-stack":
5110
5415
  if (scope === "global") {
5111
5416
  console.error(`Aviso: el stack (CodeGraph/Engram) se instala siempre local por proyecto. Ignorando --scope global y usando local.`);