@sechroom/cli 2026.7.19 → 2026.7.20-rc.5cee4cf5
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/README.md +43 -19
- package/dist/index.js +1292 -1127
- package/package.json +1 -1
package/dist/index.js
CHANGED
|
@@ -1518,8 +1518,8 @@ target:gpt-codex-agent), the dispatchable workers your loop skills call
|
|
|
1518
1518
|
}
|
|
1519
1519
|
|
|
1520
1520
|
// src/commands/channel.ts
|
|
1521
|
-
import { existsSync as
|
|
1522
|
-
import { dirname as
|
|
1521
|
+
import { existsSync as existsSync8, mkdirSync as mkdirSync7, readFileSync as readFileSync6, writeFileSync as writeFileSync7 } from "fs";
|
|
1522
|
+
import { dirname as dirname6, join as join9 } from "path";
|
|
1523
1523
|
import {
|
|
1524
1524
|
HttpTransportType,
|
|
1525
1525
|
HubConnectionBuilder
|
|
@@ -1527,52 +1527,218 @@ import {
|
|
|
1527
1527
|
import { Server } from "@modelcontextprotocol/sdk/server/index.js";
|
|
1528
1528
|
import { StdioServerTransport } from "@modelcontextprotocol/sdk/server/stdio.js";
|
|
1529
1529
|
|
|
1530
|
+
// src/commands/executor.ts
|
|
1531
|
+
import { existsSync as existsSync7, mkdirSync as mkdirSync6, readFileSync as readFileSync5, writeFileSync as writeFileSync6 } from "fs";
|
|
1532
|
+
import { dirname as dirname5, join as join8 } from "path";
|
|
1533
|
+
|
|
1534
|
+
// src/sem.ts
|
|
1535
|
+
import { dirname as dirname2, join as join5 } from "path";
|
|
1536
|
+
import { appendFileSync, existsSync as existsSync4, mkdirSync as mkdirSync4, readdirSync, readFileSync as readFileSync3, statSync, writeFileSync as writeFileSync4 } from "fs";
|
|
1537
|
+
var SEM_FILE = join5(".sechroom", "lane.json");
|
|
1538
|
+
var STATE_DIR_NAME2 = ".sechroom";
|
|
1539
|
+
function localSemPath(cwd = process.cwd()) {
|
|
1540
|
+
return join5(cwd, SEM_FILE);
|
|
1541
|
+
}
|
|
1542
|
+
function resolveSemPathForRead(start = process.cwd()) {
|
|
1543
|
+
let dir = start;
|
|
1544
|
+
while (true) {
|
|
1545
|
+
const candidate = join5(dir, SEM_FILE);
|
|
1546
|
+
if (existsSync4(candidate)) return candidate;
|
|
1547
|
+
const parent = dirname2(dir);
|
|
1548
|
+
if (parent === dir) return void 0;
|
|
1549
|
+
dir = parent;
|
|
1550
|
+
}
|
|
1551
|
+
}
|
|
1552
|
+
function applyWorktreeLaneSuffix(lane, start = process.cwd()) {
|
|
1553
|
+
try {
|
|
1554
|
+
let dir = start;
|
|
1555
|
+
let gitPath;
|
|
1556
|
+
for (; ; ) {
|
|
1557
|
+
const candidate = join5(dir, ".git");
|
|
1558
|
+
if (existsSync4(candidate)) {
|
|
1559
|
+
gitPath = candidate;
|
|
1560
|
+
break;
|
|
1561
|
+
}
|
|
1562
|
+
const parent = dirname2(dir);
|
|
1563
|
+
if (parent === dir) break;
|
|
1564
|
+
dir = parent;
|
|
1565
|
+
}
|
|
1566
|
+
if (!gitPath || statSync(gitPath).isDirectory()) return lane;
|
|
1567
|
+
const gitFile = readFileSync3(gitPath, "utf8");
|
|
1568
|
+
const common = gitFile.trim().match(/^gitdir:\s*(.+)\/worktrees\/[^/\s]+\s*$/);
|
|
1569
|
+
if (!common) return lane;
|
|
1570
|
+
const worktreesDir = join5(common[1], "worktrees");
|
|
1571
|
+
const siblings = readdirSync(worktreesDir).filter((n) => {
|
|
1572
|
+
try {
|
|
1573
|
+
return statSync(join5(worktreesDir, n)).isDirectory();
|
|
1574
|
+
} catch {
|
|
1575
|
+
return false;
|
|
1576
|
+
}
|
|
1577
|
+
});
|
|
1578
|
+
return laneWithWorktreeSuffix(lane, gitFile, siblings);
|
|
1579
|
+
} catch {
|
|
1580
|
+
return lane;
|
|
1581
|
+
}
|
|
1582
|
+
}
|
|
1583
|
+
function laneWithWorktreeSuffix(lane, gitFile, siblings) {
|
|
1584
|
+
const m = gitFile.trim().match(/\/worktrees\/([^/\s]+)\s*$/);
|
|
1585
|
+
if (!m) return lane;
|
|
1586
|
+
const idx = [...siblings].sort().indexOf(m[1]);
|
|
1587
|
+
return idx < 0 ? lane : `${lane}-${idx + 2}`;
|
|
1588
|
+
}
|
|
1589
|
+
function serializeSem(values) {
|
|
1590
|
+
return JSON.stringify(values, null, 2) + "\n";
|
|
1591
|
+
}
|
|
1592
|
+
function readSem(path) {
|
|
1593
|
+
const p = path ?? resolveSemPathForRead();
|
|
1594
|
+
if (!p || !existsSync4(p)) return void 0;
|
|
1595
|
+
return { path: p, values: parseLaneJson(readFileSync3(p, "utf8")) };
|
|
1596
|
+
}
|
|
1597
|
+
function readLocalSemValues(cwd = process.cwd()) {
|
|
1598
|
+
const next = join5(cwd, SEM_FILE);
|
|
1599
|
+
if (existsSync4(next)) return readSem(next)?.values ?? {};
|
|
1600
|
+
return {};
|
|
1601
|
+
}
|
|
1602
|
+
function parseLaneJson(text2) {
|
|
1603
|
+
try {
|
|
1604
|
+
const parsed = JSON.parse(text2);
|
|
1605
|
+
const out = {};
|
|
1606
|
+
for (const [k, v] of Object.entries(parsed)) {
|
|
1607
|
+
if (typeof v === "string") out[k] = v;
|
|
1608
|
+
}
|
|
1609
|
+
return out;
|
|
1610
|
+
} catch {
|
|
1611
|
+
return {};
|
|
1612
|
+
}
|
|
1613
|
+
}
|
|
1614
|
+
var STATE_DIR_IGNORE = `${STATE_DIR_NAME2}/`;
|
|
1615
|
+
function writeSem(values, path = localSemPath()) {
|
|
1616
|
+
mkdirSync4(dirname2(path), { recursive: true });
|
|
1617
|
+
writeFileSync4(path, serializeSem(values));
|
|
1618
|
+
ensureSemIgnored(path);
|
|
1619
|
+
ensureContinuityScaffold(path);
|
|
1620
|
+
return path;
|
|
1621
|
+
}
|
|
1622
|
+
function ensureStateDirIgnored(cwd = process.cwd()) {
|
|
1623
|
+
ensureSemIgnored(localSemPath(cwd));
|
|
1624
|
+
}
|
|
1625
|
+
var CONTINUITY_FILE_NAME = "continuity.json";
|
|
1626
|
+
var CONTINUITY_SCAFFOLD = JSON.stringify(
|
|
1627
|
+
{
|
|
1628
|
+
_readme: "Agent-maintained continuity intent. Keep these current during the session; `sechroom checkpoint` and the PreCompact hook snapshot from here. The five required fields (objective, state, lastAction, nextAction, resumeInstruction) must all be non-empty for a snapshot to be created.",
|
|
1629
|
+
objective: "",
|
|
1630
|
+
state: "",
|
|
1631
|
+
lastAction: "",
|
|
1632
|
+
nextAction: "",
|
|
1633
|
+
resumeInstruction: "",
|
|
1634
|
+
constraints: [],
|
|
1635
|
+
questions: [],
|
|
1636
|
+
artifacts: [],
|
|
1637
|
+
confidence: null
|
|
1638
|
+
},
|
|
1639
|
+
null,
|
|
1640
|
+
2
|
|
1641
|
+
) + "\n";
|
|
1642
|
+
function ensureContinuityScaffold(semPath) {
|
|
1643
|
+
try {
|
|
1644
|
+
const target = join5(dirname2(semPath), CONTINUITY_FILE_NAME);
|
|
1645
|
+
if (existsSync4(target)) return;
|
|
1646
|
+
writeFileSync4(target, CONTINUITY_SCAFFOLD);
|
|
1647
|
+
} catch {
|
|
1648
|
+
}
|
|
1649
|
+
}
|
|
1650
|
+
function ignoresSem(content) {
|
|
1651
|
+
return content.split("\n").some((line) => {
|
|
1652
|
+
const t = line.trim();
|
|
1653
|
+
return t === STATE_DIR_NAME2 || t === STATE_DIR_IGNORE || t === `/${STATE_DIR_NAME2}` || t === `/${STATE_DIR_IGNORE}` || t === `**/${STATE_DIR_NAME2}` || t === `**/${STATE_DIR_IGNORE}`;
|
|
1654
|
+
});
|
|
1655
|
+
}
|
|
1656
|
+
function inGitRepo(startDir) {
|
|
1657
|
+
let dir = startDir;
|
|
1658
|
+
for (; ; ) {
|
|
1659
|
+
if (existsSync4(join5(dir, ".git"))) return true;
|
|
1660
|
+
const parent = dirname2(dir);
|
|
1661
|
+
if (parent === dir) return false;
|
|
1662
|
+
dir = parent;
|
|
1663
|
+
}
|
|
1664
|
+
}
|
|
1665
|
+
function resolveGitignoreTarget(startDir) {
|
|
1666
|
+
let dir = startDir;
|
|
1667
|
+
for (; ; ) {
|
|
1668
|
+
const gi = join5(dir, ".gitignore");
|
|
1669
|
+
if (existsSync4(gi)) return { path: gi, exists: true };
|
|
1670
|
+
const parent = dirname2(dir);
|
|
1671
|
+
if (existsSync4(join5(dir, ".git")) || parent === dir) {
|
|
1672
|
+
return { path: join5(startDir, ".gitignore"), exists: false };
|
|
1673
|
+
}
|
|
1674
|
+
dir = parent;
|
|
1675
|
+
}
|
|
1676
|
+
}
|
|
1677
|
+
function ensureSemIgnored(semPath) {
|
|
1678
|
+
try {
|
|
1679
|
+
const checkoutDir = dirname2(dirname2(semPath));
|
|
1680
|
+
if (!inGitRepo(checkoutDir)) return;
|
|
1681
|
+
const target = resolveGitignoreTarget(checkoutDir);
|
|
1682
|
+
if (target.exists) {
|
|
1683
|
+
const content = readFileSync3(target.path, "utf8");
|
|
1684
|
+
if (ignoresSem(content)) return;
|
|
1685
|
+
const sep = content.length === 0 || content.endsWith("\n") ? "" : "\n";
|
|
1686
|
+
appendFileSync(target.path, `${sep}${STATE_DIR_IGNORE}
|
|
1687
|
+
`);
|
|
1688
|
+
} else {
|
|
1689
|
+
writeFileSync4(target.path, `${STATE_DIR_IGNORE}
|
|
1690
|
+
`);
|
|
1691
|
+
}
|
|
1692
|
+
} catch {
|
|
1693
|
+
}
|
|
1694
|
+
}
|
|
1695
|
+
|
|
1530
1696
|
// src/commands/hook-install.ts
|
|
1531
|
-
import { existsSync as
|
|
1532
|
-
import { delimiter, dirname as
|
|
1697
|
+
import { existsSync as existsSync6, mkdirSync as mkdirSync5, readFileSync as readFileSync4, writeFileSync as writeFileSync5 } from "fs";
|
|
1698
|
+
import { delimiter, dirname as dirname4, join as join7 } from "path";
|
|
1533
1699
|
|
|
1534
1700
|
// src/setup/clients.ts
|
|
1535
|
-
import { existsSync as
|
|
1701
|
+
import { existsSync as existsSync5 } from "fs";
|
|
1536
1702
|
import { homedir as homedir3 } from "os";
|
|
1537
|
-
import { dirname as
|
|
1703
|
+
import { dirname as dirname3, join as join6 } from "path";
|
|
1538
1704
|
function claudeDesktopConfigPath(home) {
|
|
1539
1705
|
switch (process.platform) {
|
|
1540
1706
|
case "darwin":
|
|
1541
|
-
return
|
|
1707
|
+
return join6(home, "Library", "Application Support", "Claude", "claude_desktop_config.json");
|
|
1542
1708
|
case "win32":
|
|
1543
|
-
return
|
|
1709
|
+
return join6(process.env.APPDATA ?? join6(home, "AppData", "Roaming"), "Claude", "claude_desktop_config.json");
|
|
1544
1710
|
default:
|
|
1545
|
-
return
|
|
1711
|
+
return join6(home, ".config", "Claude", "claude_desktop_config.json");
|
|
1546
1712
|
}
|
|
1547
1713
|
}
|
|
1548
1714
|
function clientTargets(cwd, opts = {}) {
|
|
1549
1715
|
const home = homedir3();
|
|
1550
|
-
const claudeDir = opts.claudeDir ??
|
|
1551
|
-
const codexHome = opts.codexHome ??
|
|
1716
|
+
const claudeDir = opts.claudeDir ?? join6(home, ".claude");
|
|
1717
|
+
const codexHome = opts.codexHome ?? join6(home, ".codex");
|
|
1552
1718
|
return {
|
|
1553
1719
|
"claude-code": {
|
|
1554
1720
|
key: "claude-code",
|
|
1555
1721
|
label: "Claude Code",
|
|
1556
|
-
mcp: { surfaceKey: "claude-code", sectionType: SectionType.McpConfig, path:
|
|
1557
|
-
instruction: { surfaceKey: "claude-code", path:
|
|
1722
|
+
mcp: { surfaceKey: "claude-code", sectionType: SectionType.McpConfig, path: join6(cwd, ".mcp.json"), format: "json" },
|
|
1723
|
+
instruction: { surfaceKey: "claude-code", path: join6(cwd, "CLAUDE.md") }
|
|
1558
1724
|
},
|
|
1559
1725
|
"claude-desktop": {
|
|
1560
1726
|
key: "claude-desktop",
|
|
1561
1727
|
label: "Claude Desktop",
|
|
1562
1728
|
mcp: { surfaceKey: "claude-desktop", sectionType: SectionType.McpConfig, path: claudeDesktopConfigPath(home), format: "json" },
|
|
1563
|
-
instruction: { surfaceKey: "claude-desktop", path:
|
|
1729
|
+
instruction: { surfaceKey: "claude-desktop", path: join6(claudeDir, "CLAUDE.md") }
|
|
1564
1730
|
},
|
|
1565
1731
|
codex: {
|
|
1566
1732
|
key: "codex",
|
|
1567
1733
|
label: "Codex CLI",
|
|
1568
|
-
mcp: { surfaceKey: "chatgpt", sectionType: SectionType.McpConfigToml, path:
|
|
1569
|
-
instruction: { surfaceKey: "chatgpt", path:
|
|
1734
|
+
mcp: { surfaceKey: "chatgpt", sectionType: SectionType.McpConfigToml, path: join6(codexHome, "config.toml"), format: "toml" },
|
|
1735
|
+
instruction: { surfaceKey: "chatgpt", path: join6(cwd, "AGENTS.md") }
|
|
1570
1736
|
},
|
|
1571
1737
|
cursor: {
|
|
1572
1738
|
key: "cursor",
|
|
1573
1739
|
label: "Cursor",
|
|
1574
|
-
mcp: { surfaceKey: "claude-code", sectionType: SectionType.McpConfig, path:
|
|
1575
|
-
instruction: { surfaceKey: "chatgpt", path:
|
|
1740
|
+
mcp: { surfaceKey: "claude-code", sectionType: SectionType.McpConfig, path: join6(cwd, ".cursor", "mcp.json"), format: "json" },
|
|
1741
|
+
instruction: { surfaceKey: "chatgpt", path: join6(cwd, "AGENTS.md") }
|
|
1576
1742
|
},
|
|
1577
1743
|
antigravity: {
|
|
1578
1744
|
key: "antigravity",
|
|
@@ -1583,8 +1749,8 @@ function clientTargets(cwd, opts = {}) {
|
|
|
1583
1749
|
// `type` — comes from the `antigravity` server surface, so we don't
|
|
1584
1750
|
// hardcode it here. Instructions go in the project `AGENTS.md`
|
|
1585
1751
|
// (cross-tool, shared with Codex/Cursor).
|
|
1586
|
-
mcp: { surfaceKey: "antigravity", sectionType: SectionType.McpConfig, path:
|
|
1587
|
-
instruction: { surfaceKey: "antigravity", path:
|
|
1752
|
+
mcp: { surfaceKey: "antigravity", sectionType: SectionType.McpConfig, path: join6(home, ".gemini", "config", "mcp_config.json"), format: "json" },
|
|
1753
|
+
instruction: { surfaceKey: "antigravity", path: join6(cwd, "AGENTS.md") }
|
|
1588
1754
|
}
|
|
1589
1755
|
};
|
|
1590
1756
|
}
|
|
@@ -1593,11 +1759,11 @@ var DEFAULT_CLIENT_KEY = "claude-code";
|
|
|
1593
1759
|
function detectInstalledClients(cwd) {
|
|
1594
1760
|
const home = homedir3();
|
|
1595
1761
|
const detected = [];
|
|
1596
|
-
if (resolveClaudeTargets({}).some((t) =>
|
|
1597
|
-
if (
|
|
1598
|
-
if (resolveCodexHomes({}).some((d) =>
|
|
1599
|
-
if (
|
|
1600
|
-
if (
|
|
1762
|
+
if (resolveClaudeTargets({}).some((t) => existsSync5(t.dir))) detected.push("claude-code");
|
|
1763
|
+
if (existsSync5(dirname3(claudeDesktopConfigPath(home)))) detected.push("claude-desktop");
|
|
1764
|
+
if (resolveCodexHomes({}).some((d) => existsSync5(d))) detected.push("codex");
|
|
1765
|
+
if (existsSync5(join6(home, ".cursor")) || existsSync5(join6(cwd, ".cursor"))) detected.push("cursor");
|
|
1766
|
+
if (existsSync5(join6(home, ".gemini"))) detected.push("antigravity");
|
|
1601
1767
|
return detected;
|
|
1602
1768
|
}
|
|
1603
1769
|
|
|
@@ -1640,29 +1806,29 @@ function mergeHooks(config2, commands) {
|
|
|
1640
1806
|
return added;
|
|
1641
1807
|
}
|
|
1642
1808
|
function readJsonConfig2(path) {
|
|
1643
|
-
if (!
|
|
1644
|
-
const raw =
|
|
1809
|
+
if (!existsSync6(path)) return {};
|
|
1810
|
+
const raw = readFileSync4(path, "utf8");
|
|
1645
1811
|
if (!raw.trim()) return {};
|
|
1646
1812
|
return JSON.parse(raw);
|
|
1647
1813
|
}
|
|
1648
1814
|
function installHooksJson(path, commands, dryRun) {
|
|
1649
|
-
const existed =
|
|
1815
|
+
const existed = existsSync6(path) && readFileSync4(path, "utf8").trim().length > 0;
|
|
1650
1816
|
const config2 = readJsonConfig2(path);
|
|
1651
1817
|
const added = mergeHooks(config2, commands);
|
|
1652
1818
|
if (added === 0 && existed) return { path, status: "current" };
|
|
1653
1819
|
if (!dryRun) {
|
|
1654
|
-
|
|
1655
|
-
|
|
1820
|
+
mkdirSync5(dirname4(path), { recursive: true });
|
|
1821
|
+
writeFileSync5(path, JSON.stringify(config2, null, 2) + "\n");
|
|
1656
1822
|
}
|
|
1657
1823
|
return { path, status: existed ? "merged" : "created" };
|
|
1658
1824
|
}
|
|
1659
1825
|
function installClaudeCommands(claudeDir, commands, dryRun) {
|
|
1660
|
-
return installHooksJson(
|
|
1826
|
+
return installHooksJson(join7(claudeDir, "settings.json"), commands, dryRun);
|
|
1661
1827
|
}
|
|
1662
1828
|
function installCodexCommands(codexHome, commands, dryRun) {
|
|
1663
1829
|
return [
|
|
1664
|
-
installHooksJson(
|
|
1665
|
-
installCodexFeatureFlag(
|
|
1830
|
+
installHooksJson(join7(codexHome, "hooks.json"), commands, dryRun),
|
|
1831
|
+
installCodexFeatureFlag(join7(codexHome, "config.toml"), dryRun)
|
|
1666
1832
|
];
|
|
1667
1833
|
}
|
|
1668
1834
|
function ensureCodexFeaturesHooks(content) {
|
|
@@ -1686,13 +1852,13 @@ function ensureCodexFeaturesHooks(content) {
|
|
|
1686
1852
|
return { next: lines.join("\n"), changed: true };
|
|
1687
1853
|
}
|
|
1688
1854
|
function installCodexFeatureFlag(path, dryRun) {
|
|
1689
|
-
const existed =
|
|
1690
|
-
const content = existed ?
|
|
1855
|
+
const existed = existsSync6(path);
|
|
1856
|
+
const content = existed ? readFileSync4(path, "utf8") : "";
|
|
1691
1857
|
const { next, changed } = ensureCodexFeaturesHooks(content);
|
|
1692
1858
|
if (!changed) return { path, status: "current" };
|
|
1693
1859
|
if (!dryRun) {
|
|
1694
|
-
|
|
1695
|
-
|
|
1860
|
+
mkdirSync5(dirname4(path), { recursive: true });
|
|
1861
|
+
writeFileSync5(path, next);
|
|
1696
1862
|
}
|
|
1697
1863
|
return { path, status: existed ? "merged" : "created" };
|
|
1698
1864
|
}
|
|
@@ -1717,11 +1883,11 @@ function installHookSurfaces(surfaces, opts) {
|
|
|
1717
1883
|
const out = [];
|
|
1718
1884
|
for (const surface of surfaces) {
|
|
1719
1885
|
if (surface === "claude") {
|
|
1720
|
-
const path =
|
|
1886
|
+
const path = join7(opts.claudeDir, "settings.json");
|
|
1721
1887
|
out.push({ surface, results: [installHooksJson(path, CLAUDE_HOOK_COMMANDS, opts.dryRun)] });
|
|
1722
1888
|
} else {
|
|
1723
|
-
const hooksJson = installHooksJson(
|
|
1724
|
-
const featureFlag = installCodexFeatureFlag(
|
|
1889
|
+
const hooksJson = installHooksJson(join7(opts.codexHome, "hooks.json"), CODEX_HOOK_COMMANDS, opts.dryRun);
|
|
1890
|
+
const featureFlag = installCodexFeatureFlag(join7(opts.codexHome, "config.toml"), opts.dryRun);
|
|
1725
1891
|
out.push({ surface, results: [hooksJson, featureFlag] });
|
|
1726
1892
|
}
|
|
1727
1893
|
}
|
|
@@ -1741,7 +1907,7 @@ function isSechroomOnPath() {
|
|
|
1741
1907
|
for (const dir of pathEnv.split(delimiter)) {
|
|
1742
1908
|
if (!dir) continue;
|
|
1743
1909
|
for (const name of names) {
|
|
1744
|
-
if (
|
|
1910
|
+
if (existsSync6(join7(dir, name))) return true;
|
|
1745
1911
|
}
|
|
1746
1912
|
}
|
|
1747
1913
|
return false;
|
|
@@ -1754,619 +1920,901 @@ function warnIfSechroomNotOnPath(write = (s) => void process.stderr.write(s)) {
|
|
|
1754
1920
|
return true;
|
|
1755
1921
|
}
|
|
1756
1922
|
|
|
1757
|
-
// src/commands/
|
|
1758
|
-
function
|
|
1759
|
-
|
|
1760
|
-
|
|
1923
|
+
// src/commands/executor.ts
|
|
1924
|
+
function executorSubscriptionInput(name) {
|
|
1925
|
+
return {
|
|
1926
|
+
name,
|
|
1927
|
+
enabled: true,
|
|
1928
|
+
filter: { tags: ["kind:task"], workspaceScope: [] }
|
|
1929
|
+
};
|
|
1930
|
+
}
|
|
1931
|
+
function executorRegistrationInput(state, deliverySubscriptionId) {
|
|
1932
|
+
return {
|
|
1933
|
+
relayId: state.relayId,
|
|
1934
|
+
instanceKey: state.instanceKey,
|
|
1935
|
+
laneId: state.laneId ?? state.instanceKey,
|
|
1936
|
+
runtimeKind: parseRuntimeKind(state.runtime),
|
|
1937
|
+
activationMode: "Attached",
|
|
1938
|
+
deliverySubscriptionId,
|
|
1939
|
+
connectorId: state.connectorId,
|
|
1940
|
+
claimedCapabilityKeys: state.capabilityKeys,
|
|
1941
|
+
toolSetRef: null,
|
|
1942
|
+
ttlSeconds: state.ttlSeconds
|
|
1943
|
+
};
|
|
1944
|
+
}
|
|
1945
|
+
var EXECUTOR_STATE = "executor.json";
|
|
1946
|
+
var EXECUTOR_PULSE_COMMAND = "sechroom executor hook-pulse";
|
|
1947
|
+
var EXECUTOR_STOP_COMMAND = "sechroom executor hook-stop";
|
|
1948
|
+
var CLAUDE_EXECUTOR_HOOKS = {
|
|
1949
|
+
SessionStart: EXECUTOR_PULSE_COMMAND,
|
|
1950
|
+
UserPromptSubmit: EXECUTOR_PULSE_COMMAND,
|
|
1951
|
+
PreToolUse: EXECUTOR_PULSE_COMMAND,
|
|
1952
|
+
Stop: EXECUTOR_PULSE_COMMAND,
|
|
1953
|
+
SessionEnd: EXECUTOR_STOP_COMMAND
|
|
1954
|
+
};
|
|
1955
|
+
var CODEX_EXECUTOR_HOOKS = {
|
|
1956
|
+
SessionStart: EXECUTOR_PULSE_COMMAND,
|
|
1957
|
+
UserPromptSubmit: EXECUTOR_PULSE_COMMAND,
|
|
1958
|
+
PreToolUse: EXECUTOR_PULSE_COMMAND,
|
|
1959
|
+
Stop: EXECUTOR_PULSE_COMMAND
|
|
1960
|
+
};
|
|
1961
|
+
function registerExecutor(program2) {
|
|
1962
|
+
const executor = program2.command("executor").description(
|
|
1963
|
+
"Register and operate a local Claude Code/Codex executor advertisement"
|
|
1761
1964
|
);
|
|
1762
|
-
|
|
1763
|
-
"
|
|
1764
|
-
|
|
1765
|
-
"
|
|
1965
|
+
executor.command("install").description(
|
|
1966
|
+
"Configure this checkout's harness to advertise itself as a WLP executor"
|
|
1967
|
+
).option("--connector <id>", "Approved local-session ConnectorDefinition id").option(
|
|
1968
|
+
"--instance-key <key>",
|
|
1969
|
+
"Stable executor identity (defaults to .sechroom/lane.json code-lane)"
|
|
1766
1970
|
).option(
|
|
1767
|
-
"--
|
|
1768
|
-
"
|
|
1769
|
-
|
|
1770
|
-
|
|
1771
|
-
"
|
|
1772
|
-
|
|
1773
|
-
|
|
1774
|
-
|
|
1775
|
-
|
|
1776
|
-
|
|
1777
|
-
|
|
1778
|
-
|
|
1779
|
-
|
|
1780
|
-
|
|
1781
|
-
|
|
1782
|
-
|
|
1783
|
-
|
|
1784
|
-
|
|
1785
|
-
|
|
1786
|
-
|
|
1787
|
-
|
|
1788
|
-
|
|
1789
|
-
|
|
1790
|
-
);
|
|
1791
|
-
const
|
|
1792
|
-
|
|
1793
|
-
|
|
1794
|
-
|
|
1795
|
-
|
|
1796
|
-
|
|
1797
|
-
|
|
1798
|
-
|
|
1799
|
-
|
|
1800
|
-
|
|
1801
|
-
|
|
1971
|
+
"--lane-id <lane>",
|
|
1972
|
+
"Canonical affinity lane (defaults to .sechroom/lane.json code-lane)"
|
|
1973
|
+
).option("--runtime <kind>", "claude-code | codex").option("--surface <surface>", "claude | codex").option(
|
|
1974
|
+
"--capability <key...>",
|
|
1975
|
+
"Capability operation keys claimed by this instance"
|
|
1976
|
+
).option(
|
|
1977
|
+
"--relay <id>",
|
|
1978
|
+
"Relay identity shared by sibling instances",
|
|
1979
|
+
"sechroom-cli-local"
|
|
1980
|
+
).option(
|
|
1981
|
+
"--subscription-name <name>",
|
|
1982
|
+
"SignalR delivery binding name",
|
|
1983
|
+
"executor-dispatch"
|
|
1984
|
+
).option("--ttl <seconds>", "Advertisement TTL (30-600)", parseInteger, 600).option(
|
|
1985
|
+
"--refresh-after <seconds>",
|
|
1986
|
+
"Minimum age before a hook refreshes",
|
|
1987
|
+
parseInteger,
|
|
1988
|
+
40
|
|
1989
|
+
).option(
|
|
1990
|
+
"-y, --yes",
|
|
1991
|
+
"Non-interactive: accept detected surface and lane defaults",
|
|
1992
|
+
false
|
|
1993
|
+
).option("--dry-run", "Show hook files without writing", false).action(async (opts, cmd) => {
|
|
1994
|
+
const globals = cmd.optsWithGlobals();
|
|
1995
|
+
const lane = readSem()?.values["code-lane"];
|
|
1996
|
+
const detected = detectHookSurfaces(process.cwd());
|
|
1997
|
+
let surface = opts.surface;
|
|
1998
|
+
let instanceKey = opts.instanceKey;
|
|
1999
|
+
let runtime = opts.runtime;
|
|
2000
|
+
let laneId = opts.laneId;
|
|
2001
|
+
let connector = opts.connector;
|
|
2002
|
+
let capabilities = opts.capability;
|
|
2003
|
+
const surfaceDefault = detected.length === 1 ? detected[0] : lane?.includes("codex") ? "codex" : "claude";
|
|
2004
|
+
if (!opts.yes && canPrompt()) {
|
|
2005
|
+
surface = await promptText(
|
|
2006
|
+
"Harness surface (claude or codex)?",
|
|
2007
|
+
surface ?? surfaceDefault
|
|
1802
2008
|
);
|
|
1803
|
-
|
|
1804
|
-
|
|
1805
|
-
|
|
1806
|
-
|
|
1807
|
-
|
|
1808
|
-
|
|
2009
|
+
instanceKey = await promptText(
|
|
2010
|
+
"Executor instance key?",
|
|
2011
|
+
instanceKey ?? lane ?? ""
|
|
2012
|
+
);
|
|
2013
|
+
laneId = await promptText(
|
|
2014
|
+
"Executor affinity lane?",
|
|
2015
|
+
laneId ?? lane ?? ""
|
|
2016
|
+
);
|
|
2017
|
+
runtime = await promptText(
|
|
2018
|
+
"Runtime (claude-code or codex)?",
|
|
2019
|
+
runtime ?? (surface === "codex" ? "codex" : "claude-code")
|
|
1809
2020
|
);
|
|
2021
|
+
connector = await promptText(
|
|
2022
|
+
"Approved local-session connector id?",
|
|
2023
|
+
connector ?? ""
|
|
2024
|
+
);
|
|
2025
|
+
const capabilityText = await promptText(
|
|
2026
|
+
"Capability keys (comma-separated; blank for none)?",
|
|
2027
|
+
capabilities?.join(",") ?? ""
|
|
2028
|
+
);
|
|
2029
|
+
capabilities = capabilityText.split(",").map((x) => x.trim()).filter(Boolean);
|
|
1810
2030
|
}
|
|
1811
|
-
|
|
1812
|
-
|
|
1813
|
-
|
|
1814
|
-
|
|
1815
|
-
|
|
1816
|
-
|
|
1817
|
-
|
|
1818
|
-
const cfg = resolveConfig(cmd.optsWithGlobals());
|
|
1819
|
-
const filter = readFilter(opts);
|
|
1820
|
-
const mcp = new Server(
|
|
1821
|
-
{ name: "sechroom", version: "0.1.0" },
|
|
1822
|
-
{
|
|
1823
|
-
capabilities: { experimental: { "claude/channel": {} } },
|
|
1824
|
-
instructions: 'Matched Sechroom substrate events arrive as <channel source="sechroom"> tags. A WLP dispatch (kind:task \u2192 status:in-progress) means a task is runnable now: load the memory id from the event, do the work, then write a closeout memory tagged wlp-decomposition:{id} + wlp-task:{taskId} + verdict:{pass|soft-fail|plan-invalid|blocked}.'
|
|
1825
|
-
}
|
|
1826
|
-
);
|
|
1827
|
-
await mcp.connect(new StdioServerTransport());
|
|
1828
|
-
await ensureSubscription(cfg, opts.name, filter);
|
|
1829
|
-
const seen = /* @__PURE__ */ new Set();
|
|
1830
|
-
const deliver = makeDeliver(filter, seen, (payload) => {
|
|
1831
|
-
const { content, meta } = summarizeEvent(payload);
|
|
1832
|
-
void mcp.notification({
|
|
1833
|
-
method: "notifications/claude/channel",
|
|
1834
|
-
params: { content, meta }
|
|
1835
|
-
}).catch(
|
|
1836
|
-
(e) => process.stderr.write(err(`channel push failed: ${String(e)}
|
|
1837
|
-
`))
|
|
2031
|
+
surface ??= surfaceDefault;
|
|
2032
|
+
instanceKey ??= lane;
|
|
2033
|
+
laneId ??= lane;
|
|
2034
|
+
runtime ??= surface === "codex" ? "codex" : "claude-code";
|
|
2035
|
+
if (!connector)
|
|
2036
|
+
fail(
|
|
2037
|
+
"executor install requires --connector (or an interactive connector id)"
|
|
1838
2038
|
);
|
|
1839
|
-
|
|
1840
|
-
|
|
1841
|
-
|
|
1842
|
-
|
|
1843
|
-
|
|
1844
|
-
|
|
1845
|
-
|
|
1846
|
-
|
|
1847
|
-
|
|
1848
|
-
|
|
1849
|
-
|
|
1850
|
-
|
|
1851
|
-
|
|
1852
|
-
|
|
1853
|
-
|
|
1854
|
-
|
|
1855
|
-
|
|
1856
|
-
|
|
1857
|
-
|
|
1858
|
-
|
|
1859
|
-
|
|
1860
|
-
|
|
1861
|
-
|
|
1862
|
-
|
|
1863
|
-
|
|
1864
|
-
|
|
1865
|
-
|
|
1866
|
-
|
|
1867
|
-
|
|
1868
|
-
|
|
1869
|
-
for (const t of opts.tag ?? []) args.push("--tag", t);
|
|
1870
|
-
const entry = { command: "sechroom", args };
|
|
1871
|
-
const config2 = readMcpConfig(path);
|
|
1872
|
-
config2.mcpServers ??= {};
|
|
1873
|
-
const existing = config2.mcpServers[opts.name];
|
|
1874
|
-
const status = JSON.stringify(existing) === JSON.stringify(entry) ? "current" : existing ? "updated" : "created";
|
|
1875
|
-
if (status !== "current" && !dryRun) {
|
|
1876
|
-
config2.mcpServers[opts.name] = entry;
|
|
1877
|
-
mkdirSync5(dirname4(path), { recursive: true });
|
|
1878
|
-
writeFileSync5(path, JSON.stringify(config2, null, 2) + "\n");
|
|
2039
|
+
if (!instanceKey)
|
|
2040
|
+
fail(
|
|
2041
|
+
"no instance key resolved; pass --instance-key or pin .sechroom/lane.json code-lane"
|
|
2042
|
+
);
|
|
2043
|
+
if (!opts.yes && !canPrompt())
|
|
2044
|
+
fail("non-interactive executor install requires --yes");
|
|
2045
|
+
parseRuntimeKind(runtime);
|
|
2046
|
+
if (!["claude", "codex"].includes(surface))
|
|
2047
|
+
fail("surface must be claude or codex");
|
|
2048
|
+
if (opts.refreshAfter >= opts.ttl)
|
|
2049
|
+
fail("refresh-after must be shorter than the TTL");
|
|
2050
|
+
const sem = readSem();
|
|
2051
|
+
const checkout = sem ? dirname5(dirname5(sem.path)) : process.cwd();
|
|
2052
|
+
const statePath = join8(checkout, ".sechroom", EXECUTOR_STATE);
|
|
2053
|
+
const state = {
|
|
2054
|
+
schemaVersion: 1,
|
|
2055
|
+
instanceKey,
|
|
2056
|
+
laneId,
|
|
2057
|
+
runtime: runtime.toLowerCase() === "codex" ? "codex" : "claude-code",
|
|
2058
|
+
connectorId: connector,
|
|
2059
|
+
capabilityKeys: capabilities ?? [],
|
|
2060
|
+
relayId: opts.relay,
|
|
2061
|
+
subscriptionName: opts.subscriptionName,
|
|
2062
|
+
ttlSeconds: opts.ttl,
|
|
2063
|
+
refreshAfterSeconds: opts.refreshAfter
|
|
2064
|
+
};
|
|
2065
|
+
if (!opts.dryRun) {
|
|
2066
|
+
mkdirSync6(dirname5(statePath), { recursive: true });
|
|
2067
|
+
writeFileSync6(statePath, JSON.stringify(state, null, 2) + "\n");
|
|
2068
|
+
ensureStateDirIgnored(checkout);
|
|
1879
2069
|
}
|
|
1880
|
-
const
|
|
1881
|
-
|
|
1882
|
-
|
|
1883
|
-
process.
|
|
1884
|
-
|
|
2070
|
+
const configuredClaudeDirs = globals.claudeConfigDir || process.env.CLAUDE_CONFIG_DIR ? resolveClaudeTargets({ override: globals.claudeConfigDir }).map(
|
|
2071
|
+
(target) => target.dir
|
|
2072
|
+
) : [join8(checkout, ".claude")];
|
|
2073
|
+
const configuredCodexHomes = globals.codexHome || process.env.CODEX_HOME ? resolveCodexHomes({ override: globals.codexHome }) : [join8(checkout, ".codex")];
|
|
2074
|
+
const hookTargets = surface === "claude" ? configuredClaudeDirs : configuredCodexHomes;
|
|
2075
|
+
for (const target of hookTargets) {
|
|
2076
|
+
const results = surface === "claude" ? [
|
|
2077
|
+
installClaudeCommands(
|
|
2078
|
+
target,
|
|
2079
|
+
CLAUDE_EXECUTOR_HOOKS,
|
|
2080
|
+
opts.dryRun
|
|
2081
|
+
)
|
|
2082
|
+
] : installCodexCommands(target, CODEX_EXECUTOR_HOOKS, opts.dryRun);
|
|
2083
|
+
for (const result of results)
|
|
2084
|
+
process.stderr.write(describe(result, opts.dryRun) + "\n");
|
|
2085
|
+
}
|
|
2086
|
+
warnIfSechroomNotOnPath();
|
|
2087
|
+
process.stderr.write(
|
|
2088
|
+
style.green("executor harness configured") + style.dim(` \u2014 ${instanceKey}
|
|
1885
2089
|
`)
|
|
1886
2090
|
);
|
|
1887
|
-
|
|
1888
|
-
|
|
2091
|
+
});
|
|
2092
|
+
executor.command("hook-pulse").description("Hook adapter: register or refresh this checkout's executor").action(async (_opts, cmd) => {
|
|
2093
|
+
await drainStdin();
|
|
2094
|
+
const located = readExecutorState();
|
|
2095
|
+
if (!located) return;
|
|
2096
|
+
const { state, path } = located;
|
|
2097
|
+
const age = state.lastRefreshAt ? Date.now() - Date.parse(state.lastRefreshAt) : Number.POSITIVE_INFINITY;
|
|
2098
|
+
if (state.instanceId && age < state.refreshAfterSeconds * 1e3) return;
|
|
2099
|
+
const cfg = resolveConfig(cmd.optsWithGlobals());
|
|
2100
|
+
try {
|
|
2101
|
+
await ensureExecutorInstance(cfg, { state, path });
|
|
2102
|
+
} catch {
|
|
2103
|
+
}
|
|
2104
|
+
});
|
|
2105
|
+
executor.command("hook-stop").description("Hook adapter: deregister this checkout's executor").action(async (_opts, cmd) => {
|
|
2106
|
+
await drainStdin();
|
|
2107
|
+
const located = readExecutorState();
|
|
2108
|
+
if (!located?.state.instanceId) return;
|
|
2109
|
+
try {
|
|
2110
|
+
await api(
|
|
2111
|
+
resolveConfig(cmd.optsWithGlobals()),
|
|
2112
|
+
`/me/executor-instances/${encodeURIComponent(located.state.instanceId)}`,
|
|
2113
|
+
{ method: "DELETE", body: JSON.stringify({}) }
|
|
2114
|
+
);
|
|
2115
|
+
delete located.state.instanceId;
|
|
2116
|
+
delete located.state.lastRefreshAt;
|
|
2117
|
+
writeFileSync6(
|
|
2118
|
+
located.path,
|
|
2119
|
+
JSON.stringify(located.state, null, 2) + "\n"
|
|
2120
|
+
);
|
|
2121
|
+
} catch {
|
|
2122
|
+
}
|
|
2123
|
+
});
|
|
2124
|
+
executor.command("submit-connector").description(
|
|
2125
|
+
"Submit a local-session connector definition for governed approval"
|
|
2126
|
+
).requiredOption("--slug <slug>", "Unique connector definition slug").requiredOption("--display-name <name>", "Human-readable connector name").requiredOption("--transport <kind>", "push | pull").option("--profile <profile...>", "Advertised runtime profiles", [
|
|
2127
|
+
"base",
|
|
2128
|
+
"dotnet-10"
|
|
2129
|
+
]).action(async (opts, cmd) => {
|
|
2130
|
+
const cfg = resolveConfig(cmd.optsWithGlobals());
|
|
2131
|
+
const data = await api(cfg, "/connectors/definitions", {
|
|
2132
|
+
method: "POST",
|
|
2133
|
+
body: JSON.stringify({
|
|
2134
|
+
slug: opts.slug,
|
|
2135
|
+
displayName: opts.displayName,
|
|
2136
|
+
runtimeProfiles: opts.profile,
|
|
2137
|
+
connectorKind: "ExecutionRuntime",
|
|
2138
|
+
providerKind: "local-session",
|
|
2139
|
+
dispatchTransport: parseTransport(opts.transport)
|
|
2140
|
+
})
|
|
2141
|
+
});
|
|
2142
|
+
emit(data, Boolean(cmd.optsWithGlobals().json));
|
|
2143
|
+
if (!cmd.optsWithGlobals().json) {
|
|
2144
|
+
process.stderr.write(
|
|
1889
2145
|
style.dim(
|
|
1890
|
-
|
|
1891
|
-
Load it (Channels research preview) by launching your agent with:
|
|
1892
|
-
claude --dangerously-load-development-channels server:${opts.name}
|
|
1893
|
-
`
|
|
2146
|
+
"approve this connector definition before registering executors\n"
|
|
1894
2147
|
)
|
|
1895
2148
|
);
|
|
1896
2149
|
}
|
|
1897
|
-
warnIfSechroomNotOnPath();
|
|
1898
2150
|
});
|
|
1899
|
-
|
|
1900
|
-
"
|
|
1901
|
-
|
|
1902
|
-
|
|
1903
|
-
|
|
1904
|
-
|
|
1905
|
-
|
|
1906
|
-
|
|
1907
|
-
|
|
1908
|
-
|
|
1909
|
-
|
|
1910
|
-
)
|
|
1911
|
-
|
|
1912
|
-
|
|
1913
|
-
|
|
1914
|
-
|
|
1915
|
-
|
|
1916
|
-
|
|
1917
|
-
|
|
1918
|
-
|
|
1919
|
-
|
|
1920
|
-
|
|
2151
|
+
executor.command("register").description(
|
|
2152
|
+
"Create/reuse a SignalR binding and register this local executor instance"
|
|
2153
|
+
).requiredOption(
|
|
2154
|
+
"--instance-key <key>",
|
|
2155
|
+
"Stable key for this concrete session/lane"
|
|
2156
|
+
).requiredOption(
|
|
2157
|
+
"--connector <id>",
|
|
2158
|
+
"Approved local-session ConnectorDefinition id"
|
|
2159
|
+
).option("--runtime <kind>", "claude-code | codex", "claude-code").option(
|
|
2160
|
+
"--lane-id <lane>",
|
|
2161
|
+
"Canonical affinity lane (defaults to instance key)"
|
|
2162
|
+
).option(
|
|
2163
|
+
"--relay <id>",
|
|
2164
|
+
"Relay identity shared by sibling instances",
|
|
2165
|
+
"sechroom-cli-local"
|
|
2166
|
+
).option(
|
|
2167
|
+
"--subscription-name <name>",
|
|
2168
|
+
"SignalR delivery binding name",
|
|
2169
|
+
"executor-dispatch"
|
|
2170
|
+
).option(
|
|
2171
|
+
"--capability <key...>",
|
|
2172
|
+
"Capability operation keys claimed by this instance"
|
|
2173
|
+
).option("--tool-set-ref <ref>", "Optional governed tool-set reference").option("--ttl <seconds>", "Advertisement TTL (30-600)", parseInteger, 120).action(async (opts, cmd) => {
|
|
2174
|
+
const cfg = resolveConfig(cmd.optsWithGlobals());
|
|
2175
|
+
const subscription = await api(
|
|
2176
|
+
cfg,
|
|
2177
|
+
"/me/delivery-subscriptions/signalr",
|
|
2178
|
+
{
|
|
2179
|
+
method: "POST",
|
|
2180
|
+
body: JSON.stringify({
|
|
2181
|
+
name: opts.subscriptionName,
|
|
2182
|
+
enabled: true,
|
|
2183
|
+
// Exact executor fanout ignores this generic filter; the fixed tag only
|
|
2184
|
+
// satisfies the legacy SignalR subscription shape.
|
|
2185
|
+
filter: { tags: ["kind:task"], workspaceScope: [] }
|
|
2186
|
+
})
|
|
2187
|
+
}
|
|
2188
|
+
);
|
|
2189
|
+
const data = await api(
|
|
2190
|
+
cfg,
|
|
2191
|
+
"/me/executor-instances",
|
|
2192
|
+
{
|
|
2193
|
+
method: "POST",
|
|
2194
|
+
body: JSON.stringify({
|
|
2195
|
+
relayId: opts.relay,
|
|
2196
|
+
instanceKey: opts.instanceKey,
|
|
2197
|
+
laneId: opts.laneId ?? opts.instanceKey,
|
|
2198
|
+
runtimeKind: parseRuntimeKind(opts.runtime),
|
|
2199
|
+
activationMode: "Attached",
|
|
2200
|
+
deliverySubscriptionId: subscription.id,
|
|
2201
|
+
connectorId: opts.connector,
|
|
2202
|
+
claimedCapabilityKeys: opts.capability ?? [],
|
|
2203
|
+
toolSetRef: opts.toolSetRef ?? null,
|
|
2204
|
+
ttlSeconds: opts.ttl
|
|
2205
|
+
})
|
|
2206
|
+
}
|
|
2207
|
+
);
|
|
2208
|
+
emit(data, Boolean(cmd.optsWithGlobals().json));
|
|
2209
|
+
if (!cmd.optsWithGlobals().json)
|
|
2210
|
+
process.stderr.write(
|
|
2211
|
+
style.dim(`refresh with: sechroom executor heartbeat ${data.id}
|
|
2212
|
+
`)
|
|
2213
|
+
);
|
|
2214
|
+
});
|
|
2215
|
+
executor.command("refresh <id>").description("Refresh one advertisement lease once").option("--ttl <seconds>", "Advertisement TTL (30-600)", parseInteger, 120).action(async (id, opts, cmd) => {
|
|
2216
|
+
const data = await refreshExecutorInstance(
|
|
2217
|
+
resolveConfig(cmd.optsWithGlobals()),
|
|
2218
|
+
id,
|
|
2219
|
+
opts.ttl
|
|
2220
|
+
);
|
|
2221
|
+
emit(data, Boolean(cmd.optsWithGlobals().json));
|
|
2222
|
+
});
|
|
2223
|
+
executor.command("heartbeat <id>").description("Keep an advertisement alive until interrupted").option("--ttl <seconds>", "Advertisement TTL (30-600)", parseInteger, 120).option("--interval <seconds>", "Refresh interval", parseInteger, 40).action(async (id, opts, cmd) => {
|
|
2224
|
+
if (opts.interval >= opts.ttl)
|
|
2225
|
+
fail("heartbeat interval must be shorter than the TTL");
|
|
2226
|
+
const cfg = resolveConfig(cmd.optsWithGlobals());
|
|
2227
|
+
await refreshExecutorInstance(cfg, id, opts.ttl);
|
|
2228
|
+
process.stderr.write(
|
|
2229
|
+
style.green("executor heartbeat active") + style.dim(` \u2014 ${id}
|
|
2230
|
+
`)
|
|
2231
|
+
);
|
|
2232
|
+
await holdHeartbeat(async () => {
|
|
2233
|
+
await refreshExecutorInstance(cfg, id, opts.ttl);
|
|
2234
|
+
}, opts.interval * 1e3);
|
|
2235
|
+
});
|
|
2236
|
+
executor.command("offers <id>").description("List live dispatch offers addressed to this exact instance").action(async (id, _opts, cmd) => {
|
|
2237
|
+
const cfg = resolveConfig(cmd.optsWithGlobals());
|
|
2238
|
+
const data = await api(
|
|
2239
|
+
cfg,
|
|
2240
|
+
`/me/executor-instances/${encodeURIComponent(id)}/dispatch-offers`
|
|
2241
|
+
);
|
|
2242
|
+
emit(data, Boolean(cmd.optsWithGlobals().json));
|
|
2243
|
+
});
|
|
2244
|
+
executor.command("deregister <id>").description("Stop advertising this executor instance").action(async (id, _opts, cmd) => {
|
|
2245
|
+
const cfg = resolveConfig(cmd.optsWithGlobals());
|
|
2246
|
+
const data = await api(
|
|
2247
|
+
cfg,
|
|
2248
|
+
`/me/executor-instances/${encodeURIComponent(id)}`,
|
|
2249
|
+
{
|
|
2250
|
+
method: "DELETE",
|
|
2251
|
+
body: JSON.stringify({})
|
|
2252
|
+
}
|
|
1921
2253
|
);
|
|
2254
|
+
emit(data, Boolean(cmd.optsWithGlobals().json));
|
|
2255
|
+
});
|
|
2256
|
+
}
|
|
2257
|
+
function parseRuntimeKind(value) {
|
|
2258
|
+
switch (value.trim().toLowerCase()) {
|
|
2259
|
+
case "claude":
|
|
2260
|
+
case "claude-code":
|
|
2261
|
+
return "ClaudeCode";
|
|
2262
|
+
case "codex":
|
|
2263
|
+
return "Codex";
|
|
2264
|
+
default:
|
|
2265
|
+
return fail("runtime must be claude-code or codex");
|
|
1922
2266
|
}
|
|
1923
2267
|
}
|
|
1924
|
-
function
|
|
1925
|
-
|
|
1926
|
-
|
|
1927
|
-
|
|
1928
|
-
|
|
1929
|
-
|
|
1930
|
-
|
|
1931
|
-
|
|
2268
|
+
function parseTransport(value) {
|
|
2269
|
+
switch (value.trim().toLowerCase()) {
|
|
2270
|
+
case "push":
|
|
2271
|
+
return "Push";
|
|
2272
|
+
case "pull":
|
|
2273
|
+
return "Pull";
|
|
2274
|
+
default:
|
|
2275
|
+
return fail("transport must be push or pull");
|
|
2276
|
+
}
|
|
1932
2277
|
}
|
|
1933
|
-
async function
|
|
1934
|
-
|
|
1935
|
-
|
|
2278
|
+
async function refreshExecutorInstance(cfg, id, ttlSeconds) {
|
|
2279
|
+
return api(
|
|
2280
|
+
cfg,
|
|
2281
|
+
`/me/executor-instances/${encodeURIComponent(id)}/refresh`,
|
|
2282
|
+
{
|
|
2283
|
+
method: "POST",
|
|
2284
|
+
body: JSON.stringify({ ttlSeconds })
|
|
2285
|
+
}
|
|
2286
|
+
);
|
|
2287
|
+
}
|
|
2288
|
+
async function registerInstance(cfg, state) {
|
|
2289
|
+
const subscription = await api(
|
|
2290
|
+
cfg,
|
|
2291
|
+
"/me/delivery-subscriptions/signalr",
|
|
2292
|
+
{
|
|
2293
|
+
method: "POST",
|
|
2294
|
+
body: JSON.stringify(executorSubscriptionInput(state.subscriptionName))
|
|
2295
|
+
}
|
|
2296
|
+
);
|
|
2297
|
+
return api(cfg, "/me/executor-instances", {
|
|
1936
2298
|
method: "POST",
|
|
2299
|
+
body: JSON.stringify(executorRegistrationInput(state, subscription.id))
|
|
2300
|
+
});
|
|
2301
|
+
}
|
|
2302
|
+
async function ensureExecutorInstance(cfg, located) {
|
|
2303
|
+
const { state, path } = located;
|
|
2304
|
+
state.laneId ??= state.instanceKey;
|
|
2305
|
+
const data = await registerInstance(cfg, state);
|
|
2306
|
+
state.instanceId = data.id;
|
|
2307
|
+
state.lastRefreshAt = (/* @__PURE__ */ new Date()).toISOString();
|
|
2308
|
+
writeFileSync6(path, JSON.stringify(state, null, 2) + "\n");
|
|
2309
|
+
return data;
|
|
2310
|
+
}
|
|
2311
|
+
function readExecutorState(start = process.cwd()) {
|
|
2312
|
+
const semPath = resolveSemPathForRead(start);
|
|
2313
|
+
const sem = semPath ? readSem(semPath) : void 0;
|
|
2314
|
+
const path = join8(
|
|
2315
|
+
sem ? dirname5(sem.path) : join8(start, ".sechroom"),
|
|
2316
|
+
EXECUTOR_STATE
|
|
2317
|
+
);
|
|
2318
|
+
if (!existsSync7(path)) return void 0;
|
|
2319
|
+
return {
|
|
2320
|
+
state: JSON.parse(readFileSync5(path, "utf8")),
|
|
2321
|
+
path
|
|
2322
|
+
};
|
|
2323
|
+
}
|
|
2324
|
+
async function drainStdin() {
|
|
2325
|
+
if (process.stdin.isTTY) return;
|
|
2326
|
+
for await (const _chunk of process.stdin) {
|
|
2327
|
+
}
|
|
2328
|
+
}
|
|
2329
|
+
async function api(cfg, path, init) {
|
|
2330
|
+
const token = await requireToken(cfg);
|
|
2331
|
+
const response = await fetch(`${cfg.baseUrl}${path}`, {
|
|
2332
|
+
...init,
|
|
1937
2333
|
headers: {
|
|
1938
2334
|
authorization: `Bearer ${token}`,
|
|
1939
2335
|
tenant: cfg.tenant,
|
|
1940
2336
|
"content-type": "application/json",
|
|
1941
2337
|
"x-sechroom-surface": "cli"
|
|
1942
|
-
}
|
|
1943
|
-
body: JSON.stringify({ name, enabled: true, filter })
|
|
2338
|
+
}
|
|
1944
2339
|
});
|
|
1945
|
-
if (!
|
|
2340
|
+
if (!response.ok)
|
|
1946
2341
|
fail(
|
|
1947
|
-
|
|
2342
|
+
`${init?.method ?? "GET"} ${path} failed (${response.status}): ${await response.text()}`
|
|
1948
2343
|
);
|
|
1949
|
-
return
|
|
2344
|
+
return response.json();
|
|
1950
2345
|
}
|
|
1951
|
-
|
|
1952
|
-
const
|
|
1953
|
-
|
|
1954
|
-
|
|
1955
|
-
accessTokenFactory: () => requireToken(cfg)
|
|
1956
|
-
}).withAutomaticReconnect().build();
|
|
1957
|
-
conn.on("ReceiveMessage", onEvent);
|
|
1958
|
-
conn.onreconnecting(
|
|
1959
|
-
() => process.stderr.write(style.dim("channel: reconnecting\u2026\n"))
|
|
1960
|
-
);
|
|
1961
|
-
conn.onclose((e) => {
|
|
1962
|
-
if (e) process.stderr.write(err(`channel closed: ${e.message}
|
|
1963
|
-
`));
|
|
1964
|
-
});
|
|
1965
|
-
await conn.start();
|
|
1966
|
-
return conn;
|
|
2346
|
+
function parseInteger(value) {
|
|
2347
|
+
const parsed = Number.parseInt(value, 10);
|
|
2348
|
+
if (!Number.isFinite(parsed)) fail(`expected an integer, got '${value}'`);
|
|
2349
|
+
return parsed;
|
|
1967
2350
|
}
|
|
1968
|
-
function
|
|
1969
|
-
return new Promise((resolve3) => {
|
|
2351
|
+
function holdHeartbeat(tick, intervalMs) {
|
|
2352
|
+
return new Promise((resolve3, reject) => {
|
|
2353
|
+
const timer = setInterval(() => void tick().catch(reject), intervalMs);
|
|
1970
2354
|
const stop = () => {
|
|
1971
|
-
|
|
2355
|
+
clearInterval(timer);
|
|
2356
|
+
resolve3();
|
|
1972
2357
|
};
|
|
1973
|
-
process.
|
|
1974
|
-
process.
|
|
2358
|
+
process.once("SIGINT", stop);
|
|
2359
|
+
process.once("SIGTERM", stop);
|
|
1975
2360
|
});
|
|
1976
2361
|
}
|
|
1977
|
-
|
|
1978
|
-
|
|
1979
|
-
|
|
1980
|
-
|
|
1981
|
-
|
|
1982
|
-
|
|
1983
|
-
|
|
1984
|
-
|
|
1985
|
-
|
|
1986
|
-
|
|
1987
|
-
|
|
1988
|
-
|
|
1989
|
-
|
|
1990
|
-
|
|
1991
|
-
|
|
1992
|
-
|
|
1993
|
-
|
|
1994
|
-
|
|
1995
|
-
|
|
1996
|
-
|
|
1997
|
-
|
|
1998
|
-
|
|
1999
|
-
|
|
2000
|
-
|
|
2001
|
-
|
|
2002
|
-
|
|
2003
|
-
|
|
2004
|
-
|
|
2005
|
-
|
|
2006
|
-
|
|
2007
|
-
|
|
2008
|
-
if (!shouldDeliver(payload, filter)) return;
|
|
2009
|
-
const { memoryId } = parseEvent(payload);
|
|
2010
|
-
if (memoryId) {
|
|
2011
|
-
if (seen.has(memoryId)) return;
|
|
2012
|
-
seen.add(memoryId);
|
|
2013
|
-
}
|
|
2014
|
-
forward(payload);
|
|
2015
|
-
};
|
|
2016
|
-
}
|
|
2017
|
-
async function reconcile(cfg, filter, deliver) {
|
|
2018
|
-
if (filter.workspaceScope.length === 0) {
|
|
2019
|
-
process.stderr.write(
|
|
2020
|
-
style.dim(
|
|
2021
|
-
"channel: no --workspace to reconcile against; live feed only (a dropped dispatch won't be recovered).\n"
|
|
2022
|
-
)
|
|
2362
|
+
|
|
2363
|
+
// src/commands/channel.ts
|
|
2364
|
+
function registerChannel(program2) {
|
|
2365
|
+
const channel = program2.command("channel").description(
|
|
2366
|
+
"Receive matched substrate events over the held SignalR push leg (D-WLP-9)"
|
|
2367
|
+
);
|
|
2368
|
+
const withFilterOpts = (c) => c.option(
|
|
2369
|
+
"--name <name>",
|
|
2370
|
+
"Deprecated: ignored; the installed executor selects its delivery subscription"
|
|
2371
|
+
).option(
|
|
2372
|
+
"--tag <tag...>",
|
|
2373
|
+
"Deprecated: executor eligibility comes from the installed capability advertisement"
|
|
2374
|
+
).option(
|
|
2375
|
+
"--workspace <wsp...>",
|
|
2376
|
+
"Deprecated: workspace authority is resolved by the server"
|
|
2377
|
+
).option(
|
|
2378
|
+
"--executor-instance <id>",
|
|
2379
|
+
"Deprecated: the instance is read from .sechroom/executor.json"
|
|
2380
|
+
);
|
|
2381
|
+
withFilterOpts(
|
|
2382
|
+
channel.command("connect").description(
|
|
2383
|
+
"Register a SignalR subscription and stream matched events to stdout"
|
|
2384
|
+
)
|
|
2385
|
+
).action(async (opts, cmd) => {
|
|
2386
|
+
const json = Boolean(cmd.optsWithGlobals().json);
|
|
2387
|
+
const cfg = resolveConfig(cmd.optsWithGlobals());
|
|
2388
|
+
warnLegacyChannelOptions(opts);
|
|
2389
|
+
const located = requireExecutorState();
|
|
2390
|
+
const instance = await ensureExecutorInstance(cfg, located);
|
|
2391
|
+
const deliver = (payload) => process.stdout.write(
|
|
2392
|
+
(typeof payload === "string" ? payload : JSON.stringify(payload)) + "\n"
|
|
2023
2393
|
);
|
|
2024
|
-
|
|
2025
|
-
|
|
2026
|
-
|
|
2027
|
-
|
|
2028
|
-
|
|
2029
|
-
|
|
2030
|
-
|
|
2031
|
-
|
|
2032
|
-
|
|
2033
|
-
|
|
2034
|
-
|
|
2035
|
-
|
|
2036
|
-
|
|
2037
|
-
|
|
2038
|
-
|
|
2394
|
+
const drain = createClaimDrain(cfg, instance.id, deliver);
|
|
2395
|
+
const conn = await openConnection(
|
|
2396
|
+
cfg,
|
|
2397
|
+
() => {
|
|
2398
|
+
void drain().catch(
|
|
2399
|
+
(e) => process.stderr.write(err(`channel claim failed: ${String(e)}
|
|
2400
|
+
`))
|
|
2401
|
+
);
|
|
2402
|
+
},
|
|
2403
|
+
instance.id
|
|
2404
|
+
);
|
|
2405
|
+
await drain();
|
|
2406
|
+
const stopReconciliation = startOfferReconciliation(drain);
|
|
2407
|
+
const stopHeartbeat = startExecutorHeartbeat(
|
|
2408
|
+
() => refreshExecutorInstance(cfg, instance.id, located.state.ttlSeconds),
|
|
2409
|
+
located.state.refreshAfterSeconds * 1e3
|
|
2410
|
+
);
|
|
2411
|
+
if (json) {
|
|
2412
|
+
emit(
|
|
2039
2413
|
{
|
|
2040
|
-
|
|
2041
|
-
|
|
2042
|
-
|
|
2043
|
-
|
|
2044
|
-
|
|
2045
|
-
}
|
|
2414
|
+
connected: true,
|
|
2415
|
+
tenant: cfg.tenant,
|
|
2416
|
+
executorInstanceId: instance.id,
|
|
2417
|
+
instanceKey: located.state.instanceKey,
|
|
2418
|
+
laneId: located.state.laneId
|
|
2419
|
+
},
|
|
2420
|
+
true
|
|
2046
2421
|
);
|
|
2047
|
-
|
|
2048
|
-
process.stderr.write(
|
|
2049
|
-
err(
|
|
2050
|
-
`channel: reconcile query for ${ws} failed (HTTP ${resp.status})
|
|
2051
|
-
`
|
|
2052
|
-
)
|
|
2053
|
-
);
|
|
2054
|
-
continue;
|
|
2055
|
-
}
|
|
2056
|
-
const data = await resp.json();
|
|
2057
|
-
for (const m of data.results ?? []) {
|
|
2058
|
-
if (!m.id) continue;
|
|
2059
|
-
deliver({
|
|
2060
|
-
eventType: "reconcile",
|
|
2061
|
-
memoryId: m.id,
|
|
2062
|
-
workspaceId: ws,
|
|
2063
|
-
tags: m.tags ?? []
|
|
2064
|
-
});
|
|
2065
|
-
recovered++;
|
|
2066
|
-
}
|
|
2067
|
-
} catch (e) {
|
|
2422
|
+
} else {
|
|
2068
2423
|
process.stderr.write(
|
|
2069
|
-
|
|
2070
|
-
`
|
|
2424
|
+
style.green("channel connected") + style.dim(
|
|
2425
|
+
` \u2014 tenant ${cfg.tenant}, executor ${located.state.instanceKey}
|
|
2426
|
+
`
|
|
2427
|
+
) + style.dim("streaming matched events to stdout; Ctrl-C to stop.\n")
|
|
2071
2428
|
);
|
|
2072
2429
|
}
|
|
2073
|
-
|
|
2074
|
-
|
|
2430
|
+
try {
|
|
2431
|
+
await holdOpen(conn);
|
|
2432
|
+
} finally {
|
|
2433
|
+
stopReconciliation();
|
|
2434
|
+
stopHeartbeat();
|
|
2435
|
+
}
|
|
2436
|
+
});
|
|
2437
|
+
withFilterOpts(
|
|
2438
|
+
channel.command("mcp").description(
|
|
2439
|
+
"Run as a Claude Code channel (local-stdio MCP server) \u2014 push matched events into the session"
|
|
2440
|
+
)
|
|
2441
|
+
).action(async (opts, cmd) => {
|
|
2442
|
+
const cfg = resolveConfig(cmd.optsWithGlobals());
|
|
2443
|
+
warnLegacyChannelOptions(opts);
|
|
2444
|
+
const located = requireExecutorState();
|
|
2445
|
+
const instance = await ensureExecutorInstance(cfg, located);
|
|
2446
|
+
const mcp = new Server(
|
|
2447
|
+
{ name: "sechroom", version: "0.1.0" },
|
|
2448
|
+
{
|
|
2449
|
+
capabilities: { experimental: { "claude/channel": {} } },
|
|
2450
|
+
instructions: 'Matched Sechroom substrate events arrive as <channel source="sechroom"> tags. A WLP dispatch delivered here has already been atomically claimed for this executor. Load the memory id from the event and retain the lease and claim token for holder-bound completion.'
|
|
2451
|
+
}
|
|
2452
|
+
);
|
|
2453
|
+
await mcp.connect(new StdioServerTransport());
|
|
2454
|
+
const deliver = (payload) => {
|
|
2455
|
+
const { content, meta } = summarizeEvent(payload);
|
|
2456
|
+
void mcp.notification({
|
|
2457
|
+
method: "notifications/claude/channel",
|
|
2458
|
+
params: { content, meta }
|
|
2459
|
+
}).catch(
|
|
2460
|
+
(e) => process.stderr.write(err(`channel push failed: ${String(e)}
|
|
2461
|
+
`))
|
|
2462
|
+
);
|
|
2463
|
+
};
|
|
2464
|
+
const drain = createClaimDrain(cfg, instance.id, deliver);
|
|
2465
|
+
const conn = await openConnection(
|
|
2466
|
+
cfg,
|
|
2467
|
+
() => {
|
|
2468
|
+
void drain().catch(
|
|
2469
|
+
(e) => process.stderr.write(err(`channel claim failed: ${String(e)}
|
|
2470
|
+
`))
|
|
2471
|
+
);
|
|
2472
|
+
},
|
|
2473
|
+
instance.id
|
|
2474
|
+
);
|
|
2475
|
+
await drain();
|
|
2476
|
+
const stopReconciliation = startOfferReconciliation(drain);
|
|
2477
|
+
const stopHeartbeat = startExecutorHeartbeat(
|
|
2478
|
+
() => refreshExecutorInstance(cfg, instance.id, located.state.ttlSeconds),
|
|
2479
|
+
located.state.refreshAfterSeconds * 1e3
|
|
2480
|
+
);
|
|
2075
2481
|
process.stderr.write(
|
|
2076
2482
|
style.dim(
|
|
2077
|
-
`channel
|
|
2483
|
+
`sechroom channel (mcp) \u2014 tenant ${cfg.tenant}, executor ${located.state.instanceKey}
|
|
2078
2484
|
`
|
|
2079
2485
|
)
|
|
2080
2486
|
);
|
|
2081
|
-
|
|
2082
|
-
|
|
2083
|
-
|
|
2084
|
-
|
|
2085
|
-
|
|
2086
|
-
|
|
2087
|
-
|
|
2088
|
-
|
|
2089
|
-
|
|
2090
|
-
|
|
2091
|
-
|
|
2092
|
-
|
|
2093
|
-
|
|
2094
|
-
|
|
2095
|
-
|
|
2096
|
-
|
|
2097
|
-
|
|
2098
|
-
|
|
2099
|
-
|
|
2100
|
-
|
|
2101
|
-
|
|
2102
|
-
|
|
2103
|
-
|
|
2104
|
-
|
|
2105
|
-
|
|
2106
|
-
|
|
2107
|
-
|
|
2108
|
-
|
|
2109
|
-
|
|
2110
|
-
|
|
2111
|
-
}
|
|
2112
|
-
|
|
2113
|
-
|
|
2114
|
-
}
|
|
2115
|
-
|
|
2116
|
-
|
|
2117
|
-
|
|
2118
|
-
|
|
2119
|
-
|
|
2120
|
-
|
|
2121
|
-
|
|
2122
|
-
|
|
2123
|
-
|
|
2124
|
-
|
|
2125
|
-
|
|
2126
|
-
|
|
2127
|
-
$ sechroom chat replies 1718049600.123456 --surface slack
|
|
2128
|
-
$ sechroom chat stop-tracking 1718049600.123456 --surface slack`
|
|
2129
|
-
);
|
|
2130
|
-
chat.command("send <channelId> <text>").description("Send a message to a channel (POST /chat/channel-messages/{surface})").option("--guild <guildId>", "Discord guild snowflake \u2014 required for --surface discord").option("--memory <memoryId>", "Attach a sechroom memory id").option("--no-track", "Don't capture replies to this message").option("--parent <parentMessage>", "Thread under a parent (Slack thread_ts / Discord message id)").option("--source <source>", "Source / lane stamp (renders an attribution footer)", "cli").option("--as <as>", "Slack only: 'bot' (default) or 'user' (your linked Slack identity)", "bot").action(async (channelId, text2, opts, cmd) => {
|
|
2131
|
-
const { surface, ...globals } = cmd.optsWithGlobals();
|
|
2132
|
-
const json = Boolean(cmd.optsWithGlobals().json);
|
|
2133
|
-
const cfg = resolveConfig(globals);
|
|
2134
|
-
const data = await runApi("Sending message", async () => {
|
|
2135
|
-
const client = await makeClient(cfg);
|
|
2136
|
-
return client.POST("/chat/channel-messages/{surface}", {
|
|
2137
|
-
params: { path: { surface: String(surface) } },
|
|
2138
|
-
body: {
|
|
2139
|
-
channelId,
|
|
2140
|
-
text: text2,
|
|
2141
|
-
guildId: opts.guild ?? null,
|
|
2142
|
-
attachedMemoryId: opts.memory ?? null,
|
|
2143
|
-
trackReplies: opts.track,
|
|
2144
|
-
parentMessage: opts.parent ?? null,
|
|
2145
|
-
source: opts.source,
|
|
2146
|
-
as: opts.as
|
|
2147
|
-
}
|
|
2148
|
-
});
|
|
2149
|
-
});
|
|
2150
|
-
if (!data.ok) {
|
|
2151
|
-
if (json) {
|
|
2152
|
-
emit(data, true);
|
|
2153
|
-
} else {
|
|
2154
|
-
process.stderr.write(
|
|
2155
|
-
`${err("\u2717")} send failed: ${data.upstreamError ?? "error"}${data.errorDescription ? ` \u2014 ${data.errorDescription}` : ""}
|
|
2487
|
+
try {
|
|
2488
|
+
await holdOpen(conn);
|
|
2489
|
+
} finally {
|
|
2490
|
+
stopReconciliation();
|
|
2491
|
+
stopHeartbeat();
|
|
2492
|
+
}
|
|
2493
|
+
});
|
|
2494
|
+
channel.command("install").description(
|
|
2495
|
+
"Wire `sechroom channel mcp` into the project .mcp.json as a Claude Code channel MCP server (idempotent)"
|
|
2496
|
+
).option(
|
|
2497
|
+
"--workspace <wsp...>",
|
|
2498
|
+
"Deprecated: accepted only to migrate an existing managed entry"
|
|
2499
|
+
).option(
|
|
2500
|
+
"--tag <tag...>",
|
|
2501
|
+
"Deprecated: accepted only to migrate an existing managed entry"
|
|
2502
|
+
).option(
|
|
2503
|
+
"--name <name>",
|
|
2504
|
+
"MCP server + subscription name (idempotent per name)",
|
|
2505
|
+
"sechroom-channel"
|
|
2506
|
+
).option("--dry-run", "Print what would change; write nothing").action((opts) => {
|
|
2507
|
+
const path = join9(process.cwd(), ".mcp.json");
|
|
2508
|
+
const dryRun = Boolean(opts.dryRun);
|
|
2509
|
+
const args = ["channel", "mcp"];
|
|
2510
|
+
const entry = { command: "sechroom", args };
|
|
2511
|
+
const config2 = readMcpConfig(path);
|
|
2512
|
+
config2.mcpServers ??= {};
|
|
2513
|
+
const existing = config2.mcpServers[opts.name];
|
|
2514
|
+
const status = JSON.stringify(existing) === JSON.stringify(entry) ? "current" : existing ? "updated" : "created";
|
|
2515
|
+
if (status !== "current" && !dryRun) {
|
|
2516
|
+
config2.mcpServers[opts.name] = entry;
|
|
2517
|
+
mkdirSync7(dirname6(path), { recursive: true });
|
|
2518
|
+
writeFileSync7(path, JSON.stringify(config2, null, 2) + "\n");
|
|
2519
|
+
}
|
|
2520
|
+
const verb = status === "current" ? "already configured" : dryRun ? `would ${status === "created" ? "create" : "update"}` : status;
|
|
2521
|
+
process.stdout.write(`${style.green("channel")} ${path} (${verb})
|
|
2522
|
+
`);
|
|
2523
|
+
process.stdout.write(
|
|
2524
|
+
style.dim(` server "${opts.name}": sechroom ${args.join(" ")}
|
|
2525
|
+
`)
|
|
2526
|
+
);
|
|
2527
|
+
if (status !== "current") {
|
|
2528
|
+
process.stdout.write(
|
|
2529
|
+
style.dim(
|
|
2530
|
+
`
|
|
2531
|
+
Load it (Channels research preview) by launching your agent with:
|
|
2532
|
+
claude --dangerously-load-development-channels server:${opts.name}
|
|
2156
2533
|
`
|
|
2157
|
-
)
|
|
2158
|
-
|
|
2159
|
-
process.exit(1);
|
|
2534
|
+
)
|
|
2535
|
+
);
|
|
2160
2536
|
}
|
|
2161
|
-
|
|
2162
|
-
|
|
2163
|
-
|
|
2164
|
-
|
|
2165
|
-
|
|
2166
|
-
|
|
2167
|
-
|
|
2168
|
-
const client = await makeClient(cfg);
|
|
2169
|
-
return client.GET("/chat/channel-messages/{surface}", {
|
|
2170
|
-
params: { path: { surface: String(surface) } }
|
|
2171
|
-
});
|
|
2172
|
-
});
|
|
2173
|
-
emit(data, cmd.optsWithGlobals().json);
|
|
2174
|
-
});
|
|
2175
|
-
chat.command("replies <messageId>").description("List thread replies for a message (GET /chat/channel-messages/by-id/{id}/replies)").action(async (messageId, _opts, cmd) => {
|
|
2176
|
-
const cfg = resolveConfig(cmd.optsWithGlobals());
|
|
2177
|
-
const data = await runApi("Fetching replies", async () => {
|
|
2178
|
-
const client = await makeClient(cfg);
|
|
2179
|
-
return client.GET("/chat/channel-messages/by-id/{id}/replies", {
|
|
2180
|
-
params: { path: { id: messageId } }
|
|
2181
|
-
});
|
|
2182
|
-
});
|
|
2183
|
-
emit(data, cmd.optsWithGlobals().json);
|
|
2184
|
-
});
|
|
2185
|
-
chat.command("stop-tracking <messageId>").description("Stop watching a message for replies (POST .../by-id/{id}/stop-tracking-replies)").action(async (messageId, _opts, cmd) => {
|
|
2186
|
-
const cfg = resolveConfig(cmd.optsWithGlobals());
|
|
2187
|
-
const data = await runApi("Stopping reply tracking", async () => {
|
|
2188
|
-
const client = await makeClient(cfg);
|
|
2189
|
-
return client.POST("/chat/channel-messages/by-id/{id}/stop-tracking-replies", {
|
|
2190
|
-
params: { path: { id: messageId } },
|
|
2191
|
-
body: {}
|
|
2192
|
-
});
|
|
2193
|
-
});
|
|
2194
|
-
emitAction(`stopped tracking replies on ${style.bold(messageId)}`, data, cmd.optsWithGlobals().json);
|
|
2537
|
+
warnIfSechroomNotOnPath();
|
|
2538
|
+
if ((opts.workspace?.length ?? 0) > 0 || (opts.tag?.length ?? 0) > 0)
|
|
2539
|
+
process.stderr.write(
|
|
2540
|
+
style.dim(
|
|
2541
|
+
"channel: --workspace/--tag are retired; the managed entry now uses the installed executor advertisement.\n"
|
|
2542
|
+
)
|
|
2543
|
+
);
|
|
2195
2544
|
});
|
|
2196
|
-
|
|
2197
|
-
|
|
2198
|
-
|
|
2199
|
-
|
|
2200
|
-
|
|
2201
|
-
|
|
2202
|
-
// src/commands/hook.ts
|
|
2203
|
-
import { createHash as createHash2 } from "crypto";
|
|
2204
|
-
import { existsSync as existsSync8, mkdirSync as mkdirSync7, readFileSync as readFileSync6, statSync as statSync2, writeFileSync as writeFileSync7 } from "fs";
|
|
2205
|
-
import { dirname as dirname6, join as join9 } from "path";
|
|
2545
|
+
channel.addHelpText(
|
|
2546
|
+
"after",
|
|
2547
|
+
`
|
|
2548
|
+
Examples:
|
|
2549
|
+
$ sechroom executor install configure capability + lane advertisement
|
|
2550
|
+
$ sechroom channel connect claim WLP dispatches and stream them to stdout
|
|
2206
2551
|
|
|
2207
|
-
|
|
2208
|
-
|
|
2209
|
-
|
|
2210
|
-
|
|
2211
|
-
var STATE_DIR_NAME2 = ".sechroom";
|
|
2212
|
-
function localSemPath(cwd = process.cwd()) {
|
|
2213
|
-
return join8(cwd, SEM_FILE);
|
|
2214
|
-
}
|
|
2215
|
-
function resolveSemPathForRead(start = process.cwd()) {
|
|
2216
|
-
let dir = start;
|
|
2217
|
-
while (true) {
|
|
2218
|
-
const candidate = join8(dir, SEM_FILE);
|
|
2219
|
-
if (existsSync7(candidate)) return candidate;
|
|
2220
|
-
const parent = dirname5(dir);
|
|
2221
|
-
if (parent === dir) return void 0;
|
|
2222
|
-
dir = parent;
|
|
2223
|
-
}
|
|
2224
|
-
}
|
|
2225
|
-
function applyWorktreeLaneSuffix(lane, start = process.cwd()) {
|
|
2226
|
-
try {
|
|
2227
|
-
let dir = start;
|
|
2228
|
-
let gitPath;
|
|
2229
|
-
for (; ; ) {
|
|
2230
|
-
const candidate = join8(dir, ".git");
|
|
2231
|
-
if (existsSync7(candidate)) {
|
|
2232
|
-
gitPath = candidate;
|
|
2233
|
-
break;
|
|
2234
|
-
}
|
|
2235
|
-
const parent = dirname5(dir);
|
|
2236
|
-
if (parent === dir) break;
|
|
2237
|
-
dir = parent;
|
|
2238
|
-
}
|
|
2239
|
-
if (!gitPath || statSync(gitPath).isDirectory()) return lane;
|
|
2240
|
-
const gitFile = readFileSync5(gitPath, "utf8");
|
|
2241
|
-
const common = gitFile.trim().match(/^gitdir:\s*(.+)\/worktrees\/[^/\s]+\s*$/);
|
|
2242
|
-
if (!common) return lane;
|
|
2243
|
-
const worktreesDir = join8(common[1], "worktrees");
|
|
2244
|
-
const siblings = readdirSync(worktreesDir).filter((n) => {
|
|
2245
|
-
try {
|
|
2246
|
-
return statSync(join8(worktreesDir, n)).isDirectory();
|
|
2247
|
-
} catch {
|
|
2248
|
-
return false;
|
|
2249
|
-
}
|
|
2250
|
-
});
|
|
2251
|
-
return laneWithWorktreeSuffix(lane, gitFile, siblings);
|
|
2252
|
-
} catch {
|
|
2253
|
-
return lane;
|
|
2254
|
-
}
|
|
2255
|
-
}
|
|
2256
|
-
function laneWithWorktreeSuffix(lane, gitFile, siblings) {
|
|
2257
|
-
const m = gitFile.trim().match(/\/worktrees\/([^/\s]+)\s*$/);
|
|
2258
|
-
if (!m) return lane;
|
|
2259
|
-
const idx = [...siblings].sort().indexOf(m[1]);
|
|
2260
|
-
return idx < 0 ? lane : `${lane}-${idx + 2}`;
|
|
2552
|
+
# Wire it as a Claude Code channel MCP server (research preview, v2.1.80+):
|
|
2553
|
+
$ sechroom channel install migrate/install the exact-instance channel
|
|
2554
|
+
# then: claude --dangerously-load-development-channels server:sechroom-channel`
|
|
2555
|
+
);
|
|
2261
2556
|
}
|
|
2262
|
-
function
|
|
2263
|
-
|
|
2557
|
+
function requireExecutorState() {
|
|
2558
|
+
const located = readExecutorState();
|
|
2559
|
+
if (!located)
|
|
2560
|
+
return fail(
|
|
2561
|
+
"channel requires an installed executor advertisement; run `sechroom executor install` first."
|
|
2562
|
+
);
|
|
2563
|
+
return located;
|
|
2264
2564
|
}
|
|
2265
|
-
function
|
|
2266
|
-
|
|
2267
|
-
|
|
2268
|
-
|
|
2565
|
+
function warnLegacyChannelOptions(opts) {
|
|
2566
|
+
if (!opts.name && (opts.workspace?.length ?? 0) === 0 && (opts.tag?.length ?? 0) === 0 && !opts.executorInstance)
|
|
2567
|
+
return;
|
|
2568
|
+
process.stderr.write(
|
|
2569
|
+
style.dim(
|
|
2570
|
+
"channel: --name, --workspace, --tag, and --executor-instance are retired; delivery, eligibility, and identity come from the installed executor advertisement.\n"
|
|
2571
|
+
)
|
|
2572
|
+
);
|
|
2269
2573
|
}
|
|
2270
|
-
function
|
|
2271
|
-
|
|
2272
|
-
|
|
2273
|
-
return {
|
|
2574
|
+
function createClaimDrain(cfg, executorInstanceId, deliver, dependencies = {}) {
|
|
2575
|
+
let active2;
|
|
2576
|
+
const state = {};
|
|
2577
|
+
return () => {
|
|
2578
|
+
active2 ??= drainClaims(cfg, executorInstanceId, deliver, {
|
|
2579
|
+
...dependencies,
|
|
2580
|
+
state
|
|
2581
|
+
}).finally(() => {
|
|
2582
|
+
active2 = void 0;
|
|
2583
|
+
});
|
|
2584
|
+
return active2;
|
|
2585
|
+
};
|
|
2274
2586
|
}
|
|
2275
|
-
function
|
|
2276
|
-
|
|
2277
|
-
|
|
2278
|
-
|
|
2279
|
-
|
|
2280
|
-
|
|
2587
|
+
function startOfferReconciliation(drain, intervalMilliseconds = 5e3, dependencies = {}) {
|
|
2588
|
+
const schedule = dependencies.setInterval ?? setInterval;
|
|
2589
|
+
const cancel = dependencies.clearInterval ?? clearInterval;
|
|
2590
|
+
const onError = dependencies.onError ?? ((error) => process.stderr.write(err(`channel claim failed: ${String(error)}
|
|
2591
|
+
`)));
|
|
2592
|
+
const timer = schedule(() => {
|
|
2593
|
+
void drain().catch(onError);
|
|
2594
|
+
}, intervalMilliseconds);
|
|
2595
|
+
return () => cancel(timer);
|
|
2596
|
+
}
|
|
2597
|
+
function startExecutorHeartbeat(refresh, intervalMilliseconds, dependencies = {}) {
|
|
2598
|
+
const schedule = dependencies.setInterval ?? setInterval;
|
|
2599
|
+
const cancel = dependencies.clearInterval ?? clearInterval;
|
|
2600
|
+
const onError = dependencies.onError ?? ((error) => process.stderr.write(err(`channel heartbeat failed: ${String(error)}
|
|
2601
|
+
`)));
|
|
2602
|
+
const timer = schedule(() => {
|
|
2603
|
+
void refresh().catch(onError);
|
|
2604
|
+
}, intervalMilliseconds);
|
|
2605
|
+
return () => cancel(timer);
|
|
2606
|
+
}
|
|
2607
|
+
async function drainClaims(cfg, executorInstanceId, deliver, dependencies = {}) {
|
|
2608
|
+
const request = dependencies.request ?? api;
|
|
2609
|
+
const sleep = dependencies.sleep ?? ((milliseconds) => new Promise((resolve3) => setTimeout(resolve3, milliseconds)));
|
|
2610
|
+
const idempotencyKey = dependencies.idempotencyKey ?? ((offer) => `channel:${offer.generationId}`);
|
|
2611
|
+
const state = dependencies.state ?? {};
|
|
2612
|
+
for (; ; ) {
|
|
2613
|
+
if (state.pendingIdempotencyKey) {
|
|
2614
|
+
const replay = await request(
|
|
2615
|
+
cfg,
|
|
2616
|
+
`/me/executor-instances/${encodeURIComponent(executorInstanceId)}/dispatch-offers/claim-next`,
|
|
2617
|
+
{
|
|
2618
|
+
method: "POST",
|
|
2619
|
+
body: JSON.stringify({ idempotencyKey: state.pendingIdempotencyKey })
|
|
2620
|
+
}
|
|
2621
|
+
);
|
|
2622
|
+
state.pendingIdempotencyKey = void 0;
|
|
2623
|
+
if (replay.outcome === "Claimed" || replay.outcome === "AlreadyHeld") {
|
|
2624
|
+
deliver(replay);
|
|
2625
|
+
continue;
|
|
2626
|
+
}
|
|
2627
|
+
return;
|
|
2281
2628
|
}
|
|
2282
|
-
|
|
2283
|
-
|
|
2284
|
-
|
|
2629
|
+
const offers = await request(
|
|
2630
|
+
cfg,
|
|
2631
|
+
`/me/executor-instances/${encodeURIComponent(executorInstanceId)}/dispatch-offers`
|
|
2632
|
+
);
|
|
2633
|
+
const offer = offers[0];
|
|
2634
|
+
if (!offer) return;
|
|
2635
|
+
if (offer.suggestedClaimDelayMs > 0)
|
|
2636
|
+
await sleep(offer.suggestedClaimDelayMs);
|
|
2637
|
+
state.pendingIdempotencyKey = idempotencyKey(offer);
|
|
2638
|
+
const claim = await request(
|
|
2639
|
+
cfg,
|
|
2640
|
+
`/me/executor-instances/${encodeURIComponent(executorInstanceId)}/dispatch-offers/claim-next`,
|
|
2641
|
+
{
|
|
2642
|
+
method: "POST",
|
|
2643
|
+
body: JSON.stringify({ idempotencyKey: state.pendingIdempotencyKey })
|
|
2644
|
+
}
|
|
2645
|
+
);
|
|
2646
|
+
state.pendingIdempotencyKey = void 0;
|
|
2647
|
+
if (claim.outcome === "NoOffer") return;
|
|
2648
|
+
if (claim.outcome === "Claimed" || claim.outcome === "AlreadyHeld")
|
|
2649
|
+
deliver(claim);
|
|
2650
|
+
else return;
|
|
2285
2651
|
}
|
|
2286
2652
|
}
|
|
2287
|
-
|
|
2288
|
-
|
|
2289
|
-
|
|
2290
|
-
|
|
2291
|
-
ensureSemIgnored(path);
|
|
2292
|
-
ensureContinuityScaffold(path);
|
|
2293
|
-
return path;
|
|
2294
|
-
}
|
|
2295
|
-
function ensureStateDirIgnored(cwd = process.cwd()) {
|
|
2296
|
-
ensureSemIgnored(localSemPath(cwd));
|
|
2297
|
-
}
|
|
2298
|
-
var CONTINUITY_FILE_NAME = "continuity.json";
|
|
2299
|
-
var CONTINUITY_SCAFFOLD = JSON.stringify(
|
|
2300
|
-
{
|
|
2301
|
-
_readme: "Agent-maintained continuity intent. Keep these current during the session; `sechroom checkpoint` and the PreCompact hook snapshot from here. The five required fields (objective, state, lastAction, nextAction, resumeInstruction) must all be non-empty for a snapshot to be created.",
|
|
2302
|
-
objective: "",
|
|
2303
|
-
state: "",
|
|
2304
|
-
lastAction: "",
|
|
2305
|
-
nextAction: "",
|
|
2306
|
-
resumeInstruction: "",
|
|
2307
|
-
constraints: [],
|
|
2308
|
-
questions: [],
|
|
2309
|
-
artifacts: [],
|
|
2310
|
-
confidence: null
|
|
2311
|
-
},
|
|
2312
|
-
null,
|
|
2313
|
-
2
|
|
2314
|
-
) + "\n";
|
|
2315
|
-
function ensureContinuityScaffold(semPath) {
|
|
2653
|
+
function readMcpConfig(path) {
|
|
2654
|
+
if (!existsSync8(path)) return {};
|
|
2655
|
+
const raw = readFileSync6(path, "utf8");
|
|
2656
|
+
if (!raw.trim()) return {};
|
|
2316
2657
|
try {
|
|
2317
|
-
|
|
2318
|
-
if (existsSync7(target)) return;
|
|
2319
|
-
writeFileSync6(target, CONTINUITY_SCAFFOLD);
|
|
2658
|
+
return JSON.parse(raw);
|
|
2320
2659
|
} catch {
|
|
2660
|
+
return fail(
|
|
2661
|
+
`Could not parse ${path} as JSON \u2014 fix or remove it before installing the channel.`
|
|
2662
|
+
);
|
|
2321
2663
|
}
|
|
2322
2664
|
}
|
|
2323
|
-
function
|
|
2324
|
-
|
|
2325
|
-
|
|
2326
|
-
|
|
2665
|
+
async function openConnection(cfg, onEvent, executorInstanceId) {
|
|
2666
|
+
const query = executorInstanceId ? `?executorInstanceId=${encodeURIComponent(executorInstanceId)}` : "";
|
|
2667
|
+
const conn = new HubConnectionBuilder().withUrl(`${cfg.baseUrl}/notifications/${cfg.tenant}${query}`, {
|
|
2668
|
+
transport: HttpTransportType.LongPolling,
|
|
2669
|
+
accessTokenFactory: () => requireToken(cfg)
|
|
2670
|
+
}).withAutomaticReconnect().build();
|
|
2671
|
+
conn.on("ReceiveMessage", onEvent);
|
|
2672
|
+
conn.onreconnecting(
|
|
2673
|
+
() => process.stderr.write(style.dim("channel: reconnecting\u2026\n"))
|
|
2674
|
+
);
|
|
2675
|
+
conn.onclose((e) => {
|
|
2676
|
+
if (e) process.stderr.write(err(`channel closed: ${e.message}
|
|
2677
|
+
`));
|
|
2327
2678
|
});
|
|
2679
|
+
await conn.start();
|
|
2680
|
+
return conn;
|
|
2328
2681
|
}
|
|
2329
|
-
function
|
|
2330
|
-
|
|
2331
|
-
|
|
2332
|
-
|
|
2333
|
-
|
|
2334
|
-
|
|
2335
|
-
|
|
2336
|
-
}
|
|
2682
|
+
function holdOpen(conn) {
|
|
2683
|
+
return new Promise((resolve3) => {
|
|
2684
|
+
const stop = () => {
|
|
2685
|
+
void conn.stop().finally(resolve3);
|
|
2686
|
+
};
|
|
2687
|
+
process.on("SIGINT", stop);
|
|
2688
|
+
process.on("SIGTERM", stop);
|
|
2689
|
+
});
|
|
2337
2690
|
}
|
|
2338
|
-
function
|
|
2339
|
-
let
|
|
2340
|
-
|
|
2341
|
-
|
|
2342
|
-
|
|
2343
|
-
|
|
2344
|
-
|
|
2345
|
-
return { path: join8(startDir, ".gitignore"), exists: false };
|
|
2691
|
+
function parseEvent(payload) {
|
|
2692
|
+
let data = payload;
|
|
2693
|
+
if (typeof payload === "string") {
|
|
2694
|
+
try {
|
|
2695
|
+
data = JSON.parse(payload);
|
|
2696
|
+
} catch {
|
|
2697
|
+
return { eventType: "", memoryId: "", workspaceId: "", tags: void 0 };
|
|
2346
2698
|
}
|
|
2347
|
-
dir = parent;
|
|
2348
2699
|
}
|
|
2700
|
+
const obj = data ?? {};
|
|
2701
|
+
const envelope = obj.data ?? obj;
|
|
2702
|
+
const inner = envelope.offer ?? envelope;
|
|
2703
|
+
const rawTags = inner.tags ?? inner.Tags;
|
|
2704
|
+
return {
|
|
2705
|
+
eventType: str(inner.eventType ?? inner.EventType ?? obj.type) || "substrate.event",
|
|
2706
|
+
memoryId: str(inner.memoryId ?? inner.MemoryId),
|
|
2707
|
+
workspaceId: str(inner.workspaceId ?? inner.WorkspaceId),
|
|
2708
|
+
tags: Array.isArray(rawTags) ? rawTags.filter((t) => typeof t === "string") : void 0
|
|
2709
|
+
};
|
|
2349
2710
|
}
|
|
2350
|
-
function
|
|
2351
|
-
|
|
2352
|
-
|
|
2353
|
-
|
|
2354
|
-
|
|
2355
|
-
|
|
2356
|
-
|
|
2357
|
-
|
|
2358
|
-
|
|
2359
|
-
|
|
2360
|
-
|
|
2361
|
-
|
|
2362
|
-
|
|
2363
|
-
|
|
2711
|
+
function summarizeEvent(payload) {
|
|
2712
|
+
const { eventType, memoryId, workspaceId } = parseEvent(payload);
|
|
2713
|
+
const content = memoryId ? `${eventType}: ${memoryId}${workspaceId ? ` (workspace ${workspaceId})` : ""}` : typeof payload === "string" ? payload : JSON.stringify(payload);
|
|
2714
|
+
const meta = {};
|
|
2715
|
+
if (eventType) meta.event_type = eventType;
|
|
2716
|
+
if (memoryId) meta.memory_id = memoryId;
|
|
2717
|
+
if (workspaceId) meta.workspace_id = workspaceId;
|
|
2718
|
+
const claim = payload ?? {};
|
|
2719
|
+
if (claim.outcome) meta.claim_outcome = claim.outcome;
|
|
2720
|
+
if (claim.lease?.id) meta.lease_id = claim.lease.id;
|
|
2721
|
+
if (claim.claimToken) meta.claim_token = claim.claimToken;
|
|
2722
|
+
return { content, meta };
|
|
2723
|
+
}
|
|
2724
|
+
function str(v) {
|
|
2725
|
+
return typeof v === "string" ? v : v == null ? "" : String(v);
|
|
2726
|
+
}
|
|
2727
|
+
|
|
2728
|
+
// src/commands/chat.ts
|
|
2729
|
+
function registerChat(program2) {
|
|
2730
|
+
const chat = program2.command("chat").description("Send and read Slack / Discord channel messages").option("--surface <surface>", "slack | discord", "slack");
|
|
2731
|
+
chat.addHelpText(
|
|
2732
|
+
"after",
|
|
2733
|
+
`
|
|
2734
|
+
Examples:
|
|
2735
|
+
$ sechroom chat send C0123456789 "deploy is green" --surface slack
|
|
2736
|
+
$ sechroom chat send 987654321098765432 "deploy is green" --surface discord --guild 123456789012345678
|
|
2737
|
+
$ sechroom chat send C0123456789 "lgtm" --surface slack --as user --parent 1718049600.123456
|
|
2738
|
+
$ sechroom chat messages --surface slack
|
|
2739
|
+
$ sechroom chat replies 1718049600.123456 --surface slack
|
|
2740
|
+
$ sechroom chat stop-tracking 1718049600.123456 --surface slack`
|
|
2741
|
+
);
|
|
2742
|
+
chat.command("send <channelId> <text>").description("Send a message to a channel (POST /chat/channel-messages/{surface})").option("--guild <guildId>", "Discord guild snowflake \u2014 required for --surface discord").option("--memory <memoryId>", "Attach a sechroom memory id").option("--no-track", "Don't capture replies to this message").option("--parent <parentMessage>", "Thread under a parent (Slack thread_ts / Discord message id)").option("--source <source>", "Source / lane stamp (renders an attribution footer)", "cli").option("--as <as>", "Slack only: 'bot' (default) or 'user' (your linked Slack identity)", "bot").action(async (channelId, text2, opts, cmd) => {
|
|
2743
|
+
const { surface, ...globals } = cmd.optsWithGlobals();
|
|
2744
|
+
const json = Boolean(cmd.optsWithGlobals().json);
|
|
2745
|
+
const cfg = resolveConfig(globals);
|
|
2746
|
+
const data = await runApi("Sending message", async () => {
|
|
2747
|
+
const client = await makeClient(cfg);
|
|
2748
|
+
return client.POST("/chat/channel-messages/{surface}", {
|
|
2749
|
+
params: { path: { surface: String(surface) } },
|
|
2750
|
+
body: {
|
|
2751
|
+
channelId,
|
|
2752
|
+
text: text2,
|
|
2753
|
+
guildId: opts.guild ?? null,
|
|
2754
|
+
attachedMemoryId: opts.memory ?? null,
|
|
2755
|
+
trackReplies: opts.track,
|
|
2756
|
+
parentMessage: opts.parent ?? null,
|
|
2757
|
+
source: opts.source,
|
|
2758
|
+
as: opts.as
|
|
2759
|
+
}
|
|
2760
|
+
});
|
|
2761
|
+
});
|
|
2762
|
+
if (!data.ok) {
|
|
2763
|
+
if (json) {
|
|
2764
|
+
emit(data, true);
|
|
2765
|
+
} else {
|
|
2766
|
+
process.stderr.write(
|
|
2767
|
+
`${err("\u2717")} send failed: ${data.upstreamError ?? "error"}${data.errorDescription ? ` \u2014 ${data.errorDescription}` : ""}
|
|
2768
|
+
`
|
|
2769
|
+
);
|
|
2770
|
+
}
|
|
2771
|
+
process.exit(1);
|
|
2364
2772
|
}
|
|
2365
|
-
|
|
2366
|
-
|
|
2773
|
+
const idPart = data.persistedId ? ` ${style.dim(`(${data.persistedId})`)}` : "";
|
|
2774
|
+
emitAction(`sent to ${surface} ${style.bold(channelId)}${idPart}`, data, json);
|
|
2775
|
+
});
|
|
2776
|
+
chat.command("messages").description("List recent channel messages (GET /chat/channel-messages/{surface})").action(async (_opts, cmd) => {
|
|
2777
|
+
const { surface, ...globals } = cmd.optsWithGlobals();
|
|
2778
|
+
const cfg = resolveConfig(globals);
|
|
2779
|
+
const data = await runApi("Fetching messages", async () => {
|
|
2780
|
+
const client = await makeClient(cfg);
|
|
2781
|
+
return client.GET("/chat/channel-messages/{surface}", {
|
|
2782
|
+
params: { path: { surface: String(surface) } }
|
|
2783
|
+
});
|
|
2784
|
+
});
|
|
2785
|
+
emit(data, cmd.optsWithGlobals().json);
|
|
2786
|
+
});
|
|
2787
|
+
chat.command("replies <messageId>").description("List thread replies for a message (GET /chat/channel-messages/by-id/{id}/replies)").action(async (messageId, _opts, cmd) => {
|
|
2788
|
+
const cfg = resolveConfig(cmd.optsWithGlobals());
|
|
2789
|
+
const data = await runApi("Fetching replies", async () => {
|
|
2790
|
+
const client = await makeClient(cfg);
|
|
2791
|
+
return client.GET("/chat/channel-messages/by-id/{id}/replies", {
|
|
2792
|
+
params: { path: { id: messageId } }
|
|
2793
|
+
});
|
|
2794
|
+
});
|
|
2795
|
+
emit(data, cmd.optsWithGlobals().json);
|
|
2796
|
+
});
|
|
2797
|
+
chat.command("stop-tracking <messageId>").description("Stop watching a message for replies (POST .../by-id/{id}/stop-tracking-replies)").action(async (messageId, _opts, cmd) => {
|
|
2798
|
+
const cfg = resolveConfig(cmd.optsWithGlobals());
|
|
2799
|
+
const data = await runApi("Stopping reply tracking", async () => {
|
|
2800
|
+
const client = await makeClient(cfg);
|
|
2801
|
+
return client.POST("/chat/channel-messages/by-id/{id}/stop-tracking-replies", {
|
|
2802
|
+
params: { path: { id: messageId } },
|
|
2803
|
+
body: {}
|
|
2804
|
+
});
|
|
2805
|
+
});
|
|
2806
|
+
emitAction(`stopped tracking replies on ${style.bold(messageId)}`, data, cmd.optsWithGlobals().json);
|
|
2807
|
+
});
|
|
2367
2808
|
}
|
|
2368
2809
|
|
|
2810
|
+
// src/commands/checkpoint.ts
|
|
2811
|
+
import { mkdirSync as mkdirSync9, writeFileSync as writeFileSync9 } from "fs";
|
|
2812
|
+
import { dirname as dirname8, join as join11 } from "path";
|
|
2813
|
+
|
|
2369
2814
|
// src/commands/hook.ts
|
|
2815
|
+
import { createHash as createHash2 } from "crypto";
|
|
2816
|
+
import { existsSync as existsSync9, mkdirSync as mkdirSync8, readFileSync as readFileSync7, statSync as statSync2, writeFileSync as writeFileSync8 } from "fs";
|
|
2817
|
+
import { dirname as dirname7, join as join10 } from "path";
|
|
2370
2818
|
async function readStdin() {
|
|
2371
2819
|
if (process.stdin.isTTY) return "";
|
|
2372
2820
|
const chunks = [];
|
|
@@ -2390,13 +2838,13 @@ function resolveLane(flagLane, cwd) {
|
|
|
2390
2838
|
if (!base) return void 0;
|
|
2391
2839
|
return applyWorktreeLaneSuffix(base, start);
|
|
2392
2840
|
}
|
|
2393
|
-
var INTENT_FILE =
|
|
2841
|
+
var INTENT_FILE = join10(".sechroom", "continuity.json");
|
|
2394
2842
|
function resolveIntentPath(start) {
|
|
2395
2843
|
let dir = start;
|
|
2396
2844
|
for (; ; ) {
|
|
2397
|
-
const candidate =
|
|
2398
|
-
if (
|
|
2399
|
-
const parent =
|
|
2845
|
+
const candidate = join10(dir, INTENT_FILE);
|
|
2846
|
+
if (existsSync9(candidate)) return candidate;
|
|
2847
|
+
const parent = dirname7(dir);
|
|
2400
2848
|
if (parent === dir) return void 0;
|
|
2401
2849
|
dir = parent;
|
|
2402
2850
|
}
|
|
@@ -2405,7 +2853,7 @@ function readIntent(start) {
|
|
|
2405
2853
|
const path = resolveIntentPath(start);
|
|
2406
2854
|
if (!path) return void 0;
|
|
2407
2855
|
try {
|
|
2408
|
-
return JSON.parse(
|
|
2856
|
+
return JSON.parse(readFileSync7(path, "utf8"));
|
|
2409
2857
|
} catch {
|
|
2410
2858
|
return void 0;
|
|
2411
2859
|
}
|
|
@@ -2447,14 +2895,14 @@ async function saveSnapshotFromIntent(cmd, cwd, laneFlag, scopeFlag, defaultScop
|
|
|
2447
2895
|
}
|
|
2448
2896
|
function ledgerPath(start) {
|
|
2449
2897
|
const intent = resolveIntentPath(start);
|
|
2450
|
-
const dir = intent ?
|
|
2451
|
-
return
|
|
2898
|
+
const dir = intent ? dirname7(intent) : join10(start, ".sechroom");
|
|
2899
|
+
return join10(dir, ".checkpoint-state.json");
|
|
2452
2900
|
}
|
|
2453
2901
|
function readLedger(start) {
|
|
2454
2902
|
try {
|
|
2455
2903
|
const p = ledgerPath(start);
|
|
2456
|
-
if (!
|
|
2457
|
-
return JSON.parse(
|
|
2904
|
+
if (!existsSync9(p)) return {};
|
|
2905
|
+
return JSON.parse(readFileSync7(p, "utf8"));
|
|
2458
2906
|
} catch {
|
|
2459
2907
|
return {};
|
|
2460
2908
|
}
|
|
@@ -2501,13 +2949,13 @@ function recordPush(start, intent) {
|
|
|
2501
2949
|
} catch {
|
|
2502
2950
|
mtimeMs = void 0;
|
|
2503
2951
|
}
|
|
2504
|
-
|
|
2952
|
+
mkdirSync8(dirname7(p), { recursive: true });
|
|
2505
2953
|
const ledger = {
|
|
2506
2954
|
lastEpochMs: Date.now(),
|
|
2507
2955
|
lastMtimeMs: mtimeMs,
|
|
2508
2956
|
lastHash: intentHash(intent)
|
|
2509
2957
|
};
|
|
2510
|
-
|
|
2958
|
+
writeFileSync8(p, JSON.stringify(ledger) + "\n");
|
|
2511
2959
|
} catch {
|
|
2512
2960
|
}
|
|
2513
2961
|
}
|
|
@@ -2760,10 +3208,10 @@ Examples:
|
|
|
2760
3208
|
const client = await makeClient(cfg);
|
|
2761
3209
|
return client.POST("/continuity/snapshots", { body });
|
|
2762
3210
|
});
|
|
2763
|
-
const path = resolveIntentPath(cwd) ??
|
|
3211
|
+
const path = resolveIntentPath(cwd) ?? join11(cwd, INTENT_FILE);
|
|
2764
3212
|
const fileBody = { ...merged, scope, lastSnapshotId: data.snapshotId };
|
|
2765
|
-
|
|
2766
|
-
|
|
3213
|
+
mkdirSync9(dirname8(path), { recursive: true });
|
|
3214
|
+
writeFileSync9(path, JSON.stringify(fileBody, null, 2) + "\n");
|
|
2767
3215
|
recordPush(cwd, merged);
|
|
2768
3216
|
if (json) {
|
|
2769
3217
|
emit({ snapshotId: data.snapshotId, lane, scope, file: path }, true);
|
|
@@ -2777,7 +3225,7 @@ Examples:
|
|
|
2777
3225
|
}
|
|
2778
3226
|
|
|
2779
3227
|
// src/commands/close.ts
|
|
2780
|
-
import { readFileSync as
|
|
3228
|
+
import { readFileSync as readFileSync8 } from "fs";
|
|
2781
3229
|
var VERDICTS = ["pass", "soft-fail", "plan-invalid", "blocked"];
|
|
2782
3230
|
function registerClose(program2) {
|
|
2783
3231
|
program2.command("close").description(
|
|
@@ -2818,7 +3266,7 @@ Examples:
|
|
|
2818
3266
|
);
|
|
2819
3267
|
let bodyText;
|
|
2820
3268
|
try {
|
|
2821
|
-
bodyText = opts.file ?
|
|
3269
|
+
bodyText = opts.file ? readFileSync8(opts.file, "utf8") : readFileSync8(0, "utf8");
|
|
2822
3270
|
} catch {
|
|
2823
3271
|
fail(
|
|
2824
3272
|
opts.file ? `could not read --file ${opts.file}` : "no closeout body \u2014 pass --file <path> or pipe it on stdin"
|
|
@@ -2986,561 +3434,227 @@ Examples:
|
|
|
2986
3434
|
}
|
|
2987
3435
|
});
|
|
2988
3436
|
});
|
|
2989
|
-
emitAction(`created snapshot ${style.bold(data.snapshotId)}`, data, cmd.optsWithGlobals().json);
|
|
2990
|
-
});
|
|
2991
|
-
continuity.command("snapshot-get <id>").description("Fetch a snapshot by id (GET /continuity/snapshots/{id})").action(async (id, _opts, cmd) => {
|
|
2992
|
-
const cfg = resolveConfig(cmd.optsWithGlobals());
|
|
2993
|
-
const data = await runApi("Fetching snapshot", async () => {
|
|
2994
|
-
const client = await makeClient(cfg);
|
|
2995
|
-
return client.GET("/continuity/snapshots/{id}", { params: { path: { id } } });
|
|
2996
|
-
});
|
|
2997
|
-
emit(data, cmd.optsWithGlobals().json);
|
|
2998
|
-
});
|
|
2999
|
-
continuity.command("snapshots").description("List the caller's own snapshots (GET /me/continuity/snapshots)").option("--scope <scope>", "Filter by scope").option("--lane <laneId>", "Filter by lane id").action(async (opts, cmd) => {
|
|
3000
|
-
const cfg = resolveConfig(cmd.optsWithGlobals());
|
|
3001
|
-
const data = await runApi("Listing snapshots", async () => {
|
|
3002
|
-
const client = await makeClient(cfg);
|
|
3003
|
-
return client.GET("/me/continuity/snapshots", {
|
|
3004
|
-
params: {
|
|
3005
|
-
query: {
|
|
3006
|
-
...opts.scope ? { scope: opts.scope } : {},
|
|
3007
|
-
...opts.lane ? { laneId: opts.lane } : {}
|
|
3008
|
-
}
|
|
3009
|
-
}
|
|
3010
|
-
});
|
|
3011
|
-
});
|
|
3012
|
-
emit(data, cmd.optsWithGlobals().json);
|
|
3013
|
-
});
|
|
3014
|
-
continuity.command("resume-me").description("Resume the caller's own lane (POST /continuity/resume/me)").option("--workspace <workspaceId>", "Scope to a workspace").option("--max-artifacts <n>", "Cap artifacts in the bundle").option("--changed-since <iso>", "Only include changes since this ISO timestamp").option("--looking-at-myself", "Include the caller's own changes", false).action(async (opts, cmd) => {
|
|
3015
|
-
const cfg = resolveConfig(cmd.optsWithGlobals());
|
|
3016
|
-
const data = await runApi("Resuming", async () => {
|
|
3017
|
-
const client = await makeClient(cfg);
|
|
3018
|
-
return client.POST("/continuity/resume/me", {
|
|
3019
|
-
body: {
|
|
3020
|
-
workspaceId: opts.workspace ?? null,
|
|
3021
|
-
maxArtifacts: opts.maxArtifacts != null ? Number(opts.maxArtifacts) : null,
|
|
3022
|
-
includeLookingAtMyself: opts.lookingAtMyself ? true : null,
|
|
3023
|
-
changedSince: opts.changedSince ?? null
|
|
3024
|
-
}
|
|
3025
|
-
});
|
|
3026
|
-
});
|
|
3027
|
-
emit(data, cmd.optsWithGlobals().json);
|
|
3028
|
-
});
|
|
3029
|
-
continuity.command("resume-lane <laneId>").description("Resume a specific lane (POST /continuity/resume/lane)").option("--workspace <workspaceId>", "Scope to a workspace").option("--max-artifacts <n>", "Cap artifacts in the bundle").option("--changed-since <iso>", "Only include changes since this ISO timestamp").option("--looking-at-myself", "Include the caller's own changes", false).action(async (laneId, opts, cmd) => {
|
|
3030
|
-
const cfg = resolveConfig(cmd.optsWithGlobals());
|
|
3031
|
-
const data = await runApi("Resuming lane", async () => {
|
|
3032
|
-
const client = await makeClient(cfg);
|
|
3033
|
-
return client.POST("/continuity/resume/lane", {
|
|
3034
|
-
body: {
|
|
3035
|
-
laneId,
|
|
3036
|
-
workspaceId: opts.workspace ?? null,
|
|
3037
|
-
maxArtifacts: opts.maxArtifacts != null ? Number(opts.maxArtifacts) : null,
|
|
3038
|
-
includeLookingAtMyself: opts.lookingAtMyself ? true : null,
|
|
3039
|
-
changedSince: opts.changedSince ?? null
|
|
3040
|
-
}
|
|
3041
|
-
});
|
|
3042
|
-
});
|
|
3043
|
-
emit(data, cmd.optsWithGlobals().json);
|
|
3044
|
-
});
|
|
3045
|
-
continuity.command("changed-since").description("What changed since a timestamp (POST /continuity/changed-since)").requiredOption("--since <iso>", "ISO-8601 timestamp to compare against").option("--looking-at-myself", "Include the caller's own changes", false).action(async (opts, cmd) => {
|
|
3046
|
-
const cfg = resolveConfig(cmd.optsWithGlobals());
|
|
3047
|
-
const data = await runApi("Computing changes", async () => {
|
|
3048
|
-
const client = await makeClient(cfg);
|
|
3049
|
-
return client.POST("/continuity/changed-since", {
|
|
3050
|
-
body: {
|
|
3051
|
-
since: opts.since,
|
|
3052
|
-
includeLookingAtMyself: opts.lookingAtMyself ? true : null
|
|
3053
|
-
}
|
|
3054
|
-
});
|
|
3055
|
-
});
|
|
3056
|
-
emit(data, cmd.optsWithGlobals().json);
|
|
3057
|
-
});
|
|
3058
|
-
continuity.command("load-set").description("Derive the active load set (POST /continuity/load-set/derive)").option("--workspace <workspaceId>", "Scope to a workspace").option("--max-artifacts <n>", "Cap artifacts in the load set").option("--looking-at-myself", "Include the caller's own changes", false).action(async (opts, cmd) => {
|
|
3059
|
-
const cfg = resolveConfig(cmd.optsWithGlobals());
|
|
3060
|
-
const data = await runApi("Deriving load set", async () => {
|
|
3061
|
-
const client = await makeClient(cfg);
|
|
3062
|
-
return client.POST("/continuity/load-set/derive", {
|
|
3063
|
-
body: {
|
|
3064
|
-
workspaceId: opts.workspace ?? null,
|
|
3065
|
-
maxArtifacts: opts.maxArtifacts != null ? Number(opts.maxArtifacts) : null,
|
|
3066
|
-
includeLookingAtMyself: opts.lookingAtMyself ? true : null
|
|
3067
|
-
}
|
|
3068
|
-
});
|
|
3069
|
-
});
|
|
3070
|
-
emit(data, cmd.optsWithGlobals().json);
|
|
3071
|
-
});
|
|
3072
|
-
continuity.command("grant <snapshotId>").description("Grant another operator read access (POST /continuity/snapshots/{snapshotId}/grants)").requiredOption("--grantee <userId>", "Sechroom user id being granted read access").option("--source <source>", "Permission-set source kind", "TenantRole").option("--source-id <sourceId>", "Permission-set source id (e.g. a tenant role)", "viewer").option("--valid-from <iso>", "Optional ISO-8601 grant start").option("--valid-to <iso>", "Optional ISO-8601 grant expiry").action(async (snapshotId, opts, cmd) => {
|
|
3073
|
-
const cfg = resolveConfig(cmd.optsWithGlobals());
|
|
3074
|
-
const data = await runApi("Minting grant", async () => {
|
|
3075
|
-
const client = await makeClient(cfg);
|
|
3076
|
-
return client.POST("/continuity/snapshots/{snapshotId}/grants", {
|
|
3077
|
-
params: { path: { snapshotId } },
|
|
3078
|
-
body: {
|
|
3079
|
-
userId: opts.grantee,
|
|
3080
|
-
kind: "Allow",
|
|
3081
|
-
source: opts.source,
|
|
3082
|
-
sourceId: opts.sourceId,
|
|
3083
|
-
...opts.validFrom ? { validFrom: opts.validFrom } : {},
|
|
3084
|
-
...opts.validTo ? { validTo: opts.validTo } : {}
|
|
3085
|
-
}
|
|
3086
|
-
});
|
|
3087
|
-
});
|
|
3088
|
-
emitAction(
|
|
3089
|
-
`granted ${style.bold(data.userId)} read on ${style.bold(snapshotId)} ${style.dim(`(grant ${data.grantId})`)}`,
|
|
3090
|
-
data,
|
|
3091
|
-
cmd.optsWithGlobals().json
|
|
3092
|
-
);
|
|
3093
|
-
});
|
|
3094
|
-
continuity.command("revoke-grant <snapshotId> <grantId>").description("Revoke a grant (DELETE /continuity/snapshots/{snapshotId}/grants/{grantId})").action(async (snapshotId, grantId, _opts, cmd) => {
|
|
3095
|
-
const cfg = resolveConfig(cmd.optsWithGlobals());
|
|
3096
|
-
const data = await runApi("Revoking grant", async () => {
|
|
3097
|
-
const client = await makeClient(cfg);
|
|
3098
|
-
return client.DELETE("/continuity/snapshots/{snapshotId}/grants/{grantId}", {
|
|
3099
|
-
params: { path: { snapshotId, grantId } },
|
|
3100
|
-
body: {}
|
|
3101
|
-
});
|
|
3102
|
-
});
|
|
3103
|
-
emitAction(
|
|
3104
|
-
`revoked grant ${style.bold(grantId)} on ${style.bold(snapshotId)}`,
|
|
3105
|
-
data,
|
|
3106
|
-
cmd.optsWithGlobals().json
|
|
3107
|
-
);
|
|
3108
|
-
});
|
|
3109
|
-
}
|
|
3110
|
-
|
|
3111
|
-
// src/commands/decomposition.ts
|
|
3112
|
-
function registerDecomposition(program2) {
|
|
3113
|
-
const decomposition = program2.command("decomposition").description(
|
|
3114
|
-
"Drive a WLP decomposition: decompose a brief, then execute / accept / reject"
|
|
3115
|
-
);
|
|
3116
|
-
decomposition.addHelpText(
|
|
3117
|
-
"after",
|
|
3118
|
-
`
|
|
3119
|
-
Examples:
|
|
3120
|
-
$ sechroom decomposition decompose mem_XXXX
|
|
3121
|
-
$ sechroom decomposition execute sug_XXXX
|
|
3122
|
-
$ sechroom decomposition publish-run sug_XXXX
|
|
3123
|
-
$ sechroom decomposition accept sug_XXXX
|
|
3124
|
-
$ sechroom decomposition reject sug_XXXX --reason "wrong shape"`
|
|
3125
|
-
);
|
|
3126
|
-
decomposition.command("decompose <briefId>").description(
|
|
3127
|
-
"Decompose a work brief into a candidate Task graph (POST /work-briefs/{id}/decompose)"
|
|
3128
|
-
).action(async (briefId, _opts, cmd) => {
|
|
3129
|
-
const cfg = resolveConfig(cmd.optsWithGlobals());
|
|
3130
|
-
const data = await runApi("Queueing decomposition", async () => {
|
|
3131
|
-
const client = await makeClient(cfg);
|
|
3132
|
-
return client.POST("/work-briefs/{id}/decompose", {
|
|
3133
|
-
params: { path: { id: briefId } },
|
|
3134
|
-
body: { id: briefId }
|
|
3135
|
-
});
|
|
3136
|
-
});
|
|
3137
|
-
emitAction(
|
|
3138
|
-
`queued decomposition of ${style.bold(briefId)} \u2192 ${style.bold(data.suggestionId)}`,
|
|
3139
|
-
data,
|
|
3140
|
-
cmd.optsWithGlobals().json
|
|
3141
|
-
);
|
|
3142
|
-
});
|
|
3143
|
-
decomposition.command("execute <decompositionId>").description(
|
|
3144
|
-
"Execute a decomposition's Task graph (POST /decompositions/{id}/execute)"
|
|
3145
|
-
).action(async (decompositionId, _opts, cmd) => {
|
|
3146
|
-
const cfg = resolveConfig(cmd.optsWithGlobals());
|
|
3147
|
-
const data = await runApi("Executing decomposition", async () => {
|
|
3148
|
-
const client = await makeClient(cfg);
|
|
3149
|
-
return client.POST("/decompositions/{id}/execute", {
|
|
3150
|
-
params: { path: { id: decompositionId } },
|
|
3151
|
-
body: {}
|
|
3152
|
-
});
|
|
3153
|
-
});
|
|
3154
|
-
emitAction(
|
|
3155
|
-
`executed ${style.bold(decompositionId)} \u2192 run ${style.bold(data.runRecordId)} (${data.outcome})`,
|
|
3156
|
-
data,
|
|
3157
|
-
cmd.optsWithGlobals().json
|
|
3158
|
-
);
|
|
3437
|
+
emitAction(`created snapshot ${style.bold(data.snapshotId)}`, data, cmd.optsWithGlobals().json);
|
|
3159
3438
|
});
|
|
3160
|
-
|
|
3161
|
-
"Publish an accepted decomposition's context pack on demand (POST /decompositions/{id}/publish-run)"
|
|
3162
|
-
).action(async (decompositionId, _opts, cmd) => {
|
|
3439
|
+
continuity.command("snapshot-get <id>").description("Fetch a snapshot by id (GET /continuity/snapshots/{id})").action(async (id, _opts, cmd) => {
|
|
3163
3440
|
const cfg = resolveConfig(cmd.optsWithGlobals());
|
|
3164
|
-
const data = await runApi("
|
|
3441
|
+
const data = await runApi("Fetching snapshot", async () => {
|
|
3165
3442
|
const client = await makeClient(cfg);
|
|
3166
|
-
return client.
|
|
3167
|
-
params: { path: { id: decompositionId } },
|
|
3168
|
-
body: {}
|
|
3169
|
-
});
|
|
3443
|
+
return client.GET("/continuity/snapshots/{id}", { params: { path: { id } } });
|
|
3170
3444
|
});
|
|
3171
|
-
|
|
3172
|
-
`published ${style.bold(decompositionId)} \u2192 run ${style.bold(data.runRecordId)} (${data.outcome})`,
|
|
3173
|
-
data,
|
|
3174
|
-
cmd.optsWithGlobals().json
|
|
3175
|
-
);
|
|
3445
|
+
emit(data, cmd.optsWithGlobals().json);
|
|
3176
3446
|
});
|
|
3177
|
-
|
|
3178
|
-
"Accept a Pending decomposition \u2014 promote + ratify its Tasks (POST /decompositions/{id}/accept)"
|
|
3179
|
-
).action(async (decompositionId, _opts, cmd) => {
|
|
3447
|
+
continuity.command("snapshots").description("List the caller's own snapshots (GET /me/continuity/snapshots)").option("--scope <scope>", "Filter by scope").option("--lane <laneId>", "Filter by lane id").action(async (opts, cmd) => {
|
|
3180
3448
|
const cfg = resolveConfig(cmd.optsWithGlobals());
|
|
3181
|
-
const data = await runApi("
|
|
3449
|
+
const data = await runApi("Listing snapshots", async () => {
|
|
3182
3450
|
const client = await makeClient(cfg);
|
|
3183
|
-
return client.
|
|
3184
|
-
params: {
|
|
3185
|
-
|
|
3451
|
+
return client.GET("/me/continuity/snapshots", {
|
|
3452
|
+
params: {
|
|
3453
|
+
query: {
|
|
3454
|
+
...opts.scope ? { scope: opts.scope } : {},
|
|
3455
|
+
...opts.lane ? { laneId: opts.lane } : {}
|
|
3456
|
+
}
|
|
3457
|
+
}
|
|
3186
3458
|
});
|
|
3187
3459
|
});
|
|
3188
|
-
|
|
3189
|
-
`accepted decomposition ${style.bold(decompositionId)}`,
|
|
3190
|
-
data,
|
|
3191
|
-
cmd.optsWithGlobals().json
|
|
3192
|
-
);
|
|
3460
|
+
emit(data, cmd.optsWithGlobals().json);
|
|
3193
3461
|
});
|
|
3194
|
-
|
|
3195
|
-
"Reject a Pending decomposition \u2014 archive its Tasks, bounce the brief (POST /decompositions/{id}/reject)"
|
|
3196
|
-
).option("--reason <reason>", "Optional free-text rejection reason").action(async (decompositionId, opts, cmd) => {
|
|
3462
|
+
continuity.command("resume-me").description("Resume the caller's own lane (POST /continuity/resume/me)").option("--workspace <workspaceId>", "Scope to a workspace").option("--max-artifacts <n>", "Cap artifacts in the bundle").option("--changed-since <iso>", "Only include changes since this ISO timestamp").option("--looking-at-myself", "Include the caller's own changes", false).action(async (opts, cmd) => {
|
|
3197
3463
|
const cfg = resolveConfig(cmd.optsWithGlobals());
|
|
3198
|
-
const data = await runApi("
|
|
3464
|
+
const data = await runApi("Resuming", async () => {
|
|
3199
3465
|
const client = await makeClient(cfg);
|
|
3200
|
-
return client.POST("/
|
|
3201
|
-
|
|
3202
|
-
|
|
3466
|
+
return client.POST("/continuity/resume/me", {
|
|
3467
|
+
body: {
|
|
3468
|
+
workspaceId: opts.workspace ?? null,
|
|
3469
|
+
maxArtifacts: opts.maxArtifacts != null ? Number(opts.maxArtifacts) : null,
|
|
3470
|
+
includeLookingAtMyself: opts.lookingAtMyself ? true : null,
|
|
3471
|
+
changedSince: opts.changedSince ?? null
|
|
3472
|
+
}
|
|
3203
3473
|
});
|
|
3204
3474
|
});
|
|
3205
|
-
|
|
3206
|
-
`rejected decomposition ${style.bold(decompositionId)}`,
|
|
3207
|
-
data,
|
|
3208
|
-
cmd.optsWithGlobals().json
|
|
3209
|
-
);
|
|
3210
|
-
});
|
|
3211
|
-
}
|
|
3212
|
-
|
|
3213
|
-
// src/commands/executor.ts
|
|
3214
|
-
import { dirname as dirname8, join as join11 } from "path";
|
|
3215
|
-
import { existsSync as existsSync9, mkdirSync as mkdirSync9, readFileSync as readFileSync8, writeFileSync as writeFileSync9 } from "fs";
|
|
3216
|
-
var EXECUTOR_STATE = "executor.json";
|
|
3217
|
-
var EXECUTOR_PULSE_COMMAND = "sechroom executor hook-pulse";
|
|
3218
|
-
var EXECUTOR_STOP_COMMAND = "sechroom executor hook-stop";
|
|
3219
|
-
var CLAUDE_EXECUTOR_HOOKS = {
|
|
3220
|
-
SessionStart: EXECUTOR_PULSE_COMMAND,
|
|
3221
|
-
UserPromptSubmit: EXECUTOR_PULSE_COMMAND,
|
|
3222
|
-
PreToolUse: EXECUTOR_PULSE_COMMAND,
|
|
3223
|
-
Stop: EXECUTOR_PULSE_COMMAND,
|
|
3224
|
-
SessionEnd: EXECUTOR_STOP_COMMAND
|
|
3225
|
-
};
|
|
3226
|
-
var CODEX_EXECUTOR_HOOKS = {
|
|
3227
|
-
SessionStart: EXECUTOR_PULSE_COMMAND,
|
|
3228
|
-
UserPromptSubmit: EXECUTOR_PULSE_COMMAND,
|
|
3229
|
-
PreToolUse: EXECUTOR_PULSE_COMMAND,
|
|
3230
|
-
Stop: EXECUTOR_PULSE_COMMAND
|
|
3231
|
-
};
|
|
3232
|
-
function registerExecutor(program2) {
|
|
3233
|
-
const executor = program2.command("executor").description(
|
|
3234
|
-
"Register and operate a local Claude Code/Codex executor advertisement"
|
|
3235
|
-
);
|
|
3236
|
-
executor.command("install").description("Configure this checkout's harness to advertise itself as a WLP executor").option("--connector <id>", "Approved local-session ConnectorDefinition id").option("--instance-key <key>", "Stable executor identity (defaults to .sechroom/lane.json code-lane)").option("--runtime <kind>", "claude-code | codex").option("--surface <surface>", "claude | codex").option("--capability <key...>", "Capability operation keys claimed by this instance").option("--relay <id>", "Relay identity shared by sibling instances", "sechroom-cli-local").option("--subscription-name <name>", "SignalR delivery binding name", "executor-dispatch").option("--ttl <seconds>", "Advertisement TTL (30-600)", parseInteger, 600).option("--refresh-after <seconds>", "Minimum age before a hook refreshes", parseInteger, 40).option("-y, --yes", "Non-interactive: accept detected surface and lane defaults", false).option("--dry-run", "Show hook files without writing", false).action(async (opts, cmd) => {
|
|
3237
|
-
const globals = cmd.optsWithGlobals();
|
|
3238
|
-
const lane = readSem()?.values["code-lane"];
|
|
3239
|
-
const detected = detectHookSurfaces(process.cwd());
|
|
3240
|
-
let surface = opts.surface;
|
|
3241
|
-
let instanceKey = opts.instanceKey;
|
|
3242
|
-
let runtime = opts.runtime;
|
|
3243
|
-
let connector = opts.connector;
|
|
3244
|
-
let capabilities = opts.capability;
|
|
3245
|
-
const surfaceDefault = detected.length === 1 ? detected[0] : lane?.includes("codex") ? "codex" : "claude";
|
|
3246
|
-
if (!opts.yes && canPrompt()) {
|
|
3247
|
-
surface = await promptText("Harness surface (claude or codex)?", surface ?? surfaceDefault);
|
|
3248
|
-
instanceKey = await promptText("Executor instance key?", instanceKey ?? lane ?? "");
|
|
3249
|
-
runtime = await promptText("Runtime (claude-code or codex)?", runtime ?? (surface === "codex" ? "codex" : "claude-code"));
|
|
3250
|
-
connector = await promptText("Approved local-session connector id?", connector ?? "");
|
|
3251
|
-
const capabilityText = await promptText("Capability keys (comma-separated; blank for none)?", capabilities?.join(",") ?? "");
|
|
3252
|
-
capabilities = capabilityText.split(",").map((x) => x.trim()).filter(Boolean);
|
|
3253
|
-
}
|
|
3254
|
-
surface ??= surfaceDefault;
|
|
3255
|
-
instanceKey ??= lane;
|
|
3256
|
-
runtime ??= surface === "codex" ? "codex" : "claude-code";
|
|
3257
|
-
if (!connector) fail("executor install requires --connector (or an interactive connector id)");
|
|
3258
|
-
if (!instanceKey) fail("no instance key resolved; pass --instance-key or pin .sechroom/lane.json code-lane");
|
|
3259
|
-
if (!opts.yes && !canPrompt()) fail("non-interactive executor install requires --yes");
|
|
3260
|
-
parseRuntimeKind(runtime);
|
|
3261
|
-
if (!["claude", "codex"].includes(surface)) fail("surface must be claude or codex");
|
|
3262
|
-
if (opts.refreshAfter >= opts.ttl) fail("refresh-after must be shorter than the TTL");
|
|
3263
|
-
const sem = readSem();
|
|
3264
|
-
const checkout = sem ? dirname8(dirname8(sem.path)) : process.cwd();
|
|
3265
|
-
const statePath = join11(checkout, ".sechroom", EXECUTOR_STATE);
|
|
3266
|
-
const state = {
|
|
3267
|
-
schemaVersion: 1,
|
|
3268
|
-
instanceKey,
|
|
3269
|
-
runtime: runtime.toLowerCase() === "codex" ? "codex" : "claude-code",
|
|
3270
|
-
connectorId: connector,
|
|
3271
|
-
capabilityKeys: capabilities ?? [],
|
|
3272
|
-
relayId: opts.relay,
|
|
3273
|
-
subscriptionName: opts.subscriptionName,
|
|
3274
|
-
ttlSeconds: opts.ttl,
|
|
3275
|
-
refreshAfterSeconds: opts.refreshAfter
|
|
3276
|
-
};
|
|
3277
|
-
if (!opts.dryRun) {
|
|
3278
|
-
mkdirSync9(dirname8(statePath), { recursive: true });
|
|
3279
|
-
writeFileSync9(statePath, JSON.stringify(state, null, 2) + "\n");
|
|
3280
|
-
ensureStateDirIgnored(checkout);
|
|
3281
|
-
}
|
|
3282
|
-
const configuredClaudeDirs = globals.claudeConfigDir || process.env.CLAUDE_CONFIG_DIR ? resolveClaudeTargets({ override: globals.claudeConfigDir }).map((target) => target.dir) : [join11(checkout, ".claude")];
|
|
3283
|
-
const configuredCodexHomes = globals.codexHome || process.env.CODEX_HOME ? resolveCodexHomes({ override: globals.codexHome }) : [join11(checkout, ".codex")];
|
|
3284
|
-
const hookTargets = surface === "claude" ? configuredClaudeDirs : configuredCodexHomes;
|
|
3285
|
-
for (const target of hookTargets) {
|
|
3286
|
-
const results = surface === "claude" ? [installClaudeCommands(target, CLAUDE_EXECUTOR_HOOKS, opts.dryRun)] : installCodexCommands(target, CODEX_EXECUTOR_HOOKS, opts.dryRun);
|
|
3287
|
-
for (const result of results) process.stderr.write(describe(result, opts.dryRun) + "\n");
|
|
3288
|
-
}
|
|
3289
|
-
warnIfSechroomNotOnPath();
|
|
3290
|
-
process.stderr.write(style.green("executor harness configured") + style.dim(` \u2014 ${instanceKey}
|
|
3291
|
-
`));
|
|
3475
|
+
emit(data, cmd.optsWithGlobals().json);
|
|
3292
3476
|
});
|
|
3293
|
-
|
|
3294
|
-
await drainStdin();
|
|
3295
|
-
const located = readExecutorState();
|
|
3296
|
-
if (!located) return;
|
|
3297
|
-
const { state, path } = located;
|
|
3298
|
-
const age = state.lastRefreshAt ? Date.now() - Date.parse(state.lastRefreshAt) : Number.POSITIVE_INFINITY;
|
|
3299
|
-
if (state.instanceId && age < state.refreshAfterSeconds * 1e3) return;
|
|
3477
|
+
continuity.command("resume-lane <laneId>").description("Resume a specific lane (POST /continuity/resume/lane)").option("--workspace <workspaceId>", "Scope to a workspace").option("--max-artifacts <n>", "Cap artifacts in the bundle").option("--changed-since <iso>", "Only include changes since this ISO timestamp").option("--looking-at-myself", "Include the caller's own changes", false).action(async (laneId, opts, cmd) => {
|
|
3300
3478
|
const cfg = resolveConfig(cmd.optsWithGlobals());
|
|
3301
|
-
|
|
3302
|
-
|
|
3303
|
-
|
|
3304
|
-
|
|
3305
|
-
|
|
3306
|
-
|
|
3307
|
-
|
|
3479
|
+
const data = await runApi("Resuming lane", async () => {
|
|
3480
|
+
const client = await makeClient(cfg);
|
|
3481
|
+
return client.POST("/continuity/resume/lane", {
|
|
3482
|
+
body: {
|
|
3483
|
+
laneId,
|
|
3484
|
+
workspaceId: opts.workspace ?? null,
|
|
3485
|
+
maxArtifacts: opts.maxArtifacts != null ? Number(opts.maxArtifacts) : null,
|
|
3486
|
+
includeLookingAtMyself: opts.lookingAtMyself ? true : null,
|
|
3487
|
+
changedSince: opts.changedSince ?? null
|
|
3308
3488
|
}
|
|
3309
|
-
}
|
|
3310
|
-
data = await registerInstance(cfg, state);
|
|
3311
|
-
}
|
|
3312
|
-
state.instanceId = data.id;
|
|
3313
|
-
state.lastRefreshAt = (/* @__PURE__ */ new Date()).toISOString();
|
|
3314
|
-
writeFileSync9(path, JSON.stringify(state, null, 2) + "\n");
|
|
3315
|
-
} catch {
|
|
3316
|
-
}
|
|
3317
|
-
});
|
|
3318
|
-
executor.command("hook-stop").description("Hook adapter: deregister this checkout's executor").action(async (_opts, cmd) => {
|
|
3319
|
-
await drainStdin();
|
|
3320
|
-
const located = readExecutorState();
|
|
3321
|
-
if (!located?.state.instanceId) return;
|
|
3322
|
-
try {
|
|
3323
|
-
await api(resolveConfig(cmd.optsWithGlobals()), `/me/executor-instances/${encodeURIComponent(located.state.instanceId)}`, { method: "DELETE", body: JSON.stringify({}) });
|
|
3324
|
-
delete located.state.instanceId;
|
|
3325
|
-
delete located.state.lastRefreshAt;
|
|
3326
|
-
writeFileSync9(located.path, JSON.stringify(located.state, null, 2) + "\n");
|
|
3327
|
-
} catch {
|
|
3328
|
-
}
|
|
3329
|
-
});
|
|
3330
|
-
executor.command("submit-connector").description(
|
|
3331
|
-
"Submit a local-session connector definition for governed approval"
|
|
3332
|
-
).requiredOption("--slug <slug>", "Unique connector definition slug").requiredOption("--display-name <name>", "Human-readable connector name").requiredOption("--transport <kind>", "push | pull").option("--profile <profile...>", "Advertised runtime profiles", [
|
|
3333
|
-
"base",
|
|
3334
|
-
"dotnet-10"
|
|
3335
|
-
]).action(async (opts, cmd) => {
|
|
3336
|
-
const cfg = resolveConfig(cmd.optsWithGlobals());
|
|
3337
|
-
const data = await api(cfg, "/connectors/definitions", {
|
|
3338
|
-
method: "POST",
|
|
3339
|
-
body: JSON.stringify({
|
|
3340
|
-
slug: opts.slug,
|
|
3341
|
-
displayName: opts.displayName,
|
|
3342
|
-
runtimeProfiles: opts.profile,
|
|
3343
|
-
connectorKind: "ExecutionRuntime",
|
|
3344
|
-
providerKind: "local-session",
|
|
3345
|
-
dispatchTransport: parseTransport(opts.transport)
|
|
3346
|
-
})
|
|
3489
|
+
});
|
|
3347
3490
|
});
|
|
3348
|
-
emit(data,
|
|
3349
|
-
if (!cmd.optsWithGlobals().json) {
|
|
3350
|
-
process.stderr.write(
|
|
3351
|
-
style.dim(
|
|
3352
|
-
"approve this connector definition before registering executors\n"
|
|
3353
|
-
)
|
|
3354
|
-
);
|
|
3355
|
-
}
|
|
3491
|
+
emit(data, cmd.optsWithGlobals().json);
|
|
3356
3492
|
});
|
|
3357
|
-
|
|
3358
|
-
"Create/reuse a SignalR binding and register this local executor instance"
|
|
3359
|
-
).requiredOption(
|
|
3360
|
-
"--instance-key <key>",
|
|
3361
|
-
"Stable key for this concrete session/lane"
|
|
3362
|
-
).requiredOption(
|
|
3363
|
-
"--connector <id>",
|
|
3364
|
-
"Approved local-session ConnectorDefinition id"
|
|
3365
|
-
).option("--runtime <kind>", "claude-code | codex", "claude-code").option(
|
|
3366
|
-
"--relay <id>",
|
|
3367
|
-
"Relay identity shared by sibling instances",
|
|
3368
|
-
"sechroom-cli-local"
|
|
3369
|
-
).option(
|
|
3370
|
-
"--subscription-name <name>",
|
|
3371
|
-
"SignalR delivery binding name",
|
|
3372
|
-
"executor-dispatch"
|
|
3373
|
-
).option(
|
|
3374
|
-
"--capability <key...>",
|
|
3375
|
-
"Capability operation keys claimed by this instance"
|
|
3376
|
-
).option("--tool-set-ref <ref>", "Optional governed tool-set reference").option("--ttl <seconds>", "Advertisement TTL (30-600)", parseInteger, 120).action(async (opts, cmd) => {
|
|
3493
|
+
continuity.command("changed-since").description("What changed since a timestamp (POST /continuity/changed-since)").requiredOption("--since <iso>", "ISO-8601 timestamp to compare against").option("--looking-at-myself", "Include the caller's own changes", false).action(async (opts, cmd) => {
|
|
3377
3494
|
const cfg = resolveConfig(cmd.optsWithGlobals());
|
|
3378
|
-
|
|
3379
|
-
|
|
3380
|
-
|
|
3381
|
-
|
|
3382
|
-
|
|
3383
|
-
|
|
3384
|
-
|
|
3385
|
-
|
|
3386
|
-
|
|
3387
|
-
|
|
3388
|
-
filter: { tags: ["kind:task"], workspaceScope: [cfg.workspaceId] }
|
|
3389
|
-
})
|
|
3390
|
-
}
|
|
3391
|
-
);
|
|
3392
|
-
const data = await api(
|
|
3393
|
-
cfg,
|
|
3394
|
-
"/me/executor-instances",
|
|
3395
|
-
{
|
|
3396
|
-
method: "POST",
|
|
3397
|
-
body: JSON.stringify({
|
|
3398
|
-
relayId: opts.relay,
|
|
3399
|
-
instanceKey: opts.instanceKey,
|
|
3400
|
-
runtimeKind: parseRuntimeKind(opts.runtime),
|
|
3401
|
-
activationMode: "Attached",
|
|
3402
|
-
deliverySubscriptionId: subscription.id,
|
|
3403
|
-
connectorId: opts.connector,
|
|
3404
|
-
claimedCapabilityKeys: opts.capability ?? [],
|
|
3405
|
-
toolSetRef: opts.toolSetRef ?? null,
|
|
3406
|
-
ttlSeconds: opts.ttl
|
|
3407
|
-
})
|
|
3408
|
-
}
|
|
3409
|
-
);
|
|
3410
|
-
emit(data, Boolean(cmd.optsWithGlobals().json));
|
|
3411
|
-
if (!cmd.optsWithGlobals().json)
|
|
3412
|
-
process.stderr.write(
|
|
3413
|
-
style.dim(`refresh with: sechroom executor heartbeat ${data.id}
|
|
3414
|
-
`)
|
|
3415
|
-
);
|
|
3416
|
-
});
|
|
3417
|
-
executor.command("refresh <id>").description("Refresh one advertisement lease once").option("--ttl <seconds>", "Advertisement TTL (30-600)", parseInteger, 120).action(async (id, opts, cmd) => {
|
|
3418
|
-
const data = await refresh(
|
|
3419
|
-
resolveConfig(cmd.optsWithGlobals()),
|
|
3420
|
-
id,
|
|
3421
|
-
opts.ttl
|
|
3422
|
-
);
|
|
3423
|
-
emit(data, Boolean(cmd.optsWithGlobals().json));
|
|
3495
|
+
const data = await runApi("Computing changes", async () => {
|
|
3496
|
+
const client = await makeClient(cfg);
|
|
3497
|
+
return client.POST("/continuity/changed-since", {
|
|
3498
|
+
body: {
|
|
3499
|
+
since: opts.since,
|
|
3500
|
+
includeLookingAtMyself: opts.lookingAtMyself ? true : null
|
|
3501
|
+
}
|
|
3502
|
+
});
|
|
3503
|
+
});
|
|
3504
|
+
emit(data, cmd.optsWithGlobals().json);
|
|
3424
3505
|
});
|
|
3425
|
-
|
|
3426
|
-
if (opts.interval >= opts.ttl)
|
|
3427
|
-
fail("heartbeat interval must be shorter than the TTL");
|
|
3506
|
+
continuity.command("load-set").description("Derive the active load set (POST /continuity/load-set/derive)").option("--workspace <workspaceId>", "Scope to a workspace").option("--max-artifacts <n>", "Cap artifacts in the load set").option("--looking-at-myself", "Include the caller's own changes", false).action(async (opts, cmd) => {
|
|
3428
3507
|
const cfg = resolveConfig(cmd.optsWithGlobals());
|
|
3429
|
-
await
|
|
3430
|
-
|
|
3431
|
-
|
|
3432
|
-
|
|
3433
|
-
|
|
3434
|
-
|
|
3435
|
-
|
|
3436
|
-
|
|
3508
|
+
const data = await runApi("Deriving load set", async () => {
|
|
3509
|
+
const client = await makeClient(cfg);
|
|
3510
|
+
return client.POST("/continuity/load-set/derive", {
|
|
3511
|
+
body: {
|
|
3512
|
+
workspaceId: opts.workspace ?? null,
|
|
3513
|
+
maxArtifacts: opts.maxArtifacts != null ? Number(opts.maxArtifacts) : null,
|
|
3514
|
+
includeLookingAtMyself: opts.lookingAtMyself ? true : null
|
|
3515
|
+
}
|
|
3516
|
+
});
|
|
3517
|
+
});
|
|
3518
|
+
emit(data, cmd.optsWithGlobals().json);
|
|
3437
3519
|
});
|
|
3438
|
-
|
|
3520
|
+
continuity.command("grant <snapshotId>").description("Grant another operator read access (POST /continuity/snapshots/{snapshotId}/grants)").requiredOption("--grantee <userId>", "Sechroom user id being granted read access").option("--source <source>", "Permission-set source kind", "TenantRole").option("--source-id <sourceId>", "Permission-set source id (e.g. a tenant role)", "viewer").option("--valid-from <iso>", "Optional ISO-8601 grant start").option("--valid-to <iso>", "Optional ISO-8601 grant expiry").action(async (snapshotId, opts, cmd) => {
|
|
3439
3521
|
const cfg = resolveConfig(cmd.optsWithGlobals());
|
|
3440
|
-
const data = await
|
|
3441
|
-
cfg
|
|
3442
|
-
|
|
3522
|
+
const data = await runApi("Minting grant", async () => {
|
|
3523
|
+
const client = await makeClient(cfg);
|
|
3524
|
+
return client.POST("/continuity/snapshots/{snapshotId}/grants", {
|
|
3525
|
+
params: { path: { snapshotId } },
|
|
3526
|
+
body: {
|
|
3527
|
+
userId: opts.grantee,
|
|
3528
|
+
kind: "Allow",
|
|
3529
|
+
source: opts.source,
|
|
3530
|
+
sourceId: opts.sourceId,
|
|
3531
|
+
...opts.validFrom ? { validFrom: opts.validFrom } : {},
|
|
3532
|
+
...opts.validTo ? { validTo: opts.validTo } : {}
|
|
3533
|
+
}
|
|
3534
|
+
});
|
|
3535
|
+
});
|
|
3536
|
+
emitAction(
|
|
3537
|
+
`granted ${style.bold(data.userId)} read on ${style.bold(snapshotId)} ${style.dim(`(grant ${data.grantId})`)}`,
|
|
3538
|
+
data,
|
|
3539
|
+
cmd.optsWithGlobals().json
|
|
3443
3540
|
);
|
|
3444
|
-
emit(data, Boolean(cmd.optsWithGlobals().json));
|
|
3445
3541
|
});
|
|
3446
|
-
|
|
3542
|
+
continuity.command("revoke-grant <snapshotId> <grantId>").description("Revoke a grant (DELETE /continuity/snapshots/{snapshotId}/grants/{grantId})").action(async (snapshotId, grantId, _opts, cmd) => {
|
|
3447
3543
|
const cfg = resolveConfig(cmd.optsWithGlobals());
|
|
3448
|
-
const data = await
|
|
3449
|
-
cfg
|
|
3450
|
-
|
|
3451
|
-
|
|
3452
|
-
|
|
3453
|
-
|
|
3454
|
-
|
|
3544
|
+
const data = await runApi("Revoking grant", async () => {
|
|
3545
|
+
const client = await makeClient(cfg);
|
|
3546
|
+
return client.DELETE("/continuity/snapshots/{snapshotId}/grants/{grantId}", {
|
|
3547
|
+
params: { path: { snapshotId, grantId } },
|
|
3548
|
+
body: {}
|
|
3549
|
+
});
|
|
3550
|
+
});
|
|
3551
|
+
emitAction(
|
|
3552
|
+
`revoked grant ${style.bold(grantId)} on ${style.bold(snapshotId)}`,
|
|
3553
|
+
data,
|
|
3554
|
+
cmd.optsWithGlobals().json
|
|
3455
3555
|
);
|
|
3456
|
-
emit(data, Boolean(cmd.optsWithGlobals().json));
|
|
3457
3556
|
});
|
|
3458
3557
|
}
|
|
3459
|
-
|
|
3460
|
-
|
|
3461
|
-
|
|
3462
|
-
|
|
3463
|
-
|
|
3464
|
-
case "codex":
|
|
3465
|
-
return "Codex";
|
|
3466
|
-
default:
|
|
3467
|
-
return fail("runtime must be claude-code or codex");
|
|
3468
|
-
}
|
|
3469
|
-
}
|
|
3470
|
-
function parseTransport(value) {
|
|
3471
|
-
switch (value.trim().toLowerCase()) {
|
|
3472
|
-
case "push":
|
|
3473
|
-
return "Push";
|
|
3474
|
-
case "pull":
|
|
3475
|
-
return "Pull";
|
|
3476
|
-
default:
|
|
3477
|
-
return fail("transport must be push or pull");
|
|
3478
|
-
}
|
|
3479
|
-
}
|
|
3480
|
-
async function refresh(cfg, id, ttlSeconds) {
|
|
3481
|
-
return api(
|
|
3482
|
-
cfg,
|
|
3483
|
-
`/me/executor-instances/${encodeURIComponent(id)}/refresh`,
|
|
3484
|
-
{
|
|
3485
|
-
method: "POST",
|
|
3486
|
-
body: JSON.stringify({ ttlSeconds })
|
|
3487
|
-
}
|
|
3558
|
+
|
|
3559
|
+
// src/commands/decomposition.ts
|
|
3560
|
+
function registerDecomposition(program2) {
|
|
3561
|
+
const decomposition = program2.command("decomposition").description(
|
|
3562
|
+
"Drive a WLP decomposition: decompose a brief, then execute / accept / reject"
|
|
3488
3563
|
);
|
|
3489
|
-
|
|
3490
|
-
|
|
3491
|
-
|
|
3492
|
-
|
|
3493
|
-
|
|
3494
|
-
|
|
3564
|
+
decomposition.addHelpText(
|
|
3565
|
+
"after",
|
|
3566
|
+
`
|
|
3567
|
+
Examples:
|
|
3568
|
+
$ sechroom decomposition decompose mem_XXXX
|
|
3569
|
+
$ sechroom decomposition execute sug_XXXX
|
|
3570
|
+
$ sechroom decomposition publish-run sug_XXXX
|
|
3571
|
+
$ sechroom decomposition accept sug_XXXX
|
|
3572
|
+
$ sechroom decomposition reject sug_XXXX --reason "wrong shape"`
|
|
3573
|
+
);
|
|
3574
|
+
decomposition.command("decompose <briefId>").description(
|
|
3575
|
+
"Decompose a work brief into a candidate Task graph (POST /work-briefs/{id}/decompose)"
|
|
3576
|
+
).action(async (briefId, _opts, cmd) => {
|
|
3577
|
+
const cfg = resolveConfig(cmd.optsWithGlobals());
|
|
3578
|
+
const data = await runApi("Queueing decomposition", async () => {
|
|
3579
|
+
const client = await makeClient(cfg);
|
|
3580
|
+
return client.POST("/work-briefs/{id}/decompose", {
|
|
3581
|
+
params: { path: { id: briefId } },
|
|
3582
|
+
body: { id: briefId }
|
|
3583
|
+
});
|
|
3584
|
+
});
|
|
3585
|
+
emitAction(
|
|
3586
|
+
`queued decomposition of ${style.bold(briefId)} \u2192 ${style.bold(data.suggestionId)}`,
|
|
3587
|
+
data,
|
|
3588
|
+
cmd.optsWithGlobals().json
|
|
3589
|
+
);
|
|
3495
3590
|
});
|
|
3496
|
-
|
|
3497
|
-
|
|
3498
|
-
|
|
3591
|
+
decomposition.command("execute <decompositionId>").description(
|
|
3592
|
+
"Execute a decomposition's Task graph (POST /decompositions/{id}/execute)"
|
|
3593
|
+
).action(async (decompositionId, _opts, cmd) => {
|
|
3594
|
+
const cfg = resolveConfig(cmd.optsWithGlobals());
|
|
3595
|
+
const data = await runApi("Executing decomposition", async () => {
|
|
3596
|
+
const client = await makeClient(cfg);
|
|
3597
|
+
return client.POST("/decompositions/{id}/execute", {
|
|
3598
|
+
params: { path: { id: decompositionId } },
|
|
3599
|
+
body: {}
|
|
3600
|
+
});
|
|
3601
|
+
});
|
|
3602
|
+
emitAction(
|
|
3603
|
+
`executed ${style.bold(decompositionId)} \u2192 run ${style.bold(data.runRecordId)} (${data.outcome})`,
|
|
3604
|
+
data,
|
|
3605
|
+
cmd.optsWithGlobals().json
|
|
3606
|
+
);
|
|
3499
3607
|
});
|
|
3500
|
-
|
|
3501
|
-
|
|
3502
|
-
|
|
3503
|
-
|
|
3504
|
-
|
|
3505
|
-
|
|
3506
|
-
|
|
3507
|
-
}
|
|
3508
|
-
|
|
3509
|
-
|
|
3510
|
-
|
|
3511
|
-
|
|
3512
|
-
}
|
|
3513
|
-
|
|
3514
|
-
|
|
3515
|
-
|
|
3516
|
-
...init,
|
|
3517
|
-
headers: {
|
|
3518
|
-
authorization: `Bearer ${token}`,
|
|
3519
|
-
tenant: cfg.tenant,
|
|
3520
|
-
"content-type": "application/json",
|
|
3521
|
-
"x-sechroom-surface": "cli"
|
|
3522
|
-
}
|
|
3608
|
+
decomposition.command("publish-run <decompositionId>").description(
|
|
3609
|
+
"Publish an accepted decomposition's context pack on demand (POST /decompositions/{id}/publish-run)"
|
|
3610
|
+
).action(async (decompositionId, _opts, cmd) => {
|
|
3611
|
+
const cfg = resolveConfig(cmd.optsWithGlobals());
|
|
3612
|
+
const data = await runApi("Publishing context pack", async () => {
|
|
3613
|
+
const client = await makeClient(cfg);
|
|
3614
|
+
return client.POST("/decompositions/{id}/publish-run", {
|
|
3615
|
+
params: { path: { id: decompositionId } },
|
|
3616
|
+
body: {}
|
|
3617
|
+
});
|
|
3618
|
+
});
|
|
3619
|
+
emitAction(
|
|
3620
|
+
`published ${style.bold(decompositionId)} \u2192 run ${style.bold(data.runRecordId)} (${data.outcome})`,
|
|
3621
|
+
data,
|
|
3622
|
+
cmd.optsWithGlobals().json
|
|
3623
|
+
);
|
|
3523
3624
|
});
|
|
3524
|
-
|
|
3525
|
-
|
|
3526
|
-
|
|
3625
|
+
decomposition.command("accept <decompositionId>").description(
|
|
3626
|
+
"Accept a Pending decomposition \u2014 promote + ratify its Tasks (POST /decompositions/{id}/accept)"
|
|
3627
|
+
).action(async (decompositionId, _opts, cmd) => {
|
|
3628
|
+
const cfg = resolveConfig(cmd.optsWithGlobals());
|
|
3629
|
+
const data = await runApi("Accepting decomposition", async () => {
|
|
3630
|
+
const client = await makeClient(cfg);
|
|
3631
|
+
return client.POST("/decompositions/{id}/accept", {
|
|
3632
|
+
params: { path: { id: decompositionId } },
|
|
3633
|
+
body: {}
|
|
3634
|
+
});
|
|
3635
|
+
});
|
|
3636
|
+
emitAction(
|
|
3637
|
+
`accepted decomposition ${style.bold(decompositionId)}`,
|
|
3638
|
+
data,
|
|
3639
|
+
cmd.optsWithGlobals().json
|
|
3640
|
+
);
|
|
3641
|
+
});
|
|
3642
|
+
decomposition.command("reject <decompositionId>").description(
|
|
3643
|
+
"Reject a Pending decomposition \u2014 archive its Tasks, bounce the brief (POST /decompositions/{id}/reject)"
|
|
3644
|
+
).option("--reason <reason>", "Optional free-text rejection reason").action(async (decompositionId, opts, cmd) => {
|
|
3645
|
+
const cfg = resolveConfig(cmd.optsWithGlobals());
|
|
3646
|
+
const data = await runApi("Rejecting decomposition", async () => {
|
|
3647
|
+
const client = await makeClient(cfg);
|
|
3648
|
+
return client.POST("/decompositions/{id}/reject", {
|
|
3649
|
+
params: { path: { id: decompositionId } },
|
|
3650
|
+
body: { reasonText: opts.reason ?? null }
|
|
3651
|
+
});
|
|
3652
|
+
});
|
|
3653
|
+
emitAction(
|
|
3654
|
+
`rejected decomposition ${style.bold(decompositionId)}`,
|
|
3655
|
+
data,
|
|
3656
|
+
cmd.optsWithGlobals().json
|
|
3527
3657
|
);
|
|
3528
|
-
return response.json();
|
|
3529
|
-
}
|
|
3530
|
-
function parseInteger(value) {
|
|
3531
|
-
const parsed = Number.parseInt(value, 10);
|
|
3532
|
-
if (!Number.isFinite(parsed)) fail(`expected an integer, got '${value}'`);
|
|
3533
|
-
return parsed;
|
|
3534
|
-
}
|
|
3535
|
-
function holdHeartbeat(tick, intervalMs) {
|
|
3536
|
-
return new Promise((resolve3, reject) => {
|
|
3537
|
-
const timer = setInterval(() => void tick().catch(reject), intervalMs);
|
|
3538
|
-
const stop = () => {
|
|
3539
|
-
clearInterval(timer);
|
|
3540
|
-
resolve3();
|
|
3541
|
-
};
|
|
3542
|
-
process.once("SIGINT", stop);
|
|
3543
|
-
process.once("SIGTERM", stop);
|
|
3544
3658
|
});
|
|
3545
3659
|
}
|
|
3546
3660
|
|
|
@@ -5808,23 +5922,23 @@ Examples:
|
|
|
5808
5922
|
});
|
|
5809
5923
|
emit(data, cmd.optsWithGlobals().json);
|
|
5810
5924
|
});
|
|
5811
|
-
suggestion.command("accept <id>").description("Accept a suggestion (POST /relationship-suggestions/{
|
|
5925
|
+
suggestion.command("accept <id>").description("Accept a suggestion (POST /relationship-suggestions/{instanceId}/accept)").action(async (id, _opts, cmd) => {
|
|
5812
5926
|
const cfg = resolveConfig(cmd.optsWithGlobals());
|
|
5813
5927
|
const data = await runApi("Accepting suggestion", async () => {
|
|
5814
5928
|
const client = await makeClient(cfg);
|
|
5815
|
-
return client.POST("/relationship-suggestions/{
|
|
5816
|
-
params: { path: { id } },
|
|
5929
|
+
return client.POST("/relationship-suggestions/{instanceId}/accept", {
|
|
5930
|
+
params: { path: { instanceId: id } },
|
|
5817
5931
|
body: {}
|
|
5818
5932
|
});
|
|
5819
5933
|
});
|
|
5820
5934
|
emitAction(`accepted suggestion ${style.bold(id)}`, data, cmd.optsWithGlobals().json);
|
|
5821
5935
|
});
|
|
5822
|
-
suggestion.command("reject <id>").description("Reject a suggestion (POST /relationship-suggestions/{
|
|
5936
|
+
suggestion.command("reject <id>").description("Reject a suggestion (POST /relationship-suggestions/{instanceId}/reject)").option("--reason <reason>", "Why it's being rejected").option("--reason-code <code>", "Structured reason code").action(async (id, opts, cmd) => {
|
|
5823
5937
|
const cfg = resolveConfig(cmd.optsWithGlobals());
|
|
5824
5938
|
const data = await runApi("Rejecting suggestion", async () => {
|
|
5825
5939
|
const client = await makeClient(cfg);
|
|
5826
|
-
return client.POST("/relationship-suggestions/{
|
|
5827
|
-
params: { path: { id } },
|
|
5940
|
+
return client.POST("/relationship-suggestions/{instanceId}/reject", {
|
|
5941
|
+
params: { path: { instanceId: id } },
|
|
5828
5942
|
body: {
|
|
5829
5943
|
reason: opts.reason ?? null,
|
|
5830
5944
|
...opts.reasonCode ? { reasonCode: opts.reasonCode } : {}
|
|
@@ -6799,6 +6913,56 @@ Examples:
|
|
|
6799
6913
|
});
|
|
6800
6914
|
}
|
|
6801
6915
|
|
|
6916
|
+
// src/commands/work-brief.ts
|
|
6917
|
+
function registerWorkBrief(program2) {
|
|
6918
|
+
const workBrief = program2.command("work-brief").description("Control an active work brief run");
|
|
6919
|
+
workBrief.addHelpText(
|
|
6920
|
+
"after",
|
|
6921
|
+
`
|
|
6922
|
+
Examples:
|
|
6923
|
+
$ sechroom work-brief pause mem_XXXX --reason-code operator-hold --source claude-code-chris
|
|
6924
|
+
$ sechroom work-brief resume mem_XXXX --reason-code operator-resume --source claude-code-chris --reason "Ready to continue"
|
|
6925
|
+
$ sechroom work-brief cancel mem_XXXX --reason-code operator-stopped --source claude-code-chris --reason "Work no longer required"`
|
|
6926
|
+
);
|
|
6927
|
+
registerLifecycleAction(workBrief, "pause");
|
|
6928
|
+
registerLifecycleAction(workBrief, "resume");
|
|
6929
|
+
registerLifecycleAction(workBrief, "cancel");
|
|
6930
|
+
}
|
|
6931
|
+
function registerLifecycleAction(workBrief, action) {
|
|
6932
|
+
const presentParticiple = action === "pause" ? "Pausing" : action === "resume" ? "Resuming" : "Cancelling";
|
|
6933
|
+
const pastTense = action === "pause" ? "paused" : action === "resume" ? "resumed" : "cancelled";
|
|
6934
|
+
workBrief.command(`${action} <briefId>`).description(`${capitalize(action)} an active work brief run`).requiredOption(
|
|
6935
|
+
"--reason-code <code>",
|
|
6936
|
+
"Stable machine-readable reason code"
|
|
6937
|
+
).requiredOption(
|
|
6938
|
+
"--source <source>",
|
|
6939
|
+
"Calling surface or lane recorded in the audit"
|
|
6940
|
+
).option("--reason <text>", "Optional human-readable reason").action(async (briefId, opts, cmd) => {
|
|
6941
|
+
const globals = cmd.optsWithGlobals();
|
|
6942
|
+
const cfg = resolveConfig(globals);
|
|
6943
|
+
const data = await runApi(`${presentParticiple} work brief`, async () => {
|
|
6944
|
+
const client = await makeClient(cfg);
|
|
6945
|
+
return client.POST("/work-briefs/{id}/lifecycle", {
|
|
6946
|
+
params: { path: { id: briefId } },
|
|
6947
|
+
body: {
|
|
6948
|
+
action,
|
|
6949
|
+
reasonCode: opts.reasonCode,
|
|
6950
|
+
source: opts.source,
|
|
6951
|
+
reasonText: opts.reason ?? null
|
|
6952
|
+
}
|
|
6953
|
+
});
|
|
6954
|
+
});
|
|
6955
|
+
emitAction(
|
|
6956
|
+
`${pastTense} work brief ${style.bold(briefId)} \u2192 ${data.outcome}`,
|
|
6957
|
+
data,
|
|
6958
|
+
globals.json
|
|
6959
|
+
);
|
|
6960
|
+
});
|
|
6961
|
+
}
|
|
6962
|
+
function capitalize(value) {
|
|
6963
|
+
return value.charAt(0).toUpperCase() + value.slice(1);
|
|
6964
|
+
}
|
|
6965
|
+
|
|
6802
6966
|
// src/index.ts
|
|
6803
6967
|
function resolveVersion() {
|
|
6804
6968
|
try {
|
|
@@ -6961,6 +7125,7 @@ registerLookup(program);
|
|
|
6961
7125
|
registerRelationships(program);
|
|
6962
7126
|
registerWorkspace(program);
|
|
6963
7127
|
registerProject(program);
|
|
7128
|
+
registerWorkBrief(program);
|
|
6964
7129
|
registerDecomposition(program);
|
|
6965
7130
|
registerExecutor(program);
|
|
6966
7131
|
registerClose(program);
|