codeam-cli 2.65.2 → 2.65.3
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/CHANGELOG.md +10 -0
- package/dist/index.js +742 -716
- package/package.json +1 -1
package/dist/index.js
CHANGED
|
@@ -3321,9 +3321,9 @@ var _default = makeConfig();
|
|
|
3321
3321
|
var { getConfig, ensurePluginId, addSession, removeSession, setActiveSession, getActiveSession, getActiveSessionForAgent, setDisable1mContext, setSessionAgent, setSquadAuto, getSquadAuto, clearAll, saveCliConfig, loadCliConfig } = _default;
|
|
3322
3322
|
|
|
3323
3323
|
// src/commands/pair-auto.ts
|
|
3324
|
-
var
|
|
3325
|
-
var
|
|
3326
|
-
var
|
|
3324
|
+
var fs65 = __toESM(require("fs"));
|
|
3325
|
+
var os55 = __toESM(require("os"));
|
|
3326
|
+
var path70 = __toESM(require("path"));
|
|
3327
3327
|
var import_crypto4 = require("crypto");
|
|
3328
3328
|
|
|
3329
3329
|
// src/services/telemetry.service.ts
|
|
@@ -8073,7 +8073,7 @@ function readAnonId() {
|
|
|
8073
8073
|
}
|
|
8074
8074
|
function superProperties() {
|
|
8075
8075
|
return {
|
|
8076
|
-
cliVersion: true ? "2.65.
|
|
8076
|
+
cliVersion: true ? "2.65.3" : "0.0.0-dev",
|
|
8077
8077
|
nodeVersion: process.version,
|
|
8078
8078
|
platform: process.platform,
|
|
8079
8079
|
arch: process.arch,
|
|
@@ -8254,7 +8254,7 @@ var os4 = __toESM(require("os"));
|
|
|
8254
8254
|
// package.json
|
|
8255
8255
|
var package_default = {
|
|
8256
8256
|
name: "codeam-cli",
|
|
8257
|
-
version: "2.65.
|
|
8257
|
+
version: "2.65.3",
|
|
8258
8258
|
description: "Workflow-continuity bridge for AI coding agents. Wrap Claude Code or Codex in a PTY and supervise, approve, and redirect the session from any device \u2014 async. The terminal companion for CodeAgent Mobile.",
|
|
8259
8259
|
type: "commonjs",
|
|
8260
8260
|
main: "dist/index.js",
|
|
@@ -9706,7 +9706,7 @@ var CommandRelayService = class _CommandRelayService {
|
|
|
9706
9706
|
// fresh + clear the "CLI update available" banner after a self-update
|
|
9707
9707
|
// (a codespace that reinstalls @latest reconnects via heartbeat, not
|
|
9708
9708
|
// pair/reconnect). Older backends ignore the extra field.
|
|
9709
|
-
..."2.65.
|
|
9709
|
+
..."2.65.3" ? { ideVersion: "2.65.3" } : {}
|
|
9710
9710
|
}).then(() => log.trace("relay", `heartbeat ok online=${online}`)).catch((err) => log.trace("relay", `heartbeat failed online=${online}`, err));
|
|
9711
9711
|
}
|
|
9712
9712
|
/**
|
|
@@ -11098,9 +11098,9 @@ function closeAllTerminals() {
|
|
|
11098
11098
|
}
|
|
11099
11099
|
|
|
11100
11100
|
// src/commands/start/handlers.ts
|
|
11101
|
-
var
|
|
11102
|
-
var
|
|
11103
|
-
var
|
|
11101
|
+
var fs64 = __toESM(require("fs"));
|
|
11102
|
+
var os54 = __toESM(require("os"));
|
|
11103
|
+
var path69 = __toESM(require("path"));
|
|
11104
11104
|
var import_crypto3 = require("crypto");
|
|
11105
11105
|
var import_child_process26 = require("child_process");
|
|
11106
11106
|
|
|
@@ -11932,8 +11932,8 @@ function findGitRoot2(startDir) {
|
|
|
11932
11932
|
|
|
11933
11933
|
// src/commands/link.ts
|
|
11934
11934
|
var import_node_crypto8 = require("crypto");
|
|
11935
|
-
var
|
|
11936
|
-
var
|
|
11935
|
+
var fs33 = __toESM(require("fs"));
|
|
11936
|
+
var path38 = __toESM(require("path"));
|
|
11937
11937
|
var import_chokidar = __toESM(require("chokidar"));
|
|
11938
11938
|
var import_picocolors2 = __toESM(require("picocolors"));
|
|
11939
11939
|
|
|
@@ -15556,12 +15556,302 @@ var ClaudeDeployStrategy = class {
|
|
|
15556
15556
|
|
|
15557
15557
|
// src/agents/codex/runtime.ts
|
|
15558
15558
|
var import_node_child_process5 = require("child_process");
|
|
15559
|
-
var
|
|
15559
|
+
var path26 = __toESM(require("path"));
|
|
15560
15560
|
|
|
15561
15561
|
// src/agents/codex/history.ts
|
|
15562
15562
|
var import_node_fs3 = __toESM(require("fs"));
|
|
15563
15563
|
var import_node_path2 = __toESM(require("path"));
|
|
15564
15564
|
var import_node_os = __toESM(require("os"));
|
|
15565
|
+
|
|
15566
|
+
// src/agents/acp/squad-roster.ts
|
|
15567
|
+
var fs20 = __toESM(require("fs"));
|
|
15568
|
+
var os18 = __toESM(require("os"));
|
|
15569
|
+
var path23 = __toESM(require("path"));
|
|
15570
|
+
var PROMPT_MAX = 500;
|
|
15571
|
+
var REPLY_SUMMARY_MAX = 1e3;
|
|
15572
|
+
var PREAMBLE_MAX = 2e3;
|
|
15573
|
+
var BRIEFING_DEFAULT_MAX = 8e3;
|
|
15574
|
+
var GENERIC_SPECIALTY = "general implementation tasks";
|
|
15575
|
+
function clip(s, max) {
|
|
15576
|
+
return s.length > max ? s.slice(0, max) : s;
|
|
15577
|
+
}
|
|
15578
|
+
function defaultMember() {
|
|
15579
|
+
return {
|
|
15580
|
+
acpSessionId: null,
|
|
15581
|
+
provisioned: false,
|
|
15582
|
+
binaryVerified: false,
|
|
15583
|
+
lastTurnIndex: 0,
|
|
15584
|
+
contextTextFallback: false
|
|
15585
|
+
};
|
|
15586
|
+
}
|
|
15587
|
+
function journalPathFor(homeDir2, sessionId) {
|
|
15588
|
+
return path23.join(homeDir2, ".codeam", `squad-journal-${sessionId}.json`);
|
|
15589
|
+
}
|
|
15590
|
+
function loadJournal(journalPath) {
|
|
15591
|
+
try {
|
|
15592
|
+
const raw = JSON.parse(fs20.readFileSync(journalPath, "utf-8"));
|
|
15593
|
+
return Array.isArray(raw.turns) ? raw.turns : [];
|
|
15594
|
+
} catch {
|
|
15595
|
+
return [];
|
|
15596
|
+
}
|
|
15597
|
+
}
|
|
15598
|
+
var SquadState = class {
|
|
15599
|
+
/** Set by the caller after fetchSquadRoster; null until then. */
|
|
15600
|
+
roster = null;
|
|
15601
|
+
/**
|
|
15602
|
+
* Autonomous chained handoffs (P2-2, PRO). Seeded from the persisted
|
|
15603
|
+
* `SavedSession.squadAuto` at session start and rewritten by
|
|
15604
|
+
* `squad_configure`. Read-only to callers — mutate via {@link setAuto}, which
|
|
15605
|
+
* clamps the budget and re-arms the chain.
|
|
15606
|
+
*/
|
|
15607
|
+
autoConfig = { enabled: false, hopBudget: SQUAD_HOP_BUDGET_DEFAULT };
|
|
15608
|
+
/**
|
|
15609
|
+
* Hops left in the CURRENT chain. Reset to the budget on every USER-initiated
|
|
15610
|
+
* prompt (so a user turn always interrupts and re-arms) and decremented by
|
|
15611
|
+
* each self-accepted handoff.
|
|
15612
|
+
*/
|
|
15613
|
+
hopsLeft = 0;
|
|
15614
|
+
/** Lifetime handoff counters for `squad_stats` (in-memory, this process). */
|
|
15615
|
+
handoffCounters = { proposed: 0, accepted: 0, auto: 0 };
|
|
15616
|
+
journalPath;
|
|
15617
|
+
turns;
|
|
15618
|
+
members = /* @__PURE__ */ new Map();
|
|
15619
|
+
constructor(opts) {
|
|
15620
|
+
this.journalPath = journalPathFor(opts.homeDir ?? os18.homedir(), opts.sessionId);
|
|
15621
|
+
this.turns = loadJournal(this.journalPath);
|
|
15622
|
+
if (opts.auto) this.setAuto(opts.auto);
|
|
15623
|
+
}
|
|
15624
|
+
get auto() {
|
|
15625
|
+
return this.autoConfig;
|
|
15626
|
+
}
|
|
15627
|
+
/** Apply a new mode (clamping the budget) and re-arm the chain. */
|
|
15628
|
+
setAuto(value) {
|
|
15629
|
+
this.autoConfig = {
|
|
15630
|
+
enabled: value.enabled === true,
|
|
15631
|
+
hopBudget: clampHopBudget(value.hopBudget)
|
|
15632
|
+
};
|
|
15633
|
+
this.resetHops();
|
|
15634
|
+
return this.autoConfig;
|
|
15635
|
+
}
|
|
15636
|
+
hopsRemaining() {
|
|
15637
|
+
return this.hopsLeft;
|
|
15638
|
+
}
|
|
15639
|
+
/** Re-arm the chain — called at the start of every USER-initiated turn. */
|
|
15640
|
+
resetHops() {
|
|
15641
|
+
this.hopsLeft = this.autoConfig.enabled ? this.autoConfig.hopBudget : 0;
|
|
15642
|
+
}
|
|
15643
|
+
/** Spend one hop on a self-accepted handoff. */
|
|
15644
|
+
consumeHop() {
|
|
15645
|
+
if (this.hopsLeft > 0) this.hopsLeft -= 1;
|
|
15646
|
+
}
|
|
15647
|
+
countProposal(opts) {
|
|
15648
|
+
this.handoffCounters.proposed += 1;
|
|
15649
|
+
if (opts.auto) this.handoffCounters.auto += 1;
|
|
15650
|
+
}
|
|
15651
|
+
countAccepted() {
|
|
15652
|
+
this.handoffCounters.accepted += 1;
|
|
15653
|
+
}
|
|
15654
|
+
/**
|
|
15655
|
+
* Per-member activity for the `squad_stats` relay command, derived from the
|
|
15656
|
+
* journal (the same shared history the delta briefing reads) plus the
|
|
15657
|
+
* in-memory handoff counters. `filesTouched` counts DISTINCT paths — a member
|
|
15658
|
+
* that edited the same file across three turns touched ONE file.
|
|
15659
|
+
*/
|
|
15660
|
+
stats() {
|
|
15661
|
+
const byAgent = /* @__PURE__ */ new Map();
|
|
15662
|
+
for (const t2 of this.turns) {
|
|
15663
|
+
let row = byAgent.get(t2.agentId);
|
|
15664
|
+
if (!row) {
|
|
15665
|
+
row = { turns: 0, files: /* @__PURE__ */ new Set() };
|
|
15666
|
+
byAgent.set(t2.agentId, row);
|
|
15667
|
+
}
|
|
15668
|
+
row.turns += 1;
|
|
15669
|
+
for (const f of t2.filesTouched) row.files.add(f);
|
|
15670
|
+
}
|
|
15671
|
+
const members = [...byAgent.entries()].map(([agentId, row]) => ({
|
|
15672
|
+
agentId,
|
|
15673
|
+
turns: row.turns,
|
|
15674
|
+
filesTouched: row.files.size
|
|
15675
|
+
}));
|
|
15676
|
+
return { members, handoffs: { ...this.handoffCounters }, sinceTurn: 1 };
|
|
15677
|
+
}
|
|
15678
|
+
/** Returns (creating on first access) the mutable per-agent state. */
|
|
15679
|
+
member(agentId) {
|
|
15680
|
+
let m = this.members.get(agentId);
|
|
15681
|
+
if (!m) {
|
|
15682
|
+
m = defaultMember();
|
|
15683
|
+
this.members.set(agentId, m);
|
|
15684
|
+
}
|
|
15685
|
+
return m;
|
|
15686
|
+
}
|
|
15687
|
+
/** Appends a journal entry and persists (fire-and-forget durability). */
|
|
15688
|
+
recordTurn(entry) {
|
|
15689
|
+
const turn = {
|
|
15690
|
+
turn: this.turns.length + 1,
|
|
15691
|
+
agentId: entry.agentId,
|
|
15692
|
+
prompt: clip(entry.prompt, PROMPT_MAX),
|
|
15693
|
+
replySummary: clip(entry.replySummary, REPLY_SUMMARY_MAX),
|
|
15694
|
+
filesTouched: entry.filesTouched
|
|
15695
|
+
};
|
|
15696
|
+
this.turns.push(turn);
|
|
15697
|
+
this.persist();
|
|
15698
|
+
}
|
|
15699
|
+
turnCount() {
|
|
15700
|
+
return this.turns.length;
|
|
15701
|
+
}
|
|
15702
|
+
entriesSince(turnIndex) {
|
|
15703
|
+
return this.turns.filter((t2) => t2.turn > turnIndex);
|
|
15704
|
+
}
|
|
15705
|
+
persist() {
|
|
15706
|
+
try {
|
|
15707
|
+
fs20.mkdirSync(path23.dirname(this.journalPath), { recursive: true, mode: 448 });
|
|
15708
|
+
fs20.writeFileSync(this.journalPath, JSON.stringify({ turns: this.turns }), { mode: 384 });
|
|
15709
|
+
} catch {
|
|
15710
|
+
}
|
|
15711
|
+
}
|
|
15712
|
+
};
|
|
15713
|
+
function specialtyFor(agentId) {
|
|
15714
|
+
return SQUAD_SPECIALTIES[agentId] ?? GENERIC_SPECIALTY;
|
|
15715
|
+
}
|
|
15716
|
+
var TEAM_PREAMBLE_MARKER = "[Team context]";
|
|
15717
|
+
var TEAM_PREAMBLE_LINES = [
|
|
15718
|
+
"[Team context] You are the active agent in a CodeAgent Mobile session where the user",
|
|
15719
|
+
"has a squad of agents and can pass work between them. Your available teammates:",
|
|
15720
|
+
"If a task clearly fits a teammate better than you, you MAY propose a handoff by ending",
|
|
15721
|
+
`your reply with a fenced code block tagged ${HANDOFF_FENCE_TAG} containing ONE JSON object:`,
|
|
15722
|
+
'{"to":"<teammate id>","reason":"<one sentence>","prompt":"<the prompt they should run>"}',
|
|
15723
|
+
"Propose at most one handoff per reply, only when genuinely better, and never announce",
|
|
15724
|
+
"the block in prose \u2014 the app renders it as a card the user can accept."
|
|
15725
|
+
];
|
|
15726
|
+
var TEAM_PREAMBLE_BULLET_RE = /^- .+ — best at: /;
|
|
15727
|
+
var BRIEFING_MARKER = "[Team update]";
|
|
15728
|
+
var BRIEFING_HEADER = "[Team update] While you were away, other agents worked on this session:";
|
|
15729
|
+
var BRIEFING_FOOTER = "Continue from the CURRENT state of the working tree.";
|
|
15730
|
+
function buildTeamPreamble(roster, currentAgent, opts) {
|
|
15731
|
+
const others = roster.agents.filter((a) => a.agentId !== currentAgent);
|
|
15732
|
+
if (others.length === 0) return null;
|
|
15733
|
+
const lines = [
|
|
15734
|
+
TEAM_PREAMBLE_LINES[0],
|
|
15735
|
+
TEAM_PREAMBLE_LINES[1],
|
|
15736
|
+
...others.map((a) => `- ${a.displayName} \u2014 best at: ${specialtyFor(a.agentId)}`)
|
|
15737
|
+
];
|
|
15738
|
+
if (opts.handoffInstructions) {
|
|
15739
|
+
lines.push(...TEAM_PREAMBLE_LINES.slice(2));
|
|
15740
|
+
}
|
|
15741
|
+
return clip(lines.join("\n"), PREAMBLE_MAX);
|
|
15742
|
+
}
|
|
15743
|
+
function renderJournalEntry(e) {
|
|
15744
|
+
const filesClause = e.filesTouched.length > 0 ? ` (files: ${e.filesTouched.join(", ")})` : "";
|
|
15745
|
+
return `- turn ${e.turn} (${e.agentId}): ${e.prompt} \u2192 ${e.replySummary}${filesClause}`;
|
|
15746
|
+
}
|
|
15747
|
+
function buildDeltaBriefing(entries, maxChars = BRIEFING_DEFAULT_MAX) {
|
|
15748
|
+
if (entries.length === 0) return null;
|
|
15749
|
+
const header = BRIEFING_HEADER;
|
|
15750
|
+
const footer = BRIEFING_FOOTER;
|
|
15751
|
+
const envelope = header.length + 1 + footer.length + 1;
|
|
15752
|
+
const sorted = [...entries].sort((a, b) => a.turn - b.turn);
|
|
15753
|
+
const lines = [];
|
|
15754
|
+
let bodyLen = 0;
|
|
15755
|
+
for (let i = sorted.length - 1; i >= 0; i--) {
|
|
15756
|
+
const line = renderJournalEntry(sorted[i]);
|
|
15757
|
+
const addedLen = line.length + (lines.length > 0 ? 1 : 0);
|
|
15758
|
+
if (lines.length > 0 && envelope + bodyLen + addedLen > maxChars) break;
|
|
15759
|
+
lines.unshift(line);
|
|
15760
|
+
bodyLen += addedLen;
|
|
15761
|
+
}
|
|
15762
|
+
return [header, lines.join("\n"), footer].join("\n");
|
|
15763
|
+
}
|
|
15764
|
+
|
|
15765
|
+
// src/agents/acp/squad-context.ts
|
|
15766
|
+
var SQUAD_CONTEXT_URI = "codeam://squad-context";
|
|
15767
|
+
var HANDOFF_MARKER = "[Session handoff]";
|
|
15768
|
+
var HANDOFF_TERMINATOR = "--- End of handoff context ---";
|
|
15769
|
+
function buildSquadContextBlock(text) {
|
|
15770
|
+
return {
|
|
15771
|
+
type: "resource",
|
|
15772
|
+
resource: { uri: SQUAD_CONTEXT_URI, mimeType: "text/plain", text }
|
|
15773
|
+
};
|
|
15774
|
+
}
|
|
15775
|
+
function isSquadContextBlock(block) {
|
|
15776
|
+
return block.type === "resource" && block.resource.uri === SQUAD_CONTEXT_URI;
|
|
15777
|
+
}
|
|
15778
|
+
function isLeakedSquadContextText(text) {
|
|
15779
|
+
return text.trim().startsWith(SQUAD_CONTEXT_URI);
|
|
15780
|
+
}
|
|
15781
|
+
function looksLikeUnsupportedPromptShape(err) {
|
|
15782
|
+
const code = err?.code;
|
|
15783
|
+
if (code === -32602) return true;
|
|
15784
|
+
const message = err instanceof Error ? err.message : String(err ?? "");
|
|
15785
|
+
if (/invalid[ _]params|-32602/i.test(message)) return true;
|
|
15786
|
+
return /\bresource\b/i.test(message) && /unsupported|not supported/i.test(message);
|
|
15787
|
+
}
|
|
15788
|
+
function skipWhile(lines, start2, keepGoing) {
|
|
15789
|
+
let i = start2;
|
|
15790
|
+
while (i < lines.length && keepGoing(lines[i])) i++;
|
|
15791
|
+
return i;
|
|
15792
|
+
}
|
|
15793
|
+
function endOfTeamPreamble(lines, start2) {
|
|
15794
|
+
if (lines[start2] !== TEAM_PREAMBLE_LINES[0]) return -1;
|
|
15795
|
+
if (lines[start2 + 1] !== TEAM_PREAMBLE_LINES[1]) return -1;
|
|
15796
|
+
return skipWhile(
|
|
15797
|
+
lines,
|
|
15798
|
+
start2 + 2,
|
|
15799
|
+
(line) => TEAM_PREAMBLE_BULLET_RE.test(line) || TEAM_PREAMBLE_LINES.includes(line)
|
|
15800
|
+
);
|
|
15801
|
+
}
|
|
15802
|
+
function endOfTerminatedBlock(lines, start2, terminator) {
|
|
15803
|
+
for (let i = start2; i < lines.length; i++) {
|
|
15804
|
+
if (lines[i].trimEnd() === terminator) return i + 1;
|
|
15805
|
+
}
|
|
15806
|
+
return -1;
|
|
15807
|
+
}
|
|
15808
|
+
function stripSquadContext(text) {
|
|
15809
|
+
if (!text.includes(HANDOFF_MARKER) && !text.includes(BRIEFING_MARKER) && !text.includes(TEAM_PREAMBLE_MARKER)) {
|
|
15810
|
+
return text;
|
|
15811
|
+
}
|
|
15812
|
+
const lines = text.split("\n");
|
|
15813
|
+
const kept = [];
|
|
15814
|
+
let i = 0;
|
|
15815
|
+
let stripped = false;
|
|
15816
|
+
while (i < lines.length) {
|
|
15817
|
+
const line = lines[i];
|
|
15818
|
+
if (line.startsWith(HANDOFF_MARKER)) {
|
|
15819
|
+
const end = endOfTerminatedBlock(lines, i, HANDOFF_TERMINATOR);
|
|
15820
|
+
if (end !== -1) {
|
|
15821
|
+
i = end;
|
|
15822
|
+
stripped = true;
|
|
15823
|
+
continue;
|
|
15824
|
+
}
|
|
15825
|
+
} else if (line.startsWith(BRIEFING_MARKER)) {
|
|
15826
|
+
const end = endOfTerminatedBlock(lines, i, BRIEFING_FOOTER);
|
|
15827
|
+
if (end !== -1) {
|
|
15828
|
+
i = end;
|
|
15829
|
+
stripped = true;
|
|
15830
|
+
continue;
|
|
15831
|
+
}
|
|
15832
|
+
} else if (line.startsWith(TEAM_PREAMBLE_MARKER)) {
|
|
15833
|
+
const end = endOfTeamPreamble(lines, i);
|
|
15834
|
+
if (end !== -1) {
|
|
15835
|
+
i = end;
|
|
15836
|
+
stripped = true;
|
|
15837
|
+
continue;
|
|
15838
|
+
}
|
|
15839
|
+
}
|
|
15840
|
+
kept.push(line);
|
|
15841
|
+
i++;
|
|
15842
|
+
}
|
|
15843
|
+
if (!stripped) return text;
|
|
15844
|
+
return kept.join("\n").trim();
|
|
15845
|
+
}
|
|
15846
|
+
|
|
15847
|
+
// src/agents/acp/agent-meta-blocks.ts
|
|
15848
|
+
var AGENT_META_BLOCK_MARKERS = ["<recommended_plugins>"];
|
|
15849
|
+
function isAgentMetaBlock(text) {
|
|
15850
|
+
const trimmed = text.trim();
|
|
15851
|
+
return AGENT_META_BLOCK_MARKERS.some((marker) => trimmed.startsWith(marker));
|
|
15852
|
+
}
|
|
15853
|
+
|
|
15854
|
+
// src/agents/codex/history.ts
|
|
15565
15855
|
function resolveHistoryDir2(_cwd, homeOverride) {
|
|
15566
15856
|
const home = homeOverride ?? import_node_os.default.homedir();
|
|
15567
15857
|
const sessionsRoot = import_node_path2.default.join(home, ".codex", "sessions");
|
|
@@ -15620,6 +15910,8 @@ function isSyntheticCodexTurn(role, text) {
|
|
|
15620
15910
|
if (trimmed.startsWith("<environment_context>")) return true;
|
|
15621
15911
|
if (trimmed.startsWith("<turn_aborted>")) return true;
|
|
15622
15912
|
if (/^(<<ccr:[^>]*>>\s*)+$/.test(trimmed)) return true;
|
|
15913
|
+
if (isLeakedSquadContextText(trimmed)) return true;
|
|
15914
|
+
if (isAgentMetaBlock(trimmed)) return true;
|
|
15623
15915
|
return false;
|
|
15624
15916
|
}
|
|
15625
15917
|
function parseHistoryFile2(filePath) {
|
|
@@ -15916,16 +16208,16 @@ function getCurrentUsage2(historyDir) {
|
|
|
15916
16208
|
var import_node_child_process4 = require("child_process");
|
|
15917
16209
|
|
|
15918
16210
|
// src/agents/codex/local-token.ts
|
|
15919
|
-
var
|
|
15920
|
-
var
|
|
15921
|
-
var
|
|
16211
|
+
var fs22 = __toESM(require("fs"));
|
|
16212
|
+
var os20 = __toESM(require("os"));
|
|
16213
|
+
var path25 = __toESM(require("path"));
|
|
15922
16214
|
function codexCredentialsPath() {
|
|
15923
|
-
return
|
|
16215
|
+
return path25.join(os20.homedir(), ".codex", "auth.json");
|
|
15924
16216
|
}
|
|
15925
16217
|
async function extractLocalCodexToken() {
|
|
15926
16218
|
const file = codexCredentialsPath();
|
|
15927
|
-
if (!
|
|
15928
|
-
const credential =
|
|
16219
|
+
if (!fs22.existsSync(file)) return null;
|
|
16220
|
+
const credential = fs22.readFileSync(file, "utf8").trim();
|
|
15929
16221
|
if (credential.length === 0) return null;
|
|
15930
16222
|
return { method: "oauth", credential, source: "flat-file" };
|
|
15931
16223
|
}
|
|
@@ -16148,7 +16440,7 @@ function augmentNpmGlobalBin(os67) {
|
|
|
16148
16440
|
if (result.status !== 0) return;
|
|
16149
16441
|
const prefix = result.stdout.toString().trim();
|
|
16150
16442
|
if (!prefix) return;
|
|
16151
|
-
const binDir = os67.id === "win32" ? prefix :
|
|
16443
|
+
const binDir = os67.id === "win32" ? prefix : path26.join(prefix, "bin");
|
|
16152
16444
|
os67.augmentPath([binDir]);
|
|
16153
16445
|
} catch {
|
|
16154
16446
|
}
|
|
@@ -16233,7 +16525,7 @@ var import_node_child_process9 = require("child_process");
|
|
|
16233
16525
|
// src/agents/coderabbit/installer.ts
|
|
16234
16526
|
var import_node_child_process7 = require("child_process");
|
|
16235
16527
|
var import_node_fs5 = require("fs");
|
|
16236
|
-
var
|
|
16528
|
+
var path28 = __toESM(require("path"));
|
|
16237
16529
|
|
|
16238
16530
|
// src/commands/host/os-packages.ts
|
|
16239
16531
|
var import_node_child_process6 = require("child_process");
|
|
@@ -16564,7 +16856,7 @@ function writeUnzipShim(os67, runner) {
|
|
|
16564
16856
|
const python = ["python3", "python"].find((p2) => runner.which(p2));
|
|
16565
16857
|
if (!python) return null;
|
|
16566
16858
|
const dir = os67.scratchPath("codeam-cr-prereq");
|
|
16567
|
-
const shim =
|
|
16859
|
+
const shim = path28.join(dir, "unzip");
|
|
16568
16860
|
const script = `#!/bin/sh
|
|
16569
16861
|
set -e
|
|
16570
16862
|
archive=""
|
|
@@ -16714,9 +17006,9 @@ async function ensureCoderabbitInstalled(os67, deps = {}) {
|
|
|
16714
17006
|
|
|
16715
17007
|
// src/agents/coderabbit/link.ts
|
|
16716
17008
|
var import_node_child_process8 = require("child_process");
|
|
16717
|
-
var
|
|
16718
|
-
var
|
|
16719
|
-
var
|
|
17009
|
+
var fs24 = __toESM(require("fs"));
|
|
17010
|
+
var os22 = __toESM(require("os"));
|
|
17011
|
+
var path29 = __toESM(require("path"));
|
|
16720
17012
|
|
|
16721
17013
|
// src/agents/strategy.ts
|
|
16722
17014
|
function validateNonEmptyCredential(token) {
|
|
@@ -16725,12 +17017,12 @@ function validateNonEmptyCredential(token) {
|
|
|
16725
17017
|
|
|
16726
17018
|
// src/agents/coderabbit/link.ts
|
|
16727
17019
|
function authPath() {
|
|
16728
|
-
return
|
|
17020
|
+
return path29.join(os22.homedir(), ".coderabbit", "auth.json");
|
|
16729
17021
|
}
|
|
16730
17022
|
async function extractLocalCoderabbitToken() {
|
|
16731
17023
|
const file = authPath();
|
|
16732
|
-
if (!
|
|
16733
|
-
const credential =
|
|
17024
|
+
if (!fs24.existsSync(file)) return null;
|
|
17025
|
+
const credential = fs24.readFileSync(file, "utf8").trim();
|
|
16734
17026
|
if (credential.length === 0) return null;
|
|
16735
17027
|
return { method: "oauth", credential, source: "flat-file" };
|
|
16736
17028
|
}
|
|
@@ -17074,39 +17366,39 @@ CodeRabbit review timed out after ${Math.round(
|
|
|
17074
17366
|
};
|
|
17075
17367
|
|
|
17076
17368
|
// src/agents/cursor/history.ts
|
|
17077
|
-
var
|
|
17078
|
-
var
|
|
17079
|
-
var
|
|
17369
|
+
var fs25 = __toESM(require("fs"));
|
|
17370
|
+
var os23 = __toESM(require("os"));
|
|
17371
|
+
var path30 = __toESM(require("path"));
|
|
17080
17372
|
var import_node_crypto5 = require("crypto");
|
|
17081
|
-
var HISTORY_ROOT =
|
|
17082
|
-
var CURSOR_HOME =
|
|
17373
|
+
var HISTORY_ROOT = path30.join(os23.homedir(), ".cursor", "projects");
|
|
17374
|
+
var CURSOR_HOME = path30.join(os23.homedir(), ".cursor");
|
|
17083
17375
|
var STORE_FILES = ["store.db", "store.db-wal", "store.db-shm"];
|
|
17084
17376
|
function acpSessionDir(sessionId) {
|
|
17085
|
-
return
|
|
17377
|
+
return path30.join(CURSOR_HOME, "acp-sessions", sessionId);
|
|
17086
17378
|
}
|
|
17087
17379
|
function nativeStoreDir(cwd, sessionId) {
|
|
17088
|
-
const chatsRoot =
|
|
17380
|
+
const chatsRoot = path30.join(CURSOR_HOME, "chats");
|
|
17089
17381
|
let buckets = [];
|
|
17090
17382
|
try {
|
|
17091
|
-
buckets =
|
|
17383
|
+
buckets = fs25.readdirSync(chatsRoot);
|
|
17092
17384
|
} catch {
|
|
17093
17385
|
}
|
|
17094
17386
|
for (const b of buckets) {
|
|
17095
|
-
const candidate =
|
|
17096
|
-
if (
|
|
17387
|
+
const candidate = path30.join(chatsRoot, b, sessionId);
|
|
17388
|
+
if (fs25.existsSync(path30.join(candidate, "store.db"))) return candidate;
|
|
17097
17389
|
}
|
|
17098
|
-
const computed =
|
|
17099
|
-
return
|
|
17390
|
+
const computed = path30.join(chatsRoot, (0, import_node_crypto5.createHash)("md5").update(cwd).digest("hex"), sessionId);
|
|
17391
|
+
return fs25.existsSync(computed) ? computed : null;
|
|
17100
17392
|
}
|
|
17101
17393
|
function copyStoreFiles(srcDir, dstDir) {
|
|
17102
|
-
|
|
17394
|
+
fs25.mkdirSync(dstDir, { recursive: true });
|
|
17103
17395
|
for (const f of STORE_FILES) {
|
|
17104
|
-
const dst =
|
|
17105
|
-
if (
|
|
17396
|
+
const dst = path30.join(dstDir, f);
|
|
17397
|
+
if (fs25.existsSync(dst)) fs25.rmSync(dst, { force: true });
|
|
17106
17398
|
}
|
|
17107
17399
|
for (const f of STORE_FILES) {
|
|
17108
|
-
const src =
|
|
17109
|
-
if (
|
|
17400
|
+
const src = path30.join(srcDir, f);
|
|
17401
|
+
if (fs25.existsSync(src)) fs25.copyFileSync(src, path30.join(dstDir, f));
|
|
17110
17402
|
}
|
|
17111
17403
|
}
|
|
17112
17404
|
function bridgeNativeToAcp(cwd, sessionId) {
|
|
@@ -17118,8 +17410,8 @@ function bridgeNativeToAcp(cwd, sessionId) {
|
|
|
17118
17410
|
}
|
|
17119
17411
|
const dst = acpSessionDir(sessionId);
|
|
17120
17412
|
copyStoreFiles(src, dst);
|
|
17121
|
-
|
|
17122
|
-
|
|
17413
|
+
fs25.writeFileSync(
|
|
17414
|
+
path30.join(dst, "meta.json"),
|
|
17123
17415
|
JSON.stringify({ schemaVersion: 1, cwd })
|
|
17124
17416
|
);
|
|
17125
17417
|
log.info("cursor", `baton bridge native\u2192acp ok (${sessionId.slice(0, 8)})`);
|
|
@@ -17130,11 +17422,11 @@ function bridgeNativeToAcp(cwd, sessionId) {
|
|
|
17130
17422
|
function bridgeAcpToNative(cwd, sessionId) {
|
|
17131
17423
|
try {
|
|
17132
17424
|
const src = acpSessionDir(sessionId);
|
|
17133
|
-
if (!
|
|
17425
|
+
if (!fs25.existsSync(path30.join(src, "store.db"))) {
|
|
17134
17426
|
log.warn("cursor", `baton bridge: no acp store for ${sessionId.slice(0, 8)} \u2014 skip`);
|
|
17135
17427
|
return;
|
|
17136
17428
|
}
|
|
17137
|
-
const dst = nativeStoreDir(cwd, sessionId) ??
|
|
17429
|
+
const dst = nativeStoreDir(cwd, sessionId) ?? path30.join(CURSOR_HOME, "chats", (0, import_node_crypto5.createHash)("md5").update(cwd).digest("hex"), sessionId);
|
|
17138
17430
|
copyStoreFiles(src, dst);
|
|
17139
17431
|
log.info("cursor", `baton bridge acp\u2192native ok (${sessionId.slice(0, 8)})`);
|
|
17140
17432
|
} catch (err) {
|
|
@@ -17145,26 +17437,26 @@ function encodeCursorCwd(cwd) {
|
|
|
17145
17437
|
return cwd.replace(/^[/\\]+/, "").replace(/[/\\:]/g, "-");
|
|
17146
17438
|
}
|
|
17147
17439
|
function resolveHistoryFile3(cwd, sessionId, root = HISTORY_ROOT) {
|
|
17148
|
-
const rel =
|
|
17149
|
-
const primary =
|
|
17150
|
-
if (
|
|
17440
|
+
const rel = path30.join("agent-transcripts", sessionId, `${sessionId}.jsonl`);
|
|
17441
|
+
const primary = path30.join(root, encodeCursorCwd(cwd), rel);
|
|
17442
|
+
if (fs25.existsSync(primary)) return primary;
|
|
17151
17443
|
let entries;
|
|
17152
17444
|
try {
|
|
17153
|
-
entries =
|
|
17445
|
+
entries = fs25.readdirSync(root, { withFileTypes: true });
|
|
17154
17446
|
} catch {
|
|
17155
17447
|
return null;
|
|
17156
17448
|
}
|
|
17157
17449
|
for (const e of entries) {
|
|
17158
17450
|
if (!e.isDirectory()) continue;
|
|
17159
|
-
const candidate =
|
|
17160
|
-
if (
|
|
17451
|
+
const candidate = path30.join(root, e.name, rel);
|
|
17452
|
+
if (fs25.existsSync(candidate)) return candidate;
|
|
17161
17453
|
}
|
|
17162
17454
|
return null;
|
|
17163
17455
|
}
|
|
17164
17456
|
function resolveHistoryDir3(cwd) {
|
|
17165
|
-
if (!
|
|
17166
|
-
const dir =
|
|
17167
|
-
return
|
|
17457
|
+
if (!fs25.existsSync(HISTORY_ROOT)) return null;
|
|
17458
|
+
const dir = path30.join(HISTORY_ROOT, encodeCursorCwd(cwd));
|
|
17459
|
+
return fs25.existsSync(dir) ? dir : null;
|
|
17168
17460
|
}
|
|
17169
17461
|
function extractText2(content) {
|
|
17170
17462
|
if (!Array.isArray(content)) return "";
|
|
@@ -17177,7 +17469,7 @@ function unwrapUserQuery(text) {
|
|
|
17177
17469
|
function parseHistoryFile3(filePath) {
|
|
17178
17470
|
let raw;
|
|
17179
17471
|
try {
|
|
17180
|
-
raw =
|
|
17472
|
+
raw = fs25.readFileSync(filePath, "utf8");
|
|
17181
17473
|
} catch {
|
|
17182
17474
|
return [];
|
|
17183
17475
|
}
|
|
@@ -17215,16 +17507,16 @@ function getCurrentUsage3(_historyDir) {
|
|
|
17215
17507
|
var import_node_child_process10 = require("child_process");
|
|
17216
17508
|
|
|
17217
17509
|
// src/agents/cursor/local-token.ts
|
|
17218
|
-
var
|
|
17219
|
-
var
|
|
17220
|
-
var
|
|
17510
|
+
var fs26 = __toESM(require("fs"));
|
|
17511
|
+
var os24 = __toESM(require("os"));
|
|
17512
|
+
var path31 = __toESM(require("path"));
|
|
17221
17513
|
function cursorCredentialsPath() {
|
|
17222
|
-
return
|
|
17514
|
+
return path31.join(os24.homedir(), ".cursor", "auth.json");
|
|
17223
17515
|
}
|
|
17224
17516
|
async function extractLocalCursorToken() {
|
|
17225
17517
|
const file = cursorCredentialsPath();
|
|
17226
|
-
if (!
|
|
17227
|
-
const credential =
|
|
17518
|
+
if (!fs26.existsSync(file)) return null;
|
|
17519
|
+
const credential = fs26.readFileSync(file, "utf8").trim();
|
|
17228
17520
|
if (credential.length === 0) return null;
|
|
17229
17521
|
return { method: "oauth", credential, source: "flat-file" };
|
|
17230
17522
|
}
|
|
@@ -17467,12 +17759,12 @@ var CursorRuntimeStrategy = class {
|
|
|
17467
17759
|
};
|
|
17468
17760
|
|
|
17469
17761
|
// src/agents/aider/history.ts
|
|
17470
|
-
var
|
|
17471
|
-
var
|
|
17762
|
+
var fs27 = __toESM(require("fs"));
|
|
17763
|
+
var path32 = __toESM(require("path"));
|
|
17472
17764
|
var AIDER_HISTORY_FILE = ".aider.chat.history.md";
|
|
17473
17765
|
function resolveHistoryDir4(cwd) {
|
|
17474
|
-
const candidate =
|
|
17475
|
-
return
|
|
17766
|
+
const candidate = path32.join(cwd, AIDER_HISTORY_FILE);
|
|
17767
|
+
return fs27.existsSync(candidate) ? cwd : null;
|
|
17476
17768
|
}
|
|
17477
17769
|
function parseHistoryFile4(_filePath) {
|
|
17478
17770
|
return [];
|
|
@@ -17485,10 +17777,10 @@ function getCurrentUsage4(_historyDir) {
|
|
|
17485
17777
|
var import_node_child_process12 = require("child_process");
|
|
17486
17778
|
|
|
17487
17779
|
// src/agents/aider/local-token.ts
|
|
17488
|
-
var
|
|
17489
|
-
var
|
|
17490
|
-
var
|
|
17491
|
-
var AIDER_CONF_FILE =
|
|
17780
|
+
var fs28 = __toESM(require("fs"));
|
|
17781
|
+
var os25 = __toESM(require("os"));
|
|
17782
|
+
var path33 = __toESM(require("path"));
|
|
17783
|
+
var AIDER_CONF_FILE = path33.join(os25.homedir(), ".aider.conf.yml");
|
|
17492
17784
|
var API_KEY_ENV_VARS = [
|
|
17493
17785
|
"ANTHROPIC_API_KEY",
|
|
17494
17786
|
"OPENAI_API_KEY",
|
|
@@ -17503,8 +17795,8 @@ async function extractLocalAiderToken() {
|
|
|
17503
17795
|
return { method: "api_key", credential: value.trim(), source: "flat-file" };
|
|
17504
17796
|
}
|
|
17505
17797
|
}
|
|
17506
|
-
if (
|
|
17507
|
-
const conf =
|
|
17798
|
+
if (fs28.existsSync(AIDER_CONF_FILE)) {
|
|
17799
|
+
const conf = fs28.readFileSync(AIDER_CONF_FILE, "utf8");
|
|
17508
17800
|
const match = conf.match(/^api-key:\s*['"]?([^'"\n]+)['"]?\s*$/m);
|
|
17509
17801
|
if (match) {
|
|
17510
17802
|
return { method: "api_key", credential: match[1].trim(), source: "flat-file" };
|
|
@@ -17880,19 +18172,19 @@ var import_node_crypto6 = require("crypto");
|
|
|
17880
18172
|
var import_node_child_process13 = require("child_process");
|
|
17881
18173
|
|
|
17882
18174
|
// src/agents/gemini/local-token.ts
|
|
17883
|
-
var
|
|
17884
|
-
var
|
|
17885
|
-
var
|
|
18175
|
+
var fs30 = __toESM(require("fs"));
|
|
18176
|
+
var os27 = __toESM(require("os"));
|
|
18177
|
+
var path35 = __toESM(require("path"));
|
|
17886
18178
|
function geminiCredentialsPath() {
|
|
17887
|
-
return
|
|
18179
|
+
return path35.join(os27.homedir(), ".gemini", "oauth_creds.json");
|
|
17888
18180
|
}
|
|
17889
18181
|
function geminiCredentialsPaths() {
|
|
17890
18182
|
return [geminiCredentialsPath()];
|
|
17891
18183
|
}
|
|
17892
18184
|
async function extractLocalGeminiToken() {
|
|
17893
18185
|
const file = geminiCredentialsPath();
|
|
17894
|
-
if (!
|
|
17895
|
-
const credential =
|
|
18186
|
+
if (!fs30.existsSync(file)) return null;
|
|
18187
|
+
const credential = fs30.readFileSync(file, "utf8").trim();
|
|
17896
18188
|
if (credential.length === 0) return null;
|
|
17897
18189
|
return { method: "oauth", credential, source: "flat-file" };
|
|
17898
18190
|
}
|
|
@@ -17948,20 +18240,20 @@ function geminiLoginLauncher() {
|
|
|
17948
18240
|
}
|
|
17949
18241
|
|
|
17950
18242
|
// src/agents/gemini/history.ts
|
|
17951
|
-
var
|
|
17952
|
-
var
|
|
17953
|
-
var
|
|
17954
|
-
var GEMINI_ROOT =
|
|
18243
|
+
var fs31 = __toESM(require("fs"));
|
|
18244
|
+
var os28 = __toESM(require("os"));
|
|
18245
|
+
var path36 = __toESM(require("path"));
|
|
18246
|
+
var GEMINI_ROOT = path36.join(os28.homedir(), ".gemini");
|
|
17955
18247
|
function projectNameForCwd(cwd, root) {
|
|
17956
18248
|
try {
|
|
17957
18249
|
const parsed = JSON.parse(
|
|
17958
|
-
|
|
18250
|
+
fs31.readFileSync(path36.join(root, "projects.json"), "utf8")
|
|
17959
18251
|
);
|
|
17960
18252
|
const map = parsed.projects;
|
|
17961
18253
|
if (map && typeof map === "object") {
|
|
17962
18254
|
if (typeof map[cwd] === "string") return map[cwd];
|
|
17963
18255
|
try {
|
|
17964
|
-
const rp =
|
|
18256
|
+
const rp = fs31.realpathSync(cwd);
|
|
17965
18257
|
if (typeof map[rp] === "string") return map[rp];
|
|
17966
18258
|
} catch {
|
|
17967
18259
|
}
|
|
@@ -17970,7 +18262,7 @@ function projectNameForCwd(cwd, root) {
|
|
|
17970
18262
|
} catch (err) {
|
|
17971
18263
|
log.debug("gemini", `projects.json unreadable at ${root} \u2014 using basename fallback`, err);
|
|
17972
18264
|
}
|
|
17973
|
-
return
|
|
18265
|
+
return path36.basename(cwd) || null;
|
|
17974
18266
|
}
|
|
17975
18267
|
function resolveHistoryDir5(cwd, root = GEMINI_ROOT) {
|
|
17976
18268
|
const name = projectNameForCwd(cwd, root);
|
|
@@ -17978,8 +18270,8 @@ function resolveHistoryDir5(cwd, root = GEMINI_ROOT) {
|
|
|
17978
18270
|
log.warn("gemini", `resolveHistoryDir \u2014 could not derive a project name for cwd=${cwd}`);
|
|
17979
18271
|
return null;
|
|
17980
18272
|
}
|
|
17981
|
-
const dir =
|
|
17982
|
-
if (!
|
|
18273
|
+
const dir = path36.join(root, "tmp", name, "chats");
|
|
18274
|
+
if (!fs31.existsSync(dir)) {
|
|
17983
18275
|
log.debug("gemini", `resolveHistoryDir \u2014 chats dir not present yet: ${dir} (project=${name})`);
|
|
17984
18276
|
return null;
|
|
17985
18277
|
}
|
|
@@ -17991,7 +18283,7 @@ function resolveHistoryFile4(cwd, sessionId, root = GEMINI_ROOT) {
|
|
|
17991
18283
|
if (!dir) return null;
|
|
17992
18284
|
let files;
|
|
17993
18285
|
try {
|
|
17994
|
-
files =
|
|
18286
|
+
files = fs31.readdirSync(dir).filter((f) => f.startsWith("session-") && f.endsWith(".jsonl"));
|
|
17995
18287
|
} catch (err) {
|
|
17996
18288
|
log.warn("gemini", `resolveHistoryFile \u2014 cannot read chats dir ${dir} (id8=${id8})`, err);
|
|
17997
18289
|
return null;
|
|
@@ -18003,12 +18295,12 @@ function resolveHistoryFile4(cwd, sessionId, root = GEMINI_ROOT) {
|
|
|
18003
18295
|
const byName = files.find((f) => id8.length > 0 && f.includes(id8));
|
|
18004
18296
|
if (byName) {
|
|
18005
18297
|
log.info("gemini", `resolveHistoryFile \u2014 matched by filename id8=${id8}: ${byName}`);
|
|
18006
|
-
return
|
|
18298
|
+
return path36.join(dir, byName);
|
|
18007
18299
|
}
|
|
18008
18300
|
for (const f of files) {
|
|
18009
|
-
const full =
|
|
18301
|
+
const full = path36.join(dir, f);
|
|
18010
18302
|
try {
|
|
18011
|
-
const firstLine =
|
|
18303
|
+
const firstLine = fs31.readFileSync(full, "utf8").split("\n", 1)[0] ?? "";
|
|
18012
18304
|
const hdr = JSON.parse(firstLine);
|
|
18013
18305
|
if (hdr.sessionId === sessionId) {
|
|
18014
18306
|
log.info("gemini", `resolveHistoryFile \u2014 matched by header sessionId: ${f}`);
|
|
@@ -18021,7 +18313,7 @@ function resolveHistoryFile4(cwd, sessionId, root = GEMINI_ROOT) {
|
|
|
18021
18313
|
let newest = null;
|
|
18022
18314
|
for (const f of files) {
|
|
18023
18315
|
try {
|
|
18024
|
-
const mtime =
|
|
18316
|
+
const mtime = fs31.statSync(path36.join(dir, f)).mtimeMs;
|
|
18025
18317
|
if (!newest || mtime > newest.mtime) newest = { file: f, mtime };
|
|
18026
18318
|
} catch {
|
|
18027
18319
|
}
|
|
@@ -18030,7 +18322,7 @@ function resolveHistoryFile4(cwd, sessionId, root = GEMINI_ROOT) {
|
|
|
18030
18322
|
"gemini",
|
|
18031
18323
|
`resolveHistoryFile \u2014 no id8=${id8} match among ${files.length} file(s) in ${dir}; falling back to newest=${newest?.file ?? "none"}`
|
|
18032
18324
|
);
|
|
18033
|
-
return newest ?
|
|
18325
|
+
return newest ? path36.join(dir, newest.file) : null;
|
|
18034
18326
|
}
|
|
18035
18327
|
function extractGeminiText(content) {
|
|
18036
18328
|
const fromParts = (arr) => Array.isArray(arr) ? arr.map((p2) => {
|
|
@@ -18058,7 +18350,7 @@ function isSyntheticGeminiTurn(text) {
|
|
|
18058
18350
|
function parseHistoryFile5(filePath) {
|
|
18059
18351
|
let raw;
|
|
18060
18352
|
try {
|
|
18061
|
-
raw =
|
|
18353
|
+
raw = fs31.readFileSync(filePath, "utf8");
|
|
18062
18354
|
} catch (err) {
|
|
18063
18355
|
log.warn("gemini", `parseHistoryFile \u2014 cannot read ${filePath}`, err);
|
|
18064
18356
|
return [];
|
|
@@ -18099,7 +18391,7 @@ function parseHistoryFile5(filePath) {
|
|
|
18099
18391
|
}
|
|
18100
18392
|
log.trace(
|
|
18101
18393
|
"gemini",
|
|
18102
|
-
`parseHistoryFile \u2014 ${out2.length} turn(s) from ${
|
|
18394
|
+
`parseHistoryFile \u2014 ${out2.length} turn(s) from ${path36.basename(filePath)}` + (malformed > 0 ? ` (${malformed} malformed line(s) skipped)` : "")
|
|
18103
18395
|
);
|
|
18104
18396
|
return out2;
|
|
18105
18397
|
}
|
|
@@ -18243,42 +18535,42 @@ var import_node_os3 = require("os");
|
|
|
18243
18535
|
var import_node_path4 = require("path");
|
|
18244
18536
|
|
|
18245
18537
|
// src/agents/kimi/history.ts
|
|
18246
|
-
var
|
|
18247
|
-
var
|
|
18248
|
-
var
|
|
18538
|
+
var fs32 = __toESM(require("fs"));
|
|
18539
|
+
var os29 = __toESM(require("os"));
|
|
18540
|
+
var path37 = __toESM(require("path"));
|
|
18249
18541
|
var import_node_crypto7 = require("crypto");
|
|
18250
18542
|
function kimiHome() {
|
|
18251
|
-
return process.env.KIMI_CODE_HOME ||
|
|
18543
|
+
return process.env.KIMI_CODE_HOME || path37.join(os29.homedir(), ".kimi-code");
|
|
18252
18544
|
}
|
|
18253
18545
|
function workDirKey(cwd) {
|
|
18254
18546
|
const hash = (0, import_node_crypto7.createHash)("sha256").update(cwd).digest("hex").slice(0, 12);
|
|
18255
|
-
return `wd_${
|
|
18547
|
+
return `wd_${path37.basename(cwd)}_${hash}`;
|
|
18256
18548
|
}
|
|
18257
18549
|
function resolveHistoryDir6(cwd) {
|
|
18258
|
-
const dir =
|
|
18259
|
-
if (!
|
|
18550
|
+
const dir = path37.join(kimiHome(), "sessions", workDirKey(cwd));
|
|
18551
|
+
if (!fs32.existsSync(dir)) {
|
|
18260
18552
|
log.debug("kimi", `resolveHistoryDir \u2014 session bucket not present yet: ${dir}`);
|
|
18261
18553
|
return null;
|
|
18262
18554
|
}
|
|
18263
18555
|
return dir;
|
|
18264
18556
|
}
|
|
18265
|
-
var WIRE_REL =
|
|
18557
|
+
var WIRE_REL = path37.join("agents", "main", "wire.jsonl");
|
|
18266
18558
|
function resolveHistoryFile5(cwd, sessionId) {
|
|
18267
18559
|
const fromIndex = sessionDirFromIndex(sessionId);
|
|
18268
18560
|
if (fromIndex) {
|
|
18269
|
-
const p2 =
|
|
18270
|
-
if (
|
|
18561
|
+
const p2 = path37.join(fromIndex, WIRE_REL);
|
|
18562
|
+
if (fs32.existsSync(p2)) return p2;
|
|
18271
18563
|
}
|
|
18272
|
-
const bucket2 =
|
|
18273
|
-
const computed =
|
|
18274
|
-
if (
|
|
18564
|
+
const bucket2 = path37.join(kimiHome(), "sessions", workDirKey(cwd));
|
|
18565
|
+
const computed = path37.join(bucket2, sessionId, WIRE_REL);
|
|
18566
|
+
if (fs32.existsSync(computed)) return computed;
|
|
18275
18567
|
const scanned = scanBucketsForSession(sessionId);
|
|
18276
18568
|
if (scanned) return scanned;
|
|
18277
18569
|
return null;
|
|
18278
18570
|
}
|
|
18279
18571
|
function sessionDirFromIndex(sessionId) {
|
|
18280
18572
|
try {
|
|
18281
|
-
const raw =
|
|
18573
|
+
const raw = fs32.readFileSync(path37.join(kimiHome(), "session_index.jsonl"), "utf8");
|
|
18282
18574
|
for (const line of raw.split("\n")) {
|
|
18283
18575
|
if (!line.includes(sessionId)) continue;
|
|
18284
18576
|
try {
|
|
@@ -18294,22 +18586,22 @@ function sessionDirFromIndex(sessionId) {
|
|
|
18294
18586
|
return null;
|
|
18295
18587
|
}
|
|
18296
18588
|
function scanBucketsForSession(sessionId) {
|
|
18297
|
-
const sessionsRoot =
|
|
18589
|
+
const sessionsRoot = path37.join(kimiHome(), "sessions");
|
|
18298
18590
|
let buckets;
|
|
18299
18591
|
try {
|
|
18300
|
-
buckets =
|
|
18592
|
+
buckets = fs32.readdirSync(sessionsRoot, { withFileTypes: true });
|
|
18301
18593
|
} catch {
|
|
18302
18594
|
return null;
|
|
18303
18595
|
}
|
|
18304
18596
|
for (const b of buckets) {
|
|
18305
18597
|
if (!b.isDirectory()) continue;
|
|
18306
|
-
const candidate =
|
|
18307
|
-
if (
|
|
18598
|
+
const candidate = path37.join(sessionsRoot, b.name, sessionId, WIRE_REL);
|
|
18599
|
+
if (fs32.existsSync(candidate)) return candidate;
|
|
18308
18600
|
}
|
|
18309
18601
|
return null;
|
|
18310
18602
|
}
|
|
18311
18603
|
async function discoverSessionId2(cwd, opts) {
|
|
18312
|
-
const bucket2 =
|
|
18604
|
+
const bucket2 = path37.join(kimiHome(), "sessions", workDirKey(cwd));
|
|
18313
18605
|
const floor = opts.sinceMs - 2e3;
|
|
18314
18606
|
const deadline = Date.now() + (opts.timeoutMs ?? 15e3);
|
|
18315
18607
|
for (; ; ) {
|
|
@@ -18322,7 +18614,7 @@ async function discoverSessionId2(cwd, opts) {
|
|
|
18322
18614
|
function newestSessionSince(bucket2, floorMs) {
|
|
18323
18615
|
let entries;
|
|
18324
18616
|
try {
|
|
18325
|
-
entries =
|
|
18617
|
+
entries = fs32.readdirSync(bucket2, { withFileTypes: true });
|
|
18326
18618
|
} catch {
|
|
18327
18619
|
return null;
|
|
18328
18620
|
}
|
|
@@ -18332,7 +18624,7 @@ function newestSessionSince(bucket2, floorMs) {
|
|
|
18332
18624
|
if (!e.isDirectory() || !e.name.startsWith("session_")) continue;
|
|
18333
18625
|
let mtime;
|
|
18334
18626
|
try {
|
|
18335
|
-
mtime =
|
|
18627
|
+
mtime = fs32.statSync(path37.join(bucket2, e.name)).mtimeMs;
|
|
18336
18628
|
} catch {
|
|
18337
18629
|
continue;
|
|
18338
18630
|
}
|
|
@@ -18353,7 +18645,7 @@ function joinTextParts(parts) {
|
|
|
18353
18645
|
function parseHistoryFile6(filePath) {
|
|
18354
18646
|
let raw;
|
|
18355
18647
|
try {
|
|
18356
|
-
raw =
|
|
18648
|
+
raw = fs32.readFileSync(filePath, "utf8");
|
|
18357
18649
|
} catch {
|
|
18358
18650
|
return [];
|
|
18359
18651
|
}
|
|
@@ -18731,7 +19023,7 @@ function parseLinkArgs(args2) {
|
|
|
18731
19023
|
if (apiKeyFileArg) {
|
|
18732
19024
|
const filePath = apiKeyFileArg.slice("--api-key-file=".length);
|
|
18733
19025
|
try {
|
|
18734
|
-
apiKey =
|
|
19026
|
+
apiKey = fs33.readFileSync(path38.resolve(filePath), "utf8").trim();
|
|
18735
19027
|
} catch (err) {
|
|
18736
19028
|
throw new Error(`Could not read --api-key-file ${filePath}: ${err.message}`);
|
|
18737
19029
|
}
|
|
@@ -18858,7 +19150,7 @@ async function link(args2 = []) {
|
|
|
18858
19150
|
return;
|
|
18859
19151
|
}
|
|
18860
19152
|
if (parsed.tokenFile) {
|
|
18861
|
-
const credential =
|
|
19153
|
+
const credential = fs33.readFileSync(path38.resolve(parsed.tokenFile), "utf8").trim();
|
|
18862
19154
|
if (!credential) {
|
|
18863
19155
|
showError(`--token-file ${parsed.tokenFile} is empty.`);
|
|
18864
19156
|
process.exit(1);
|
|
@@ -19077,13 +19369,13 @@ async function linkDryRunPreflight(ctx) {
|
|
|
19077
19369
|
// src/agents/coderabbit/configure.ts
|
|
19078
19370
|
var import_node_child_process17 = require("child_process");
|
|
19079
19371
|
var import_node_fs6 = require("fs");
|
|
19080
|
-
var
|
|
19372
|
+
var path40 = __toESM(require("path"));
|
|
19081
19373
|
|
|
19082
19374
|
// src/agents/coderabbit/oauth.ts
|
|
19083
19375
|
var import_node_child_process16 = require("child_process");
|
|
19084
|
-
var
|
|
19085
|
-
var
|
|
19086
|
-
var
|
|
19376
|
+
var fs34 = __toESM(require("fs"));
|
|
19377
|
+
var os30 = __toESM(require("os"));
|
|
19378
|
+
var path39 = __toESM(require("path"));
|
|
19087
19379
|
function parseCoderabbitAuthEvent(line) {
|
|
19088
19380
|
const l = line.replace(/\x1b\[[0-9;?]*[A-Za-z]/g, "").trim();
|
|
19089
19381
|
if (!l || l[0] !== "{") return null;
|
|
@@ -19132,8 +19424,8 @@ function resolvePython() {
|
|
|
19132
19424
|
function spawnCoderabbitLoginProc(cmd, args2) {
|
|
19133
19425
|
const python = resolvePython();
|
|
19134
19426
|
if (python) {
|
|
19135
|
-
const helper =
|
|
19136
|
-
|
|
19427
|
+
const helper = path39.join(os30.tmpdir(), "codeam-cr-pty.py");
|
|
19428
|
+
fs34.writeFileSync(helper, PYTHON_PTY_HELPER, { mode: 420 });
|
|
19137
19429
|
return (0, import_node_child_process16.spawn)(python, [helper, cmd, ...args2], {
|
|
19138
19430
|
stdio: ["pipe", "pipe", "pipe"],
|
|
19139
19431
|
env: { ...process.env, TERM: "xterm-256color", COLUMNS: "220", LINES: "50" },
|
|
@@ -19244,7 +19536,7 @@ function runCoderabbitOAuthLogin(deps) {
|
|
|
19244
19536
|
});
|
|
19245
19537
|
}
|
|
19246
19538
|
function coderabbitDir(home) {
|
|
19247
|
-
return
|
|
19539
|
+
return path39.join(home ?? os30.homedir(), ".coderabbit");
|
|
19248
19540
|
}
|
|
19249
19541
|
var NON_CREDENTIAL = /* @__PURE__ */ new Set(["doctor.json", "machine-id"]);
|
|
19250
19542
|
function snapshotCredentialDir(home) {
|
|
@@ -19252,14 +19544,14 @@ function snapshotCredentialDir(home) {
|
|
|
19252
19544
|
const snap = {};
|
|
19253
19545
|
let entries;
|
|
19254
19546
|
try {
|
|
19255
|
-
entries =
|
|
19547
|
+
entries = fs34.readdirSync(dir, { withFileTypes: true });
|
|
19256
19548
|
} catch {
|
|
19257
19549
|
return snap;
|
|
19258
19550
|
}
|
|
19259
19551
|
for (const e of entries) {
|
|
19260
19552
|
if (!e.isFile() || NON_CREDENTIAL.has(e.name)) continue;
|
|
19261
19553
|
try {
|
|
19262
|
-
const st3 =
|
|
19554
|
+
const st3 = fs34.statSync(path39.join(dir, e.name));
|
|
19263
19555
|
snap[e.name] = `${st3.mtimeMs}:${st3.size}`;
|
|
19264
19556
|
} catch {
|
|
19265
19557
|
}
|
|
@@ -19277,7 +19569,7 @@ function diffCapturedCredential(before, home) {
|
|
|
19277
19569
|
}
|
|
19278
19570
|
if (!best) return null;
|
|
19279
19571
|
try {
|
|
19280
|
-
return { file: best.file, contents:
|
|
19572
|
+
return { file: best.file, contents: fs34.readFileSync(path39.join(dir, best.file), "utf8") };
|
|
19281
19573
|
} catch {
|
|
19282
19574
|
return null;
|
|
19283
19575
|
}
|
|
@@ -19354,7 +19646,7 @@ function collectChangedFiles(cwd) {
|
|
|
19354
19646
|
return [...byPath.values()];
|
|
19355
19647
|
}
|
|
19356
19648
|
function restoreCoderabbitOauthBlob(os67, value) {
|
|
19357
|
-
const dir =
|
|
19649
|
+
const dir = path40.join(os67.homeDir(), ".coderabbit");
|
|
19358
19650
|
(0, import_node_fs6.mkdirSync)(dir, { recursive: true });
|
|
19359
19651
|
let file = "auth.json";
|
|
19360
19652
|
let contents = value.trim();
|
|
@@ -19362,13 +19654,13 @@ function restoreCoderabbitOauthBlob(os67, value) {
|
|
|
19362
19654
|
try {
|
|
19363
19655
|
const parsed = JSON.parse(contents);
|
|
19364
19656
|
if (typeof parsed.file === "string" && typeof parsed.contents === "string") {
|
|
19365
|
-
file =
|
|
19657
|
+
file = path40.basename(parsed.file);
|
|
19366
19658
|
contents = parsed.contents;
|
|
19367
19659
|
}
|
|
19368
19660
|
} catch {
|
|
19369
19661
|
}
|
|
19370
19662
|
}
|
|
19371
|
-
(0, import_node_fs6.writeFileSync)(
|
|
19663
|
+
(0, import_node_fs6.writeFileSync)(path40.join(dir, file), contents, { mode: 384 });
|
|
19372
19664
|
}
|
|
19373
19665
|
function installFailureMessage(result) {
|
|
19374
19666
|
return result.error ?? "CodeRabbit CLI could not be installed";
|
|
@@ -19384,10 +19676,10 @@ async function configureCoderabbit(input, deps = {}) {
|
|
|
19384
19676
|
const home = os67.homeDir();
|
|
19385
19677
|
os67.augmentPath(
|
|
19386
19678
|
os67.id === "win32" ? [
|
|
19387
|
-
|
|
19388
|
-
|
|
19389
|
-
|
|
19390
|
-
] : [
|
|
19679
|
+
path40.join(home, ".local", "bin"),
|
|
19680
|
+
path40.join(process.env.APPDATA ?? path40.join(home, "AppData", "Roaming"), "npm"),
|
|
19681
|
+
path40.join(home, "scoop", "shims")
|
|
19682
|
+
] : [path40.join(home, ".local", "bin"), "/opt/homebrew/bin", "/usr/local/bin"]
|
|
19391
19683
|
);
|
|
19392
19684
|
const installed2 = os67.findInPath("coderabbit") !== null;
|
|
19393
19685
|
const base = () => ({
|
|
@@ -19696,9 +19988,9 @@ function defaultRunGh(args2) {
|
|
|
19696
19988
|
|
|
19697
19989
|
// src/commands/host-agent.ts
|
|
19698
19990
|
var import_node_child_process25 = require("child_process");
|
|
19699
|
-
var
|
|
19700
|
-
var
|
|
19701
|
-
var
|
|
19991
|
+
var os43 = __toESM(require("os"));
|
|
19992
|
+
var fs47 = __toESM(require("fs"));
|
|
19993
|
+
var path51 = __toESM(require("path"));
|
|
19702
19994
|
|
|
19703
19995
|
// src/integrations/manifest.ts
|
|
19704
19996
|
var import_node_fs8 = __toESM(require("fs"));
|
|
@@ -19822,12 +20114,12 @@ function persistOrClearSkillsFromPayload(skills) {
|
|
|
19822
20114
|
|
|
19823
20115
|
// src/commands/host/agent-install.ts
|
|
19824
20116
|
var import_child_process14 = require("child_process");
|
|
19825
|
-
var
|
|
20117
|
+
var os34 = __toESM(require("os"));
|
|
19826
20118
|
function runAgentInstallScript(script, opts = {}) {
|
|
19827
20119
|
const timeoutMs = opts.timeoutMs ?? 18e4;
|
|
19828
20120
|
const scope = opts.logScope ?? "agent-install";
|
|
19829
20121
|
return new Promise((resolve9) => {
|
|
19830
|
-
const home = process.env.HOME ||
|
|
20122
|
+
const home = process.env.HOME || os34.homedir();
|
|
19831
20123
|
const child = (0, import_child_process14.spawn)("sh", ["-c", script], {
|
|
19832
20124
|
env: { ...process.env, HOME: home },
|
|
19833
20125
|
stdio: ["ignore", "pipe", "pipe"]
|
|
@@ -19893,14 +20185,14 @@ function describeReason(reason) {
|
|
|
19893
20185
|
}
|
|
19894
20186
|
|
|
19895
20187
|
// src/commands/host/host-client.ts
|
|
19896
|
-
var
|
|
19897
|
-
var
|
|
19898
|
-
var
|
|
20188
|
+
var fs38 = __toESM(require("fs"));
|
|
20189
|
+
var os35 = __toESM(require("os"));
|
|
20190
|
+
var path43 = __toESM(require("path"));
|
|
19899
20191
|
var import_node_crypto9 = require("crypto");
|
|
19900
20192
|
function sampleCpuTimes() {
|
|
19901
20193
|
let idle = 0;
|
|
19902
20194
|
let total = 0;
|
|
19903
|
-
for (const cpu of
|
|
20195
|
+
for (const cpu of os35.cpus()) {
|
|
19904
20196
|
const t2 = cpu.times;
|
|
19905
20197
|
idle += t2.idle;
|
|
19906
20198
|
total += t2.user + t2.nice + t2.sys + t2.idle + t2.irq;
|
|
@@ -19919,8 +20211,8 @@ var MetricsCollector = class {
|
|
|
19919
20211
|
const prev = this.prevCpu;
|
|
19920
20212
|
this.prevCpu = current2;
|
|
19921
20213
|
if (!prev) {
|
|
19922
|
-
const cores =
|
|
19923
|
-
const proxy =
|
|
20214
|
+
const cores = os35.cpus().length || 1;
|
|
20215
|
+
const proxy = os35.loadavg()[0] / cores * 100;
|
|
19924
20216
|
return Math.min(100, Math.max(0, Math.round(proxy)));
|
|
19925
20217
|
}
|
|
19926
20218
|
const idleDelta = current2.idle - prev.idle;
|
|
@@ -19933,8 +20225,8 @@ var MetricsCollector = class {
|
|
|
19933
20225
|
collect() {
|
|
19934
20226
|
return {
|
|
19935
20227
|
cpuPct: this.cpuPct(),
|
|
19936
|
-
ramUsedMb: Math.round((
|
|
19937
|
-
ramTotalMb: Math.round(
|
|
20228
|
+
ramUsedMb: Math.round((os35.totalmem() - os35.freemem()) / 1048576),
|
|
20229
|
+
ramTotalMb: Math.round(os35.totalmem() / 1048576),
|
|
19938
20230
|
latencyMs: this.lastLatencyMs
|
|
19939
20231
|
};
|
|
19940
20232
|
}
|
|
@@ -19943,19 +20235,19 @@ function apiBase() {
|
|
|
19943
20235
|
return process.env.CODEAM_API_URL ?? resolveApiBaseUrl();
|
|
19944
20236
|
}
|
|
19945
20237
|
function hostIdentityPath() {
|
|
19946
|
-
return
|
|
20238
|
+
return path43.join(os35.homedir(), ".codeam", "host-agent.json");
|
|
19947
20239
|
}
|
|
19948
20240
|
function collectOsInfo() {
|
|
19949
20241
|
return {
|
|
19950
|
-
distro:
|
|
19951
|
-
arch:
|
|
19952
|
-
kernel:
|
|
20242
|
+
distro: os35.platform(),
|
|
20243
|
+
arch: os35.arch(),
|
|
20244
|
+
kernel: os35.release(),
|
|
19953
20245
|
nodeVersion: process.versions.node
|
|
19954
20246
|
};
|
|
19955
20247
|
}
|
|
19956
20248
|
function loadHostIdentity() {
|
|
19957
20249
|
try {
|
|
19958
|
-
const raw =
|
|
20250
|
+
const raw = fs38.readFileSync(hostIdentityPath(), "utf8");
|
|
19959
20251
|
const parsed = JSON.parse(raw);
|
|
19960
20252
|
if (typeof parsed === "object" && parsed !== null && typeof parsed.hostId === "string" && typeof parsed.hostToken === "string" && typeof parsed.controlPluginId === "string") {
|
|
19961
20253
|
const p2 = parsed;
|
|
@@ -19974,8 +20266,8 @@ function loadHostIdentity() {
|
|
|
19974
20266
|
}
|
|
19975
20267
|
function saveHostIdentity(identity) {
|
|
19976
20268
|
const file = hostIdentityPath();
|
|
19977
|
-
|
|
19978
|
-
|
|
20269
|
+
fs38.mkdirSync(path43.dirname(file), { recursive: true, mode: 448 });
|
|
20270
|
+
fs38.writeFileSync(file, JSON.stringify(identity, null, 2), {
|
|
19979
20271
|
encoding: "utf8",
|
|
19980
20272
|
mode: 384
|
|
19981
20273
|
});
|
|
@@ -20020,7 +20312,7 @@ function isTerminalEnrollError(err) {
|
|
|
20020
20312
|
}
|
|
20021
20313
|
function deleteHostIdentity() {
|
|
20022
20314
|
try {
|
|
20023
|
-
|
|
20315
|
+
fs38.rmSync(hostIdentityPath(), { force: true });
|
|
20024
20316
|
} catch {
|
|
20025
20317
|
}
|
|
20026
20318
|
}
|
|
@@ -20044,7 +20336,7 @@ async function postJson(pathname, body) {
|
|
|
20044
20336
|
function resolveHostLabel(label) {
|
|
20045
20337
|
const explicit = label?.trim();
|
|
20046
20338
|
const envLabel = process.env.CODEAM_HOST_LABEL?.trim();
|
|
20047
|
-
const resolved = explicit || envLabel ||
|
|
20339
|
+
const resolved = explicit || envLabel || os35.hostname();
|
|
20048
20340
|
return resolved.slice(0, 80);
|
|
20049
20341
|
}
|
|
20050
20342
|
async function redeemEnrollToken(token, label) {
|
|
@@ -20155,17 +20447,17 @@ async function reportDeployProgress(auth, deployId, step, message, sessionId) {
|
|
|
20155
20447
|
}
|
|
20156
20448
|
|
|
20157
20449
|
// src/commands/host/workspace.ts
|
|
20158
|
-
var
|
|
20159
|
-
var
|
|
20160
|
-
var
|
|
20450
|
+
var fs39 = __toESM(require("fs"));
|
|
20451
|
+
var os36 = __toESM(require("os"));
|
|
20452
|
+
var path44 = __toESM(require("path"));
|
|
20161
20453
|
var import_node_child_process20 = require("child_process");
|
|
20162
20454
|
var import_node_util4 = require("util");
|
|
20163
20455
|
var execFileP4 = (0, import_node_util4.promisify)(import_node_child_process20.execFile);
|
|
20164
20456
|
function isAbsolutePathTarget(target) {
|
|
20165
|
-
return
|
|
20457
|
+
return path44.isAbsolute(target);
|
|
20166
20458
|
}
|
|
20167
20459
|
function selfHostedWorkspaceRoot() {
|
|
20168
|
-
return
|
|
20460
|
+
return path44.join(os36.homedir(), ".codeam", "self-hosted");
|
|
20169
20461
|
}
|
|
20170
20462
|
function nonInteractiveGitEnv() {
|
|
20171
20463
|
return {
|
|
@@ -20235,15 +20527,15 @@ async function configureGitCredentials(dest, repoRef, cloneToken, provider = "gi
|
|
|
20235
20527
|
const isGitlab = provider === "gitlab";
|
|
20236
20528
|
if (isGitlab ? !gitlabProjectPath(repoRef.trim()) : !githubOwnerRepo(repoRef.trim())) return;
|
|
20237
20529
|
if (!cloneToken) return;
|
|
20238
|
-
const credFile =
|
|
20530
|
+
const credFile = path44.join(dest, ".git", "codeam-credentials");
|
|
20239
20531
|
const credLine = isGitlab ? `https://oauth2:${cloneToken}@gitlab.com
|
|
20240
20532
|
` : `https://x-access-token:${cloneToken}@github.com
|
|
20241
20533
|
`;
|
|
20242
|
-
|
|
20534
|
+
fs39.writeFileSync(credFile, credLine, { mode: 384 });
|
|
20243
20535
|
restrictToOwner(credFile);
|
|
20244
20536
|
const env = nonInteractiveGitEnv();
|
|
20245
20537
|
const git2 = (args2) => execFileP4("git", ["-C", dest, ...args2], { timeout: 3e4, env });
|
|
20246
|
-
const credFilePosix = credFile.split(
|
|
20538
|
+
const credFilePosix = credFile.split(path44.sep).join("/");
|
|
20247
20539
|
await git2(["config", "--local", "--replace-all", "credential.helper", ""]).catch(() => {
|
|
20248
20540
|
});
|
|
20249
20541
|
await git2([
|
|
@@ -20276,17 +20568,17 @@ function maskToken(text, cloneToken) {
|
|
|
20276
20568
|
}
|
|
20277
20569
|
async function prepareWorkspace(repoOrPath, deployId, cloneToken, provider = "github", branch) {
|
|
20278
20570
|
if (isAbsolutePathTarget(repoOrPath)) {
|
|
20279
|
-
if (!
|
|
20571
|
+
if (!fs39.existsSync(repoOrPath)) {
|
|
20280
20572
|
throw new Error(`deploy target path does not exist: ${repoOrPath}`);
|
|
20281
20573
|
}
|
|
20282
20574
|
return repoOrPath;
|
|
20283
20575
|
}
|
|
20284
|
-
const dest =
|
|
20285
|
-
if (
|
|
20576
|
+
const dest = path44.join(selfHostedWorkspaceRoot(), deployId);
|
|
20577
|
+
if (fs39.existsSync(path44.join(dest, ".git"))) {
|
|
20286
20578
|
if (cloneToken) await configureGitCredentials(dest, repoOrPath, cloneToken, provider);
|
|
20287
20579
|
return dest;
|
|
20288
20580
|
}
|
|
20289
|
-
|
|
20581
|
+
fs39.mkdirSync(selfHostedWorkspaceRoot(), { recursive: true, mode: 448 });
|
|
20290
20582
|
const cloneUrl = repoCloneUrl(repoOrPath, cloneToken, provider);
|
|
20291
20583
|
const cloneArgs = branch ? ["clone", "--depth", "1", "--branch", branch, cloneUrl, dest] : ["clone", "--depth", "1", cloneUrl, dest];
|
|
20292
20584
|
try {
|
|
@@ -20304,9 +20596,9 @@ async function prepareWorkspace(repoOrPath, deployId, cloneToken, provider = "gi
|
|
|
20304
20596
|
}
|
|
20305
20597
|
|
|
20306
20598
|
// src/commands/host/agent-provisioning.ts
|
|
20307
|
-
var
|
|
20308
|
-
var
|
|
20309
|
-
var
|
|
20599
|
+
var fs40 = __toESM(require("fs"));
|
|
20600
|
+
var os37 = __toESM(require("os"));
|
|
20601
|
+
var path45 = __toESM(require("path"));
|
|
20310
20602
|
var PUBLIC_TO_INTERNAL_AGENT = {
|
|
20311
20603
|
claude_code: "claude",
|
|
20312
20604
|
claude: "claude",
|
|
@@ -20323,22 +20615,22 @@ function toInternalAgentId(publicAgentId) {
|
|
|
20323
20615
|
return PUBLIC_TO_INTERNAL_AGENT[publicAgentId] ?? null;
|
|
20324
20616
|
}
|
|
20325
20617
|
function ensureDir(dir) {
|
|
20326
|
-
|
|
20618
|
+
fs40.mkdirSync(dir, { recursive: true, mode: 448 });
|
|
20327
20619
|
}
|
|
20328
20620
|
function writeFile0600(filePath, contents) {
|
|
20329
|
-
ensureDir(
|
|
20330
|
-
|
|
20621
|
+
ensureDir(path45.dirname(filePath));
|
|
20622
|
+
fs40.writeFileSync(filePath, contents, { encoding: "utf8", mode: 384 });
|
|
20331
20623
|
restrictToOwner(filePath);
|
|
20332
20624
|
}
|
|
20333
20625
|
function rmIfExists(filePath) {
|
|
20334
20626
|
try {
|
|
20335
|
-
|
|
20627
|
+
fs40.rmSync(filePath, { force: true });
|
|
20336
20628
|
} catch {
|
|
20337
20629
|
}
|
|
20338
20630
|
}
|
|
20339
20631
|
var claudeProvisioner = {
|
|
20340
20632
|
write(auth, home) {
|
|
20341
|
-
const credentialsJson =
|
|
20633
|
+
const credentialsJson = path45.join(home, ".claude", ".credentials.json");
|
|
20342
20634
|
if (auth.kind === "api_key") {
|
|
20343
20635
|
rmIfExists(credentialsJson);
|
|
20344
20636
|
return { ANTHROPIC_API_KEY: auth.value };
|
|
@@ -20350,8 +20642,8 @@ var claudeProvisioner = {
|
|
|
20350
20642
|
} else {
|
|
20351
20643
|
rmIfExists(credentialsJson);
|
|
20352
20644
|
}
|
|
20353
|
-
const claudeJson =
|
|
20354
|
-
if (!
|
|
20645
|
+
const claudeJson = path45.join(home, ".claude.json");
|
|
20646
|
+
if (!fs40.existsSync(claudeJson)) {
|
|
20355
20647
|
writeFile0600(
|
|
20356
20648
|
claudeJson,
|
|
20357
20649
|
JSON.stringify({ hasCompletedOnboarding: true, customApiKeyResponses: { approved: [] } })
|
|
@@ -20362,7 +20654,7 @@ var claudeProvisioner = {
|
|
|
20362
20654
|
};
|
|
20363
20655
|
var codexProvisioner = {
|
|
20364
20656
|
write(auth, home) {
|
|
20365
|
-
const authJson =
|
|
20657
|
+
const authJson = path45.join(home, ".codex", "auth.json");
|
|
20366
20658
|
if (auth.kind === "api_key") {
|
|
20367
20659
|
rmIfExists(authJson);
|
|
20368
20660
|
return { OPENAI_API_KEY: auth.value };
|
|
@@ -20373,8 +20665,8 @@ var codexProvisioner = {
|
|
|
20373
20665
|
};
|
|
20374
20666
|
var geminiProvisioner = {
|
|
20375
20667
|
write(auth, home) {
|
|
20376
|
-
const settingsJson =
|
|
20377
|
-
const oauthCreds =
|
|
20668
|
+
const settingsJson = path45.join(home, ".gemini", "settings.json");
|
|
20669
|
+
const oauthCreds = path45.join(home, ".gemini", "oauth_creds.json");
|
|
20378
20670
|
if (auth.kind === "api_key") {
|
|
20379
20671
|
rmIfExists(oauthCreds);
|
|
20380
20672
|
writeFile0600(settingsJson, '{"security":{"auth":{"selectedType":"gemini-api-key"}}}');
|
|
@@ -20387,7 +20679,7 @@ var geminiProvisioner = {
|
|
|
20387
20679
|
};
|
|
20388
20680
|
var cursorProvisioner = {
|
|
20389
20681
|
write(auth, home) {
|
|
20390
|
-
const authJson =
|
|
20682
|
+
const authJson = path45.join(home, ".config", "cursor", "auth.json");
|
|
20391
20683
|
if (auth.kind === "api_key") {
|
|
20392
20684
|
rmIfExists(authJson);
|
|
20393
20685
|
return { CURSOR_API_KEY: auth.value };
|
|
@@ -20429,22 +20721,22 @@ max_context_size = 262144
|
|
|
20429
20721
|
var kimiProvisioner = {
|
|
20430
20722
|
write(auth, home) {
|
|
20431
20723
|
const credentialsFiles = [
|
|
20432
|
-
|
|
20433
|
-
|
|
20724
|
+
path45.join(home, ".kimi", "credentials", "kimi-code.json"),
|
|
20725
|
+
path45.join(home, ".kimi-code", "credentials", "kimi-code.json")
|
|
20434
20726
|
];
|
|
20435
20727
|
if (auth.kind === "api_key") {
|
|
20436
20728
|
credentialsFiles.forEach(rmIfExists);
|
|
20437
20729
|
return { KIMI_API_KEY: auth.value };
|
|
20438
20730
|
}
|
|
20439
20731
|
credentialsFiles.forEach((f) => writeFile0600(f, auth.value));
|
|
20440
|
-
writeFile0600(
|
|
20732
|
+
writeFile0600(path45.join(home, ".kimi-code", "config.toml"), KIMI_MANAGED_CONFIG_TOML);
|
|
20441
20733
|
return {};
|
|
20442
20734
|
}
|
|
20443
20735
|
};
|
|
20444
20736
|
var coderabbitProvisioner = {
|
|
20445
20737
|
write(auth, home) {
|
|
20446
|
-
const dir =
|
|
20447
|
-
const authJson =
|
|
20738
|
+
const dir = path45.join(home, ".coderabbit");
|
|
20739
|
+
const authJson = path45.join(dir, "auth.json");
|
|
20448
20740
|
if (auth.kind === "api_key") {
|
|
20449
20741
|
rmIfExists(authJson);
|
|
20450
20742
|
return { CODERABBIT_API_KEY: auth.value };
|
|
@@ -20456,13 +20748,13 @@ var coderabbitProvisioner = {
|
|
|
20456
20748
|
try {
|
|
20457
20749
|
const parsed = JSON.parse(value);
|
|
20458
20750
|
if (typeof parsed.file === "string" && typeof parsed.contents === "string") {
|
|
20459
|
-
file =
|
|
20751
|
+
file = path45.basename(parsed.file);
|
|
20460
20752
|
contents = parsed.contents;
|
|
20461
20753
|
}
|
|
20462
20754
|
} catch {
|
|
20463
20755
|
}
|
|
20464
20756
|
}
|
|
20465
|
-
writeFile0600(
|
|
20757
|
+
writeFile0600(path45.join(dir, file), contents);
|
|
20466
20758
|
return {};
|
|
20467
20759
|
}
|
|
20468
20760
|
};
|
|
@@ -20490,7 +20782,7 @@ var UnsupportedAgentError = class extends Error {
|
|
|
20490
20782
|
this.agentId = agentId;
|
|
20491
20783
|
}
|
|
20492
20784
|
};
|
|
20493
|
-
function provisionAgentCredentials(publicAgentId, auth, homeDir2 =
|
|
20785
|
+
function provisionAgentCredentials(publicAgentId, auth, homeDir2 = os37.homedir()) {
|
|
20494
20786
|
const internal = toInternalAgentId(publicAgentId);
|
|
20495
20787
|
if (!internal) throw new UnsupportedAgentError(publicAgentId);
|
|
20496
20788
|
const provisioner = PROVISIONERS[internal];
|
|
@@ -20500,11 +20792,11 @@ function provisionAgentCredentials(publicAgentId, auth, homeDir2 = os36.homedir(
|
|
|
20500
20792
|
|
|
20501
20793
|
// src/commands/host/git-tooling.ts
|
|
20502
20794
|
var import_node_child_process21 = require("child_process");
|
|
20503
|
-
var
|
|
20504
|
-
var
|
|
20505
|
-
var
|
|
20795
|
+
var fs41 = __toESM(require("fs"));
|
|
20796
|
+
var os38 = __toESM(require("os"));
|
|
20797
|
+
var path46 = __toESM(require("path"));
|
|
20506
20798
|
function codeamBinDir() {
|
|
20507
|
-
return process.env.CODEAM_BIN_DIR ??
|
|
20799
|
+
return process.env.CODEAM_BIN_DIR ?? path46.join(os38.homedir(), ".codeam", "bin");
|
|
20508
20800
|
}
|
|
20509
20801
|
var FALLBACK_GH_VERSION = "2.62.0";
|
|
20510
20802
|
var RELEASE_API = "https://api.github.com/repos/cli/cli/releases/latest";
|
|
@@ -20536,7 +20828,7 @@ async function download(url2, dest) {
|
|
|
20536
20828
|
const res = await fetch(url2, { headers: { "User-Agent": "codeam-cli" } });
|
|
20537
20829
|
if (!res.ok || !res.body) return false;
|
|
20538
20830
|
const buf = Buffer.from(await res.arrayBuffer());
|
|
20539
|
-
|
|
20831
|
+
fs41.writeFileSync(dest, buf);
|
|
20540
20832
|
return true;
|
|
20541
20833
|
} catch {
|
|
20542
20834
|
return false;
|
|
@@ -20559,8 +20851,8 @@ async function ensureGhCli(runner, token, deps = {}) {
|
|
|
20559
20851
|
const version3 = await resolveVersionFn(token);
|
|
20560
20852
|
const asset = `gh_${version3}_${osToken}_${arch2}`;
|
|
20561
20853
|
const url2 = `https://github.com/cli/cli/releases/download/v${version3}/${asset}.${ext}`;
|
|
20562
|
-
const tmpRoot =
|
|
20563
|
-
const archive =
|
|
20854
|
+
const tmpRoot = fs41.mkdtempSync(path46.join(os38.tmpdir(), "codeam-gh-"));
|
|
20855
|
+
const archive = path46.join(tmpRoot, `${asset}.${ext}`);
|
|
20564
20856
|
if (!await downloadFn(url2, archive)) {
|
|
20565
20857
|
log.warn("host-agent", "gh download failed \u2014 skipping (git pull/push still work via the credential helper)");
|
|
20566
20858
|
return null;
|
|
@@ -20570,16 +20862,16 @@ async function ensureGhCli(runner, token, deps = {}) {
|
|
|
20570
20862
|
log.warn("host-agent", `gh archive extraction failed (code=${String(extract.code)}) \u2014 skipping`);
|
|
20571
20863
|
return null;
|
|
20572
20864
|
}
|
|
20573
|
-
const extractedBin =
|
|
20574
|
-
if (!
|
|
20865
|
+
const extractedBin = path46.join(tmpRoot, asset, "bin", binaryName);
|
|
20866
|
+
if (!fs41.existsSync(extractedBin)) {
|
|
20575
20867
|
log.warn("host-agent", "gh binary not found in the extracted archive \u2014 skipping");
|
|
20576
20868
|
return null;
|
|
20577
20869
|
}
|
|
20578
20870
|
const binDir = codeamBinDir();
|
|
20579
|
-
|
|
20580
|
-
const target =
|
|
20581
|
-
|
|
20582
|
-
|
|
20871
|
+
fs41.mkdirSync(binDir, { recursive: true });
|
|
20872
|
+
const target = path46.join(binDir, binaryName);
|
|
20873
|
+
fs41.copyFileSync(extractedBin, target);
|
|
20874
|
+
fs41.chmodSync(target, 493);
|
|
20583
20875
|
log.info("host-agent", `gh installed to ${target} (v${version3})`);
|
|
20584
20876
|
return target;
|
|
20585
20877
|
} catch (e) {
|
|
@@ -20639,8 +20931,8 @@ async function ensureGlabCli(runner, deps = {}) {
|
|
|
20639
20931
|
const version3 = await resolveLatestGlabVersion();
|
|
20640
20932
|
const asset = `glab_${version3}_${osToken}_${arch2}`;
|
|
20641
20933
|
const url2 = `https://gitlab.com/gitlab-org/cli/-/releases/v${version3}/downloads/${asset}.${ext}`;
|
|
20642
|
-
const tmpRoot =
|
|
20643
|
-
const archive =
|
|
20934
|
+
const tmpRoot = fs41.mkdtempSync(path46.join(os38.tmpdir(), "codeam-glab-"));
|
|
20935
|
+
const archive = path46.join(tmpRoot, `${asset}.${ext}`);
|
|
20644
20936
|
if (!await downloadFn(url2, archive)) {
|
|
20645
20937
|
log.warn("host-agent", "glab download failed \u2014 skipping (git push/pull still work)");
|
|
20646
20938
|
return null;
|
|
@@ -20651,20 +20943,20 @@ async function ensureGlabCli(runner, deps = {}) {
|
|
|
20651
20943
|
return null;
|
|
20652
20944
|
}
|
|
20653
20945
|
const candidates = [
|
|
20654
|
-
|
|
20655
|
-
|
|
20656
|
-
|
|
20946
|
+
path46.join(tmpRoot, "bin", binaryName),
|
|
20947
|
+
path46.join(tmpRoot, asset, "bin", binaryName),
|
|
20948
|
+
path46.join(tmpRoot, binaryName)
|
|
20657
20949
|
];
|
|
20658
|
-
const extractedBin = candidates.find((c2) =>
|
|
20950
|
+
const extractedBin = candidates.find((c2) => fs41.existsSync(c2));
|
|
20659
20951
|
if (!extractedBin) {
|
|
20660
20952
|
log.warn("host-agent", "glab binary not found in the extracted archive \u2014 skipping");
|
|
20661
20953
|
return null;
|
|
20662
20954
|
}
|
|
20663
20955
|
const binDir = codeamBinDir();
|
|
20664
|
-
|
|
20665
|
-
const target =
|
|
20666
|
-
|
|
20667
|
-
|
|
20956
|
+
fs41.mkdirSync(binDir, { recursive: true });
|
|
20957
|
+
const target = path46.join(binDir, binaryName);
|
|
20958
|
+
fs41.copyFileSync(extractedBin, target);
|
|
20959
|
+
fs41.chmodSync(target, 493);
|
|
20668
20960
|
log.info("host-agent", `glab installed to ${target} (v${version3})`);
|
|
20669
20961
|
return target;
|
|
20670
20962
|
} catch (e) {
|
|
@@ -20861,24 +21153,24 @@ var HeadroomStatsReporter = class {
|
|
|
20861
21153
|
};
|
|
20862
21154
|
|
|
20863
21155
|
// src/commands/host/headroom-bootstrap.ts
|
|
20864
|
-
var
|
|
20865
|
-
var
|
|
20866
|
-
var
|
|
21156
|
+
var fs43 = __toESM(require("fs"));
|
|
21157
|
+
var path48 = __toESM(require("path"));
|
|
21158
|
+
var os40 = __toESM(require("os"));
|
|
20867
21159
|
|
|
20868
21160
|
// src/commands/host/headroom-config.ts
|
|
20869
|
-
var
|
|
20870
|
-
var
|
|
20871
|
-
var
|
|
21161
|
+
var fs42 = __toESM(require("fs"));
|
|
21162
|
+
var os39 = __toESM(require("os"));
|
|
21163
|
+
var path47 = __toESM(require("path"));
|
|
20872
21164
|
function headroomConfigPath() {
|
|
20873
|
-
return
|
|
21165
|
+
return path47.join(os39.homedir(), ".codeam", "headroom-config.json");
|
|
20874
21166
|
}
|
|
20875
21167
|
function persistHeadroomConfig(config) {
|
|
20876
21168
|
try {
|
|
20877
21169
|
const file = headroomConfigPath();
|
|
20878
|
-
|
|
21170
|
+
fs42.mkdirSync(path47.dirname(file), { recursive: true, mode: 448 });
|
|
20879
21171
|
const tmp = `${file}.tmp-${process.pid}`;
|
|
20880
|
-
|
|
20881
|
-
|
|
21172
|
+
fs42.writeFileSync(tmp, JSON.stringify(config, null, 2), { encoding: "utf8", mode: 384 });
|
|
21173
|
+
fs42.renameSync(tmp, file);
|
|
20882
21174
|
restrictToOwner(file);
|
|
20883
21175
|
} catch (err) {
|
|
20884
21176
|
log.warn(
|
|
@@ -20888,21 +21180,21 @@ function persistHeadroomConfig(config) {
|
|
|
20888
21180
|
}
|
|
20889
21181
|
}
|
|
20890
21182
|
function agentSettingsPath(kind) {
|
|
20891
|
-
const home =
|
|
20892
|
-
if (kind === "claude") return
|
|
20893
|
-
if (kind === "codex") return
|
|
20894
|
-
if (kind === "copilot") return
|
|
21183
|
+
const home = os39.homedir();
|
|
21184
|
+
if (kind === "claude") return path47.join(home, ".claude", "settings.json");
|
|
21185
|
+
if (kind === "codex") return path47.join(home, ".codex", "auth.json");
|
|
21186
|
+
if (kind === "copilot") return path47.join(home, ".config", "github-copilot", "hosts.json");
|
|
20895
21187
|
return null;
|
|
20896
21188
|
}
|
|
20897
21189
|
function backupAgentHeadroomConfig(kind) {
|
|
20898
21190
|
const src = agentSettingsPath(kind);
|
|
20899
21191
|
if (!src) return;
|
|
20900
21192
|
try {
|
|
20901
|
-
if (!
|
|
20902
|
-
const dest =
|
|
20903
|
-
|
|
20904
|
-
|
|
20905
|
-
|
|
21193
|
+
if (!fs42.existsSync(src)) return;
|
|
21194
|
+
const dest = path47.join(os39.homedir(), ".codeam", `headroom-backup-${kind}.json`);
|
|
21195
|
+
fs42.mkdirSync(path47.dirname(dest), { recursive: true, mode: 448 });
|
|
21196
|
+
fs42.copyFileSync(src, dest);
|
|
21197
|
+
fs42.chmodSync(dest, 384);
|
|
20906
21198
|
log.info("host-agent", `headroom config backup: ${src} \u2192 ${dest}`);
|
|
20907
21199
|
} catch (err) {
|
|
20908
21200
|
log.warn(
|
|
@@ -20914,12 +21206,12 @@ function backupAgentHeadroomConfig(kind) {
|
|
|
20914
21206
|
function restoreAgentHeadroomConfig(kind) {
|
|
20915
21207
|
const dest = agentSettingsPath(kind);
|
|
20916
21208
|
if (!dest) return false;
|
|
20917
|
-
const src =
|
|
20918
|
-
if (!
|
|
21209
|
+
const src = path47.join(os39.homedir(), ".codeam", `headroom-backup-${kind}.json`);
|
|
21210
|
+
if (!fs42.existsSync(src)) return false;
|
|
20919
21211
|
try {
|
|
20920
|
-
|
|
20921
|
-
|
|
20922
|
-
|
|
21212
|
+
fs42.mkdirSync(path47.dirname(dest), { recursive: true, mode: 448 });
|
|
21213
|
+
fs42.copyFileSync(src, dest);
|
|
21214
|
+
fs42.chmodSync(dest, 384);
|
|
20923
21215
|
log.info("host-agent", `headroom config restored: ${src} \u2192 ${dest}`);
|
|
20924
21216
|
return true;
|
|
20925
21217
|
} catch (err) {
|
|
@@ -20932,7 +21224,7 @@ function restoreAgentHeadroomConfig(kind) {
|
|
|
20932
21224
|
}
|
|
20933
21225
|
function readHeadroomChildEnv() {
|
|
20934
21226
|
try {
|
|
20935
|
-
const raw =
|
|
21227
|
+
const raw = fs42.readFileSync(headroomConfigPath(), "utf8");
|
|
20936
21228
|
const parsed = JSON.parse(raw);
|
|
20937
21229
|
if (typeof parsed !== "object" || parsed === null) return {};
|
|
20938
21230
|
const o = parsed;
|
|
@@ -20968,49 +21260,49 @@ function bundledClaudeBinDir() {
|
|
|
20968
21260
|
const roots = /* @__PURE__ */ new Set();
|
|
20969
21261
|
let dir = __dirname;
|
|
20970
21262
|
for (let i = 0; i < 6; i++) {
|
|
20971
|
-
roots.add(
|
|
20972
|
-
const parent =
|
|
21263
|
+
roots.add(path48.join(dir, "node_modules"));
|
|
21264
|
+
const parent = path48.dirname(dir);
|
|
20973
21265
|
if (parent === dir) break;
|
|
20974
21266
|
dir = parent;
|
|
20975
21267
|
}
|
|
20976
21268
|
try {
|
|
20977
21269
|
const main2 = require.resolve("@anthropic-ai/claude-agent-sdk");
|
|
20978
|
-
const marker = `${
|
|
21270
|
+
const marker = `${path48.sep}@anthropic-ai${path48.sep}`;
|
|
20979
21271
|
const idx = main2.lastIndexOf(marker);
|
|
20980
21272
|
if (idx !== -1) roots.add(main2.slice(0, idx));
|
|
20981
21273
|
} catch {
|
|
20982
21274
|
}
|
|
20983
21275
|
for (const nm of roots) {
|
|
20984
|
-
const atAnthropic =
|
|
21276
|
+
const atAnthropic = path48.join(nm, "@anthropic-ai");
|
|
20985
21277
|
let entries;
|
|
20986
21278
|
try {
|
|
20987
|
-
entries =
|
|
21279
|
+
entries = fs43.readdirSync(atAnthropic);
|
|
20988
21280
|
} catch {
|
|
20989
21281
|
continue;
|
|
20990
21282
|
}
|
|
20991
21283
|
for (const entry of entries) {
|
|
20992
21284
|
if (!entry.startsWith("claude-agent-sdk-")) continue;
|
|
20993
|
-
const bin =
|
|
20994
|
-
if (
|
|
21285
|
+
const bin = path48.join(atAnthropic, entry, "claude");
|
|
21286
|
+
if (fs43.existsSync(bin)) return path48.dirname(bin);
|
|
20995
21287
|
}
|
|
20996
21288
|
}
|
|
20997
21289
|
return null;
|
|
20998
21290
|
}
|
|
20999
21291
|
async function getFreeDiskBytes(dir) {
|
|
21000
21292
|
try {
|
|
21001
|
-
const s = await
|
|
21293
|
+
const s = await fs43.promises.statfs(dir);
|
|
21002
21294
|
return s.bsize * s.bavail;
|
|
21003
21295
|
} catch {
|
|
21004
21296
|
return null;
|
|
21005
21297
|
}
|
|
21006
21298
|
}
|
|
21007
21299
|
function headroomModelsCached() {
|
|
21008
|
-
const hubDir = process.env.HUGGINGFACE_HUB_CACHE ||
|
|
21009
|
-
process.env.HF_HOME ||
|
|
21300
|
+
const hubDir = process.env.HUGGINGFACE_HUB_CACHE || path48.join(
|
|
21301
|
+
process.env.HF_HOME || path48.join(os40.homedir(), ".cache", "huggingface"),
|
|
21010
21302
|
"hub"
|
|
21011
21303
|
);
|
|
21012
21304
|
return HEADROOM_MODELS.every(
|
|
21013
|
-
(m) =>
|
|
21305
|
+
(m) => fs43.existsSync(path48.join(hubDir, `models--${m.repo.replace("/", "--")}`))
|
|
21014
21306
|
);
|
|
21015
21307
|
}
|
|
21016
21308
|
async function setupHeadroomForSelfHosted(agent, runner = defaultHeadroomRunner, opts = {}) {
|
|
@@ -21079,7 +21371,7 @@ async function setupHeadroomForSelfHosted(agent, runner = defaultHeadroomRunner,
|
|
|
21079
21371
|
if (initKind === "claude") {
|
|
21080
21372
|
const claudeDir = bundledClaudeBinDir();
|
|
21081
21373
|
if (claudeDir) {
|
|
21082
|
-
initEnv.PATH = `${claudeDir}${
|
|
21374
|
+
initEnv.PATH = `${claudeDir}${path48.delimiter}${process.env["PATH"] ?? ""}`;
|
|
21083
21375
|
log.info("host-agent", `headroom init: bundled claude on PATH (${claudeDir})`);
|
|
21084
21376
|
} else {
|
|
21085
21377
|
log.warn("host-agent", "headroom init: bundled claude binary not found \u2014 init may fail");
|
|
@@ -21116,19 +21408,19 @@ async function setupHeadroomForSelfHosted(agent, runner = defaultHeadroomRunner,
|
|
|
21116
21408
|
}
|
|
21117
21409
|
|
|
21118
21410
|
// src/commands/host/house-proxy-config.ts
|
|
21119
|
-
var
|
|
21120
|
-
var
|
|
21121
|
-
var
|
|
21411
|
+
var fs44 = __toESM(require("fs"));
|
|
21412
|
+
var os41 = __toESM(require("os"));
|
|
21413
|
+
var path49 = __toESM(require("path"));
|
|
21122
21414
|
function houseProxyConfigPath() {
|
|
21123
|
-
return
|
|
21415
|
+
return path49.join(os41.homedir(), ".codeam", "house-proxy.json");
|
|
21124
21416
|
}
|
|
21125
21417
|
function persistHouseProxyConfig(config) {
|
|
21126
21418
|
try {
|
|
21127
21419
|
const file = houseProxyConfigPath();
|
|
21128
|
-
|
|
21420
|
+
fs44.mkdirSync(path49.dirname(file), { recursive: true, mode: 448 });
|
|
21129
21421
|
const tmp = `${file}.tmp-${process.pid}`;
|
|
21130
|
-
|
|
21131
|
-
|
|
21422
|
+
fs44.writeFileSync(tmp, JSON.stringify(config, null, 2), { encoding: "utf8", mode: 384 });
|
|
21423
|
+
fs44.renameSync(tmp, file);
|
|
21132
21424
|
restrictToOwner(file);
|
|
21133
21425
|
} catch (err) {
|
|
21134
21426
|
log.warn(
|
|
@@ -21139,13 +21431,13 @@ function persistHouseProxyConfig(config) {
|
|
|
21139
21431
|
}
|
|
21140
21432
|
function clearHouseProxyConfig() {
|
|
21141
21433
|
try {
|
|
21142
|
-
|
|
21434
|
+
fs44.rmSync(houseProxyConfigPath(), { force: true });
|
|
21143
21435
|
} catch {
|
|
21144
21436
|
}
|
|
21145
21437
|
}
|
|
21146
21438
|
function readHouseProxyChildEnv() {
|
|
21147
21439
|
try {
|
|
21148
|
-
const raw =
|
|
21440
|
+
const raw = fs44.readFileSync(houseProxyConfigPath(), "utf8");
|
|
21149
21441
|
const parsed = JSON.parse(raw);
|
|
21150
21442
|
if (typeof parsed !== "object" || parsed === null) return {};
|
|
21151
21443
|
const o = parsed;
|
|
@@ -21178,9 +21470,9 @@ function readHouseProxyChildEnv() {
|
|
|
21178
21470
|
var import_node_child_process23 = require("child_process");
|
|
21179
21471
|
|
|
21180
21472
|
// src/lib/updateNotifier.ts
|
|
21181
|
-
var
|
|
21182
|
-
var
|
|
21183
|
-
var
|
|
21473
|
+
var fs45 = __toESM(require("fs"));
|
|
21474
|
+
var os42 = __toESM(require("os"));
|
|
21475
|
+
var path50 = __toESM(require("path"));
|
|
21184
21476
|
var https6 = __toESM(require("https"));
|
|
21185
21477
|
var import_node_child_process22 = require("child_process");
|
|
21186
21478
|
var import_picocolors3 = __toESM(require("picocolors"));
|
|
@@ -21189,12 +21481,12 @@ var REGISTRY_URL = `https://registry.npmjs.org/${PKG_NAME}/latest`;
|
|
|
21189
21481
|
var TTL_MS = 24 * 60 * 60 * 1e3;
|
|
21190
21482
|
var REQUEST_TIMEOUT_MS = 1500;
|
|
21191
21483
|
function cachePath() {
|
|
21192
|
-
const dir =
|
|
21193
|
-
return
|
|
21484
|
+
const dir = path50.join(os42.homedir(), ".codeam");
|
|
21485
|
+
return path50.join(dir, "update-check.json");
|
|
21194
21486
|
}
|
|
21195
21487
|
function readCache() {
|
|
21196
21488
|
try {
|
|
21197
|
-
const raw =
|
|
21489
|
+
const raw = fs45.readFileSync(cachePath(), "utf8");
|
|
21198
21490
|
const parsed = JSON.parse(raw);
|
|
21199
21491
|
if (typeof parsed.fetchedAt !== "number" || typeof parsed.latest !== "string") return null;
|
|
21200
21492
|
return parsed;
|
|
@@ -21205,10 +21497,10 @@ function readCache() {
|
|
|
21205
21497
|
function writeCache(cache) {
|
|
21206
21498
|
try {
|
|
21207
21499
|
const file = cachePath();
|
|
21208
|
-
|
|
21500
|
+
fs45.mkdirSync(path50.dirname(file), { recursive: true });
|
|
21209
21501
|
const tmp = `${file}.${process.pid}.tmp`;
|
|
21210
|
-
|
|
21211
|
-
|
|
21502
|
+
fs45.writeFileSync(tmp, JSON.stringify(cache));
|
|
21503
|
+
fs45.renameSync(tmp, file);
|
|
21212
21504
|
} catch {
|
|
21213
21505
|
}
|
|
21214
21506
|
}
|
|
@@ -21282,8 +21574,8 @@ function isLinkedInstall() {
|
|
|
21282
21574
|
timeout: 2e3
|
|
21283
21575
|
}).trim();
|
|
21284
21576
|
if (!root) return false;
|
|
21285
|
-
const pkgPath =
|
|
21286
|
-
return
|
|
21577
|
+
const pkgPath = path50.join(root, PKG_NAME);
|
|
21578
|
+
return fs45.lstatSync(pkgPath).isSymbolicLink();
|
|
21287
21579
|
} catch {
|
|
21288
21580
|
return false;
|
|
21289
21581
|
}
|
|
@@ -21319,7 +21611,7 @@ function maybeAutoUpdate(currentVersion, latest) {
|
|
|
21319
21611
|
return;
|
|
21320
21612
|
}
|
|
21321
21613
|
try {
|
|
21322
|
-
|
|
21614
|
+
fs45.unlinkSync(cachePath());
|
|
21323
21615
|
} catch {
|
|
21324
21616
|
}
|
|
21325
21617
|
process.stderr.write(` ${import_picocolors3.default.green("\u2713")} Updated. Resuming session...
|
|
@@ -21335,7 +21627,7 @@ async function autoUpgradeBeforeCriticalCommand() {
|
|
|
21335
21627
|
if (process.env.NODE_ENV === "test") return;
|
|
21336
21628
|
if (process.env.CODEAM_DISABLE_UPDATE_CHECK === "1") return;
|
|
21337
21629
|
if (process.env.CI) return;
|
|
21338
|
-
const current2 = true ? "2.65.
|
|
21630
|
+
const current2 = true ? "2.65.3" : null;
|
|
21339
21631
|
if (!current2) return;
|
|
21340
21632
|
const cache = readCache();
|
|
21341
21633
|
const fresh = cache && Date.now() - cache.fetchedAt < TTL_MS;
|
|
@@ -21352,7 +21644,7 @@ function checkForUpdates() {
|
|
|
21352
21644
|
if (process.env.CODEAM_DISABLE_UPDATE_CHECK === "1") return;
|
|
21353
21645
|
if (process.env.CI) return;
|
|
21354
21646
|
if (!process.stdout.isTTY) return;
|
|
21355
|
-
const current2 = true ? "2.65.
|
|
21647
|
+
const current2 = true ? "2.65.3" : null;
|
|
21356
21648
|
if (!current2) return;
|
|
21357
21649
|
const cache = readCache();
|
|
21358
21650
|
const fresh = cache && Date.now() - cache.fetchedAt < TTL_MS;
|
|
@@ -21372,7 +21664,7 @@ var SELF_UPDATE_INTERVAL_MS = 60 * 60 * 1e3;
|
|
|
21372
21664
|
var SELF_UPDATE_VIEW_TIMEOUT_MS = 3e4;
|
|
21373
21665
|
var SELF_UPDATE_INSTALL_TIMEOUT_MS = 18e4;
|
|
21374
21666
|
function currentCliVersion() {
|
|
21375
|
-
return true ? "2.65.
|
|
21667
|
+
return true ? "2.65.3" : null;
|
|
21376
21668
|
}
|
|
21377
21669
|
function runCmd(cmd, args2, timeoutMs) {
|
|
21378
21670
|
return new Promise((resolve9) => {
|
|
@@ -21439,7 +21731,7 @@ async function runSelfUpdate() {
|
|
|
21439
21731
|
|
|
21440
21732
|
// src/commands/host/teardown.ts
|
|
21441
21733
|
var import_node_child_process24 = require("child_process");
|
|
21442
|
-
var
|
|
21734
|
+
var fs46 = __toESM(require("fs"));
|
|
21443
21735
|
var defaultDisableService = () => {
|
|
21444
21736
|
try {
|
|
21445
21737
|
(0, import_node_child_process24.execFileSync)("systemctl", ["disable", "--now", "codeam-host-agent"], { stdio: "ignore" });
|
|
@@ -21448,7 +21740,7 @@ var defaultDisableService = () => {
|
|
|
21448
21740
|
};
|
|
21449
21741
|
var defaultTeardownHeadroom = () => {
|
|
21450
21742
|
try {
|
|
21451
|
-
const kind = JSON.parse(
|
|
21743
|
+
const kind = JSON.parse(fs46.readFileSync(headroomConfigPath(), "utf8")).agent;
|
|
21452
21744
|
if (kind) {
|
|
21453
21745
|
(0, import_node_child_process24.execFileSync)("headroom", ["unwrap", kind], { stdio: "ignore", timeout: 15e3 });
|
|
21454
21746
|
}
|
|
@@ -21516,8 +21808,8 @@ function maybeResumeLocalHeadroomReporter(ctx) {
|
|
|
21516
21808
|
if (process.env["HEADROOM_ENABLED"] === "1") return null;
|
|
21517
21809
|
try {
|
|
21518
21810
|
const file = headroomConfigPath();
|
|
21519
|
-
if (!
|
|
21520
|
-
const cfg = JSON.parse(
|
|
21811
|
+
if (!fs47.existsSync(file)) return null;
|
|
21812
|
+
const cfg = JSON.parse(fs47.readFileSync(file, "utf8"));
|
|
21521
21813
|
if (!cfg?.enabled) return null;
|
|
21522
21814
|
const agent = cfg.agent ?? "claude";
|
|
21523
21815
|
const ingestUrl = `${resolveApiBaseUrl()}/api/sessions/${ctx.sessionId}/headroom-savings`;
|
|
@@ -22104,13 +22396,13 @@ var HostAgentSupervisor = class {
|
|
|
22104
22396
|
const relay = this.relay;
|
|
22105
22397
|
if (!relay) return;
|
|
22106
22398
|
const raw = cmd.payload?.path;
|
|
22107
|
-
const target = typeof raw === "string" && raw.trim() ?
|
|
22399
|
+
const target = typeof raw === "string" && raw.trim() ? path51.resolve(raw.trim()) : os43.homedir();
|
|
22108
22400
|
try {
|
|
22109
|
-
const dirents = await
|
|
22401
|
+
const dirents = await fs47.promises.readdir(target, { withFileTypes: true });
|
|
22110
22402
|
const entries = dirents.filter((d3) => !d3.name.startsWith(".")).map((d3) => ({ name: d3.name, isDir: d3.isDirectory() })).sort(
|
|
22111
22403
|
(a, b) => a.isDir === b.isDir ? a.name.localeCompare(b.name) : a.isDir ? -1 : 1
|
|
22112
22404
|
);
|
|
22113
|
-
const parent =
|
|
22405
|
+
const parent = path51.dirname(target);
|
|
22114
22406
|
await relay.sendResult(cmd.id, "completed", {
|
|
22115
22407
|
path: target,
|
|
22116
22408
|
// null at the filesystem root so the UI can hide the ".." affordance.
|
|
@@ -22343,14 +22635,14 @@ var HostAgentSupervisor = class {
|
|
|
22343
22635
|
API_TIMEOUT_MS: "3000000",
|
|
22344
22636
|
CODEAM_AUTO_TOKEN: payload.autoPairToken
|
|
22345
22637
|
};
|
|
22346
|
-
const houseConfigDir =
|
|
22347
|
-
|
|
22638
|
+
const houseConfigDir = path51.join(
|
|
22639
|
+
os43.homedir(),
|
|
22348
22640
|
".codeam",
|
|
22349
22641
|
"house-claude",
|
|
22350
22642
|
payload.deployId
|
|
22351
22643
|
);
|
|
22352
22644
|
try {
|
|
22353
|
-
|
|
22645
|
+
fs47.mkdirSync(houseConfigDir, { recursive: true, mode: 448 });
|
|
22354
22646
|
} catch {
|
|
22355
22647
|
}
|
|
22356
22648
|
childEnv.CLAUDE_CONFIG_DIR = houseConfigDir;
|
|
@@ -22376,7 +22668,7 @@ var HostAgentSupervisor = class {
|
|
|
22376
22668
|
report("installing", "installing agent CLI");
|
|
22377
22669
|
await this.runAgentInstall(payload.agentInstallScript);
|
|
22378
22670
|
}
|
|
22379
|
-
const home = process.env.HOME ||
|
|
22671
|
+
const home = process.env.HOME || os43.homedir();
|
|
22380
22672
|
childEnv.PATH = `${home}/.local/bin:${process.env.PATH ?? ""}`;
|
|
22381
22673
|
if (payload.cloneToken) {
|
|
22382
22674
|
try {
|
|
@@ -22384,13 +22676,13 @@ var HostAgentSupervisor = class {
|
|
|
22384
22676
|
if ((payload.repoProvider ?? "github") === "gitlab") {
|
|
22385
22677
|
const glabCmd = await ensureGlabCli(defaultGitToolingRunner);
|
|
22386
22678
|
if (glabCmd) {
|
|
22387
|
-
childEnv.PATH = `${codeamBinDir()}${
|
|
22679
|
+
childEnv.PATH = `${codeamBinDir()}${path51.delimiter}${childEnv.PATH}`;
|
|
22388
22680
|
await ensureGlabAuth(defaultGitToolingRunner, glabCmd, payload.cloneToken);
|
|
22389
22681
|
}
|
|
22390
22682
|
} else {
|
|
22391
22683
|
const ghCmd = await ensureGhCli(defaultGitToolingRunner, payload.cloneToken);
|
|
22392
22684
|
if (ghCmd) {
|
|
22393
|
-
childEnv.PATH = `${codeamBinDir()}${
|
|
22685
|
+
childEnv.PATH = `${codeamBinDir()}${path51.delimiter}${childEnv.PATH}`;
|
|
22394
22686
|
await ensureGhAuth(defaultGitToolingRunner, ghCmd, payload.cloneToken);
|
|
22395
22687
|
}
|
|
22396
22688
|
}
|
|
@@ -22410,7 +22702,7 @@ var HostAgentSupervisor = class {
|
|
|
22410
22702
|
}
|
|
22411
22703
|
if (payload.headroomEnabled && payload.headroomAgent && payload.headroomSavingsIngestUrl && isHeadroomSupportedAgent(payload.headroomAgent)) {
|
|
22412
22704
|
report("headroom", "setting up Headroom proxy");
|
|
22413
|
-
const freeBytes = await this.getFreeDisk(
|
|
22705
|
+
const freeBytes = await this.getFreeDisk(os43.homedir());
|
|
22414
22706
|
const alreadyInstalled = this.isHeadroomInstalled();
|
|
22415
22707
|
if (!alreadyInstalled && freeBytes !== null && freeBytes < HEADROOM_MIN_FREE_DISK_BYTES) {
|
|
22416
22708
|
const freeGb = (freeBytes / 1e9).toFixed(1);
|
|
@@ -22469,9 +22761,9 @@ var HostAgentSupervisor = class {
|
|
|
22469
22761
|
);
|
|
22470
22762
|
if (!payload.suppressOnboardingWelcome) {
|
|
22471
22763
|
try {
|
|
22472
|
-
const cfgDir = childEnv.CLAUDE_CONFIG_DIR ||
|
|
22473
|
-
const projectDir =
|
|
22474
|
-
const hasPriorConversation =
|
|
22764
|
+
const cfgDir = childEnv.CLAUDE_CONFIG_DIR || path51.join(os43.homedir(), ".claude");
|
|
22765
|
+
const projectDir = path51.join(cfgDir, "projects", encodeCwd(cwd));
|
|
22766
|
+
const hasPriorConversation = fs47.existsSync(projectDir) && fs47.readdirSync(projectDir).some((f) => f.endsWith(".jsonl"));
|
|
22475
22767
|
if (hasPriorConversation) {
|
|
22476
22768
|
childEnv.CODEAM_RESUME_LATEST = "1";
|
|
22477
22769
|
log.info(
|
|
@@ -22570,7 +22862,7 @@ var HostAgentSupervisor = class {
|
|
|
22570
22862
|
if (this.children.size > 0) return;
|
|
22571
22863
|
const session = getActiveSession();
|
|
22572
22864
|
if (!session || !session.pluginId || !session.pollSecret || !session.agent) return;
|
|
22573
|
-
const cwd = session.cwd &&
|
|
22865
|
+
const cwd = session.cwd && fs47.existsSync(session.cwd) ? session.cwd : process.cwd();
|
|
22574
22866
|
const proc = this.resumeSpawner(
|
|
22575
22867
|
{ ...readHeadroomChildEnv(), ...readHouseProxyChildEnv() },
|
|
22576
22868
|
cwd
|
|
@@ -22667,12 +22959,12 @@ var HostAgentSupervisor = class {
|
|
|
22667
22959
|
this.children.delete(deployId);
|
|
22668
22960
|
}
|
|
22669
22961
|
const dirs = [
|
|
22670
|
-
|
|
22671
|
-
|
|
22962
|
+
path51.join(selfHostedWorkspaceRoot(), deployId),
|
|
22963
|
+
path51.join(os43.homedir(), ".codeam", "house-claude", deployId)
|
|
22672
22964
|
];
|
|
22673
22965
|
for (const dir of dirs) {
|
|
22674
22966
|
try {
|
|
22675
|
-
|
|
22967
|
+
fs47.rmSync(dir, { recursive: true, force: true });
|
|
22676
22968
|
} catch (err) {
|
|
22677
22969
|
log.warn(
|
|
22678
22970
|
"host-agent",
|
|
@@ -22809,9 +23101,9 @@ async function configureHeadroom(action, ctx, deps) {
|
|
|
22809
23101
|
}
|
|
22810
23102
|
|
|
22811
23103
|
// src/services/headroom/budget-relaunch.ts
|
|
22812
|
-
var
|
|
22813
|
-
var
|
|
22814
|
-
var
|
|
23104
|
+
var fs48 = __toESM(require("fs"));
|
|
23105
|
+
var os44 = __toESM(require("os"));
|
|
23106
|
+
var path52 = __toESM(require("path"));
|
|
22815
23107
|
var import_child_process15 = require("child_process");
|
|
22816
23108
|
function amendDeploymentManifestBudget(manifest, budget) {
|
|
22817
23109
|
const rawArgs = manifest.proxy_args ?? [];
|
|
@@ -22845,7 +23137,7 @@ function amendDeploymentManifestBudget(manifest, budget) {
|
|
|
22845
23137
|
return { ...manifest, proxy_args: newArgs, base_env: newEnv };
|
|
22846
23138
|
}
|
|
22847
23139
|
function findHeadroomDeployments(homeDir2, deps) {
|
|
22848
|
-
const deployDir =
|
|
23140
|
+
const deployDir = path52.join(homeDir2, ".headroom", "deploy");
|
|
22849
23141
|
let profiles;
|
|
22850
23142
|
try {
|
|
22851
23143
|
profiles = deps.readDir(deployDir);
|
|
@@ -22854,7 +23146,7 @@ function findHeadroomDeployments(homeDir2, deps) {
|
|
|
22854
23146
|
}
|
|
22855
23147
|
const results = [];
|
|
22856
23148
|
for (const profile of profiles) {
|
|
22857
|
-
const manifestPath =
|
|
23149
|
+
const manifestPath = path52.join(deployDir, profile, "manifest.json");
|
|
22858
23150
|
let raw;
|
|
22859
23151
|
try {
|
|
22860
23152
|
raw = deps.readJson(manifestPath);
|
|
@@ -22886,8 +23178,8 @@ async function applyBudgetToHeadroom(budget, deps) {
|
|
|
22886
23178
|
}
|
|
22887
23179
|
function writeManifestReal(manifestPath, manifest) {
|
|
22888
23180
|
const tmp = manifestPath + ".codeam.tmp";
|
|
22889
|
-
|
|
22890
|
-
|
|
23181
|
+
fs48.writeFileSync(tmp, JSON.stringify(manifest, null, 2) + "\n", { mode: 384 });
|
|
23182
|
+
fs48.renameSync(tmp, manifestPath);
|
|
22891
23183
|
}
|
|
22892
23184
|
function restartDeploymentReal(profile) {
|
|
22893
23185
|
try {
|
|
@@ -22922,11 +23214,11 @@ function spawnProxyReal2(_budget) {
|
|
|
22922
23214
|
);
|
|
22923
23215
|
}
|
|
22924
23216
|
function makeRealApplyBudgetDeps() {
|
|
22925
|
-
const homeDir2 =
|
|
23217
|
+
const homeDir2 = os44.homedir();
|
|
22926
23218
|
return {
|
|
22927
23219
|
findDeployments: () => findHeadroomDeployments(homeDir2, {
|
|
22928
|
-
readDir: (dir) =>
|
|
22929
|
-
readJson: (filePath) => JSON.parse(
|
|
23220
|
+
readDir: (dir) => fs48.readdirSync(dir),
|
|
23221
|
+
readJson: (filePath) => JSON.parse(fs48.readFileSync(filePath, "utf8"))
|
|
22930
23222
|
}),
|
|
22931
23223
|
writeManifest: writeManifestReal,
|
|
22932
23224
|
restartDeployment: restartDeploymentReal,
|
|
@@ -23059,47 +23351,47 @@ async function readUsageReport(deps = {}) {
|
|
|
23059
23351
|
}
|
|
23060
23352
|
|
|
23061
23353
|
// src/agents/acp/guardrail-config.ts
|
|
23062
|
-
var
|
|
23063
|
-
var
|
|
23064
|
-
var
|
|
23354
|
+
var fs49 = __toESM(require("fs"));
|
|
23355
|
+
var path53 = __toESM(require("path"));
|
|
23356
|
+
var os45 = __toESM(require("os"));
|
|
23065
23357
|
var current = null;
|
|
23066
|
-
function guardrailConfigPath(homeDir2 =
|
|
23067
|
-
return
|
|
23358
|
+
function guardrailConfigPath(homeDir2 = os45.homedir()) {
|
|
23359
|
+
return path53.join(homeDir2, ".codeam", "guardrails.json");
|
|
23068
23360
|
}
|
|
23069
|
-
function loadGuardrailPolicy(homeDir2 =
|
|
23361
|
+
function loadGuardrailPolicy(homeDir2 = os45.homedir()) {
|
|
23070
23362
|
try {
|
|
23071
|
-
current = normalizeGuardrailPolicy(JSON.parse(
|
|
23363
|
+
current = normalizeGuardrailPolicy(JSON.parse(fs49.readFileSync(guardrailConfigPath(homeDir2), "utf8")));
|
|
23072
23364
|
} catch {
|
|
23073
23365
|
current = { ...DEFAULT_GUARDRAIL_POLICY };
|
|
23074
23366
|
}
|
|
23075
23367
|
return current;
|
|
23076
23368
|
}
|
|
23077
|
-
function getGuardrailPolicy(homeDir2 =
|
|
23369
|
+
function getGuardrailPolicy(homeDir2 = os45.homedir()) {
|
|
23078
23370
|
return current ?? loadGuardrailPolicy(homeDir2);
|
|
23079
23371
|
}
|
|
23080
|
-
function setGuardrailPolicy(raw, homeDir2 =
|
|
23372
|
+
function setGuardrailPolicy(raw, homeDir2 = os45.homedir()) {
|
|
23081
23373
|
const next = normalizeGuardrailPolicy(raw);
|
|
23082
23374
|
current = next;
|
|
23083
23375
|
try {
|
|
23084
23376
|
const p2 = guardrailConfigPath(homeDir2);
|
|
23085
|
-
|
|
23086
|
-
|
|
23377
|
+
fs49.mkdirSync(path53.dirname(p2), { recursive: true });
|
|
23378
|
+
fs49.writeFileSync(p2, JSON.stringify(next, null, 2));
|
|
23087
23379
|
} catch {
|
|
23088
23380
|
}
|
|
23089
23381
|
return next;
|
|
23090
23382
|
}
|
|
23091
23383
|
|
|
23092
23384
|
// src/services/preview/port-registry.ts
|
|
23093
|
-
var
|
|
23094
|
-
var
|
|
23095
|
-
var
|
|
23385
|
+
var fs50 = __toESM(require("fs"));
|
|
23386
|
+
var os46 = __toESM(require("os"));
|
|
23387
|
+
var path54 = __toESM(require("path"));
|
|
23096
23388
|
var import_child_process16 = require("child_process");
|
|
23097
23389
|
function registryPath() {
|
|
23098
|
-
return
|
|
23390
|
+
return path54.join(os46.homedir(), ".codeam", "preview-ports.json");
|
|
23099
23391
|
}
|
|
23100
23392
|
function readRegistry() {
|
|
23101
23393
|
try {
|
|
23102
|
-
const raw =
|
|
23394
|
+
const raw = fs50.readFileSync(registryPath(), "utf8");
|
|
23103
23395
|
const parsed = JSON.parse(raw);
|
|
23104
23396
|
if (parsed && typeof parsed === "object") return parsed;
|
|
23105
23397
|
} catch {
|
|
@@ -23109,10 +23401,10 @@ function readRegistry() {
|
|
|
23109
23401
|
function writeRegistry(reg) {
|
|
23110
23402
|
try {
|
|
23111
23403
|
const file = registryPath();
|
|
23112
|
-
|
|
23404
|
+
fs50.mkdirSync(path54.dirname(file), { recursive: true });
|
|
23113
23405
|
const tmp = `${file}.tmp`;
|
|
23114
|
-
|
|
23115
|
-
|
|
23406
|
+
fs50.writeFileSync(tmp, JSON.stringify(reg), "utf8");
|
|
23407
|
+
fs50.renameSync(tmp, file);
|
|
23116
23408
|
} catch (err) {
|
|
23117
23409
|
log.warn("preview", `port-registry write failed: ${err instanceof Error ? err.message : String(err)}`);
|
|
23118
23410
|
}
|
|
@@ -23178,7 +23470,7 @@ function reclaimOwnOrphanPort(port) {
|
|
|
23178
23470
|
|
|
23179
23471
|
// src/services/preview/host-allow.ts
|
|
23180
23472
|
var import_fs2 = require("fs");
|
|
23181
|
-
var
|
|
23473
|
+
var path55 = __toESM(require("path"));
|
|
23182
23474
|
var NEXT_ALLOWED_ORIGINS = [
|
|
23183
23475
|
"*.trycloudflare.com",
|
|
23184
23476
|
"*.preview.codeagent-mobile.com",
|
|
@@ -23198,7 +23490,7 @@ var MARKER_DIR = ".codeam";
|
|
|
23198
23490
|
var MARKER_FILE = "preview-host-allow.json";
|
|
23199
23491
|
var ORIG_INFIX = ".codeam-orig";
|
|
23200
23492
|
function markerPath(cwd) {
|
|
23201
|
-
return
|
|
23493
|
+
return path55.join(cwd, MARKER_DIR, MARKER_FILE);
|
|
23202
23494
|
}
|
|
23203
23495
|
async function fileExists(p2) {
|
|
23204
23496
|
try {
|
|
@@ -23211,13 +23503,13 @@ async function fileExists(p2) {
|
|
|
23211
23503
|
async function findConfigFile(cwd, framework) {
|
|
23212
23504
|
const base = CONFIG_BASENAMES[framework];
|
|
23213
23505
|
for (const ext of CONFIG_EXTS) {
|
|
23214
|
-
if (await fileExists(
|
|
23506
|
+
if (await fileExists(path55.join(cwd, `${base}${ext}`))) return `${base}${ext}`;
|
|
23215
23507
|
}
|
|
23216
23508
|
return null;
|
|
23217
23509
|
}
|
|
23218
23510
|
async function dependsOn(cwd, pkgName) {
|
|
23219
23511
|
try {
|
|
23220
|
-
const raw = await import_fs2.promises.readFile(
|
|
23512
|
+
const raw = await import_fs2.promises.readFile(path55.join(cwd, "package.json"), "utf8");
|
|
23221
23513
|
const pkg = JSON.parse(raw);
|
|
23222
23514
|
return !!(pkg.dependencies?.[pkgName] ?? pkg.devDependencies?.[pkgName]);
|
|
23223
23515
|
} catch {
|
|
@@ -23225,11 +23517,11 @@ async function dependsOn(cwd, pkgName) {
|
|
|
23225
23517
|
}
|
|
23226
23518
|
}
|
|
23227
23519
|
async function isEsmConfig(cwd, configFile) {
|
|
23228
|
-
const ext =
|
|
23520
|
+
const ext = path55.extname(configFile);
|
|
23229
23521
|
if (ext === ".mjs" || ext === ".mts" || ext === ".ts") return true;
|
|
23230
23522
|
if (ext === ".cjs") return false;
|
|
23231
23523
|
try {
|
|
23232
|
-
const raw = await import_fs2.promises.readFile(
|
|
23524
|
+
const raw = await import_fs2.promises.readFile(path55.join(cwd, "package.json"), "utf8");
|
|
23233
23525
|
return JSON.parse(raw).type === "module";
|
|
23234
23526
|
} catch {
|
|
23235
23527
|
return false;
|
|
@@ -23312,7 +23604,7 @@ function shimFor(framework, origBasename, esm) {
|
|
|
23312
23604
|
return framework === "next" ? nextShim(origBasename, esm) : viteShim(origBasename, esm);
|
|
23313
23605
|
}
|
|
23314
23606
|
async function writeMarker(cwd, marker) {
|
|
23315
|
-
await import_fs2.promises.mkdir(
|
|
23607
|
+
await import_fs2.promises.mkdir(path55.join(cwd, MARKER_DIR), { recursive: true });
|
|
23316
23608
|
await import_fs2.promises.writeFile(markerPath(cwd), JSON.stringify(marker, null, 2), "utf8");
|
|
23317
23609
|
}
|
|
23318
23610
|
async function readMarker(cwd) {
|
|
@@ -23327,9 +23619,9 @@ async function restorePreviewHostAllow(cwd) {
|
|
|
23327
23619
|
const marker = await readMarker(cwd);
|
|
23328
23620
|
if (!marker) return;
|
|
23329
23621
|
try {
|
|
23330
|
-
const configAbs =
|
|
23622
|
+
const configAbs = path55.join(cwd, marker.configFile);
|
|
23331
23623
|
if (marker.backupFile) {
|
|
23332
|
-
const backupAbs =
|
|
23624
|
+
const backupAbs = path55.join(cwd, marker.backupFile);
|
|
23333
23625
|
if (await fileExists(backupAbs)) {
|
|
23334
23626
|
await import_fs2.promises.rm(configAbs, { force: true });
|
|
23335
23627
|
await import_fs2.promises.rename(backupAbs, configAbs);
|
|
@@ -23362,16 +23654,16 @@ async function applyPreviewHostAllow(cwd) {
|
|
|
23362
23654
|
}
|
|
23363
23655
|
if (!framework) return;
|
|
23364
23656
|
if (existing) {
|
|
23365
|
-
const ext =
|
|
23657
|
+
const ext = path55.extname(existing);
|
|
23366
23658
|
const origBasename = `${CONFIG_BASENAMES[framework]}${ORIG_INFIX}${ext}`;
|
|
23367
23659
|
const esm = await isEsmConfig(cwd, existing);
|
|
23368
|
-
await import_fs2.promises.rename(
|
|
23369
|
-
await import_fs2.promises.writeFile(
|
|
23660
|
+
await import_fs2.promises.rename(path55.join(cwd, existing), path55.join(cwd, origBasename));
|
|
23661
|
+
await import_fs2.promises.writeFile(path55.join(cwd, existing), shimFor(framework, origBasename, esm), "utf8");
|
|
23370
23662
|
await writeMarker(cwd, { framework, configFile: existing, backupFile: origBasename });
|
|
23371
23663
|
log.info("preview", `host-allow: wrapped ${existing} (${framework}) for tunnel access`);
|
|
23372
23664
|
} else {
|
|
23373
23665
|
const configFile = `${CONFIG_BASENAMES[framework]}.mjs`;
|
|
23374
|
-
await import_fs2.promises.writeFile(
|
|
23666
|
+
await import_fs2.promises.writeFile(path55.join(cwd, configFile), shimFor(framework, null, true), "utf8");
|
|
23375
23667
|
await writeMarker(cwd, { framework, configFile, backupFile: null });
|
|
23376
23668
|
log.info("preview", `host-allow: created ${configFile} (${framework}) for tunnel access`);
|
|
23377
23669
|
}
|
|
@@ -24053,19 +24345,19 @@ function activePreviewSessionIds() {
|
|
|
24053
24345
|
|
|
24054
24346
|
// src/services/preview/start-orchestrator.ts
|
|
24055
24347
|
var import_child_process21 = require("child_process");
|
|
24056
|
-
var
|
|
24057
|
-
var
|
|
24348
|
+
var fs58 = __toESM(require("fs"));
|
|
24349
|
+
var path62 = __toESM(require("path"));
|
|
24058
24350
|
var import_which2 = __toESM(require("which"));
|
|
24059
24351
|
|
|
24060
24352
|
// src/services/project-env/index.ts
|
|
24061
24353
|
var import_fs6 = require("fs");
|
|
24062
|
-
var
|
|
24354
|
+
var path61 = __toESM(require("path"));
|
|
24063
24355
|
|
|
24064
24356
|
// src/beads/project-key.ts
|
|
24065
24357
|
var import_child_process20 = require("child_process");
|
|
24066
24358
|
var crypto2 = __toESM(require("crypto"));
|
|
24067
|
-
var
|
|
24068
|
-
var
|
|
24359
|
+
var fs56 = __toESM(require("fs"));
|
|
24360
|
+
var path60 = __toESM(require("path"));
|
|
24069
24361
|
function normalizeOrigin(raw) {
|
|
24070
24362
|
const trimmed = raw.trim();
|
|
24071
24363
|
if (!trimmed) return null;
|
|
@@ -24091,17 +24383,17 @@ function normalizeOrigin(raw) {
|
|
|
24091
24383
|
return `${host2}/${pathPart}`;
|
|
24092
24384
|
}
|
|
24093
24385
|
function findRepoRoot(cwd) {
|
|
24094
|
-
let dir =
|
|
24386
|
+
let dir = path60.resolve(cwd);
|
|
24095
24387
|
const seen = /* @__PURE__ */ new Set();
|
|
24096
24388
|
for (let i = 0; i < 256; i++) {
|
|
24097
24389
|
if (seen.has(dir)) return null;
|
|
24098
24390
|
seen.add(dir);
|
|
24099
24391
|
try {
|
|
24100
|
-
const stat3 =
|
|
24392
|
+
const stat3 = fs56.statSync(path60.join(dir, ".git"), { throwIfNoEntry: false });
|
|
24101
24393
|
if (stat3 && (stat3.isDirectory() || stat3.isFile())) return dir;
|
|
24102
24394
|
} catch {
|
|
24103
24395
|
}
|
|
24104
|
-
const parent =
|
|
24396
|
+
const parent = path60.dirname(dir);
|
|
24105
24397
|
if (parent === dir) return null;
|
|
24106
24398
|
dir = parent;
|
|
24107
24399
|
}
|
|
@@ -24112,7 +24404,7 @@ var _execSeam2 = {
|
|
|
24112
24404
|
const out2 = (0, import_child_process20.execFileSync)(file, args2, opts);
|
|
24113
24405
|
return typeof out2 === "string" ? out2 : out2.toString("utf8");
|
|
24114
24406
|
},
|
|
24115
|
-
realpath: (p2) =>
|
|
24407
|
+
realpath: (p2) => fs56.realpathSync(p2)
|
|
24116
24408
|
};
|
|
24117
24409
|
function readOrigin(cwd) {
|
|
24118
24410
|
try {
|
|
@@ -24141,7 +24433,7 @@ function deriveProjectIdentity(cwd = process.cwd()) {
|
|
|
24141
24433
|
} catch {
|
|
24142
24434
|
}
|
|
24143
24435
|
const hash = crypto2.createHash("sha256").update(real).digest("hex");
|
|
24144
|
-
return { projectKey: `path:${hash}`, projectLabel:
|
|
24436
|
+
return { projectKey: `path:${hash}`, projectLabel: path60.basename(real) || "project" };
|
|
24145
24437
|
}
|
|
24146
24438
|
|
|
24147
24439
|
// src/services/project-env/index.ts
|
|
@@ -24154,7 +24446,7 @@ async function readIfExists(p2) {
|
|
|
24154
24446
|
}
|
|
24155
24447
|
async function syncProjectEnvUp(cwd, ctx) {
|
|
24156
24448
|
if (!ctx.pluginAuthToken) return;
|
|
24157
|
-
const content = await readIfExists(
|
|
24449
|
+
const content = await readIfExists(path61.join(cwd, ".env"));
|
|
24158
24450
|
if (content == null) return;
|
|
24159
24451
|
try {
|
|
24160
24452
|
const { projectKey, projectLabel } = deriveProjectIdentity(cwd);
|
|
@@ -24176,7 +24468,7 @@ async function syncProjectEnvUp(cwd, ctx) {
|
|
|
24176
24468
|
}
|
|
24177
24469
|
async function restoreProjectEnvIfMissing(cwd, ctx) {
|
|
24178
24470
|
if (!ctx.pluginAuthToken) return false;
|
|
24179
|
-
const envPath =
|
|
24471
|
+
const envPath = path61.join(cwd, ".env");
|
|
24180
24472
|
if (await readIfExists(envPath) != null) return false;
|
|
24181
24473
|
try {
|
|
24182
24474
|
const { projectKey, projectLabel } = deriveProjectIdentity(cwd);
|
|
@@ -24187,7 +24479,7 @@ async function restoreProjectEnvIfMissing(cwd, ctx) {
|
|
|
24187
24479
|
projectKey
|
|
24188
24480
|
});
|
|
24189
24481
|
if (!stored) return false;
|
|
24190
|
-
const tmp =
|
|
24482
|
+
const tmp = path61.join(cwd, ".env.codeam-restore.tmp");
|
|
24191
24483
|
await import_fs6.promises.writeFile(tmp, stored.content, { encoding: "utf8", mode: 384 });
|
|
24192
24484
|
await import_fs6.promises.rename(tmp, envPath);
|
|
24193
24485
|
log.info("project-env", `restored .env (${stored.keyCount} vars) for ${projectLabel}`);
|
|
@@ -24264,8 +24556,8 @@ function normalizeDetectionForSpawn(detection, cwd) {
|
|
|
24264
24556
|
if (args2.length === 0) return detection;
|
|
24265
24557
|
const binName = args2[0];
|
|
24266
24558
|
if (binName.startsWith("-")) return detection;
|
|
24267
|
-
const binPath =
|
|
24268
|
-
if (!
|
|
24559
|
+
const binPath = path62.join(cwd, "node_modules", ".bin", binName);
|
|
24560
|
+
if (!fs58.existsSync(binPath)) return detection;
|
|
24269
24561
|
return {
|
|
24270
24562
|
...detection,
|
|
24271
24563
|
command: binPath,
|
|
@@ -24638,9 +24930,9 @@ async function establishTunnel(ctx, dev) {
|
|
|
24638
24930
|
|
|
24639
24931
|
// src/beads/bd-adapter.ts
|
|
24640
24932
|
var import_child_process22 = require("child_process");
|
|
24641
|
-
var
|
|
24642
|
-
var
|
|
24643
|
-
var
|
|
24933
|
+
var fs59 = __toESM(require("fs"));
|
|
24934
|
+
var os48 = __toESM(require("os"));
|
|
24935
|
+
var path63 = __toESM(require("path"));
|
|
24644
24936
|
var BD_PACKAGE = "@beads/bd";
|
|
24645
24937
|
function resolveBundledBdBinary() {
|
|
24646
24938
|
return _resolveSeam.resolveBundled();
|
|
@@ -24652,11 +24944,11 @@ function _defaultResolveBundled() {
|
|
|
24652
24944
|
} catch {
|
|
24653
24945
|
return null;
|
|
24654
24946
|
}
|
|
24655
|
-
const binDir =
|
|
24947
|
+
const binDir = path63.join(path63.dirname(pkgJsonPath), "bin");
|
|
24656
24948
|
const binaryName = process.platform === "win32" ? "bd.exe" : "bd";
|
|
24657
|
-
const binaryPath =
|
|
24949
|
+
const binaryPath = path63.join(binDir, binaryName);
|
|
24658
24950
|
try {
|
|
24659
|
-
|
|
24951
|
+
fs59.accessSync(binaryPath, fs59.constants.F_OK);
|
|
24660
24952
|
return binaryPath;
|
|
24661
24953
|
} catch {
|
|
24662
24954
|
return null;
|
|
@@ -24666,13 +24958,13 @@ function resolveBdOnPath() {
|
|
|
24666
24958
|
return _resolveSeam.resolveOnPath();
|
|
24667
24959
|
}
|
|
24668
24960
|
function _defaultResolveOnPath() {
|
|
24669
|
-
const dirs = (process.env.PATH ?? "").split(
|
|
24961
|
+
const dirs = (process.env.PATH ?? "").split(path63.delimiter).filter(Boolean);
|
|
24670
24962
|
const candidates = process.platform === "win32" ? ["bd.exe", "bd.cmd", "bd"] : ["bd"];
|
|
24671
24963
|
for (const dir of dirs) {
|
|
24672
24964
|
for (const candidate of candidates) {
|
|
24673
|
-
const full =
|
|
24965
|
+
const full = path63.join(dir, candidate);
|
|
24674
24966
|
try {
|
|
24675
|
-
|
|
24967
|
+
fs59.accessSync(full, fs59.constants.F_OK);
|
|
24676
24968
|
return full;
|
|
24677
24969
|
} catch {
|
|
24678
24970
|
}
|
|
@@ -24757,7 +25049,7 @@ var BdAdapter = class {
|
|
|
24757
25049
|
const env = { ...process.env };
|
|
24758
25050
|
if (!env.HOME) {
|
|
24759
25051
|
try {
|
|
24760
|
-
const home =
|
|
25052
|
+
const home = os48.homedir();
|
|
24761
25053
|
if (home) env.HOME = home;
|
|
24762
25054
|
} catch {
|
|
24763
25055
|
}
|
|
@@ -24849,9 +25141,9 @@ function coerceIssue(row, projectKey) {
|
|
|
24849
25141
|
|
|
24850
25142
|
// src/beads/provisioner.ts
|
|
24851
25143
|
var import_child_process25 = require("child_process");
|
|
24852
|
-
var
|
|
24853
|
-
var
|
|
24854
|
-
var
|
|
25144
|
+
var fs61 = __toESM(require("fs"));
|
|
25145
|
+
var os50 = __toESM(require("os"));
|
|
25146
|
+
var path65 = __toESM(require("path"));
|
|
24855
25147
|
|
|
24856
25148
|
// src/beads/install-bd.ts
|
|
24857
25149
|
var import_child_process23 = require("child_process");
|
|
@@ -24916,9 +25208,9 @@ async function installBd(platform3 = process.platform) {
|
|
|
24916
25208
|
|
|
24917
25209
|
// src/beads/install-dolt.ts
|
|
24918
25210
|
var import_child_process24 = require("child_process");
|
|
24919
|
-
var
|
|
24920
|
-
var
|
|
24921
|
-
var
|
|
25211
|
+
var fs60 = __toESM(require("fs"));
|
|
25212
|
+
var os49 = __toESM(require("os"));
|
|
25213
|
+
var path64 = __toESM(require("path"));
|
|
24922
25214
|
var DOLT_INSTALL_SH_URL = "https://github.com/dolthub/dolt/releases/latest/download/install.sh";
|
|
24923
25215
|
var DOLT_MSI_URL = "https://github.com/dolthub/dolt/releases/latest/download/dolt-windows-amd64.msi";
|
|
24924
25216
|
function resolveDoltInstallStrategy(platform3) {
|
|
@@ -25007,14 +25299,14 @@ async function installDoltToDir(targetDir, platform3 = process.platform, arch2 =
|
|
|
25007
25299
|
return result;
|
|
25008
25300
|
}
|
|
25009
25301
|
var _doltPathSeam = {
|
|
25010
|
-
homedir: () =>
|
|
25302
|
+
homedir: () => os49.homedir(),
|
|
25011
25303
|
getPath: () => process.env.PATH ?? "",
|
|
25012
25304
|
setPath: (p2) => {
|
|
25013
25305
|
process.env.PATH = p2;
|
|
25014
25306
|
},
|
|
25015
25307
|
exists: (p2) => {
|
|
25016
25308
|
try {
|
|
25017
|
-
|
|
25309
|
+
fs60.accessSync(p2, fs60.constants.F_OK);
|
|
25018
25310
|
return true;
|
|
25019
25311
|
} catch {
|
|
25020
25312
|
return false;
|
|
@@ -25025,7 +25317,7 @@ function doltBinaryNames(platform3) {
|
|
|
25025
25317
|
return platform3 === "win32" ? ["dolt.exe", "dolt.cmd", "dolt"] : ["dolt"];
|
|
25026
25318
|
}
|
|
25027
25319
|
function knownDoltDirs(platform3) {
|
|
25028
|
-
const P3 = platform3 === "win32" ?
|
|
25320
|
+
const P3 = platform3 === "win32" ? path64.win32 : path64.posix;
|
|
25029
25321
|
const home = _doltPathSeam.homedir();
|
|
25030
25322
|
if (platform3 === "win32") {
|
|
25031
25323
|
return [
|
|
@@ -25041,7 +25333,7 @@ function knownDoltDirs(platform3) {
|
|
|
25041
25333
|
].filter(Boolean);
|
|
25042
25334
|
}
|
|
25043
25335
|
function ensureDoltResolvable(platform3 = process.platform) {
|
|
25044
|
-
const P3 = platform3 === "win32" ?
|
|
25336
|
+
const P3 = platform3 === "win32" ? path64.win32 : path64.posix;
|
|
25045
25337
|
const delim = platform3 === "win32" ? ";" : ":";
|
|
25046
25338
|
const names = doltBinaryNames(platform3);
|
|
25047
25339
|
const pathDirs = _doltPathSeam.getPath().split(delim).filter(Boolean);
|
|
@@ -25218,17 +25510,17 @@ var _provisionSeam = {
|
|
|
25218
25510
|
};
|
|
25219
25511
|
var _linkSeam = {
|
|
25220
25512
|
platform: () => process.platform,
|
|
25221
|
-
homedir: () =>
|
|
25513
|
+
homedir: () => os50.homedir(),
|
|
25222
25514
|
isWritableDir: (dir) => {
|
|
25223
25515
|
try {
|
|
25224
|
-
|
|
25516
|
+
fs61.accessSync(dir, fs61.constants.W_OK);
|
|
25225
25517
|
return true;
|
|
25226
25518
|
} catch {
|
|
25227
25519
|
return false;
|
|
25228
25520
|
}
|
|
25229
25521
|
},
|
|
25230
25522
|
ensureDir: (dir) => {
|
|
25231
|
-
|
|
25523
|
+
fs61.mkdirSync(dir, { recursive: true });
|
|
25232
25524
|
},
|
|
25233
25525
|
/**
|
|
25234
25526
|
* A directory to symlink `bd` into so the AGENT's shell + Claude Code's
|
|
@@ -25249,9 +25541,9 @@ var _linkSeam = {
|
|
|
25249
25541
|
* which `linkBdOntoPath` creates if missing.
|
|
25250
25542
|
*/
|
|
25251
25543
|
cliBinDir: () => {
|
|
25252
|
-
const pathDirs = (process.env.PATH ?? "").split(
|
|
25544
|
+
const pathDirs = (process.env.PATH ?? "").split(path65.delimiter).filter(Boolean);
|
|
25253
25545
|
const home = _linkSeam.homedir();
|
|
25254
|
-
const localBin = home ?
|
|
25546
|
+
const localBin = home ? path65.join(home, ".local", "bin") : null;
|
|
25255
25547
|
if (localBin) {
|
|
25256
25548
|
try {
|
|
25257
25549
|
_linkSeam.ensureDir(localBin);
|
|
@@ -25261,16 +25553,16 @@ var _linkSeam = {
|
|
|
25261
25553
|
const candidates = [];
|
|
25262
25554
|
if (localBin) candidates.push(localBin);
|
|
25263
25555
|
try {
|
|
25264
|
-
candidates.push(
|
|
25556
|
+
candidates.push(path65.dirname(process.execPath));
|
|
25265
25557
|
} catch {
|
|
25266
25558
|
}
|
|
25267
25559
|
candidates.push("/usr/local/bin");
|
|
25268
25560
|
const entry = process.argv[1];
|
|
25269
25561
|
if (entry) {
|
|
25270
25562
|
try {
|
|
25271
|
-
candidates.push(
|
|
25563
|
+
candidates.push(path65.dirname(fs61.realpathSync(entry)));
|
|
25272
25564
|
} catch {
|
|
25273
|
-
candidates.push(
|
|
25565
|
+
candidates.push(path65.dirname(entry));
|
|
25274
25566
|
}
|
|
25275
25567
|
}
|
|
25276
25568
|
const onPathWritable = candidates.find(
|
|
@@ -25282,20 +25574,20 @@ var _linkSeam = {
|
|
|
25282
25574
|
/** Current symlink target at `linkPath`, or null when absent / not a link. */
|
|
25283
25575
|
readlink: (linkPath) => {
|
|
25284
25576
|
try {
|
|
25285
|
-
return
|
|
25577
|
+
return fs61.readlinkSync(linkPath);
|
|
25286
25578
|
} catch {
|
|
25287
25579
|
return null;
|
|
25288
25580
|
}
|
|
25289
25581
|
},
|
|
25290
|
-
unlink: (linkPath) =>
|
|
25291
|
-
symlink: (target, linkPath) =>
|
|
25582
|
+
unlink: (linkPath) => fs61.unlinkSync(linkPath),
|
|
25583
|
+
symlink: (target, linkPath) => fs61.symlinkSync(target, linkPath)
|
|
25292
25584
|
};
|
|
25293
25585
|
function linkBdOntoPath(binaryPath) {
|
|
25294
25586
|
if (_linkSeam.platform() === "win32") return;
|
|
25295
25587
|
const binDir = _linkSeam.cliBinDir();
|
|
25296
25588
|
if (!binDir) return;
|
|
25297
25589
|
_linkSeam.ensureDir(binDir);
|
|
25298
|
-
const linkPath =
|
|
25590
|
+
const linkPath = path65.join(binDir, "bd");
|
|
25299
25591
|
if (linkPath === binaryPath) return;
|
|
25300
25592
|
const current2 = _linkSeam.readlink(linkPath);
|
|
25301
25593
|
if (current2 === binaryPath) return;
|
|
@@ -25490,7 +25782,7 @@ function dedupeRecipes(agents) {
|
|
|
25490
25782
|
|
|
25491
25783
|
// src/beads/watcher.ts
|
|
25492
25784
|
var crypto4 = __toESM(require("crypto"));
|
|
25493
|
-
var
|
|
25785
|
+
var path66 = __toESM(require("path"));
|
|
25494
25786
|
var API_BASE6 = resolveApiBaseUrl();
|
|
25495
25787
|
var DEBOUNCE_MS2 = 400;
|
|
25496
25788
|
var ZERO_SUMMARY = {
|
|
@@ -25514,7 +25806,7 @@ var BeadsWatcher = class {
|
|
|
25514
25806
|
constructor(opts) {
|
|
25515
25807
|
this.opts = opts;
|
|
25516
25808
|
this.bd = opts.adapter ?? new BdAdapter({ cwd: opts.cwd, beadsDir: opts.beadsDir });
|
|
25517
|
-
this.feedPath = opts.feedPath ??
|
|
25809
|
+
this.feedPath = opts.feedPath ?? path66.join(opts.cwd ?? process.cwd(), ".beads", "last-touched");
|
|
25518
25810
|
this.apiBase = opts.apiBaseUrl ?? API_BASE6;
|
|
25519
25811
|
}
|
|
25520
25812
|
opts;
|
|
@@ -26013,8 +26305,8 @@ function cleanupAttachmentTempFiles() {
|
|
|
26013
26305
|
function saveFilesTemp(files) {
|
|
26014
26306
|
return files.filter(({ base64 }) => base64 && base64.length > 0).map(({ filename, base64 }) => {
|
|
26015
26307
|
const safeName = filename.replace(/[^a-zA-Z0-9._-]/g, "_").slice(0, 80);
|
|
26016
|
-
const tmpPath =
|
|
26017
|
-
|
|
26308
|
+
const tmpPath = path69.join(os54.tmpdir(), `codeam-${(0, import_crypto3.randomUUID)()}-${safeName}`);
|
|
26309
|
+
fs64.writeFileSync(tmpPath, Buffer.from(base64, "base64"));
|
|
26018
26310
|
pendingAttachmentFiles.add(tmpPath);
|
|
26019
26311
|
return tmpPath;
|
|
26020
26312
|
});
|
|
@@ -26232,10 +26524,10 @@ var listFiles = async (ctx, cmd, parsed) => {
|
|
|
26232
26524
|
await ctx.relay.sendResult(cmd.id, "completed", result);
|
|
26233
26525
|
};
|
|
26234
26526
|
var envReadH = async (ctx, cmd) => {
|
|
26235
|
-
const envPath =
|
|
26527
|
+
const envPath = path69.join(process.cwd(), ".env");
|
|
26236
26528
|
await restoreProjectEnvIfMissing(process.cwd(), ctx);
|
|
26237
26529
|
try {
|
|
26238
|
-
const raw = await
|
|
26530
|
+
const raw = await fs64.promises.readFile(envPath, "utf8");
|
|
26239
26531
|
await ctx.relay.sendResult(cmd.id, "completed", {
|
|
26240
26532
|
exists: true,
|
|
26241
26533
|
vars: parseDotenv(raw)
|
|
@@ -26266,15 +26558,15 @@ var envWriteH = async (ctx, cmd, parsed) => {
|
|
|
26266
26558
|
}
|
|
26267
26559
|
seen.add(v.key);
|
|
26268
26560
|
}
|
|
26269
|
-
const envPath =
|
|
26270
|
-
const tmpPath =
|
|
26561
|
+
const envPath = path69.join(process.cwd(), ".env");
|
|
26562
|
+
const tmpPath = path69.join(process.cwd(), ".env.codeam.tmp");
|
|
26271
26563
|
try {
|
|
26272
|
-
await
|
|
26273
|
-
await
|
|
26564
|
+
await fs64.promises.writeFile(tmpPath, serializeDotenv(vars), "utf8");
|
|
26565
|
+
await fs64.promises.rename(tmpPath, envPath);
|
|
26274
26566
|
await ctx.relay.sendResult(cmd.id, "completed", { ok: true, count: vars.length });
|
|
26275
26567
|
void syncProjectEnvUp(process.cwd(), ctx);
|
|
26276
26568
|
} catch (err) {
|
|
26277
|
-
await
|
|
26569
|
+
await fs64.promises.rm(tmpPath, { force: true }).catch(() => void 0);
|
|
26278
26570
|
await ctx.relay.sendResult(cmd.id, "failed", { error: err.message });
|
|
26279
26571
|
}
|
|
26280
26572
|
};
|
|
@@ -26323,7 +26615,7 @@ var headroomConfigureH = async (ctx, cmd, parsed) => {
|
|
|
26323
26615
|
let configuredAgent = rawAgentId;
|
|
26324
26616
|
if (!configuredAgent) {
|
|
26325
26617
|
try {
|
|
26326
|
-
const raw = JSON.parse(
|
|
26618
|
+
const raw = JSON.parse(fs64.readFileSync(headroomConfigPath(), "utf8"));
|
|
26327
26619
|
configuredAgent = raw.agent ?? "";
|
|
26328
26620
|
} catch {
|
|
26329
26621
|
}
|
|
@@ -26357,7 +26649,7 @@ var headroomConfigureH = async (ctx, cmd, parsed) => {
|
|
|
26357
26649
|
persist: persistHeadroomConfig,
|
|
26358
26650
|
readEnabled: () => {
|
|
26359
26651
|
try {
|
|
26360
|
-
const raw = JSON.parse(
|
|
26652
|
+
const raw = JSON.parse(fs64.readFileSync(headroomConfigPath(), "utf8"));
|
|
26361
26653
|
return raw.enabled === true;
|
|
26362
26654
|
} catch {
|
|
26363
26655
|
return false;
|
|
@@ -26679,7 +26971,7 @@ var headroomBudgetH = async (ctx, cmd) => {
|
|
|
26679
26971
|
}
|
|
26680
26972
|
let headroomActive = false;
|
|
26681
26973
|
try {
|
|
26682
|
-
const raw = JSON.parse(
|
|
26974
|
+
const raw = JSON.parse(fs64.readFileSync(headroomConfigPath(), "utf8"));
|
|
26683
26975
|
headroomActive = raw.enabled === true;
|
|
26684
26976
|
} catch {
|
|
26685
26977
|
}
|
|
@@ -26689,7 +26981,7 @@ var headroomBudgetH = async (ctx, cmd) => {
|
|
|
26689
26981
|
}
|
|
26690
26982
|
let existingConfig = { enabled: true };
|
|
26691
26983
|
try {
|
|
26692
|
-
existingConfig = JSON.parse(
|
|
26984
|
+
existingConfig = JSON.parse(fs64.readFileSync(headroomConfigPath(), "utf8"));
|
|
26693
26985
|
} catch {
|
|
26694
26986
|
}
|
|
26695
26987
|
if (payload.budgetEnabled && payload.budgetUsd != null) {
|
|
@@ -26802,9 +27094,9 @@ var CLI_UPDATE_MAX_ATTEMPTS = 3;
|
|
|
26802
27094
|
function buildNpmInstallInvocation(opts) {
|
|
26803
27095
|
const entryScript = opts?.entryScript ?? process.argv[1] ?? "";
|
|
26804
27096
|
const execPath = opts?.execPath ?? process.execPath;
|
|
26805
|
-
const exists2 = opts?.existsSync ??
|
|
27097
|
+
const exists2 = opts?.existsSync ?? fs64.existsSync;
|
|
26806
27098
|
const platform3 = opts?.platform ?? process.platform;
|
|
26807
|
-
const p2 = platform3 === "win32" ?
|
|
27099
|
+
const p2 = platform3 === "win32" ? path69.win32 : path69.posix;
|
|
26808
27100
|
const normalized = entryScript.split(/[\\/]/).join("/");
|
|
26809
27101
|
const marker = "/lib/node_modules/codeam-cli/";
|
|
26810
27102
|
const markerIdx = normalized.indexOf(marker);
|
|
@@ -26826,7 +27118,7 @@ function isPermissionError(stderr) {
|
|
|
26826
27118
|
function resolveGlobalNodeModulesDir(opts) {
|
|
26827
27119
|
const entryScript = opts?.entryScript ?? process.argv[1] ?? "";
|
|
26828
27120
|
const platform3 = opts?.platform ?? process.platform;
|
|
26829
|
-
const p2 = platform3 === "win32" ?
|
|
27121
|
+
const p2 = platform3 === "win32" ? path69.win32 : path69.posix;
|
|
26830
27122
|
const marker = "/lib/node_modules/codeam-cli/";
|
|
26831
27123
|
const markerIdx = entryScript.split(/[\\/]/).join("/").indexOf(marker);
|
|
26832
27124
|
if (markerIdx <= 0) return null;
|
|
@@ -26836,9 +27128,9 @@ function resolveGlobalNodeModulesDir(opts) {
|
|
|
26836
27128
|
var STALE_STAGING_AGE_MS = CLI_UPDATE_INSTALL_TIMEOUT_MS;
|
|
26837
27129
|
function sweepStaleCliStagingDirs(nodeModulesDir, now = Date.now(), deps) {
|
|
26838
27130
|
if (!nodeModulesDir) return 0;
|
|
26839
|
-
const readdirSync15 = deps?.readdirSync ??
|
|
26840
|
-
const statSync17 = deps?.statSync ??
|
|
26841
|
-
const rmSync9 = deps?.rmSync ??
|
|
27131
|
+
const readdirSync15 = deps?.readdirSync ?? fs64.readdirSync;
|
|
27132
|
+
const statSync17 = deps?.statSync ?? fs64.statSync;
|
|
27133
|
+
const rmSync9 = deps?.rmSync ?? fs64.rmSync;
|
|
26842
27134
|
let removed = 0;
|
|
26843
27135
|
let entries;
|
|
26844
27136
|
try {
|
|
@@ -26848,7 +27140,7 @@ function sweepStaleCliStagingDirs(nodeModulesDir, now = Date.now(), deps) {
|
|
|
26848
27140
|
}
|
|
26849
27141
|
for (const name of entries) {
|
|
26850
27142
|
if (!/^\.codeam-cli-/.test(name)) continue;
|
|
26851
|
-
const full =
|
|
27143
|
+
const full = path69.join(nodeModulesDir, name);
|
|
26852
27144
|
try {
|
|
26853
27145
|
const st3 = statSync17(full);
|
|
26854
27146
|
if (now - st3.mtimeMs < STALE_STAGING_AGE_MS) continue;
|
|
@@ -27728,7 +28020,7 @@ function resolveTokenValue(args2) {
|
|
|
27728
28020
|
if (fileFlag) {
|
|
27729
28021
|
const path92 = fileFlag.slice("--token-file=".length);
|
|
27730
28022
|
try {
|
|
27731
|
-
const content =
|
|
28023
|
+
const content = fs65.readFileSync(path92, "utf8").trim();
|
|
27732
28024
|
if (content.length === 0) fail(`--token-file ${path92} is empty`);
|
|
27733
28025
|
rmIfExistsQuiet(path92);
|
|
27734
28026
|
return content;
|
|
@@ -27759,7 +28051,7 @@ async function claimOnce(token, pluginId, pluginSecretHash) {
|
|
|
27759
28051
|
pluginId,
|
|
27760
28052
|
ideName: "codeam-cli (codespace)",
|
|
27761
28053
|
ideVersion: process.env.npm_package_version ?? "unknown",
|
|
27762
|
-
hostname:
|
|
28054
|
+
hostname: os55.hostname(),
|
|
27763
28055
|
codespaceName: process.env.CODESPACE_NAME ?? "",
|
|
27764
28056
|
// Current git branch of the codespace's working directory, so the
|
|
27765
28057
|
// backend can populate `PairedSession.branch` for the codespace pair.
|
|
@@ -27820,7 +28112,7 @@ async function claim(token, pluginId, pluginSecretHash) {
|
|
|
27820
28112
|
}
|
|
27821
28113
|
}
|
|
27822
28114
|
function pairAutoLockPath() {
|
|
27823
|
-
return
|
|
28115
|
+
return path70.join(os55.homedir(), ".codeam", "pair-auto.lock");
|
|
27824
28116
|
}
|
|
27825
28117
|
function isLivePairAuto(pid) {
|
|
27826
28118
|
if (!Number.isInteger(pid) || pid <= 0 || pid === process.pid) return false;
|
|
@@ -27830,7 +28122,7 @@ function isLivePairAuto(pid) {
|
|
|
27830
28122
|
if (e.code !== "EPERM") return false;
|
|
27831
28123
|
}
|
|
27832
28124
|
try {
|
|
27833
|
-
return
|
|
28125
|
+
return fs65.readFileSync(`/proc/${pid}/cmdline`, "utf8").includes("codeam");
|
|
27834
28126
|
} catch {
|
|
27835
28127
|
return true;
|
|
27836
28128
|
}
|
|
@@ -27840,24 +28132,24 @@ function isLiveCodeam(pid) {
|
|
|
27840
28132
|
}
|
|
27841
28133
|
function daemonLockPath(sessionId) {
|
|
27842
28134
|
const safe = sessionId.replace(/[^a-zA-Z0-9_-]/g, "_");
|
|
27843
|
-
return
|
|
28135
|
+
return path70.join(os55.homedir(), ".codeam", `daemon-${safe}.lock`);
|
|
27844
28136
|
}
|
|
27845
28137
|
function acquireDaemonLock(sessionId) {
|
|
27846
28138
|
const lockPath = daemonLockPath(sessionId);
|
|
27847
28139
|
try {
|
|
27848
|
-
|
|
28140
|
+
fs65.mkdirSync(path70.dirname(lockPath), { recursive: true });
|
|
27849
28141
|
try {
|
|
27850
|
-
|
|
28142
|
+
fs65.writeFileSync(lockPath, String(process.pid), { flag: "wx" });
|
|
27851
28143
|
} catch (e) {
|
|
27852
28144
|
if (e.code !== "EEXIST") throw e;
|
|
27853
|
-
const holder = Number(
|
|
28145
|
+
const holder = Number(fs65.readFileSync(lockPath, "utf8").trim());
|
|
27854
28146
|
if (holder && holder !== process.pid && isLiveCodeam(holder)) return false;
|
|
27855
|
-
|
|
28147
|
+
fs65.writeFileSync(lockPath, String(process.pid));
|
|
27856
28148
|
}
|
|
27857
28149
|
const release3 = () => {
|
|
27858
28150
|
try {
|
|
27859
|
-
if (
|
|
27860
|
-
|
|
28151
|
+
if (fs65.existsSync(lockPath) && Number(fs65.readFileSync(lockPath, "utf8").trim()) === process.pid) {
|
|
28152
|
+
fs65.unlinkSync(lockPath);
|
|
27861
28153
|
}
|
|
27862
28154
|
} catch {
|
|
27863
28155
|
}
|
|
@@ -27879,19 +28171,19 @@ function acquireDaemonLock(sessionId) {
|
|
|
27879
28171
|
function acquireSingletonLock() {
|
|
27880
28172
|
const lockPath = pairAutoLockPath();
|
|
27881
28173
|
try {
|
|
27882
|
-
|
|
28174
|
+
fs65.mkdirSync(path70.dirname(lockPath), { recursive: true });
|
|
27883
28175
|
try {
|
|
27884
|
-
|
|
28176
|
+
fs65.writeFileSync(lockPath, String(process.pid), { flag: "wx" });
|
|
27885
28177
|
} catch (e) {
|
|
27886
28178
|
if (e.code !== "EEXIST") throw e;
|
|
27887
|
-
const holder = Number(
|
|
28179
|
+
const holder = Number(fs65.readFileSync(lockPath, "utf8").trim());
|
|
27888
28180
|
if (isLivePairAuto(holder)) return false;
|
|
27889
|
-
|
|
28181
|
+
fs65.writeFileSync(lockPath, String(process.pid));
|
|
27890
28182
|
}
|
|
27891
28183
|
process.once("exit", () => {
|
|
27892
28184
|
try {
|
|
27893
|
-
if (
|
|
27894
|
-
|
|
28185
|
+
if (fs65.existsSync(lockPath) && Number(fs65.readFileSync(lockPath, "utf8").trim()) === process.pid) {
|
|
28186
|
+
fs65.unlinkSync(lockPath);
|
|
27895
28187
|
}
|
|
27896
28188
|
} catch {
|
|
27897
28189
|
}
|
|
@@ -28343,7 +28635,7 @@ var AgentService = class _AgentService {
|
|
|
28343
28635
|
};
|
|
28344
28636
|
|
|
28345
28637
|
// src/agents/acp/adapters.ts
|
|
28346
|
-
var
|
|
28638
|
+
var path71 = __toESM(require("path"));
|
|
28347
28639
|
|
|
28348
28640
|
// src/agents/kimi/installer.ts
|
|
28349
28641
|
var import_node_child_process27 = require("child_process");
|
|
@@ -28463,13 +28755,13 @@ function resolveBin(pkgName, binName) {
|
|
|
28463
28755
|
try {
|
|
28464
28756
|
const manifestPath = require_.resolve(`${pkgName}/package.json`);
|
|
28465
28757
|
const manifest = require_(`${pkgName}/package.json`);
|
|
28466
|
-
const pkgDir =
|
|
28758
|
+
const pkgDir = path71.dirname(manifestPath);
|
|
28467
28759
|
const bin = manifest.bin;
|
|
28468
28760
|
if (!bin) return null;
|
|
28469
|
-
if (typeof bin === "string") return
|
|
28761
|
+
if (typeof bin === "string") return path71.resolve(pkgDir, bin);
|
|
28470
28762
|
const target = binName ?? Object.keys(bin)[0];
|
|
28471
28763
|
if (!target || !bin[target]) return null;
|
|
28472
|
-
return
|
|
28764
|
+
return path71.resolve(pkgDir, bin[target]);
|
|
28473
28765
|
} catch {
|
|
28474
28766
|
return null;
|
|
28475
28767
|
}
|
|
@@ -28658,286 +28950,6 @@ var os56 = __toESM(require("os"));
|
|
|
28658
28950
|
var https7 = __toESM(require("https"));
|
|
28659
28951
|
var http6 = __toESM(require("http"));
|
|
28660
28952
|
var import_zod2 = require("zod");
|
|
28661
|
-
|
|
28662
|
-
// src/agents/acp/squad-roster.ts
|
|
28663
|
-
var fs65 = __toESM(require("fs"));
|
|
28664
|
-
var os55 = __toESM(require("os"));
|
|
28665
|
-
var path71 = __toESM(require("path"));
|
|
28666
|
-
var PROMPT_MAX = 500;
|
|
28667
|
-
var REPLY_SUMMARY_MAX = 1e3;
|
|
28668
|
-
var PREAMBLE_MAX = 2e3;
|
|
28669
|
-
var BRIEFING_DEFAULT_MAX = 8e3;
|
|
28670
|
-
var GENERIC_SPECIALTY = "general implementation tasks";
|
|
28671
|
-
function clip(s, max) {
|
|
28672
|
-
return s.length > max ? s.slice(0, max) : s;
|
|
28673
|
-
}
|
|
28674
|
-
function defaultMember() {
|
|
28675
|
-
return {
|
|
28676
|
-
acpSessionId: null,
|
|
28677
|
-
provisioned: false,
|
|
28678
|
-
binaryVerified: false,
|
|
28679
|
-
lastTurnIndex: 0,
|
|
28680
|
-
contextTextFallback: false
|
|
28681
|
-
};
|
|
28682
|
-
}
|
|
28683
|
-
function journalPathFor(homeDir2, sessionId) {
|
|
28684
|
-
return path71.join(homeDir2, ".codeam", `squad-journal-${sessionId}.json`);
|
|
28685
|
-
}
|
|
28686
|
-
function loadJournal(journalPath) {
|
|
28687
|
-
try {
|
|
28688
|
-
const raw = JSON.parse(fs65.readFileSync(journalPath, "utf-8"));
|
|
28689
|
-
return Array.isArray(raw.turns) ? raw.turns : [];
|
|
28690
|
-
} catch {
|
|
28691
|
-
return [];
|
|
28692
|
-
}
|
|
28693
|
-
}
|
|
28694
|
-
var SquadState = class {
|
|
28695
|
-
/** Set by the caller after fetchSquadRoster; null until then. */
|
|
28696
|
-
roster = null;
|
|
28697
|
-
/**
|
|
28698
|
-
* Autonomous chained handoffs (P2-2, PRO). Seeded from the persisted
|
|
28699
|
-
* `SavedSession.squadAuto` at session start and rewritten by
|
|
28700
|
-
* `squad_configure`. Read-only to callers — mutate via {@link setAuto}, which
|
|
28701
|
-
* clamps the budget and re-arms the chain.
|
|
28702
|
-
*/
|
|
28703
|
-
autoConfig = { enabled: false, hopBudget: SQUAD_HOP_BUDGET_DEFAULT };
|
|
28704
|
-
/**
|
|
28705
|
-
* Hops left in the CURRENT chain. Reset to the budget on every USER-initiated
|
|
28706
|
-
* prompt (so a user turn always interrupts and re-arms) and decremented by
|
|
28707
|
-
* each self-accepted handoff.
|
|
28708
|
-
*/
|
|
28709
|
-
hopsLeft = 0;
|
|
28710
|
-
/** Lifetime handoff counters for `squad_stats` (in-memory, this process). */
|
|
28711
|
-
handoffCounters = { proposed: 0, accepted: 0, auto: 0 };
|
|
28712
|
-
journalPath;
|
|
28713
|
-
turns;
|
|
28714
|
-
members = /* @__PURE__ */ new Map();
|
|
28715
|
-
constructor(opts) {
|
|
28716
|
-
this.journalPath = journalPathFor(opts.homeDir ?? os55.homedir(), opts.sessionId);
|
|
28717
|
-
this.turns = loadJournal(this.journalPath);
|
|
28718
|
-
if (opts.auto) this.setAuto(opts.auto);
|
|
28719
|
-
}
|
|
28720
|
-
get auto() {
|
|
28721
|
-
return this.autoConfig;
|
|
28722
|
-
}
|
|
28723
|
-
/** Apply a new mode (clamping the budget) and re-arm the chain. */
|
|
28724
|
-
setAuto(value) {
|
|
28725
|
-
this.autoConfig = {
|
|
28726
|
-
enabled: value.enabled === true,
|
|
28727
|
-
hopBudget: clampHopBudget(value.hopBudget)
|
|
28728
|
-
};
|
|
28729
|
-
this.resetHops();
|
|
28730
|
-
return this.autoConfig;
|
|
28731
|
-
}
|
|
28732
|
-
hopsRemaining() {
|
|
28733
|
-
return this.hopsLeft;
|
|
28734
|
-
}
|
|
28735
|
-
/** Re-arm the chain — called at the start of every USER-initiated turn. */
|
|
28736
|
-
resetHops() {
|
|
28737
|
-
this.hopsLeft = this.autoConfig.enabled ? this.autoConfig.hopBudget : 0;
|
|
28738
|
-
}
|
|
28739
|
-
/** Spend one hop on a self-accepted handoff. */
|
|
28740
|
-
consumeHop() {
|
|
28741
|
-
if (this.hopsLeft > 0) this.hopsLeft -= 1;
|
|
28742
|
-
}
|
|
28743
|
-
countProposal(opts) {
|
|
28744
|
-
this.handoffCounters.proposed += 1;
|
|
28745
|
-
if (opts.auto) this.handoffCounters.auto += 1;
|
|
28746
|
-
}
|
|
28747
|
-
countAccepted() {
|
|
28748
|
-
this.handoffCounters.accepted += 1;
|
|
28749
|
-
}
|
|
28750
|
-
/**
|
|
28751
|
-
* Per-member activity for the `squad_stats` relay command, derived from the
|
|
28752
|
-
* journal (the same shared history the delta briefing reads) plus the
|
|
28753
|
-
* in-memory handoff counters. `filesTouched` counts DISTINCT paths — a member
|
|
28754
|
-
* that edited the same file across three turns touched ONE file.
|
|
28755
|
-
*/
|
|
28756
|
-
stats() {
|
|
28757
|
-
const byAgent = /* @__PURE__ */ new Map();
|
|
28758
|
-
for (const t2 of this.turns) {
|
|
28759
|
-
let row = byAgent.get(t2.agentId);
|
|
28760
|
-
if (!row) {
|
|
28761
|
-
row = { turns: 0, files: /* @__PURE__ */ new Set() };
|
|
28762
|
-
byAgent.set(t2.agentId, row);
|
|
28763
|
-
}
|
|
28764
|
-
row.turns += 1;
|
|
28765
|
-
for (const f of t2.filesTouched) row.files.add(f);
|
|
28766
|
-
}
|
|
28767
|
-
const members = [...byAgent.entries()].map(([agentId, row]) => ({
|
|
28768
|
-
agentId,
|
|
28769
|
-
turns: row.turns,
|
|
28770
|
-
filesTouched: row.files.size
|
|
28771
|
-
}));
|
|
28772
|
-
return { members, handoffs: { ...this.handoffCounters }, sinceTurn: 1 };
|
|
28773
|
-
}
|
|
28774
|
-
/** Returns (creating on first access) the mutable per-agent state. */
|
|
28775
|
-
member(agentId) {
|
|
28776
|
-
let m = this.members.get(agentId);
|
|
28777
|
-
if (!m) {
|
|
28778
|
-
m = defaultMember();
|
|
28779
|
-
this.members.set(agentId, m);
|
|
28780
|
-
}
|
|
28781
|
-
return m;
|
|
28782
|
-
}
|
|
28783
|
-
/** Appends a journal entry and persists (fire-and-forget durability). */
|
|
28784
|
-
recordTurn(entry) {
|
|
28785
|
-
const turn = {
|
|
28786
|
-
turn: this.turns.length + 1,
|
|
28787
|
-
agentId: entry.agentId,
|
|
28788
|
-
prompt: clip(entry.prompt, PROMPT_MAX),
|
|
28789
|
-
replySummary: clip(entry.replySummary, REPLY_SUMMARY_MAX),
|
|
28790
|
-
filesTouched: entry.filesTouched
|
|
28791
|
-
};
|
|
28792
|
-
this.turns.push(turn);
|
|
28793
|
-
this.persist();
|
|
28794
|
-
}
|
|
28795
|
-
turnCount() {
|
|
28796
|
-
return this.turns.length;
|
|
28797
|
-
}
|
|
28798
|
-
entriesSince(turnIndex) {
|
|
28799
|
-
return this.turns.filter((t2) => t2.turn > turnIndex);
|
|
28800
|
-
}
|
|
28801
|
-
persist() {
|
|
28802
|
-
try {
|
|
28803
|
-
fs65.mkdirSync(path71.dirname(this.journalPath), { recursive: true, mode: 448 });
|
|
28804
|
-
fs65.writeFileSync(this.journalPath, JSON.stringify({ turns: this.turns }), { mode: 384 });
|
|
28805
|
-
} catch {
|
|
28806
|
-
}
|
|
28807
|
-
}
|
|
28808
|
-
};
|
|
28809
|
-
function specialtyFor(agentId) {
|
|
28810
|
-
return SQUAD_SPECIALTIES[agentId] ?? GENERIC_SPECIALTY;
|
|
28811
|
-
}
|
|
28812
|
-
var TEAM_PREAMBLE_MARKER = "[Team context]";
|
|
28813
|
-
var TEAM_PREAMBLE_LINES = [
|
|
28814
|
-
"[Team context] You are the active agent in a CodeAgent Mobile session where the user",
|
|
28815
|
-
"has a squad of agents and can pass work between them. Your available teammates:",
|
|
28816
|
-
"If a task clearly fits a teammate better than you, you MAY propose a handoff by ending",
|
|
28817
|
-
`your reply with a fenced code block tagged ${HANDOFF_FENCE_TAG} containing ONE JSON object:`,
|
|
28818
|
-
'{"to":"<teammate id>","reason":"<one sentence>","prompt":"<the prompt they should run>"}',
|
|
28819
|
-
"Propose at most one handoff per reply, only when genuinely better, and never announce",
|
|
28820
|
-
"the block in prose \u2014 the app renders it as a card the user can accept."
|
|
28821
|
-
];
|
|
28822
|
-
var TEAM_PREAMBLE_BULLET_RE = /^- .+ — best at: /;
|
|
28823
|
-
var BRIEFING_MARKER = "[Team update]";
|
|
28824
|
-
var BRIEFING_HEADER = "[Team update] While you were away, other agents worked on this session:";
|
|
28825
|
-
var BRIEFING_FOOTER = "Continue from the CURRENT state of the working tree.";
|
|
28826
|
-
function buildTeamPreamble(roster, currentAgent, opts) {
|
|
28827
|
-
const others = roster.agents.filter((a) => a.agentId !== currentAgent);
|
|
28828
|
-
if (others.length === 0) return null;
|
|
28829
|
-
const lines = [
|
|
28830
|
-
TEAM_PREAMBLE_LINES[0],
|
|
28831
|
-
TEAM_PREAMBLE_LINES[1],
|
|
28832
|
-
...others.map((a) => `- ${a.displayName} \u2014 best at: ${specialtyFor(a.agentId)}`)
|
|
28833
|
-
];
|
|
28834
|
-
if (opts.handoffInstructions) {
|
|
28835
|
-
lines.push(...TEAM_PREAMBLE_LINES.slice(2));
|
|
28836
|
-
}
|
|
28837
|
-
return clip(lines.join("\n"), PREAMBLE_MAX);
|
|
28838
|
-
}
|
|
28839
|
-
function renderJournalEntry(e) {
|
|
28840
|
-
const filesClause = e.filesTouched.length > 0 ? ` (files: ${e.filesTouched.join(", ")})` : "";
|
|
28841
|
-
return `- turn ${e.turn} (${e.agentId}): ${e.prompt} \u2192 ${e.replySummary}${filesClause}`;
|
|
28842
|
-
}
|
|
28843
|
-
function buildDeltaBriefing(entries, maxChars = BRIEFING_DEFAULT_MAX) {
|
|
28844
|
-
if (entries.length === 0) return null;
|
|
28845
|
-
const header = BRIEFING_HEADER;
|
|
28846
|
-
const footer = BRIEFING_FOOTER;
|
|
28847
|
-
const envelope = header.length + 1 + footer.length + 1;
|
|
28848
|
-
const sorted = [...entries].sort((a, b) => a.turn - b.turn);
|
|
28849
|
-
const lines = [];
|
|
28850
|
-
let bodyLen = 0;
|
|
28851
|
-
for (let i = sorted.length - 1; i >= 0; i--) {
|
|
28852
|
-
const line = renderJournalEntry(sorted[i]);
|
|
28853
|
-
const addedLen = line.length + (lines.length > 0 ? 1 : 0);
|
|
28854
|
-
if (lines.length > 0 && envelope + bodyLen + addedLen > maxChars) break;
|
|
28855
|
-
lines.unshift(line);
|
|
28856
|
-
bodyLen += addedLen;
|
|
28857
|
-
}
|
|
28858
|
-
return [header, lines.join("\n"), footer].join("\n");
|
|
28859
|
-
}
|
|
28860
|
-
|
|
28861
|
-
// src/agents/acp/squad-context.ts
|
|
28862
|
-
var SQUAD_CONTEXT_URI = "codeam://squad-context";
|
|
28863
|
-
var HANDOFF_MARKER = "[Session handoff]";
|
|
28864
|
-
var HANDOFF_TERMINATOR = "--- End of handoff context ---";
|
|
28865
|
-
function buildSquadContextBlock(text) {
|
|
28866
|
-
return {
|
|
28867
|
-
type: "resource",
|
|
28868
|
-
resource: { uri: SQUAD_CONTEXT_URI, mimeType: "text/plain", text }
|
|
28869
|
-
};
|
|
28870
|
-
}
|
|
28871
|
-
function isSquadContextBlock(block) {
|
|
28872
|
-
return block.type === "resource" && block.resource.uri === SQUAD_CONTEXT_URI;
|
|
28873
|
-
}
|
|
28874
|
-
function looksLikeUnsupportedPromptShape(err) {
|
|
28875
|
-
const code = err?.code;
|
|
28876
|
-
if (code === -32602) return true;
|
|
28877
|
-
const message = err instanceof Error ? err.message : String(err ?? "");
|
|
28878
|
-
if (/invalid[ _]params|-32602/i.test(message)) return true;
|
|
28879
|
-
return /\bresource\b/i.test(message) && /unsupported|not supported/i.test(message);
|
|
28880
|
-
}
|
|
28881
|
-
function skipWhile(lines, start2, keepGoing) {
|
|
28882
|
-
let i = start2;
|
|
28883
|
-
while (i < lines.length && keepGoing(lines[i])) i++;
|
|
28884
|
-
return i;
|
|
28885
|
-
}
|
|
28886
|
-
function endOfTeamPreamble(lines, start2) {
|
|
28887
|
-
if (lines[start2] !== TEAM_PREAMBLE_LINES[0]) return -1;
|
|
28888
|
-
if (lines[start2 + 1] !== TEAM_PREAMBLE_LINES[1]) return -1;
|
|
28889
|
-
return skipWhile(
|
|
28890
|
-
lines,
|
|
28891
|
-
start2 + 2,
|
|
28892
|
-
(line) => TEAM_PREAMBLE_BULLET_RE.test(line) || TEAM_PREAMBLE_LINES.includes(line)
|
|
28893
|
-
);
|
|
28894
|
-
}
|
|
28895
|
-
function endOfTerminatedBlock(lines, start2, terminator) {
|
|
28896
|
-
for (let i = start2; i < lines.length; i++) {
|
|
28897
|
-
if (lines[i].trimEnd() === terminator) return i + 1;
|
|
28898
|
-
}
|
|
28899
|
-
return -1;
|
|
28900
|
-
}
|
|
28901
|
-
function stripSquadContext(text) {
|
|
28902
|
-
if (!text.includes(HANDOFF_MARKER) && !text.includes(BRIEFING_MARKER) && !text.includes(TEAM_PREAMBLE_MARKER)) {
|
|
28903
|
-
return text;
|
|
28904
|
-
}
|
|
28905
|
-
const lines = text.split("\n");
|
|
28906
|
-
const kept = [];
|
|
28907
|
-
let i = 0;
|
|
28908
|
-
let stripped = false;
|
|
28909
|
-
while (i < lines.length) {
|
|
28910
|
-
const line = lines[i];
|
|
28911
|
-
if (line.startsWith(HANDOFF_MARKER)) {
|
|
28912
|
-
const end = endOfTerminatedBlock(lines, i, HANDOFF_TERMINATOR);
|
|
28913
|
-
if (end !== -1) {
|
|
28914
|
-
i = end;
|
|
28915
|
-
stripped = true;
|
|
28916
|
-
continue;
|
|
28917
|
-
}
|
|
28918
|
-
} else if (line.startsWith(BRIEFING_MARKER)) {
|
|
28919
|
-
const end = endOfTerminatedBlock(lines, i, BRIEFING_FOOTER);
|
|
28920
|
-
if (end !== -1) {
|
|
28921
|
-
i = end;
|
|
28922
|
-
stripped = true;
|
|
28923
|
-
continue;
|
|
28924
|
-
}
|
|
28925
|
-
} else if (line.startsWith(TEAM_PREAMBLE_MARKER)) {
|
|
28926
|
-
const end = endOfTeamPreamble(lines, i);
|
|
28927
|
-
if (end !== -1) {
|
|
28928
|
-
i = end;
|
|
28929
|
-
stripped = true;
|
|
28930
|
-
continue;
|
|
28931
|
-
}
|
|
28932
|
-
}
|
|
28933
|
-
kept.push(line);
|
|
28934
|
-
i++;
|
|
28935
|
-
}
|
|
28936
|
-
if (!stripped) return text;
|
|
28937
|
-
return kept.join("\n").trim();
|
|
28938
|
-
}
|
|
28939
|
-
|
|
28940
|
-
// src/services/history.service.ts
|
|
28941
28953
|
var historyRecordSchema = import_zod2.z.object({
|
|
28942
28954
|
type: import_zod2.z.string().optional(),
|
|
28943
28955
|
timestamp: import_zod2.z.union([import_zod2.z.string(), import_zod2.z.number()]).optional(),
|
|
@@ -28960,6 +28972,7 @@ var CONVERSATION_BATCH_SIZE = 30;
|
|
|
28960
28972
|
function scrubSquadContext(messages) {
|
|
28961
28973
|
const out2 = [];
|
|
28962
28974
|
for (const m of messages) {
|
|
28975
|
+
if (isLeakedSquadContextText(m.text) || isAgentMetaBlock(m.text)) continue;
|
|
28963
28976
|
const text = stripSquadContext(m.text);
|
|
28964
28977
|
if (text === m.text) {
|
|
28965
28978
|
out2.push(m);
|
|
@@ -28991,7 +29004,11 @@ function parseJsonl(filePath) {
|
|
|
28991
29004
|
}
|
|
28992
29005
|
const result = historyRecordSchema.safeParse(parsedJson);
|
|
28993
29006
|
if (!result.success) {
|
|
28994
|
-
log.warn(
|
|
29007
|
+
log.warn(
|
|
29008
|
+
"history:parseJsonl",
|
|
29009
|
+
`record failed schema validation in ${filePath}`,
|
|
29010
|
+
result.error.issues
|
|
29011
|
+
);
|
|
28995
29012
|
continue;
|
|
28996
29013
|
}
|
|
28997
29014
|
const record2 = result.data;
|
|
@@ -29256,7 +29273,14 @@ var HistoryService = class _HistoryService {
|
|
|
29256
29273
|
const inputTokens = (lastUsage["input_tokens"] ?? lastUsage["prompt_tokens"] ?? 0) + (lastUsage["cache_read_input_tokens"] ?? 0) + (lastUsage["cache_creation_input_tokens"] ?? 0);
|
|
29257
29274
|
const outputTokens = lastUsage["output_tokens"] ?? lastUsage["completion_tokens"] ?? 0;
|
|
29258
29275
|
const percent = Math.min(100, Math.round(inputTokens / total * 100));
|
|
29259
|
-
return {
|
|
29276
|
+
return {
|
|
29277
|
+
used: inputTokens,
|
|
29278
|
+
total,
|
|
29279
|
+
percent,
|
|
29280
|
+
model: lastModel,
|
|
29281
|
+
outputTokens,
|
|
29282
|
+
cacheReadTokens: lastUsage["cache_read_input_tokens"] ?? 0
|
|
29283
|
+
};
|
|
29260
29284
|
}
|
|
29261
29285
|
/**
|
|
29262
29286
|
* Estimate the API cost for the current month in the current project directory.
|
|
@@ -29429,7 +29453,9 @@ var HistoryService = class _HistoryService {
|
|
|
29429
29453
|
ok = await post("/api/sessions/conversation", body, this.pluginAuthToken);
|
|
29430
29454
|
}
|
|
29431
29455
|
if (!ok) {
|
|
29432
|
-
throw new Error(
|
|
29456
|
+
throw new Error(
|
|
29457
|
+
`Failed to upload conversation batch ${i + 1}/${totalBatches} after all retries`
|
|
29458
|
+
);
|
|
29433
29459
|
}
|
|
29434
29460
|
}
|
|
29435
29461
|
const last = messages[messages.length - 1];
|
|
@@ -44473,7 +44499,7 @@ function checkChokidar() {
|
|
|
44473
44499
|
}
|
|
44474
44500
|
async function doctor(args2 = []) {
|
|
44475
44501
|
const json = args2.includes("--json");
|
|
44476
|
-
const cliVersion = true ? "2.65.
|
|
44502
|
+
const cliVersion = true ? "2.65.3" : "0.0.0-dev";
|
|
44477
44503
|
const apiBase2 = resolveApiBaseUrl();
|
|
44478
44504
|
const diagnosticId = (0, import_node_crypto13.randomUUID)();
|
|
44479
44505
|
log.info("doctor", `run id=${diagnosticId} cli=${cliVersion}`);
|
|
@@ -44864,7 +44890,7 @@ async function mcpRun(args2) {
|
|
|
44864
44890
|
// src/commands/version.ts
|
|
44865
44891
|
var import_picocolors15 = __toESM(require("picocolors"));
|
|
44866
44892
|
function version2() {
|
|
44867
|
-
const v = true ? "2.65.
|
|
44893
|
+
const v = true ? "2.65.3" : "unknown";
|
|
44868
44894
|
console.log(`${import_picocolors15.default.bold("codeam-cli")} ${import_picocolors15.default.cyan(v)}`);
|
|
44869
44895
|
}
|
|
44870
44896
|
|