forge-cw 0.1.34 → 0.1.36
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/dist/index.js
CHANGED
|
@@ -597,9 +597,31 @@ var init_origin_guard = __esm({
|
|
|
597
597
|
}
|
|
598
598
|
});
|
|
599
599
|
|
|
600
|
+
// ../core/dist/cw-types.js
|
|
601
|
+
var ACCOUNT_NAME_RE, HARNESS_NAME_RE, PROVIDER_NAME_RE, MCP_TOOL_PREFIX_RE, MAX_DISABLED_MCPS, MODEL_NAME_RE;
|
|
602
|
+
var init_cw_types = __esm({
|
|
603
|
+
"../core/dist/cw-types.js"() {
|
|
604
|
+
"use strict";
|
|
605
|
+
ACCOUNT_NAME_RE = /^[a-zA-Z0-9][a-zA-Z0-9_-]{0,63}$/;
|
|
606
|
+
HARNESS_NAME_RE = /^[a-z0-9][a-z0-9_-]{0,31}$/;
|
|
607
|
+
PROVIDER_NAME_RE = /^[a-z0-9][a-z0-9_.-]{0,63}$/;
|
|
608
|
+
MCP_TOOL_PREFIX_RE = /^mcp__[A-Za-z0-9_-]{1,120}$/;
|
|
609
|
+
MAX_DISABLED_MCPS = 64;
|
|
610
|
+
MODEL_NAME_RE = /^[A-Za-z0-9][A-Za-z0-9_.:/-]{0,127}$/;
|
|
611
|
+
}
|
|
612
|
+
});
|
|
613
|
+
|
|
600
614
|
// ../core/dist/cw-reader.js
|
|
601
615
|
import { readdirSync as readdirSync2, readFileSync as readFileSync2, existsSync as existsSync2 } from "node:fs";
|
|
602
|
-
import { join as join2, resolve, sep } from "node:path";
|
|
616
|
+
import { dirname, join as join2, resolve, sep } from "node:path";
|
|
617
|
+
function readJsonObject(path) {
|
|
618
|
+
try {
|
|
619
|
+
const data = JSON.parse(readFileSync2(path, "utf-8"));
|
|
620
|
+
return isObject(data) ? data : {};
|
|
621
|
+
} catch {
|
|
622
|
+
return {};
|
|
623
|
+
}
|
|
624
|
+
}
|
|
603
625
|
function sessionFolder(cwDir, project, sessionDir = "") {
|
|
604
626
|
if (typeof project !== "string" || typeof sessionDir !== "string")
|
|
605
627
|
return null;
|
|
@@ -612,6 +634,11 @@ function sessionFolder(cwDir, project, sessionDir = "") {
|
|
|
612
634
|
const dir = resolve(root, project, ...segments);
|
|
613
635
|
return dir.startsWith(root + sep) ? dir : null;
|
|
614
636
|
}
|
|
637
|
+
function withForgeChoices(session, dir) {
|
|
638
|
+
const saved = readJsonObject(join2(dir, "forge.json")).disabledMcps;
|
|
639
|
+
const disabled2 = Array.isArray(saved) ? saved.filter((v) => typeof v === "string" && MCP_TOOL_PREFIX_RE.test(v)) : [];
|
|
640
|
+
return disabled2.length > 0 ? { ...session, disabledMcps: disabled2 } : session;
|
|
641
|
+
}
|
|
615
642
|
function* walkSessionDirs(baseDir, rel = "", depth = 0) {
|
|
616
643
|
if (depth >= MAX_SESSION_DEPTH)
|
|
617
644
|
return;
|
|
@@ -632,10 +659,13 @@ function* walkSessionDirs(baseDir, rel = "", depth = 0) {
|
|
|
632
659
|
yield* walkSessionDirs(baseDir, childRel, depth + 1);
|
|
633
660
|
}
|
|
634
661
|
}
|
|
635
|
-
var withHarnessDefaults, CWReader, MAX_SESSION_DEPTH;
|
|
662
|
+
var isObject, mcpType, withHarnessDefaults, CWReader, MAX_SESSION_DEPTH;
|
|
636
663
|
var init_cw_reader = __esm({
|
|
637
664
|
"../core/dist/cw-reader.js"() {
|
|
638
665
|
"use strict";
|
|
666
|
+
init_cw_types();
|
|
667
|
+
isObject = (v) => typeof v === "object" && v !== null && !Array.isArray(v);
|
|
668
|
+
mcpType = (cfg) => cfg.url ? "url" : cfg.type === "sse" ? "sse" : "command";
|
|
639
669
|
withHarnessDefaults = (session) => ({ ...session, harness: session.harness ?? "claude", provider: session.provider ?? "native" });
|
|
640
670
|
CWReader = class {
|
|
641
671
|
cwDir;
|
|
@@ -667,7 +697,7 @@ var init_cw_reader = __esm({
|
|
|
667
697
|
try {
|
|
668
698
|
const data = JSON.parse(readFileSync2(absPath, "utf-8"));
|
|
669
699
|
data.sessionDir = relPath;
|
|
670
|
-
sessions.push(withHarnessDefaults(data));
|
|
700
|
+
sessions.push(withForgeChoices(withHarnessDefaults(data), dirname(absPath)));
|
|
671
701
|
} catch {
|
|
672
702
|
}
|
|
673
703
|
}
|
|
@@ -684,7 +714,7 @@ var init_cw_reader = __esm({
|
|
|
684
714
|
try {
|
|
685
715
|
const data = JSON.parse(readFileSync2(path, "utf-8"));
|
|
686
716
|
data.sessionDir = sessionDir;
|
|
687
|
-
return withHarnessDefaults(data);
|
|
717
|
+
return withForgeChoices(withHarnessDefaults(data), dir);
|
|
688
718
|
} catch {
|
|
689
719
|
return null;
|
|
690
720
|
}
|
|
@@ -715,126 +745,95 @@ var init_cw_reader = __esm({
|
|
|
715
745
|
return [];
|
|
716
746
|
return readdirSync2(dir, { withFileTypes: true }).filter((e) => e.isDirectory()).map((e) => e.name);
|
|
717
747
|
}
|
|
718
|
-
getMCPs(project) {
|
|
719
|
-
const tools = this.getTools(project);
|
|
748
|
+
getMCPs(project, account) {
|
|
749
|
+
const tools = this.getTools(project, account);
|
|
720
750
|
return {
|
|
721
|
-
|
|
722
|
-
|
|
751
|
+
account: tools.account,
|
|
752
|
+
global: Object.fromEntries(tools.mcps.filter((m) => m.source === "account").map((m) => [m.name, {}])),
|
|
753
|
+
project: tools.mcps.filter((m) => m.source === "local" || m.source === "project").map((m) => m.name),
|
|
723
754
|
cw: tools.mcps.filter((m) => m.source === "cw").map((m) => m.name),
|
|
724
755
|
plugins: tools.plugins.map((p) => p.name)
|
|
725
756
|
};
|
|
726
757
|
}
|
|
727
|
-
|
|
728
|
-
|
|
758
|
+
// the folder Claude Code runs with for an account: CW keeps the flat dir unless a claude/ subdir exists
|
|
759
|
+
accountConfigDir(account) {
|
|
760
|
+
const root = join2(this.cwDir, "accounts", account);
|
|
761
|
+
return existsSync2(join2(root, "claude")) ? join2(root, "claude") : root;
|
|
762
|
+
}
|
|
763
|
+
// the config dir Claude Code runs with (~/.claude without a CW account) and whether its settings turn claude.ai connectors off
|
|
764
|
+
claudeConfig(account) {
|
|
765
|
+
const configDir = account ? this.accountConfigDir(account) : join2(process.env.HOME ?? "", ".claude");
|
|
766
|
+
return { configDir, connectorsOff: readJsonObject(join2(configDir, "settings.json")).disableClaudeAiConnectors === true };
|
|
767
|
+
}
|
|
768
|
+
/**
|
|
769
|
+
* What Claude Code will load for a project under an account: MCPs from the account's .claude.json
|
|
770
|
+
* (user and local scope), the repo's .mcp.json and .claude/settings.json, CW's mcps/, and the account's plugins.
|
|
771
|
+
* The account defaults to the project's; with neither, it reads ~/.claude as Claude Code does without CW.
|
|
772
|
+
*/
|
|
773
|
+
getTools(project, account) {
|
|
729
774
|
const home = process.env.HOME ?? "";
|
|
775
|
+
const projects = this.getProjects();
|
|
776
|
+
const projPath = project ? projects[project]?.path ?? "" : "";
|
|
777
|
+
const wanted = account ?? (project ? projects[project]?.account : void 0);
|
|
778
|
+
const acct = wanted && ACCOUNT_NAME_RE.test(wanted) && existsSync2(join2(this.cwDir, "accounts", wanted)) ? wanted : null;
|
|
779
|
+
const configDir = acct ? this.accountConfigDir(acct) : join2(home, ".claude");
|
|
780
|
+
const state = readJsonObject(acct ? join2(configDir, ".claude.json") : join2(home, ".claude.json"));
|
|
781
|
+
const settings = readJsonObject(join2(configDir, "settings.json"));
|
|
730
782
|
const mcps = [];
|
|
731
|
-
const
|
|
732
|
-
|
|
733
|
-
|
|
734
|
-
|
|
735
|
-
|
|
736
|
-
|
|
737
|
-
|
|
738
|
-
for (const [name, cfg] of Object.entries(data.mcpServers)) {
|
|
739
|
-
const type = cfg.url ? "url" : cfg.type === "sse" ? "sse" : "command";
|
|
740
|
-
mcps.push({ name, type, source: "global", url: cfg.url });
|
|
741
|
-
}
|
|
742
|
-
}
|
|
743
|
-
if (data.enabledPlugins)
|
|
744
|
-
enabledPlugins = data.enabledPlugins;
|
|
745
|
-
} catch {
|
|
746
|
-
}
|
|
747
|
-
}
|
|
748
|
-
if (project) {
|
|
749
|
-
const projects = this.getProjects();
|
|
750
|
-
const projPath = projects[project]?.path ?? "";
|
|
751
|
-
if (projPath) {
|
|
752
|
-
if (existsSync2(claudeSettings)) {
|
|
753
|
-
try {
|
|
754
|
-
const globalData = JSON.parse(readFileSync2(claudeSettings, "utf-8"));
|
|
755
|
-
const projSettings = globalData.projects?.[projPath];
|
|
756
|
-
if (projSettings?.mcpServers) {
|
|
757
|
-
for (const [name, cfg] of Object.entries(projSettings.mcpServers)) {
|
|
758
|
-
if (!mcps.some((m) => m.name === name)) {
|
|
759
|
-
const type = cfg.url ? "url" : cfg.type === "sse" ? "sse" : "command";
|
|
760
|
-
mcps.push({ name, type, source: "project", url: cfg.url });
|
|
761
|
-
}
|
|
762
|
-
}
|
|
763
|
-
}
|
|
764
|
-
} catch {
|
|
765
|
-
}
|
|
766
|
-
}
|
|
767
|
-
for (const configPath of [
|
|
768
|
-
join2(projPath, ".mcp.json"),
|
|
769
|
-
join2(projPath, ".claude", "settings.json")
|
|
770
|
-
]) {
|
|
771
|
-
if (existsSync2(configPath)) {
|
|
772
|
-
try {
|
|
773
|
-
const data = JSON.parse(readFileSync2(configPath, "utf-8"));
|
|
774
|
-
const servers = data.mcpServers ?? data;
|
|
775
|
-
if (servers && typeof servers === "object") {
|
|
776
|
-
for (const [name, cfg] of Object.entries(servers)) {
|
|
777
|
-
if (name === "mcpServers")
|
|
778
|
-
continue;
|
|
779
|
-
if (!mcps.some((m) => m.name === name)) {
|
|
780
|
-
const type = cfg.url ? "url" : cfg.type === "sse" ? "sse" : "command";
|
|
781
|
-
mcps.push({ name, type, source: "project", url: cfg.url });
|
|
782
|
-
}
|
|
783
|
-
}
|
|
784
|
-
}
|
|
785
|
-
} catch {
|
|
786
|
-
}
|
|
787
|
-
}
|
|
788
|
-
}
|
|
783
|
+
const add = (servers, source) => {
|
|
784
|
+
if (!isObject(servers))
|
|
785
|
+
return;
|
|
786
|
+
for (const [name, cfg] of Object.entries(servers)) {
|
|
787
|
+
if (!isObject(cfg) || mcps.some((m) => m.name === name))
|
|
788
|
+
continue;
|
|
789
|
+
mcps.push({ name, type: mcpType(cfg), source, url: typeof cfg.url === "string" ? cfg.url : void 0 });
|
|
789
790
|
}
|
|
790
|
-
}
|
|
791
|
+
};
|
|
792
|
+
const projectEntry = (holder) => {
|
|
793
|
+
const byPath = holder.projects;
|
|
794
|
+
return isObject(byPath) && isObject(byPath[projPath]) ? byPath[projPath].mcpServers : void 0;
|
|
795
|
+
};
|
|
796
|
+
if (projPath) {
|
|
797
|
+
add(projectEntry(state), "local");
|
|
798
|
+
add(projectEntry(settings), "local");
|
|
799
|
+
const mcpJson = readJsonObject(join2(projPath, ".mcp.json"));
|
|
800
|
+
add(mcpJson.mcpServers ?? mcpJson, "project");
|
|
801
|
+
add(readJsonObject(join2(projPath, ".claude", "settings.json")).mcpServers, "project");
|
|
802
|
+
}
|
|
803
|
+
add(state.mcpServers, "account");
|
|
804
|
+
add(settings.mcpServers, "account");
|
|
791
805
|
const mcpsDir = join2(this.cwDir, "mcps");
|
|
792
806
|
if (existsSync2(mcpsDir)) {
|
|
793
|
-
const
|
|
794
|
-
for (const f of files) {
|
|
807
|
+
for (const f of readdirSync2(mcpsDir).filter((f2) => f2.endsWith(".json"))) {
|
|
795
808
|
const name = f.replace(".json", "");
|
|
796
|
-
if (!mcps.some((m) => m.name === name))
|
|
809
|
+
if (!mcps.some((m) => m.name === name))
|
|
797
810
|
mcps.push({ name, type: "cw", source: "cw" });
|
|
798
|
-
}
|
|
799
811
|
}
|
|
800
812
|
}
|
|
801
|
-
const
|
|
802
|
-
|
|
803
|
-
|
|
804
|
-
|
|
805
|
-
|
|
806
|
-
|
|
807
|
-
|
|
808
|
-
|
|
809
|
-
|
|
810
|
-
|
|
811
|
-
|
|
812
|
-
|
|
813
|
-
|
|
814
|
-
|
|
815
|
-
|
|
816
|
-
|
|
817
|
-
|
|
818
|
-
|
|
819
|
-
|
|
820
|
-
|
|
821
|
-
|
|
822
|
-
hasMcp = true;
|
|
823
|
-
mcpName = mcpKeys[0];
|
|
824
|
-
const cfg = mcpData[mcpKeys[0]];
|
|
825
|
-
mcpType = cfg.url ? "url" : cfg.type === "sse" ? "sse" : "command";
|
|
826
|
-
}
|
|
827
|
-
} catch {
|
|
828
|
-
}
|
|
829
|
-
}
|
|
830
|
-
}
|
|
831
|
-
plugins.push({ name, enabled, hasMcp, mcpName, mcpType, marketplace });
|
|
832
|
-
}
|
|
833
|
-
}
|
|
834
|
-
} catch {
|
|
813
|
+
const plugins = [];
|
|
814
|
+
const enabledPlugins = isObject(settings.enabledPlugins) ? settings.enabledPlugins : {};
|
|
815
|
+
const installed = readJsonObject(join2(configDir, "plugins", "installed_plugins.json")).plugins;
|
|
816
|
+
if (isObject(installed)) {
|
|
817
|
+
for (const [key, entries] of Object.entries(installed)) {
|
|
818
|
+
const name = key.split("@")[0];
|
|
819
|
+
const marketplace = key.includes("@") ? key.split("@").slice(1).join("@") : "unknown";
|
|
820
|
+
const entry = Array.isArray(entries) ? entries[0] : void 0;
|
|
821
|
+
const installPath = isObject(entry) && typeof entry.installPath === "string" ? entry.installPath : "";
|
|
822
|
+
const raw = installPath ? readJsonObject(join2(installPath, ".mcp.json")) : {};
|
|
823
|
+
const servers = isObject(raw.mcpServers) ? raw.mcpServers : raw;
|
|
824
|
+
const first = Object.keys(servers).find((k) => k !== "mcpServers");
|
|
825
|
+
const cfg = first ? servers[first] : void 0;
|
|
826
|
+
plugins.push({
|
|
827
|
+
name,
|
|
828
|
+
marketplace,
|
|
829
|
+
enabled: enabledPlugins[key] === true,
|
|
830
|
+
hasMcp: Boolean(first),
|
|
831
|
+
mcpName: first,
|
|
832
|
+
mcpType: isObject(cfg) ? mcpType(cfg) : void 0
|
|
833
|
+
});
|
|
835
834
|
}
|
|
836
835
|
}
|
|
837
|
-
return { mcps, plugins };
|
|
836
|
+
return { account: acct, mcps, plugins };
|
|
838
837
|
}
|
|
839
838
|
parseFrontmatter(content) {
|
|
840
839
|
const match = content.match(/^---\n([\s\S]*?)\n---\n?([\s\S]*)$/);
|
|
@@ -983,18 +982,6 @@ var init_cw_reader = __esm({
|
|
|
983
982
|
}
|
|
984
983
|
});
|
|
985
984
|
|
|
986
|
-
// ../core/dist/cw-types.js
|
|
987
|
-
var ACCOUNT_NAME_RE, HARNESS_NAME_RE, PROVIDER_NAME_RE, MODEL_NAME_RE;
|
|
988
|
-
var init_cw_types = __esm({
|
|
989
|
-
"../core/dist/cw-types.js"() {
|
|
990
|
-
"use strict";
|
|
991
|
-
ACCOUNT_NAME_RE = /^[a-zA-Z0-9][a-zA-Z0-9_-]{0,63}$/;
|
|
992
|
-
HARNESS_NAME_RE = /^[a-z0-9][a-z0-9_-]{0,31}$/;
|
|
993
|
-
PROVIDER_NAME_RE = /^[a-z0-9][a-z0-9_.-]{0,63}$/;
|
|
994
|
-
MODEL_NAME_RE = /^[A-Za-z0-9][A-Za-z0-9_.:/-]{0,127}$/;
|
|
995
|
-
}
|
|
996
|
-
});
|
|
997
|
-
|
|
998
985
|
// ../core/dist/cw-doctor.js
|
|
999
986
|
import { execFile } from "node:child_process";
|
|
1000
987
|
import { existsSync as existsSync3, readFileSync as readFileSync3 } from "node:fs";
|
|
@@ -1471,7 +1458,8 @@ function parseCredentials(raw) {
|
|
|
1471
1458
|
const accessToken = typeof oauth?.accessToken === "string" ? oauth.accessToken : null;
|
|
1472
1459
|
if (!accessToken)
|
|
1473
1460
|
return null;
|
|
1474
|
-
|
|
1461
|
+
const scopes = Array.isArray(oauth?.scopes) ? oauth.scopes.filter((s) => typeof s === "string") : null;
|
|
1462
|
+
return { accessToken, expiresAt: typeof oauth?.expiresAt === "number" ? oauth.expiresAt : null, scopes };
|
|
1475
1463
|
} catch {
|
|
1476
1464
|
return null;
|
|
1477
1465
|
}
|
|
@@ -1696,6 +1684,103 @@ var init_usage = __esm({
|
|
|
1696
1684
|
}
|
|
1697
1685
|
});
|
|
1698
1686
|
|
|
1687
|
+
// ../core/dist/claude-connectors.js
|
|
1688
|
+
function mapConnectors(rows) {
|
|
1689
|
+
const seen = /* @__PURE__ */ new Set();
|
|
1690
|
+
return rows.flatMap((row) => {
|
|
1691
|
+
if (!isObject2(row) || row.eligible !== true || typeof row.display_name !== "string")
|
|
1692
|
+
return [];
|
|
1693
|
+
const name = row.display_name;
|
|
1694
|
+
if (seen.has(name))
|
|
1695
|
+
return [];
|
|
1696
|
+
seen.add(name);
|
|
1697
|
+
return [{
|
|
1698
|
+
name,
|
|
1699
|
+
status: row.eligibility_reason === "connected_with_error" ? "needs_auth" : "connected",
|
|
1700
|
+
tools: Array.isArray(row.tools) ? row.tools.length : 0
|
|
1701
|
+
}];
|
|
1702
|
+
});
|
|
1703
|
+
}
|
|
1704
|
+
function createClaudeConnectorsClient(deps = {}) {
|
|
1705
|
+
const now = deps.now ?? Date.now;
|
|
1706
|
+
const cacheMs = deps.cacheMs ?? CACHE_MS2;
|
|
1707
|
+
const cache = /* @__PURE__ */ new Map();
|
|
1708
|
+
const inflight = /* @__PURE__ */ new Map();
|
|
1709
|
+
async function fetchFor(configDir) {
|
|
1710
|
+
const credentials = await readCredentials(configDir, deps);
|
|
1711
|
+
if (!credentials)
|
|
1712
|
+
return { state: "not_connected", detail: null, connectors: [] };
|
|
1713
|
+
if (credentials.expiresAt !== null && credentials.expiresAt <= now()) {
|
|
1714
|
+
return { state: "expired", detail: "The stored token has expired; open a session of this account to refresh it", connectors: [] };
|
|
1715
|
+
}
|
|
1716
|
+
if (credentials.scopes && !credentials.scopes.includes(SCOPE)) {
|
|
1717
|
+
return { state: "missing_scope", detail: `The account's sign-in lacks ${SCOPE}; sign in again to load connectors`, connectors: [] };
|
|
1718
|
+
}
|
|
1719
|
+
const call = deps.fetchImpl ?? fetch;
|
|
1720
|
+
const rows = [];
|
|
1721
|
+
let page = null;
|
|
1722
|
+
try {
|
|
1723
|
+
for (let i = 0; i < MAX_PAGES; i++) {
|
|
1724
|
+
const url = page ? `${CONNECTORS_URL}&page=${encodeURIComponent(page)}` : CONNECTORS_URL;
|
|
1725
|
+
const response = await call(url, {
|
|
1726
|
+
headers: { authorization: `Bearer ${credentials.accessToken}`, "anthropic-beta": MCP_SERVERS_BETA, "anthropic-version": "2023-06-01" },
|
|
1727
|
+
signal: AbortSignal.timeout(TIMEOUT_MS4)
|
|
1728
|
+
});
|
|
1729
|
+
if (response.status === 401 || response.status === 403)
|
|
1730
|
+
return { state: "expired", detail: "Claude rejected the stored token", connectors: [] };
|
|
1731
|
+
if (!response.ok)
|
|
1732
|
+
return { state: "error", detail: `claude.ai answered ${response.status}`, connectors: [] };
|
|
1733
|
+
const body2 = await response.json();
|
|
1734
|
+
if (!isObject2(body2) || !Array.isArray(body2.data))
|
|
1735
|
+
return { state: "error", detail: "claude.ai answered an unknown shape", connectors: [] };
|
|
1736
|
+
rows.push(...body2.data);
|
|
1737
|
+
page = typeof body2.next_page === "string" && body2.next_page ? body2.next_page : null;
|
|
1738
|
+
if (!page)
|
|
1739
|
+
break;
|
|
1740
|
+
}
|
|
1741
|
+
} catch (err) {
|
|
1742
|
+
return { state: "error", detail: err instanceof Error ? err.message : String(err), connectors: [] };
|
|
1743
|
+
}
|
|
1744
|
+
return { state: "ok", detail: null, connectors: mapConnectors(rows) };
|
|
1745
|
+
}
|
|
1746
|
+
return {
|
|
1747
|
+
/** The account's claude.ai connectors; kept 5 min, and the last good list stays when a later read fails */
|
|
1748
|
+
async get(configDir, options = {}) {
|
|
1749
|
+
if (options.disabled)
|
|
1750
|
+
return { state: "disabled", detail: "disableClaudeAiConnectors is on in this account's settings", connectors: [] };
|
|
1751
|
+
const hit = cache.get(configDir);
|
|
1752
|
+
if (hit && !options.fresh && now() - hit.at < cacheMs)
|
|
1753
|
+
return hit.value;
|
|
1754
|
+
const running = inflight.get(configDir);
|
|
1755
|
+
if (running)
|
|
1756
|
+
return running;
|
|
1757
|
+
const next = fetchFor(configDir).then((value) => {
|
|
1758
|
+
if (value.state === "ok" || !hit || hit.value.state !== "ok") {
|
|
1759
|
+
cache.set(configDir, { at: now(), value });
|
|
1760
|
+
return value;
|
|
1761
|
+
}
|
|
1762
|
+
return hit.value;
|
|
1763
|
+
}).finally(() => inflight.delete(configDir));
|
|
1764
|
+
inflight.set(configDir, next);
|
|
1765
|
+
return next;
|
|
1766
|
+
}
|
|
1767
|
+
};
|
|
1768
|
+
}
|
|
1769
|
+
var CONNECTORS_URL, MCP_SERVERS_BETA, SCOPE, TIMEOUT_MS4, CACHE_MS2, MAX_PAGES, isObject2;
|
|
1770
|
+
var init_claude_connectors = __esm({
|
|
1771
|
+
"../core/dist/claude-connectors.js"() {
|
|
1772
|
+
"use strict";
|
|
1773
|
+
init_usage_claude();
|
|
1774
|
+
CONNECTORS_URL = "https://api.anthropic.com/v1/mcp_servers?limit=1000";
|
|
1775
|
+
MCP_SERVERS_BETA = "mcp-servers-2025-12-04";
|
|
1776
|
+
SCOPE = "user:mcp_servers";
|
|
1777
|
+
TIMEOUT_MS4 = 6e3;
|
|
1778
|
+
CACHE_MS2 = 5 * 6e4;
|
|
1779
|
+
MAX_PAGES = 5;
|
|
1780
|
+
isObject2 = (v) => typeof v === "object" && v !== null && !Array.isArray(v);
|
|
1781
|
+
}
|
|
1782
|
+
});
|
|
1783
|
+
|
|
1699
1784
|
// ../core/dist/harness-capabilities.js
|
|
1700
1785
|
function supports(harness, cap) {
|
|
1701
1786
|
return (HARNESS_CAPABILITIES[harness ?? "claude"] ?? []).includes(cap);
|
|
@@ -1848,7 +1933,7 @@ function importApiKey(cwBin, account, harness, apiKey) {
|
|
|
1848
1933
|
child.stderr.on("data", collect);
|
|
1849
1934
|
child.stdin.on("error", () => {
|
|
1850
1935
|
});
|
|
1851
|
-
const timer = setTimeout(() => child.kill(),
|
|
1936
|
+
const timer = setTimeout(() => child.kill(), TIMEOUT_MS5);
|
|
1852
1937
|
child.on("error", (err) => {
|
|
1853
1938
|
clearTimeout(timer);
|
|
1854
1939
|
resolve11({ ok: false, error: redact(err.message) });
|
|
@@ -1861,12 +1946,12 @@ function importApiKey(cwBin, account, harness, apiKey) {
|
|
|
1861
1946
|
`);
|
|
1862
1947
|
});
|
|
1863
1948
|
}
|
|
1864
|
-
var
|
|
1949
|
+
var TIMEOUT_MS5;
|
|
1865
1950
|
var init_api_key_login = __esm({
|
|
1866
1951
|
"../core/dist/api-key-login.js"() {
|
|
1867
1952
|
"use strict";
|
|
1868
1953
|
init_cw_doctor();
|
|
1869
|
-
|
|
1954
|
+
TIMEOUT_MS5 = 6e4;
|
|
1870
1955
|
}
|
|
1871
1956
|
});
|
|
1872
1957
|
|
|
@@ -1940,14 +2025,36 @@ var init_output = __esm({
|
|
|
1940
2025
|
});
|
|
1941
2026
|
|
|
1942
2027
|
// ../core/dist/cw-start.js
|
|
1943
|
-
import { existsSync as existsSync5, mkdirSync, readFileSync as readFileSync5, writeFileSync } from "node:fs";
|
|
2028
|
+
import { existsSync as existsSync5, mkdirSync, readFileSync as readFileSync5, rmSync, writeFileSync } from "node:fs";
|
|
1944
2029
|
import { join as join7 } from "node:path";
|
|
2030
|
+
function saveSessionMcps(dir, disabledMcps) {
|
|
2031
|
+
const file = join7(dir, SESSION_MCPS_FILE);
|
|
2032
|
+
if (disabledMcps.length === 0) {
|
|
2033
|
+
rmSync(file, { force: true });
|
|
2034
|
+
return;
|
|
2035
|
+
}
|
|
2036
|
+
mkdirSync(dir, { recursive: true });
|
|
2037
|
+
writeFileSync(file, JSON.stringify({ disabledMcps }, null, 2));
|
|
2038
|
+
}
|
|
2039
|
+
function checkDisabledMcps(value) {
|
|
2040
|
+
if (value === void 0)
|
|
2041
|
+
return [];
|
|
2042
|
+
if (!Array.isArray(value) || value.length > MAX_DISABLED_MCPS)
|
|
2043
|
+
return null;
|
|
2044
|
+
if (!value.every((v) => typeof v === "string" && MCP_TOOL_PREFIX_RE.test(v)))
|
|
2045
|
+
return null;
|
|
2046
|
+
return [...new Set(value)];
|
|
2047
|
+
}
|
|
1945
2048
|
async function prepareStart(input, deps) {
|
|
1946
2049
|
const { reader } = deps;
|
|
1947
2050
|
const { type, project, task, description, workflow, account, directory, skipPermissions, model, loopPrompt, loopInterval, name, harness } = input;
|
|
1948
2051
|
if (harness !== void 0 && !HARNESS_NAME_RE.test(harness)) {
|
|
1949
2052
|
return { ok: false, status: 400, error: "Invalid harness" };
|
|
1950
2053
|
}
|
|
2054
|
+
const checked = checkDisabledMcps(input.disabledMcps);
|
|
2055
|
+
if (!checked)
|
|
2056
|
+
return { ok: false, status: 400, error: "disabledMcps takes up to 64 MCP tool prefixes like mcp__linear" };
|
|
2057
|
+
const disabledMcps = (harness ?? "claude") === "claude" && checked.length > 0 ? checked : void 0;
|
|
1951
2058
|
if (type === "login") {
|
|
1952
2059
|
if (!account || !ACCOUNT_NAME_RE.test(account) || !reader.getAccounts().includes(account)) {
|
|
1953
2060
|
return { ok: false, status: 400, error: "Unknown account" };
|
|
@@ -1993,7 +2100,8 @@ async function prepareStart(input, deps) {
|
|
|
1993
2100
|
last_opened: (/* @__PURE__ */ new Date()).toISOString(),
|
|
1994
2101
|
opens: 0,
|
|
1995
2102
|
sessionDir: sessionDirName2,
|
|
1996
|
-
skipPermissions: skipPermissions ?? false
|
|
2103
|
+
skipPermissions: skipPermissions ?? false,
|
|
2104
|
+
disabledMcps
|
|
1997
2105
|
};
|
|
1998
2106
|
pendingSessions.set(`${projectName}::${sessionDirName2}`, sessionData2);
|
|
1999
2107
|
return { ok: true, session: sessionData2, command: `cw launch ${acct}` };
|
|
@@ -2076,8 +2184,12 @@ async function prepareStart(input, deps) {
|
|
|
2076
2184
|
last_opened: (/* @__PURE__ */ new Date()).toISOString(),
|
|
2077
2185
|
opens: 0,
|
|
2078
2186
|
sessionDir: sessionDirName2,
|
|
2079
|
-
skipPermissions: skipPermissions ?? false
|
|
2187
|
+
skipPermissions: skipPermissions ?? false,
|
|
2188
|
+
disabledMcps
|
|
2080
2189
|
};
|
|
2190
|
+
const loopDir = sessionFolder(reader.cwHome, project, sessionDirName2);
|
|
2191
|
+
if (loopDir)
|
|
2192
|
+
saveSessionMcps(loopDir, disabledMcps ?? []);
|
|
2081
2193
|
pendingSessions.set(`${project}::${sessionDirName2}`, sessionData2);
|
|
2082
2194
|
return { ok: true, session: sessionData2 };
|
|
2083
2195
|
}
|
|
@@ -2193,8 +2305,10 @@ async function prepareStart(input, deps) {
|
|
|
2193
2305
|
last_opened: (/* @__PURE__ */ new Date()).toISOString(),
|
|
2194
2306
|
opens: 0,
|
|
2195
2307
|
sessionDir: sessionDirName,
|
|
2196
|
-
skipPermissions: skipPermissions ?? false
|
|
2308
|
+
skipPermissions: skipPermissions ?? false,
|
|
2309
|
+
disabledMcps
|
|
2197
2310
|
};
|
|
2311
|
+
saveSessionMcps(sessionDir, disabledMcps ?? []);
|
|
2198
2312
|
pendingSessions.set(`${project}::${sessionDirName}`, sessionData);
|
|
2199
2313
|
return { ok: true, session: sessionData, command: `cw ${args.join(" ")}` };
|
|
2200
2314
|
}
|
|
@@ -2235,7 +2349,7 @@ function launchHeadless(project, sessionDir, deps) {
|
|
|
2235
2349
|
noteLaunch(`${project}::${sessionDir}`, taken.session);
|
|
2236
2350
|
return pty4;
|
|
2237
2351
|
}
|
|
2238
|
-
var GENERAL_PROJECT, CREATING_PROJECT, ACCOUNTS_PROJECT, pendingSessions, LAUNCH_TTL_MS, launched;
|
|
2352
|
+
var GENERAL_PROJECT, CREATING_PROJECT, ACCOUNTS_PROJECT, pendingSessions, SESSION_MCPS_FILE, LAUNCH_TTL_MS, launched;
|
|
2239
2353
|
var init_cw_start = __esm({
|
|
2240
2354
|
"../core/dist/cw-start.js"() {
|
|
2241
2355
|
"use strict";
|
|
@@ -2245,6 +2359,7 @@ var init_cw_start = __esm({
|
|
|
2245
2359
|
CREATING_PROJECT = "__creating";
|
|
2246
2360
|
ACCOUNTS_PROJECT = "__accounts";
|
|
2247
2361
|
pendingSessions = /* @__PURE__ */ new Map();
|
|
2362
|
+
SESSION_MCPS_FILE = "forge.json";
|
|
2248
2363
|
LAUNCH_TTL_MS = 15 * 6e4;
|
|
2249
2364
|
launched = /* @__PURE__ */ new Map();
|
|
2250
2365
|
}
|
|
@@ -2254,8 +2369,8 @@ var init_cw_start = __esm({
|
|
|
2254
2369
|
import { Hono } from "hono";
|
|
2255
2370
|
import { execFileSync, execFile as execFile4 } from "node:child_process";
|
|
2256
2371
|
import { promisify as promisify2 } from "node:util";
|
|
2257
|
-
import { writeFileSync as writeFileSync2, existsSync as existsSync6, rmSync, readdirSync as readdirSync3, statSync } from "node:fs";
|
|
2258
|
-
import { join as join8, resolve as resolve2, dirname, basename, isAbsolute } from "node:path";
|
|
2372
|
+
import { writeFileSync as writeFileSync2, existsSync as existsSync6, rmSync as rmSync2, readdirSync as readdirSync3, statSync } from "node:fs";
|
|
2373
|
+
import { join as join8, resolve as resolve2, dirname as dirname2, basename, isAbsolute } from "node:path";
|
|
2259
2374
|
import { homedir as homedir2 } from "node:os";
|
|
2260
2375
|
function resolveCwBin(cwHome) {
|
|
2261
2376
|
const candidate = join8(cwHome, "bin", "cw");
|
|
@@ -2317,6 +2432,7 @@ function cwRoutes(reader, options = {}) {
|
|
|
2317
2432
|
return c.json({ ...result2, capabilities, contextTokens: readContextTokens(reader.cwHome) });
|
|
2318
2433
|
});
|
|
2319
2434
|
const usage = createUsageClient(options.usage);
|
|
2435
|
+
const connectors = createClaudeConnectorsClient(options.connectors);
|
|
2320
2436
|
app.get("/usage", async (c) => {
|
|
2321
2437
|
const result2 = await doctor.get();
|
|
2322
2438
|
if (!result2.available)
|
|
@@ -2400,8 +2516,8 @@ function cwRoutes(reader, options = {}) {
|
|
|
2400
2516
|
return c.json({ ok: false, error: `Account "${name}" not found` }, 404);
|
|
2401
2517
|
}
|
|
2402
2518
|
try {
|
|
2403
|
-
const { rmSync:
|
|
2404
|
-
|
|
2519
|
+
const { rmSync: rmSync6 } = await import("node:fs");
|
|
2520
|
+
rmSync6(accountDir, { recursive: true, force: true });
|
|
2405
2521
|
return c.json({ ok: true });
|
|
2406
2522
|
} catch (err) {
|
|
2407
2523
|
const message2 = err instanceof Error ? err.message : "Unknown error";
|
|
@@ -2449,12 +2565,13 @@ function cwRoutes(reader, options = {}) {
|
|
|
2449
2565
|
return c.json(reader.detectStack(project));
|
|
2450
2566
|
});
|
|
2451
2567
|
app.get("/mcps", (c) => {
|
|
2452
|
-
|
|
2453
|
-
return c.json(reader.getMCPs(project));
|
|
2568
|
+
return c.json(reader.getMCPs(c.req.query("project"), c.req.query("account")));
|
|
2454
2569
|
});
|
|
2455
|
-
app.get("/tools", (c) => {
|
|
2456
|
-
const
|
|
2457
|
-
|
|
2570
|
+
app.get("/tools", async (c) => {
|
|
2571
|
+
const tools = reader.getTools(c.req.query("project"), c.req.query("account"));
|
|
2572
|
+
const { configDir, connectorsOff } = reader.claudeConfig(tools.account);
|
|
2573
|
+
const claudeAi = await connectors.get(configDir, { disabled: connectorsOff, fresh: c.req.query("fresh") === "1" });
|
|
2574
|
+
return c.json({ ...tools, claudeAi });
|
|
2458
2575
|
});
|
|
2459
2576
|
const loadGitSession = (project, sessionDir) => {
|
|
2460
2577
|
const session = reader.getSession(project, sessionDir);
|
|
@@ -2621,13 +2738,13 @@ ${result2.stderr}`);
|
|
|
2621
2738
|
}
|
|
2622
2739
|
if (existsSync6(sessionsDir)) {
|
|
2623
2740
|
try {
|
|
2624
|
-
|
|
2741
|
+
rmSync2(sessionsDir, { recursive: true, force: true });
|
|
2625
2742
|
} catch {
|
|
2626
2743
|
}
|
|
2627
2744
|
}
|
|
2628
2745
|
if (deleteFiles && projPath) {
|
|
2629
2746
|
try {
|
|
2630
|
-
|
|
2747
|
+
rmSync2(projPath, { recursive: true, force: true });
|
|
2631
2748
|
} catch {
|
|
2632
2749
|
return c.json({ ok: true, filesDeleted: false, reason: "Failed to delete directory" });
|
|
2633
2750
|
}
|
|
@@ -2674,7 +2791,7 @@ ${result2.stderr}`);
|
|
|
2674
2791
|
const full = join8(target, name);
|
|
2675
2792
|
return { name, path: full, isGitRepo: existsSync6(join8(full, ".git")) };
|
|
2676
2793
|
}).sort((a, b) => a.name.localeCompare(b.name));
|
|
2677
|
-
const parent =
|
|
2794
|
+
const parent = dirname2(target);
|
|
2678
2795
|
return c.json({
|
|
2679
2796
|
ok: true,
|
|
2680
2797
|
path: target,
|
|
@@ -2733,6 +2850,7 @@ var init_cw_routes = __esm({
|
|
|
2733
2850
|
init_cw_types();
|
|
2734
2851
|
init_cw_doctor();
|
|
2735
2852
|
init_usage();
|
|
2853
|
+
init_claude_connectors();
|
|
2736
2854
|
init_harness_capabilities();
|
|
2737
2855
|
init_login_manager();
|
|
2738
2856
|
init_api_key_login();
|
|
@@ -3016,8 +3134,8 @@ var init_plugins = __esm({
|
|
|
3016
3134
|
|
|
3017
3135
|
// ../core/dist/skill-routes.js
|
|
3018
3136
|
import { Hono as Hono2 } from "hono";
|
|
3019
|
-
import { mkdirSync as mkdirSync2, writeFileSync as writeFileSync3, rmSync as
|
|
3020
|
-
import { dirname as
|
|
3137
|
+
import { mkdirSync as mkdirSync2, writeFileSync as writeFileSync3, rmSync as rmSync3, existsSync as existsSync8, unlinkSync, cpSync, readdirSync as readdirSync5 } from "node:fs";
|
|
3138
|
+
import { dirname as dirname3, join as join10 } from "node:path";
|
|
3021
3139
|
function backUpSkill(backupDir, scope, ref, name, dir) {
|
|
3022
3140
|
const root = join10(backupDir, scope, ref, name);
|
|
3023
3141
|
const stamp = (/* @__PURE__ */ new Date()).toISOString().replace(/[:.]/g, "-");
|
|
@@ -3026,7 +3144,7 @@ function backUpSkill(backupDir, scope, ref, name, dir) {
|
|
|
3026
3144
|
dest = join10(root, `${stamp}-${String(n).padStart(3, "0")}`);
|
|
3027
3145
|
cpSync(dir, dest, { recursive: true, dereference: true });
|
|
3028
3146
|
for (const old of readdirSync5(root).sort().slice(0, -BACKUPS_KEPT))
|
|
3029
|
-
|
|
3147
|
+
rmSync3(join10(root, old), { recursive: true, force: true });
|
|
3030
3148
|
}
|
|
3031
3149
|
function installFailure(result2) {
|
|
3032
3150
|
try {
|
|
@@ -3227,7 +3345,7 @@ function skillRoutes(reader, options = {}) {
|
|
|
3227
3345
|
if (failed)
|
|
3228
3346
|
return c.json({ error: failed }, 500);
|
|
3229
3347
|
try {
|
|
3230
|
-
|
|
3348
|
+
rmSync3(dir, { recursive: true, force: true });
|
|
3231
3349
|
return c.json({ ok: true });
|
|
3232
3350
|
} catch (err) {
|
|
3233
3351
|
const message2 = err instanceof Error ? err.message : "Unknown error";
|
|
@@ -3271,7 +3389,7 @@ function skillRoutes(reader, options = {}) {
|
|
|
3271
3389
|
if (scope !== "project")
|
|
3272
3390
|
args.push("--global");
|
|
3273
3391
|
const run2 = runnerFor({ ...envWithoutHarness(), CLAUDE_CONFIG_DIR: configDir });
|
|
3274
|
-
const result2 = await run2("npx", args,
|
|
3392
|
+
const result2 = await run2("npx", args, dirname3(configDir));
|
|
3275
3393
|
if (result2.code !== 0) {
|
|
3276
3394
|
return c.json({ error: `Failed to install skill: ${installFailure(result2)}` }, 500);
|
|
3277
3395
|
}
|
|
@@ -3494,12 +3612,12 @@ var init_claude_hooks = __esm({
|
|
|
3494
3612
|
// ../core/dist/pty-manager.js
|
|
3495
3613
|
import * as pty2 from "node-pty";
|
|
3496
3614
|
import { existsSync as existsSync10, chmodSync, statSync as statSync2 } from "node:fs";
|
|
3497
|
-
import { join as join12, dirname as
|
|
3615
|
+
import { join as join12, dirname as dirname4 } from "node:path";
|
|
3498
3616
|
import { createRequire as createRequire2 } from "node:module";
|
|
3499
3617
|
function ensureSpawnHelperPermissions() {
|
|
3500
3618
|
try {
|
|
3501
3619
|
const require2 = createRequire2(import.meta.url);
|
|
3502
|
-
const ptyPath =
|
|
3620
|
+
const ptyPath = dirname4(require2.resolve("node-pty/package.json"));
|
|
3503
3621
|
const helper = join12(ptyPath, "prebuilds", `${process.platform}-${process.arch}`, "spawn-helper");
|
|
3504
3622
|
if (existsSync10(helper)) {
|
|
3505
3623
|
const mode = statSync2(helper).mode;
|
|
@@ -3514,7 +3632,11 @@ function slashLine(text2) {
|
|
|
3514
3632
|
const line = typeof text2 === "string" ? text2.trim() : "";
|
|
3515
3633
|
return line.length <= SLASH_MAX && /^\/[A-Za-z0-9][\w:.-]*( [^\x00-\x1f\x7f]*)?$/.test(line) ? line : null;
|
|
3516
3634
|
}
|
|
3517
|
-
function
|
|
3635
|
+
function disallowedMcpFlag(session) {
|
|
3636
|
+
const prefixes = (session.disabledMcps ?? []).filter((p) => MCP_TOOL_PREFIX_RE.test(p));
|
|
3637
|
+
return prefixes.length > 0 ? `--disallowedTools=${prefixes.join(",")}` : null;
|
|
3638
|
+
}
|
|
3639
|
+
function withHook(env, session, hook, skipPermissionsDefault) {
|
|
3518
3640
|
for (const name of FORGE_SECRETS)
|
|
3519
3641
|
delete env[name];
|
|
3520
3642
|
delete env[TOKEN_ENV];
|
|
@@ -3524,19 +3646,25 @@ function withHook(env, session, hook) {
|
|
|
3524
3646
|
env.CW_CLAUDE_FLAGS = inherited;
|
|
3525
3647
|
else
|
|
3526
3648
|
delete env.CW_CLAUDE_FLAGS;
|
|
3527
|
-
if (
|
|
3649
|
+
if ((session.harness ?? "claude") !== "claude" || session.type === "login")
|
|
3528
3650
|
return false;
|
|
3529
|
-
|
|
3530
|
-
|
|
3651
|
+
if (hook) {
|
|
3652
|
+
env[TOKEN_ENV] = hook.token;
|
|
3653
|
+
env[SESSION_ENV] = encodeURIComponent(hook.key);
|
|
3654
|
+
}
|
|
3531
3655
|
if (session.type === "general")
|
|
3532
|
-
return
|
|
3533
|
-
const
|
|
3534
|
-
|
|
3535
|
-
|
|
3656
|
+
return Boolean(hook);
|
|
3657
|
+
const extra = [hook ? `--settings ${hook.settingsPath}` : "", disallowedMcpFlag(session) ?? ""].filter(Boolean);
|
|
3658
|
+
if (extra.length === 0)
|
|
3659
|
+
return false;
|
|
3660
|
+
const skipDefault = hook ? hook.skipPermissionsDefault : skipPermissionsDefault();
|
|
3661
|
+
const flags = inherited || (skipDefault && !session.skipPermissions ? "--dangerously-skip-permissions" : "");
|
|
3662
|
+
env.CW_CLAUDE_FLAGS = [flags, ...extra].filter(Boolean).join(" ");
|
|
3663
|
+
return Boolean(hook);
|
|
3536
3664
|
}
|
|
3537
|
-
function buildLaunch(session, isNew, hook) {
|
|
3665
|
+
function buildLaunch(session, isNew, hook, cwHome = join12(process.env.HOME ?? "", ".cw")) {
|
|
3538
3666
|
const env = envWithoutHarness();
|
|
3539
|
-
const hooked = withHook(env, session, hook);
|
|
3667
|
+
const hooked = withHook(env, session, hook, () => cwSkipPermissionsDefault(cwHome));
|
|
3540
3668
|
const harness = session.harness ?? "claude";
|
|
3541
3669
|
const harnessFlag = isNew && session.harness ? ` --harness ${shellQuote(harness)}` : "";
|
|
3542
3670
|
const prefix = session.skipPermissions ? "cw --skip-permissions" : "cw";
|
|
@@ -3551,6 +3679,9 @@ function buildLaunch(session, isNew, hook) {
|
|
|
3551
3679
|
cmd2 += " --dangerously-skip-permissions";
|
|
3552
3680
|
if (hooked && hook)
|
|
3553
3681
|
cmd2 += ` --settings ${shellQuote(hook.settingsPath)}`;
|
|
3682
|
+
const disallowed = disallowedMcpFlag(session);
|
|
3683
|
+
if (disallowed)
|
|
3684
|
+
cmd2 += ` ${shellQuote(disallowed)}`;
|
|
3554
3685
|
}
|
|
3555
3686
|
if (isNew && session.harness)
|
|
3556
3687
|
env.CW_HARNESS = harness;
|
|
@@ -3609,6 +3740,7 @@ var SCROLLBACK_LIMIT, IDLE_TIMEOUT_MS, CLEANUP_INTERVAL_MS, shellQuote, SLASH_MA
|
|
|
3609
3740
|
var init_pty_manager = __esm({
|
|
3610
3741
|
"../core/dist/pty-manager.js"() {
|
|
3611
3742
|
"use strict";
|
|
3743
|
+
init_cw_types();
|
|
3612
3744
|
init_cw_doctor();
|
|
3613
3745
|
init_harness_capabilities();
|
|
3614
3746
|
init_claude_hooks();
|
|
@@ -4210,7 +4342,7 @@ var init_session_state = __esm({
|
|
|
4210
4342
|
import { mkdirSync as mkdirSync4 } from "node:fs";
|
|
4211
4343
|
import { appendFile } from "node:fs/promises";
|
|
4212
4344
|
import { homedir as homedir3 } from "node:os";
|
|
4213
|
-
import { dirname as
|
|
4345
|
+
import { dirname as dirname5, resolve as resolve4 } from "node:path";
|
|
4214
4346
|
function expandHome(path) {
|
|
4215
4347
|
return path === "~" || path.startsWith("~/") ? homedir3() + path.slice(1) : path;
|
|
4216
4348
|
}
|
|
@@ -4230,7 +4362,7 @@ function stateLogLine(call) {
|
|
|
4230
4362
|
function createStateLog(path, onError = () => {
|
|
4231
4363
|
}) {
|
|
4232
4364
|
const file = resolve4(expandHome(path));
|
|
4233
|
-
mkdirSync4(
|
|
4365
|
+
mkdirSync4(dirname5(file), { recursive: true });
|
|
4234
4366
|
let queue = Promise.resolve();
|
|
4235
4367
|
return (call) => {
|
|
4236
4368
|
const line = stateLogLine(call);
|
|
@@ -4360,7 +4492,7 @@ var init_pty_routes = __esm({
|
|
|
4360
4492
|
|
|
4361
4493
|
// ../core/dist/general-sessions.js
|
|
4362
4494
|
import { existsSync as existsSync11, readFileSync as readFileSync8, writeFileSync as writeFileSync5, mkdirSync as mkdirSync5 } from "node:fs";
|
|
4363
|
-
import { dirname as
|
|
4495
|
+
import { dirname as dirname6 } from "node:path";
|
|
4364
4496
|
var MAX_AGE_MS, GeneralSessions;
|
|
4365
4497
|
var init_general_sessions = __esm({
|
|
4366
4498
|
"../core/dist/general-sessions.js"() {
|
|
@@ -4400,7 +4532,7 @@ var init_general_sessions = __esm({
|
|
|
4400
4532
|
if (!this.file)
|
|
4401
4533
|
return;
|
|
4402
4534
|
try {
|
|
4403
|
-
mkdirSync5(
|
|
4535
|
+
mkdirSync5(dirname6(this.file), { recursive: true });
|
|
4404
4536
|
writeFileSync5(this.file, JSON.stringify(Object.fromEntries(this.sessions), null, 2));
|
|
4405
4537
|
} catch (err) {
|
|
4406
4538
|
console.warn(`[pty] could not save general sessions: ${err.message}`);
|
|
@@ -6900,7 +7032,7 @@ async function mapLimit(items, limit, fn) {
|
|
|
6900
7032
|
await Promise.all(Array.from({ length: Math.min(limit, items.length) }, worker));
|
|
6901
7033
|
return out;
|
|
6902
7034
|
}
|
|
6903
|
-
var PAGE_TYPES, KiokuError, NOT_INSTALLED, START_TIMEOUT_MS, WRITE_TIMEOUT_MS, TERMINAL_TIMEOUT_MS,
|
|
7035
|
+
var PAGE_TYPES, KiokuError, NOT_INSTALLED, START_TIMEOUT_MS, WRITE_TIMEOUT_MS, TERMINAL_TIMEOUT_MS, CACHE_MS3, RELEASES_CACHE_MS, SHOWN_BIN, ACTIVITY_SINCE, ACTIVITY_LIMIT, PARALLEL, TIERS, REPO, AREA, LANGUAGE, MISSING, brainName, Kioku;
|
|
6904
7036
|
var init_kioku = __esm({
|
|
6905
7037
|
"../core/dist/kioku.js"() {
|
|
6906
7038
|
"use strict";
|
|
@@ -6928,7 +7060,7 @@ var init_kioku = __esm({
|
|
|
6928
7060
|
START_TIMEOUT_MS = 2e4;
|
|
6929
7061
|
WRITE_TIMEOUT_MS = 6e4;
|
|
6930
7062
|
TERMINAL_TIMEOUT_MS = 3 * 6e4;
|
|
6931
|
-
|
|
7063
|
+
CACHE_MS3 = 5 * 6e4;
|
|
6932
7064
|
RELEASES_CACHE_MS = 10 * 6e4;
|
|
6933
7065
|
SHOWN_BIN = "kioku";
|
|
6934
7066
|
ACTIVITY_SINCE = "2w";
|
|
@@ -6968,7 +7100,7 @@ var init_kioku = __esm({
|
|
|
6968
7100
|
}
|
|
6969
7101
|
async status(fresh = false) {
|
|
6970
7102
|
const previous = this.snapshot;
|
|
6971
|
-
if (fresh || !previous || this.now() - previous.at >
|
|
7103
|
+
if (fresh || !previous || this.now() - previous.at > CACHE_MS3) {
|
|
6972
7104
|
const value = this.read();
|
|
6973
7105
|
this.snapshot = { at: this.now(), value };
|
|
6974
7106
|
value.catch(() => {
|
|
@@ -7411,7 +7543,7 @@ var init_dist = __esm({
|
|
|
7411
7543
|
|
|
7412
7544
|
// ../core/dist/module-permissions.js
|
|
7413
7545
|
import { realpathSync } from "node:fs";
|
|
7414
|
-
import { basename as basename3, dirname as
|
|
7546
|
+
import { basename as basename3, dirname as dirname7, join as join16, resolve as resolve5, sep as sep3 } from "node:path";
|
|
7415
7547
|
function expandGrants(permissions, settings) {
|
|
7416
7548
|
const p = permissions ?? {};
|
|
7417
7549
|
return {
|
|
@@ -7492,7 +7624,7 @@ function realOrParent(path) {
|
|
|
7492
7624
|
try {
|
|
7493
7625
|
return realpathSync(path);
|
|
7494
7626
|
} catch {
|
|
7495
|
-
const parent =
|
|
7627
|
+
const parent = dirname7(path);
|
|
7496
7628
|
return parent === path ? path : join16(realOrParent(parent), basename3(path));
|
|
7497
7629
|
}
|
|
7498
7630
|
}
|
|
@@ -7514,7 +7646,7 @@ function checkSdk(range, version = SDK_VERSION) {
|
|
|
7514
7646
|
return import_semver2.default.satisfies(version, range) ? null : `needs SDK ${range}, Forge has ${version}`;
|
|
7515
7647
|
}
|
|
7516
7648
|
function checkManifest(raw, moduleDir) {
|
|
7517
|
-
if (!
|
|
7649
|
+
if (!isObject3(raw))
|
|
7518
7650
|
return { kind: "invalid", reason: "/: must be an object" };
|
|
7519
7651
|
if (raw.sdk === void 0) {
|
|
7520
7652
|
if (V1_FIELDS.some((f) => raw[f] !== void 0))
|
|
@@ -7537,15 +7669,15 @@ function checkManifest(raw, moduleDir) {
|
|
|
7537
7669
|
err(`/${key}`, "must be a string");
|
|
7538
7670
|
}
|
|
7539
7671
|
if (raw.view !== void 0) {
|
|
7540
|
-
if (!
|
|
7672
|
+
if (!isObject3(raw.view) || typeof raw.view.entry !== "string" || raw.view.entry === "")
|
|
7541
7673
|
err("/view/entry", "required string");
|
|
7542
7674
|
else if (raw.view.title !== void 0 && typeof raw.view.title !== "string")
|
|
7543
7675
|
err("/view/title", "must be a string");
|
|
7544
|
-
if (
|
|
7676
|
+
if (isObject3(raw.view) && raw.view.banner !== void 0 && (typeof raw.view.banner !== "string" || raw.view.banner === ""))
|
|
7545
7677
|
err("/view/banner", "must be a non-empty string");
|
|
7546
7678
|
}
|
|
7547
7679
|
if (raw.permissions !== void 0) {
|
|
7548
|
-
if (!
|
|
7680
|
+
if (!isObject3(raw.permissions))
|
|
7549
7681
|
err("/permissions", "must be an object");
|
|
7550
7682
|
else {
|
|
7551
7683
|
for (const [key, value] of Object.entries(raw.permissions)) {
|
|
@@ -7563,7 +7695,7 @@ function checkManifest(raw, moduleDir) {
|
|
|
7563
7695
|
}
|
|
7564
7696
|
}
|
|
7565
7697
|
if (raw.settings !== void 0) {
|
|
7566
|
-
if (!
|
|
7698
|
+
if (!isObject3(raw.settings) || !isObject3(raw.settings.schema))
|
|
7567
7699
|
err("/settings/schema", "required object");
|
|
7568
7700
|
else
|
|
7569
7701
|
for (const [key, def] of Object.entries(raw.settings.schema))
|
|
@@ -7579,7 +7711,7 @@ function checkManifest(raw, moduleDir) {
|
|
|
7579
7711
|
return { kind: "invalid", reason: sdkReason };
|
|
7580
7712
|
}
|
|
7581
7713
|
if (errors.length === 0) {
|
|
7582
|
-
const entries = [["/server", raw.server], ["/view/entry",
|
|
7714
|
+
const entries = [["/server", raw.server], ["/view/entry", isObject3(raw.view) ? raw.view.entry : void 0], ["/view/banner", isObject3(raw.view) ? raw.view.banner : void 0]];
|
|
7583
7715
|
for (const [path, value] of entries) {
|
|
7584
7716
|
if (typeof value === "string" && !insideFolder(moduleDir, value))
|
|
7585
7717
|
err(path, "points outside the module folder");
|
|
@@ -7590,12 +7722,12 @@ function checkManifest(raw, moduleDir) {
|
|
|
7590
7722
|
return { kind: "v1", manifest: raw };
|
|
7591
7723
|
}
|
|
7592
7724
|
function checkSettingDef(def, path, allowList, err) {
|
|
7593
|
-
if (!
|
|
7725
|
+
if (!isObject3(def))
|
|
7594
7726
|
return err(path, "must be an object");
|
|
7595
7727
|
if (def.type === "list") {
|
|
7596
7728
|
if (!allowList)
|
|
7597
7729
|
return err(`${path}/type`, "lists do not nest");
|
|
7598
|
-
if (!
|
|
7730
|
+
if (!isObject3(def.item))
|
|
7599
7731
|
return err(`${path}/item`, "required object");
|
|
7600
7732
|
for (const [key, sub] of Object.entries(def.item))
|
|
7601
7733
|
checkSettingDef(sub, `${path}/item/${key}`, false, err);
|
|
@@ -7630,7 +7762,7 @@ function manifestFileFor(dir) {
|
|
|
7630
7762
|
}
|
|
7631
7763
|
}
|
|
7632
7764
|
function validateSettings(schema, values) {
|
|
7633
|
-
const input =
|
|
7765
|
+
const input = isObject3(values) ? values : {};
|
|
7634
7766
|
const errors = [];
|
|
7635
7767
|
const value = {};
|
|
7636
7768
|
for (const [key, def] of Object.entries(schema)) {
|
|
@@ -7641,8 +7773,8 @@ function validateSettings(schema, values) {
|
|
|
7641
7773
|
continue;
|
|
7642
7774
|
}
|
|
7643
7775
|
value[key] = raw.map((item, i) => {
|
|
7644
|
-
const obj2 =
|
|
7645
|
-
if (!
|
|
7776
|
+
const obj2 = isObject3(item) ? item : {};
|
|
7777
|
+
if (!isObject3(item))
|
|
7646
7778
|
errors.push({ path: `${key}[${i}]`, message: "must be an object" });
|
|
7647
7779
|
const out = {};
|
|
7648
7780
|
for (const [field, sub] of Object.entries(def.item)) {
|
|
@@ -7692,7 +7824,7 @@ function scalar(def, raw, path, errors) {
|
|
|
7692
7824
|
return typeof v === "string" && def.values.includes(v) ? v : fail(`must be one of ${def.values.join(", ")}`);
|
|
7693
7825
|
}
|
|
7694
7826
|
}
|
|
7695
|
-
var import_semver2, V1_FIELDS, TOP_LEVEL, PERMISSIONS, BOOLEAN_PERMISSIONS, SCALAR_TYPES, FORMATS,
|
|
7827
|
+
var import_semver2, V1_FIELDS, TOP_LEVEL, PERMISSIONS, BOOLEAN_PERMISSIONS, SCALAR_TYPES, FORMATS, isObject3, isStringArray;
|
|
7696
7828
|
var init_module_manifest = __esm({
|
|
7697
7829
|
"../core/dist/module-manifest.js"() {
|
|
7698
7830
|
"use strict";
|
|
@@ -7705,7 +7837,7 @@ var init_module_manifest = __esm({
|
|
|
7705
7837
|
BOOLEAN_PERMISSIONS = /* @__PURE__ */ new Set(["pty", "agent"]);
|
|
7706
7838
|
SCALAR_TYPES = /* @__PURE__ */ new Set(["string", "number", "boolean", "enum"]);
|
|
7707
7839
|
FORMATS = /* @__PURE__ */ new Set(["path", "cw-project", "url"]);
|
|
7708
|
-
|
|
7840
|
+
isObject3 = (v) => typeof v === "object" && v !== null && !Array.isArray(v);
|
|
7709
7841
|
isStringArray = (v) => Array.isArray(v) && v.every((x) => typeof x === "string");
|
|
7710
7842
|
}
|
|
7711
7843
|
});
|
|
@@ -7881,7 +8013,7 @@ var init_module_context = __esm({
|
|
|
7881
8013
|
|
|
7882
8014
|
// ../core/dist/module-host.js
|
|
7883
8015
|
import { existsSync as existsSync15, mkdirSync as mkdirSync6, readdirSync as readdirSync7, readFileSync as readFileSync12, statSync as statSync4, writeFileSync as writeFileSync7 } from "node:fs";
|
|
7884
|
-
import { basename as basename4, dirname as
|
|
8016
|
+
import { basename as basename4, dirname as dirname8, join as join18, resolve as resolve7, sep as sep5 } from "node:path";
|
|
7885
8017
|
import { pathToFileURL } from "node:url";
|
|
7886
8018
|
function disabled(id, c, reason, m) {
|
|
7887
8019
|
const text2 = (v, fallback) => typeof v === "string" && v ? v : fallback;
|
|
@@ -7912,7 +8044,7 @@ function packages(root, source, packaged) {
|
|
|
7912
8044
|
return out;
|
|
7913
8045
|
}
|
|
7914
8046
|
function nearestPackage(dir) {
|
|
7915
|
-
for (let d = dir; ; d =
|
|
8047
|
+
for (let d = dir; ; d = dirname8(d)) {
|
|
7916
8048
|
const path = join18(d, "package.json");
|
|
7917
8049
|
if (existsSync15(path)) {
|
|
7918
8050
|
try {
|
|
@@ -7921,7 +8053,7 @@ function nearestPackage(dir) {
|
|
|
7921
8053
|
return { path };
|
|
7922
8054
|
}
|
|
7923
8055
|
}
|
|
7924
|
-
if (
|
|
8056
|
+
if (dirname8(d) === d)
|
|
7925
8057
|
return null;
|
|
7926
8058
|
}
|
|
7927
8059
|
}
|
|
@@ -7980,7 +8112,7 @@ var init_module_host = __esm({
|
|
|
7980
8112
|
bannersFile;
|
|
7981
8113
|
constructor(opts) {
|
|
7982
8114
|
this.opts = opts;
|
|
7983
|
-
this.bannersFile = join18(
|
|
8115
|
+
this.bannersFile = join18(dirname8(opts.devFile), "module-banners.json");
|
|
7984
8116
|
}
|
|
7985
8117
|
list() {
|
|
7986
8118
|
return this.statuses;
|
|
@@ -7996,7 +8128,7 @@ var init_module_host = __esm({
|
|
|
7996
8128
|
// only what was installed into the modules folder; bundled, dev and Forge's own packages stay
|
|
7997
8129
|
removable(c) {
|
|
7998
8130
|
const { modulesDir } = this.opts;
|
|
7999
|
-
return c.source === "installed" &&
|
|
8131
|
+
return c.source === "installed" && dirname8(c.dir) === modulesDir || c.dir.startsWith(join18(modulesDir, "node_modules") + sep5);
|
|
8000
8132
|
}
|
|
8001
8133
|
// scans, reloads and dev changes run one at a time: each one awaits imports midway
|
|
8002
8134
|
queue = Promise.resolve();
|
|
@@ -8107,7 +8239,7 @@ var init_module_host = __esm({
|
|
|
8107
8239
|
const banner = this.loaded.get(id)?.status.banner;
|
|
8108
8240
|
if (!banner)
|
|
8109
8241
|
return;
|
|
8110
|
-
mkdirSync6(
|
|
8242
|
+
mkdirSync6(dirname8(this.bannersFile), { recursive: true });
|
|
8111
8243
|
writeFileSync7(this.bannersFile, JSON.stringify({ ...this.readBanners(), [id]: enabled }, null, 2));
|
|
8112
8244
|
banner.enabled = enabled;
|
|
8113
8245
|
}
|
|
@@ -8173,7 +8305,7 @@ var init_module_host = __esm({
|
|
|
8173
8305
|
let server;
|
|
8174
8306
|
if (m.server) {
|
|
8175
8307
|
const file = resolve7(c.dir, m.server);
|
|
8176
|
-
const owner = file.endsWith(".js") ? nearestPackage(
|
|
8308
|
+
const owner = file.endsWith(".js") ? nearestPackage(dirname8(file)) : null;
|
|
8177
8309
|
if (owner?.type === "commonjs")
|
|
8178
8310
|
return disabled(m.id, c, `${m.server} is an ES module but ${owner.path} says "type": "commonjs"; add "type": "module" to the module's package.json`, m);
|
|
8179
8311
|
try {
|
|
@@ -8291,7 +8423,7 @@ var init_module_confirmations = __esm({
|
|
|
8291
8423
|
|
|
8292
8424
|
// ../core/dist/module-install.js
|
|
8293
8425
|
import { randomBytes as randomBytes3 } from "node:crypto";
|
|
8294
|
-
import { existsSync as existsSync16, mkdirSync as mkdirSync7, mkdtempSync, readFileSync as readFileSync13, rmSync as
|
|
8426
|
+
import { existsSync as existsSync16, mkdirSync as mkdirSync7, mkdtempSync, readFileSync as readFileSync13, rmSync as rmSync4 } from "node:fs";
|
|
8295
8427
|
import { homedir as homedir7, tmpdir } from "node:os";
|
|
8296
8428
|
import { isAbsolute as isAbsolute2, join as join19, resolve as resolve8, sep as sep6 } from "node:path";
|
|
8297
8429
|
async function previewManifest(spec, opts) {
|
|
@@ -8312,7 +8444,7 @@ async function previewManifest(spec, opts) {
|
|
|
8312
8444
|
const preview = readFolder(join19(tmp, "package"));
|
|
8313
8445
|
return info.name && info.version ? { ...preview, packed: { name: info.name, version: info.version } } : preview;
|
|
8314
8446
|
} finally {
|
|
8315
|
-
|
|
8447
|
+
rmSync4(tmp, { recursive: true, force: true });
|
|
8316
8448
|
}
|
|
8317
8449
|
}
|
|
8318
8450
|
function npmPackError(spec, output) {
|
|
@@ -8452,7 +8584,7 @@ var init_module_install = __esm({
|
|
|
8452
8584
|
if (res.code !== 0)
|
|
8453
8585
|
throw new InstallError("install_failed", `npm uninstall failed: ${tailOutput(res.stderr || res.stdout, 6)}`);
|
|
8454
8586
|
} else {
|
|
8455
|
-
|
|
8587
|
+
rmSync4(found.dir, { recursive: true, force: true });
|
|
8456
8588
|
}
|
|
8457
8589
|
await this.opts.host.scan();
|
|
8458
8590
|
});
|
|
@@ -8883,7 +9015,7 @@ var init_module_cw = __esm({
|
|
|
8883
9015
|
|
|
8884
9016
|
// ../core/dist/agent-runner.js
|
|
8885
9017
|
import { spawn as nodeSpawn } from "node:child_process";
|
|
8886
|
-
import { existsSync as existsSync17, mkdtempSync as mkdtempSync2, rmSync as
|
|
9018
|
+
import { existsSync as existsSync17, mkdtempSync as mkdtempSync2, rmSync as rmSync5 } from "node:fs";
|
|
8887
9019
|
import { tmpdir as tmpdir2 } from "node:os";
|
|
8888
9020
|
import { join as join20 } from "node:path";
|
|
8889
9021
|
function runAgent(input, o) {
|
|
@@ -8903,7 +9035,7 @@ function runAgent(input, o) {
|
|
|
8903
9035
|
const spawn9 = o.spawn ?? nodeSpawn;
|
|
8904
9036
|
const timeoutMs = input.timeoutMs ?? DEFAULT_TIMEOUT_MS;
|
|
8905
9037
|
const cwd = mkdtempSync2(join20(tmpdir2(), "forge-agent-"));
|
|
8906
|
-
const cleanup = () =>
|
|
9038
|
+
const cleanup = () => rmSync5(cwd, { recursive: true, force: true });
|
|
8907
9039
|
return new Promise((resolve11, reject) => {
|
|
8908
9040
|
const child = spawn9("claude", args, { cwd, env: { ...envForAgent(), CLAUDE_CONFIG_DIR: configDir, ...CONNECTOR_ENV }, stdio: ["pipe", "pipe", "pipe"] });
|
|
8909
9041
|
child.stdin?.on("error", () => {
|