@chipschat/acp 1.0.2 → 1.0.4
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +24 -2
- package/dist/THIRD-PARTY-NOTICES.md +1 -1
- package/dist/main.js +1180 -119
- package/package.json +1 -1
package/dist/main.js
CHANGED
|
@@ -8,9 +8,9 @@ var __export = (target, all) => {
|
|
|
8
8
|
};
|
|
9
9
|
|
|
10
10
|
// src/main.ts
|
|
11
|
-
import { existsSync as
|
|
12
|
-
import { homedir as
|
|
13
|
-
import { basename as basename5, dirname as
|
|
11
|
+
import { existsSync as existsSync8, mkdirSync as mkdirSync4, readFileSync as readFileSync8, writeFileSync as writeFileSync4 } from "node:fs";
|
|
12
|
+
import { homedir as homedir7 } from "node:os";
|
|
13
|
+
import { basename as basename5, dirname as dirname5, join as join10, resolve as resolve4 } from "node:path";
|
|
14
14
|
|
|
15
15
|
// node_modules/zod/v4/classic/external.js
|
|
16
16
|
var external_exports = {};
|
|
@@ -1870,18 +1870,18 @@ var validateAsync = async (schema, value, _ctx) => {
|
|
|
1870
1870
|
return result.issues.length === 0;
|
|
1871
1871
|
};
|
|
1872
1872
|
var _encode = (_Err) => {
|
|
1873
|
-
const
|
|
1873
|
+
const parse4 = _parse(_Err);
|
|
1874
1874
|
const fn = (schema, value, _ctx, _params) => {
|
|
1875
1875
|
const ctx = _ctx ? { ..._ctx, direction: "backward" } : { direction: "backward" };
|
|
1876
|
-
return
|
|
1876
|
+
return parse4(schema, value, ctx, finalizeParams(fn, _params));
|
|
1877
1877
|
};
|
|
1878
1878
|
return fn;
|
|
1879
1879
|
};
|
|
1880
1880
|
var encode = /* @__PURE__ */ _encode($ZodRealError);
|
|
1881
1881
|
var _decode = (_Err) => {
|
|
1882
|
-
const
|
|
1882
|
+
const parse4 = _parse(_Err);
|
|
1883
1883
|
const fn = (schema, value, _ctx, _params) => {
|
|
1884
|
-
return
|
|
1884
|
+
return parse4(schema, value, _ctx, finalizeParams(fn, _params));
|
|
1885
1885
|
};
|
|
1886
1886
|
return fn;
|
|
1887
1887
|
};
|
|
@@ -3376,7 +3376,7 @@ function capSize(inst, size) {
|
|
|
3376
3376
|
if (!caps.length)
|
|
3377
3377
|
return;
|
|
3378
3378
|
const cap2 = Math.min(...caps.map((c) => c[0]));
|
|
3379
|
-
const
|
|
3379
|
+
const parse4 = inst._zod.parse;
|
|
3380
3380
|
inst._zod.parse = (payload, ctx) => {
|
|
3381
3381
|
const n = size(payload.value);
|
|
3382
3382
|
if (n > cap2 && !ctx?.skipChecks && ctx?.direction !== "backward") {
|
|
@@ -3390,7 +3390,7 @@ function capSize(inst, size) {
|
|
|
3390
3390
|
}
|
|
3391
3391
|
}
|
|
3392
3392
|
}
|
|
3393
|
-
return
|
|
3393
|
+
return parse4(payload, ctx);
|
|
3394
3394
|
};
|
|
3395
3395
|
}
|
|
3396
3396
|
var arraySize = (input2) => Array.isArray(input2) ? input2.length : -1;
|
|
@@ -20391,7 +20391,7 @@ var serverFacts = external_exports.object({
|
|
|
20391
20391
|
// node_modules/@chipschat/protocol/dist/src/room-files.js
|
|
20392
20392
|
var ROOM_FILES_IN_CONTEXT = 20;
|
|
20393
20393
|
var ROOM_FILES_CEILING = 200;
|
|
20394
|
-
var ROOM_FILES_HEADING = "Files in this
|
|
20394
|
+
var ROOM_FILES_HEADING = "Files in this space:";
|
|
20395
20395
|
var roomFile = external_exports.object({
|
|
20396
20396
|
name: external_exports.string().min(1).max(255).describe("The file's name, which its versions share."),
|
|
20397
20397
|
version: external_exports.int().positive().describe("Which version this is: 1 for the first, counting each change of its bytes."),
|
|
@@ -20482,7 +20482,7 @@ var MONTHS = [
|
|
|
20482
20482
|
|
|
20483
20483
|
// node_modules/@chipschat/protocol/dist/src/context.js
|
|
20484
20484
|
var CONTEXT_CEILING = { lines: 200, chars: 32e3 };
|
|
20485
|
-
var CONTEXT_HEADING = "Said in this
|
|
20485
|
+
var CONTEXT_HEADING = "Said in this space since you last spoke:";
|
|
20486
20486
|
var contextBudget = external_exports.object({
|
|
20487
20487
|
lines: external_exports.int().nonnegative().optional().describe("The most lines to be handed, 20 when absent. Chips hands over 200 at most, and none when this is 0."),
|
|
20488
20488
|
chars: external_exports.int().nonnegative().optional().describe("The most characters those lines may run to, as `Name: words` one per line, 4,000 when absent. Chips hands over 32,000 at most.")
|
|
@@ -20550,17 +20550,17 @@ function renderLine(line) {
|
|
|
20550
20550
|
case "said":
|
|
20551
20551
|
return `${withRole(name, line.from)}: ${wordsOf(line)}`;
|
|
20552
20552
|
case "joined":
|
|
20553
|
-
return `(${name} joined the
|
|
20553
|
+
return `(${name} joined the space)`;
|
|
20554
20554
|
case "left":
|
|
20555
|
-
return `(${name} left the
|
|
20555
|
+
return `(${name} left the space)`;
|
|
20556
20556
|
case "renamed":
|
|
20557
20557
|
if (line.title !== void 0)
|
|
20558
|
-
return `(${name} renamed the
|
|
20558
|
+
return `(${name} renamed the space "${line.title}")`;
|
|
20559
20559
|
return `(${line.previous ?? name} is now called ${line.name ?? name})`;
|
|
20560
20560
|
case "archived":
|
|
20561
|
-
return `(${name} archived the
|
|
20561
|
+
return `(${name} archived the space)`;
|
|
20562
20562
|
default:
|
|
20563
|
-
return `(${name} unarchived the
|
|
20563
|
+
return `(${name} unarchived the space)`;
|
|
20564
20564
|
}
|
|
20565
20565
|
}
|
|
20566
20566
|
function renderContext(context) {
|
|
@@ -20697,12 +20697,14 @@ var contextAnswer = {
|
|
|
20697
20697
|
message: external_exports.string().min(1).max(300).optional().describe("What went wrong, for the person.")
|
|
20698
20698
|
}).optional().describe("An edit not made. The copy beside it is the file as it is now.")
|
|
20699
20699
|
};
|
|
20700
|
+
var readNote = external_exports.string().min(1).max(300).describe("When the agent reads these, in the harness's words: `Hermes reads these when a conversation starts.` Absent: at the start of every turn.");
|
|
20700
20701
|
function uniqueNames(files) {
|
|
20701
20702
|
return new Set(files.map((file3) => file3.name)).size === files.length;
|
|
20702
20703
|
}
|
|
20703
20704
|
var agentContextPut = external_exports.object({
|
|
20704
20705
|
files: external_exports.array(contextFile).max(CONTEXT_FILES_SHOWN).refine(uniqueNames, { message: "Each file is named once." }).describe("The agent's files, in the order its page shows them: eight at most."),
|
|
20705
20706
|
not_shown: external_exports.array(notShownFile).max(CONTEXT_NOT_SHOWN_MAX).optional(),
|
|
20707
|
+
read_note: readNote.optional(),
|
|
20706
20708
|
...contextAnswer
|
|
20707
20709
|
}).describe("`PUT /v1/agents/:id/context`: a harness's copy of one of its agents' files.");
|
|
20708
20710
|
var harnessContextPut = external_exports.object({
|
|
@@ -20735,6 +20737,7 @@ var agentContextView = external_exports.object({
|
|
|
20735
20737
|
harness_id: id("harness"),
|
|
20736
20738
|
files: external_exports.array(contextFile),
|
|
20737
20739
|
not_shown: external_exports.array(notShownFile),
|
|
20740
|
+
read_note: readNote.optional(),
|
|
20738
20741
|
read_at: isoTimestamp.describe("When the harness last sent its copy."),
|
|
20739
20742
|
away: external_exports.boolean().describe("No socket of the harness hears edits now: read, but not saved.")
|
|
20740
20743
|
}).describe("`GET /v1/agents/:id/context`, for the harness's owner.");
|
|
@@ -21178,7 +21181,7 @@ function namesInWords(names) {
|
|
|
21178
21181
|
function renderProjectNote(facts, options) {
|
|
21179
21182
|
const files = `${facts.files} file${facts.files === 1 ? "" : "s"}`;
|
|
21180
21183
|
const lines2 = [
|
|
21181
|
-
`The
|
|
21184
|
+
`The space's project is a git repository. Your copy is ${facts.folder} (${files}), ${facts.trouble === void 0 ? "brought up to date just now" : "not brought up to date"}.`
|
|
21182
21185
|
];
|
|
21183
21186
|
if (facts.changed.length > 0) {
|
|
21184
21187
|
const by = facts.by.length > 0 ? `, by ${namesInWords(facts.by)}` : "";
|
|
@@ -21188,7 +21191,7 @@ function renderProjectNote(facts, options) {
|
|
|
21188
21191
|
lines2.push(`It couldn't be: ${facts.trouble}`);
|
|
21189
21192
|
if (facts.clashes.length > 0) {
|
|
21190
21193
|
const whose = facts.clashedWith.length > 0 ? `${namesInWords(facts.clashedWith)}'s` : "another change";
|
|
21191
|
-
lines2.push(`Your last change to ${namesInWords(facts.clashes)} clashed with ${whose}, which reached the
|
|
21194
|
+
lines2.push(`Your last change to ${namesInWords(facts.clashes)} clashed with ${whose}, which reached the space first. Both sides are in those files now: yours between "<<<<<<< yours" and "=======", theirs from there to the ">>>>>>>" line that names them. Settle each, keeping what both meant, and take the marks out. Nothing of yours is sent until they're gone.`);
|
|
21192
21195
|
}
|
|
21193
21196
|
for (const key of facts.keys) {
|
|
21194
21197
|
lines2.push(`${key.path} holds what looks like ${key.what}, so your last change wasn't sent: take it out and read it from outside the project.`);
|
|
@@ -22400,6 +22403,89 @@ var EVENT_TYPES = EVENTS.map((event) => event.type);
|
|
|
22400
22403
|
var byType = new Map(EVENTS.map((event) => [event.type, event]));
|
|
22401
22404
|
var schemas = new Map(EVENTS.map((event) => [event.type, eventSchema(event)]));
|
|
22402
22405
|
|
|
22406
|
+
// node_modules/@chipschat/protocol/dist/src/names.js
|
|
22407
|
+
var LOOK_LIKE = {
|
|
22408
|
+
A: "\u0410\u0391",
|
|
22409
|
+
// Cyrillic А, Greek Α
|
|
22410
|
+
B: "\u0412\u0392",
|
|
22411
|
+
// Cyrillic В, Greek Β
|
|
22412
|
+
C: "\u0421",
|
|
22413
|
+
// Cyrillic С
|
|
22414
|
+
E: "\u0415\u0395",
|
|
22415
|
+
// Cyrillic Е, Greek Ε
|
|
22416
|
+
H: "\u041D\u0397",
|
|
22417
|
+
// Cyrillic Н, Greek Η
|
|
22418
|
+
I: "\u0406\u04C0\u0399",
|
|
22419
|
+
// Cyrillic І and Ӏ, Greek Ι
|
|
22420
|
+
J: "\u0408",
|
|
22421
|
+
// Cyrillic Ј
|
|
22422
|
+
K: "\u041A\u039A",
|
|
22423
|
+
// Cyrillic К, Greek Κ
|
|
22424
|
+
M: "\u041C\u039C",
|
|
22425
|
+
// Cyrillic М, Greek Μ
|
|
22426
|
+
N: "\u039D",
|
|
22427
|
+
// Greek Ν
|
|
22428
|
+
O: "\u041E\u039F",
|
|
22429
|
+
// Cyrillic О, Greek Ο
|
|
22430
|
+
P: "\u0420\u03A1",
|
|
22431
|
+
// Cyrillic Р, Greek Ρ
|
|
22432
|
+
Q: "\u051A",
|
|
22433
|
+
// Cyrillic Ԛ
|
|
22434
|
+
S: "\u0405",
|
|
22435
|
+
// Cyrillic Ѕ
|
|
22436
|
+
T: "\u0422\u03A4",
|
|
22437
|
+
// Cyrillic Т, Greek Τ
|
|
22438
|
+
W: "\u051C",
|
|
22439
|
+
// Cyrillic Ԝ
|
|
22440
|
+
X: "\u0425\u03A7",
|
|
22441
|
+
// Cyrillic Х, Greek Χ
|
|
22442
|
+
Y: "\u0423\u04AE\u03A5",
|
|
22443
|
+
// Cyrillic У and Ү, Greek Υ
|
|
22444
|
+
Z: "\u0396",
|
|
22445
|
+
// Greek Ζ
|
|
22446
|
+
a: "\u0430\u03B1",
|
|
22447
|
+
// Cyrillic а, Greek α
|
|
22448
|
+
c: "\u0441",
|
|
22449
|
+
// Cyrillic с
|
|
22450
|
+
d: "\u0501",
|
|
22451
|
+
// Cyrillic ԁ
|
|
22452
|
+
e: "\u0435",
|
|
22453
|
+
// Cyrillic е
|
|
22454
|
+
h: "\u04BB",
|
|
22455
|
+
// Cyrillic һ
|
|
22456
|
+
i: "\u0456\u03B9\u0131",
|
|
22457
|
+
// Cyrillic і, Greek ι, Latin dotless ı
|
|
22458
|
+
j: "\u0458",
|
|
22459
|
+
// Cyrillic ј
|
|
22460
|
+
k: "\u03BA",
|
|
22461
|
+
// Greek κ
|
|
22462
|
+
l: "\u04CF",
|
|
22463
|
+
// Cyrillic ӏ
|
|
22464
|
+
o: "\u043E\u03BF",
|
|
22465
|
+
// Cyrillic о, Greek ο
|
|
22466
|
+
p: "\u0440\u03C1",
|
|
22467
|
+
// Cyrillic р, Greek ρ
|
|
22468
|
+
q: "\u051B",
|
|
22469
|
+
// Cyrillic ԛ
|
|
22470
|
+
s: "\u0455",
|
|
22471
|
+
// Cyrillic ѕ
|
|
22472
|
+
u: "\u03C5",
|
|
22473
|
+
// Greek υ
|
|
22474
|
+
v: "\u03BD",
|
|
22475
|
+
// Greek ν
|
|
22476
|
+
w: "\u051D",
|
|
22477
|
+
// Cyrillic ԝ
|
|
22478
|
+
x: "\u0445\u03C7",
|
|
22479
|
+
// Cyrillic х, Greek χ
|
|
22480
|
+
y: "\u0443\u04AF"
|
|
22481
|
+
// Cyrillic у and ү
|
|
22482
|
+
};
|
|
22483
|
+
var LATIN_OF = new Map(Object.entries(LOOK_LIKE).flatMap(([latin, others]) => [...others].map((other) => [other, latin])));
|
|
22484
|
+
var HIDDEN = "\\p{Cc}\\p{Cf}\\u034f\\u115f\\u1160\\u3164\\uffa0\\u2800";
|
|
22485
|
+
var UNSEEN = new RegExp(`[${HIDDEN}\\ufe00-\\ufe0f\\u{e0100}-\\u{e01ef}]`, "gu");
|
|
22486
|
+
var HIDDEN_ONE = new RegExp(`[${HIDDEN}]`, "u");
|
|
22487
|
+
var ALPHABETS = [new RegExp("\\p{Script=Latin}", "u"), new RegExp("\\p{Script=Cyrillic}", "u"), new RegExp("\\p{Script=Greek}", "u")];
|
|
22488
|
+
|
|
22403
22489
|
// node_modules/@chipschat/protocol/dist/src/first-names.js
|
|
22404
22490
|
var AGENT_FIRST_NAMES = [
|
|
22405
22491
|
"Abel Aldo Amir Amos Anders Ansel Anton Ari Arlo Arne Aron Arvid Asher Avi Axel Aziz",
|
|
@@ -22903,17 +22989,17 @@ function heldNote(pushed, name) {
|
|
|
22903
22989
|
return void 0;
|
|
22904
22990
|
case "clash": {
|
|
22905
22991
|
const whose = pushed.with.length === 0 ? "another change" : `${namesInWords(pushed.with)}'s change`;
|
|
22906
|
-
return `(Not in the
|
|
22992
|
+
return `(Not in the space's project yet: ${namesInWords(pushed.files)} clashed with ${whose}. ${name} is asked to settle it next turn.)`;
|
|
22907
22993
|
}
|
|
22908
22994
|
case "keys": {
|
|
22909
22995
|
const [first] = pushed.keys;
|
|
22910
22996
|
const held = pushed.keys.length === 1 && first !== void 0 ? `${first.path} looks like it holds ${first.what.replace(/, by its name$/, "")}` : `${namesInWords(pushed.keys.map((key) => key.path))} look like they hold keys`;
|
|
22911
|
-
return `(Not in the
|
|
22997
|
+
return `(Not in the space's project: ${held}, so nothing was sent.)`;
|
|
22912
22998
|
}
|
|
22913
22999
|
case "refused":
|
|
22914
|
-
return `(Not in the
|
|
23000
|
+
return `(Not in the space's project: it was turned back: ${stopped(pushed.why)})`;
|
|
22915
23001
|
case "failed":
|
|
22916
|
-
return `(Not in the
|
|
23002
|
+
return `(Not in the space's project: it couldn't be sent: ${stopped(pushed.why)})`;
|
|
22917
23003
|
}
|
|
22918
23004
|
}
|
|
22919
23005
|
async function checkGit(git2 = "git", path = process.env["PATH"] ?? "/usr/bin:/bin") {
|
|
@@ -23231,7 +23317,7 @@ ${sent.err}`;
|
|
|
23231
23317
|
const clashes = lines((await this.git(["diff", "--name-only", "--diff-filter=U"])).out);
|
|
23232
23318
|
if (clashes.length === 0)
|
|
23233
23319
|
return merged.ok ? {} : { trouble: remoteWords(merged.err) };
|
|
23234
|
-
const label2 = theirs.length === 1 ? theirs[0] ?? "the
|
|
23320
|
+
const label2 = theirs.length === 1 ? theirs[0] ?? "the space" : "the space";
|
|
23235
23321
|
for (const path of clashes)
|
|
23236
23322
|
await this.label(path, onto, label2);
|
|
23237
23323
|
return { clashes, clashedWith: theirs };
|
|
@@ -23353,7 +23439,7 @@ ${sent.err}`;
|
|
|
23353
23439
|
["merge.conflictStyle", "merge"],
|
|
23354
23440
|
["core.quotePath", "false"]
|
|
23355
23441
|
];
|
|
23356
|
-
const
|
|
23442
|
+
const env2 = {
|
|
23357
23443
|
// biome-ignore lint/style/noProcessEnv: git is found where the harness finds its tools.
|
|
23358
23444
|
PATH: options.path ?? process.env["PATH"] ?? "/usr/bin:/bin",
|
|
23359
23445
|
GIT_CONFIG_NOSYSTEM: "1",
|
|
@@ -23367,11 +23453,11 @@ ${sent.err}`;
|
|
|
23367
23453
|
GIT_CONFIG_COUNT: String(pairs.length)
|
|
23368
23454
|
};
|
|
23369
23455
|
pairs.forEach(([key, value], at) => {
|
|
23370
|
-
|
|
23371
|
-
|
|
23456
|
+
env2[`GIT_CONFIG_KEY_${at}`] = key;
|
|
23457
|
+
env2[`GIT_CONFIG_VALUE_${at}`] = value;
|
|
23372
23458
|
});
|
|
23373
23459
|
return new Promise((resolve5) => {
|
|
23374
|
-
execFile(options.git ?? "git", [...args], { cwd: this.copy, env, maxBuffer: 64 * 1024 * 1024 }, (error62, stdout, stderr) => resolve5({ ok: error62 === null, out: stdout, err: stderr }));
|
|
23460
|
+
execFile(options.git ?? "git", [...args], { cwd: this.copy, env: env2, maxBuffer: 64 * 1024 * 1024 }, (error62, stdout, stderr) => resolve5({ ok: error62 === null, out: stdout, err: stderr }));
|
|
23375
23461
|
});
|
|
23376
23462
|
}
|
|
23377
23463
|
};
|
|
@@ -24756,12 +24842,12 @@ function addPasswordCommand(account, secret) {
|
|
|
24756
24842
|
return `add-generic-password -U -a ${quoted(account)} -s ${quoted(SERVICE)} -w ${quoted(secret)}
|
|
24757
24843
|
`;
|
|
24758
24844
|
}
|
|
24759
|
-
function configHome(
|
|
24760
|
-
const own2 =
|
|
24845
|
+
function configHome(env2) {
|
|
24846
|
+
const own2 = env2["CHIPS_CONFIG_HOME"];
|
|
24761
24847
|
if (own2 !== void 0 && own2 !== "")
|
|
24762
24848
|
return own2;
|
|
24763
|
-
const xdg =
|
|
24764
|
-
return join2(xdg !== void 0 && xdg !== "" ? xdg : join2(
|
|
24849
|
+
const xdg = env2["XDG_CONFIG_HOME"];
|
|
24850
|
+
return join2(xdg !== void 0 && xdg !== "" ? xdg : join2(env2["HOME"] ?? homedir(), ".config"), "chips");
|
|
24765
24851
|
}
|
|
24766
24852
|
function answers(command, args) {
|
|
24767
24853
|
try {
|
|
@@ -24860,9 +24946,9 @@ function file2(path) {
|
|
|
24860
24946
|
}
|
|
24861
24947
|
};
|
|
24862
24948
|
}
|
|
24863
|
-
function openKeyStore(
|
|
24864
|
-
const plain = file2(join2(configHome(
|
|
24865
|
-
if (
|
|
24949
|
+
function openKeyStore(env2, platform = process.platform) {
|
|
24950
|
+
const plain = file2(join2(configHome(env2), "harness-keys.json"));
|
|
24951
|
+
if (env2["CHIPS_NO_KEYCHAIN"] === "true")
|
|
24866
24952
|
return plain;
|
|
24867
24953
|
if (platform === "darwin" && answers("/usr/bin/security", ["list-keychains"]))
|
|
24868
24954
|
return keychain();
|
|
@@ -24874,8 +24960,8 @@ function openKeyStore(env, platform = process.platform) {
|
|
|
24874
24960
|
// node_modules/@chipschat/harness/dist/steps.js
|
|
24875
24961
|
import { writeSync } from "node:fs";
|
|
24876
24962
|
var STEP_MARK = "chips-step ";
|
|
24877
|
-
function reportStep(step, detail = {},
|
|
24878
|
-
if (
|
|
24963
|
+
function reportStep(step, detail = {}, env2 = process.env, write = (line) => void writeSync(1, line)) {
|
|
24964
|
+
if (env2["CHIPS_STEPS"] !== "json")
|
|
24879
24965
|
return;
|
|
24880
24966
|
try {
|
|
24881
24967
|
write(`${STEP_MARK}${JSON.stringify({ step, ...detail })}
|
|
@@ -24893,15 +24979,15 @@ var JoinError = class extends Error {
|
|
|
24893
24979
|
this.refusal = refusal;
|
|
24894
24980
|
}
|
|
24895
24981
|
};
|
|
24896
|
-
function serverJsonUrl(
|
|
24982
|
+
function serverJsonUrl(env2) {
|
|
24897
24983
|
try {
|
|
24898
|
-
const said = JSON.parse(readFileSync2(joinPath(configHome(
|
|
24984
|
+
const said = JSON.parse(readFileSync2(joinPath(configHome(env2), "server.json"), "utf8"));
|
|
24899
24985
|
return typeof said.url === "string" && said.url !== "" ? said.url : void 0;
|
|
24900
24986
|
} catch {
|
|
24901
24987
|
return void 0;
|
|
24902
24988
|
}
|
|
24903
24989
|
}
|
|
24904
|
-
function findServer(options,
|
|
24990
|
+
function findServer(options, env2) {
|
|
24905
24991
|
if (options.link !== void 0) {
|
|
24906
24992
|
const parsed = parseJoinLink(options.link);
|
|
24907
24993
|
if (parsed === void 0) {
|
|
@@ -24909,7 +24995,7 @@ function findServer(options, env) {
|
|
|
24909
24995
|
}
|
|
24910
24996
|
return parsed;
|
|
24911
24997
|
}
|
|
24912
|
-
const url2 = options.url ??
|
|
24998
|
+
const url2 = options.url ?? env2["CHIPS_URL"] ?? serverJsonUrl(env2);
|
|
24913
24999
|
if (url2 === void 0 || url2 === "") {
|
|
24914
25000
|
throw new JoinError("nowhere", "Where is Chips? Pass a link or url, set CHIPS_URL, or run chips up on this machine.");
|
|
24915
25001
|
}
|
|
@@ -25016,10 +25102,10 @@ function askOrRedeem(server, options) {
|
|
|
25016
25102
|
}
|
|
25017
25103
|
var usedUp = (error62) => error62 instanceof JoinError && USED_UP.has(error62.refusal);
|
|
25018
25104
|
async function join3(options) {
|
|
25019
|
-
const
|
|
25020
|
-
reportStep("joining", {},
|
|
25021
|
-
const server = findServer(options,
|
|
25022
|
-
const store = options.keep ?? openKeyStore(
|
|
25105
|
+
const env2 = options.env ?? process.env;
|
|
25106
|
+
reportStep("joining", {}, env2);
|
|
25107
|
+
const server = findServer(options, env2);
|
|
25108
|
+
const store = options.keep ?? openKeyStore(env2);
|
|
25023
25109
|
const account = accountOf(server.url, options.name);
|
|
25024
25110
|
const kept2 = keptAt(store, account);
|
|
25025
25111
|
const from = server.secret === void 0 ? void 0 : linkHash(server.secret);
|
|
@@ -25066,8 +25152,8 @@ import { homedir as homedir2 } from "node:os";
|
|
|
25066
25152
|
import { basename as basename2, isAbsolute, resolve, sep } from "node:path";
|
|
25067
25153
|
import { fileURLToPath } from "node:url";
|
|
25068
25154
|
function sendingFiles(options = {}) {
|
|
25069
|
-
const which = options.project === true ? "A file that isn't in the
|
|
25070
|
-
return `${which} reaches this
|
|
25155
|
+
const which = options.project === true ? "A file that isn't in the space's project" : "A file";
|
|
25156
|
+
return `${which} reaches this space only when you send it: put MEDIA:<path> on a line of its own in your answer, one line for each file, from your own folder. A path, or a link to this machine, reaches nobody: the people and agents here cannot open your folder.`;
|
|
25071
25157
|
}
|
|
25072
25158
|
var SENDING_FILES = sendingFiles();
|
|
25073
25159
|
var MOST_FILES = 20;
|
|
@@ -25264,7 +25350,7 @@ var associatedApp = (app) => app === void 0 ? "" : ` <key>AssociatedBundleIdent
|
|
|
25264
25350
|
`;
|
|
25265
25351
|
function launchdPlist(spec, logFile, app) {
|
|
25266
25352
|
const args = spec.command.map((word) => ` <string>${xml(word)}</string>`).join("\n");
|
|
25267
|
-
const
|
|
25353
|
+
const env2 = Object.entries(spec.environment).map(([key, value]) => ` <key>${xml(key)}</key>
|
|
25268
25354
|
<string>${xml(value)}</string>`).join("\n");
|
|
25269
25355
|
return `<?xml version="1.0" encoding="UTF-8"?>
|
|
25270
25356
|
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
|
|
@@ -25281,7 +25367,7 @@ ${args}
|
|
|
25281
25367
|
<string>${xml(spec.folder)}</string>
|
|
25282
25368
|
<key>EnvironmentVariables</key>
|
|
25283
25369
|
<dict>
|
|
25284
|
-
${
|
|
25370
|
+
${env2}
|
|
25285
25371
|
</dict>
|
|
25286
25372
|
<key>RunAtLoad</key>
|
|
25287
25373
|
<true/>
|
|
@@ -25297,7 +25383,7 @@ ${env}
|
|
|
25297
25383
|
}
|
|
25298
25384
|
function systemdUnit(spec, logFile) {
|
|
25299
25385
|
const quote = (value) => `"${value.replace(/\\/g, "\\\\").replace(/"/g, '\\"')}"`;
|
|
25300
|
-
const
|
|
25386
|
+
const env2 = Object.entries(spec.environment).map(([key, value]) => `Environment=${quote(`${key}=${value}`)}`).join("\n");
|
|
25301
25387
|
return `# ${MARK}. Its bridge's \`npm run keep -- --stop\` stops it and removes this file.
|
|
25302
25388
|
[Unit]
|
|
25303
25389
|
Description=${spec.label}
|
|
@@ -25306,7 +25392,7 @@ After=network-online.target
|
|
|
25306
25392
|
[Service]
|
|
25307
25393
|
ExecStart=${spec.command.map(quote).join(" ")}
|
|
25308
25394
|
WorkingDirectory=${quote(spec.folder)}
|
|
25309
|
-
${
|
|
25395
|
+
${env2}
|
|
25310
25396
|
Restart=always
|
|
25311
25397
|
RestartSec=5
|
|
25312
25398
|
StandardOutput=append:${logFile}
|
|
@@ -25342,9 +25428,9 @@ var HANDED_OVER = /* @__PURE__ */ new Set([
|
|
|
25342
25428
|
"CHIPS_STOP_COMMAND",
|
|
25343
25429
|
"CHIPS_STEPS"
|
|
25344
25430
|
]);
|
|
25345
|
-
function keepEnvironment(url2,
|
|
25431
|
+
function keepEnvironment(url2, env2 = process.env, names = [], node2) {
|
|
25346
25432
|
const kept2 = { CHIPS_URL: url2 };
|
|
25347
|
-
for (const [name, value] of Object.entries(
|
|
25433
|
+
for (const [name, value] of Object.entries(env2)) {
|
|
25348
25434
|
if (value === void 0 || value === "")
|
|
25349
25435
|
continue;
|
|
25350
25436
|
if (name === "PATH" || names.includes(name) || name.startsWith("CHIPS_") && !HANDED_OVER.has(name))
|
|
@@ -25359,12 +25445,12 @@ function nodeFirst(folder2, path) {
|
|
|
25359
25445
|
const rest = (path ?? "").split(delimiter).filter((each) => each !== "" && each !== folder2);
|
|
25360
25446
|
return [folder2, ...rest].join(delimiter);
|
|
25361
25447
|
}
|
|
25362
|
-
function keptNode(
|
|
25363
|
-
const given =
|
|
25364
|
-
return given !== void 0 && given !== "" ? given : nodeOnPath(
|
|
25448
|
+
function keptNode(env2 = process.env) {
|
|
25449
|
+
const given = env2["CHIPS_NODE"];
|
|
25450
|
+
return given !== void 0 && given !== "" ? given : nodeOnPath(env2);
|
|
25365
25451
|
}
|
|
25366
|
-
function nodeOnPath(
|
|
25367
|
-
for (const folder2 of (
|
|
25452
|
+
function nodeOnPath(env2 = process.env) {
|
|
25453
|
+
for (const folder2 of (env2["PATH"] ?? "").split(delimiter)) {
|
|
25368
25454
|
if (folder2 === "")
|
|
25369
25455
|
continue;
|
|
25370
25456
|
try {
|
|
@@ -25475,10 +25561,10 @@ var AcpError = class extends Error {
|
|
|
25475
25561
|
function isAuthRequired(error62) {
|
|
25476
25562
|
return error62 instanceof AcpError && error62.code === -32e3 && /auth/i.test(error62.message);
|
|
25477
25563
|
}
|
|
25478
|
-
function processWire(command, cwd,
|
|
25564
|
+
function processWire(command, cwd, env2, log2) {
|
|
25479
25565
|
const [program, ...args] = command;
|
|
25480
25566
|
if (program === void 0) throw new Error("an agent needs a command");
|
|
25481
|
-
const child = spawn(program, args, { cwd, env, stdio: ["pipe", "pipe", "pipe"] });
|
|
25567
|
+
const child = spawn(program, args, { cwd, env: env2, stdio: ["pipe", "pipe", "pipe"] });
|
|
25482
25568
|
const lines2 = createInterface({ input: child.stdout });
|
|
25483
25569
|
createInterface({ input: child.stderr }).on("line", log2);
|
|
25484
25570
|
const closers = [];
|
|
@@ -25543,19 +25629,22 @@ var AcpClient = class {
|
|
|
25543
25629
|
...typeof info["name"] === "string" ? { name: info["name"] } : {}
|
|
25544
25630
|
};
|
|
25545
25631
|
}
|
|
25546
|
-
/**
|
|
25547
|
-
|
|
25548
|
-
|
|
25632
|
+
/**
|
|
25633
|
+
* A new session in `cwd`. Answers with its id and anything it said it can be set to. `meta` is
|
|
25634
|
+
* the agent's own `_meta`: Claude Code's takes its settings there (`claudeCode.options.settings`).
|
|
25635
|
+
*/
|
|
25636
|
+
async newSession(cwd, mcpServers = [], meta3) {
|
|
25637
|
+
const answer = await this.call("session/new", { cwd, mcpServers, ...metaOf(meta3) });
|
|
25549
25638
|
return { sessionId: String(answer["sessionId"]), configOptions: configOptionsOf(answer) };
|
|
25550
25639
|
}
|
|
25551
25640
|
/** A session it had before, back: its history comes as `session/update`s first. */
|
|
25552
|
-
async loadSession(sessionId, cwd, mcpServers = []) {
|
|
25553
|
-
const answer = await this.call("session/load", { sessionId, cwd, mcpServers });
|
|
25641
|
+
async loadSession(sessionId, cwd, mcpServers = [], meta3) {
|
|
25642
|
+
const answer = await this.call("session/load", { sessionId, cwd, mcpServers, ...metaOf(meta3) });
|
|
25554
25643
|
return { configOptions: configOptionsOf(answer ?? {}) };
|
|
25555
25644
|
}
|
|
25556
25645
|
/** A copy of a session, remembering everything it does, working in `cwd`. Answers with the copy's id. */
|
|
25557
|
-
async forkSession(sessionId, cwd, mcpServers = []) {
|
|
25558
|
-
const answer = await this.call("session/fork", { sessionId, cwd, mcpServers });
|
|
25646
|
+
async forkSession(sessionId, cwd, mcpServers = [], meta3) {
|
|
25647
|
+
const answer = await this.call("session/fork", { sessionId, cwd, mcpServers, ...metaOf(meta3) });
|
|
25559
25648
|
if (typeof answer["sessionId"] !== "string") throw new AcpError("the agent copied the session and named no copy", -32e3);
|
|
25560
25649
|
return answer["sessionId"];
|
|
25561
25650
|
}
|
|
@@ -25674,15 +25763,386 @@ function configOptionsOf(answer) {
|
|
|
25674
25763
|
];
|
|
25675
25764
|
});
|
|
25676
25765
|
}
|
|
25766
|
+
function metaOf(meta3) {
|
|
25767
|
+
return meta3 === void 0 ? {} : { _meta: meta3 };
|
|
25768
|
+
}
|
|
25677
25769
|
function notOffered(method) {
|
|
25678
25770
|
return new AcpError(`${method} is not offered by this client`, -32601);
|
|
25679
25771
|
}
|
|
25680
25772
|
|
|
25681
25773
|
// src/bridge.ts
|
|
25682
25774
|
import { randomBytes } from "node:crypto";
|
|
25683
|
-
import { existsSync as
|
|
25684
|
-
import { mkdir as
|
|
25775
|
+
import { existsSync as existsSync6 } from "node:fs";
|
|
25776
|
+
import { mkdir as mkdir3, writeFile as writeFile3 } from "node:fs/promises";
|
|
25777
|
+
import { homedir as homedir4 } from "node:os";
|
|
25778
|
+
import { join as join7 } from "node:path";
|
|
25779
|
+
|
|
25780
|
+
// src/claude-settings.ts
|
|
25781
|
+
import { existsSync as existsSync5, readFileSync as readFileSync5 } from "node:fs";
|
|
25685
25782
|
import { join as join5 } from "node:path";
|
|
25783
|
+
var isRecord = (value) => typeof value === "object" && value !== null && !Array.isArray(value);
|
|
25784
|
+
function readLayer(path) {
|
|
25785
|
+
if (!existsSync5(path)) return void 0;
|
|
25786
|
+
try {
|
|
25787
|
+
const read = JSON.parse(readFileSync5(path, "utf8"));
|
|
25788
|
+
return isRecord(read) ? read : void 0;
|
|
25789
|
+
} catch {
|
|
25790
|
+
return void 0;
|
|
25791
|
+
}
|
|
25792
|
+
}
|
|
25793
|
+
function settingsLayers(claudeHome, folder2) {
|
|
25794
|
+
return [
|
|
25795
|
+
join5(claudeHome, "settings.json"),
|
|
25796
|
+
join5(folder2, ".claude", "settings.json"),
|
|
25797
|
+
join5(folder2, ".claude", "settings.local.json")
|
|
25798
|
+
].flatMap((path) => {
|
|
25799
|
+
const layer = readLayer(path);
|
|
25800
|
+
return layer === void 0 ? [] : [layer];
|
|
25801
|
+
});
|
|
25802
|
+
}
|
|
25803
|
+
function lastSaid(layers, key) {
|
|
25804
|
+
return layers.findLast((layer) => layer[key] !== void 0)?.[key];
|
|
25805
|
+
}
|
|
25806
|
+
function memoryOn(layers) {
|
|
25807
|
+
return lastSaid(layers, "autoMemoryEnabled") !== false;
|
|
25808
|
+
}
|
|
25809
|
+
function autoCompactOn(layers) {
|
|
25810
|
+
return lastSaid(layers, "autoCompactEnabled") !== false;
|
|
25811
|
+
}
|
|
25812
|
+
function canonicalModel(name) {
|
|
25813
|
+
return name.trim().toLowerCase().replace(/\[1m\]$/, "").replace(/-\d{8}$/, "");
|
|
25814
|
+
}
|
|
25815
|
+
function autoCompactWindowOf(layers, model) {
|
|
25816
|
+
let top;
|
|
25817
|
+
let byModel = {};
|
|
25818
|
+
for (const layer of layers) {
|
|
25819
|
+
const mine = {};
|
|
25820
|
+
const models = layer["modelSettings"];
|
|
25821
|
+
if (isRecord(models)) {
|
|
25822
|
+
for (const [name, value] of Object.entries(models)) {
|
|
25823
|
+
if (!isRecord(value) || value["autoCompactWindow"] === void 0) continue;
|
|
25824
|
+
const key2 = canonicalModel(name);
|
|
25825
|
+
if (name === key2 || !(key2 in mine)) mine[key2] = value["autoCompactWindow"];
|
|
25826
|
+
}
|
|
25827
|
+
}
|
|
25828
|
+
if (layer["autoCompactWindow"] === void 0) byModel = { ...byModel, ...mine };
|
|
25829
|
+
else {
|
|
25830
|
+
top = layer["autoCompactWindow"];
|
|
25831
|
+
byModel = mine;
|
|
25832
|
+
}
|
|
25833
|
+
}
|
|
25834
|
+
const key = model === void 0 ? void 0 : canonicalModel(model);
|
|
25835
|
+
const chosen = key !== void 0 && key in byModel ? byModel[key] : top;
|
|
25836
|
+
return typeof chosen === "number" && Number.isFinite(chosen) && chosen > 0 ? chosen : void 0;
|
|
25837
|
+
}
|
|
25838
|
+
function autoCompactWindowFromEnv(env2) {
|
|
25839
|
+
const said = /^\s*(\d+(?:\.\d+)?)\s*([km]?)\s*$/i.exec(env2["CLAUDE_CODE_AUTO_COMPACT_WINDOW"] ?? "");
|
|
25840
|
+
if (said === null) return void 0;
|
|
25841
|
+
const scale = { "": 1, k: 1e3, m: 1e6 }[(said[2] ?? "").toLowerCase()] ?? 1;
|
|
25842
|
+
const tokens2 = Math.round(Number(said[1]) * scale);
|
|
25843
|
+
return tokens2 > 0 ? tokens2 : void 0;
|
|
25844
|
+
}
|
|
25845
|
+
function memoryPath(claudeHome, folder2) {
|
|
25846
|
+
const name = folder2.replace(/[^a-zA-Z0-9]/g, "-");
|
|
25847
|
+
return name.length > 200 ? void 0 : join5(claudeHome, "projects", name, "memory", "MEMORY.md");
|
|
25848
|
+
}
|
|
25849
|
+
|
|
25850
|
+
// src/context.ts
|
|
25851
|
+
import { createHash as createHash2 } from "node:crypto";
|
|
25852
|
+
import { readdirSync, readFileSync as readFileSync6, statSync } from "node:fs";
|
|
25853
|
+
import { mkdir as mkdir2, writeFile as writeFile2 } from "node:fs/promises";
|
|
25854
|
+
import { dirname as dirname4, join as join6, parse as parse3, relative, sep as sep2 } from "node:path";
|
|
25855
|
+
function placesOf(env2, home3) {
|
|
25856
|
+
return {
|
|
25857
|
+
home: home3,
|
|
25858
|
+
claudeHome: env2["CLAUDE_CONFIG_DIR"] || join6(home3, ".claude"),
|
|
25859
|
+
codexHome: env2["CODEX_HOME"] || join6(home3, ".codex")
|
|
25860
|
+
};
|
|
25861
|
+
}
|
|
25862
|
+
function hashOf(text) {
|
|
25863
|
+
return createHash2("sha256").update(text, "utf8").digest("hex");
|
|
25864
|
+
}
|
|
25865
|
+
function isFile(path) {
|
|
25866
|
+
try {
|
|
25867
|
+
return statSync(path).isFile();
|
|
25868
|
+
} catch {
|
|
25869
|
+
return false;
|
|
25870
|
+
}
|
|
25871
|
+
}
|
|
25872
|
+
function textOf(path) {
|
|
25873
|
+
try {
|
|
25874
|
+
return readFileSync6(path, "utf8");
|
|
25875
|
+
} catch {
|
|
25876
|
+
return void 0;
|
|
25877
|
+
}
|
|
25878
|
+
}
|
|
25879
|
+
function claudeFilesIn(dir) {
|
|
25880
|
+
const rules = join6(dir, ".claude", "rules");
|
|
25881
|
+
let named = [];
|
|
25882
|
+
try {
|
|
25883
|
+
named = readdirSync(rules).filter((name) => name.endsWith(".md")).sort();
|
|
25884
|
+
} catch {
|
|
25885
|
+
named = [];
|
|
25886
|
+
}
|
|
25887
|
+
return [
|
|
25888
|
+
join6(dir, "CLAUDE.md"),
|
|
25889
|
+
join6(dir, "CLAUDE.local.md"),
|
|
25890
|
+
join6(dir, ".claude", "CLAUDE.md"),
|
|
25891
|
+
...named.map((name) => join6(rules, name))
|
|
25892
|
+
];
|
|
25893
|
+
}
|
|
25894
|
+
function ownTitle(within3) {
|
|
25895
|
+
if (within3 === "CLAUDE.md") return "How it works";
|
|
25896
|
+
if (within3 === "CLAUDE.local.md") return "Its local instructions";
|
|
25897
|
+
if (within3 === join6(".claude", "CLAUDE.md")) return "More of how it works";
|
|
25898
|
+
return `Rule: ${parse3(within3).name}`.slice(0, 80);
|
|
25899
|
+
}
|
|
25900
|
+
function readNote2(name) {
|
|
25901
|
+
return `${name} reads these when a conversation starts. A change made here applies from the next message.`;
|
|
25902
|
+
}
|
|
25903
|
+
var within = (path, dir) => path === dir || path.startsWith(`${dir}${sep2}`);
|
|
25904
|
+
function* upFrom(dir) {
|
|
25905
|
+
for (let at = dir; ; at = dirname4(at)) {
|
|
25906
|
+
yield at;
|
|
25907
|
+
if (dirname4(at) === at) return;
|
|
25908
|
+
}
|
|
25909
|
+
}
|
|
25910
|
+
var ContextFiles = class {
|
|
25911
|
+
constructor(id2, kind2, places, docBytes) {
|
|
25912
|
+
this.id = id2;
|
|
25913
|
+
this.kind = kind2;
|
|
25914
|
+
this.places = places;
|
|
25915
|
+
this.docBytes = docBytes;
|
|
25916
|
+
}
|
|
25917
|
+
id;
|
|
25918
|
+
kind;
|
|
25919
|
+
places;
|
|
25920
|
+
docBytes;
|
|
25921
|
+
/** `~/chips-acp/claude-code/CLAUDE.md`, or the whole path where it isn't in the home. */
|
|
25922
|
+
tilde(path) {
|
|
25923
|
+
const { home: home3 } = this.places;
|
|
25924
|
+
return within(path, home3) ? `~${path.slice(home3.length)}` : path;
|
|
25925
|
+
}
|
|
25926
|
+
/** A shared file's name: where it is, a step at a time (`~ › .codex › AGENTS.md`), with no slash. */
|
|
25927
|
+
crumbs(path) {
|
|
25928
|
+
const { home: home3 } = this.places;
|
|
25929
|
+
const steps = within(path, home3) ? ["~", ...relative(home3, path).split(sep2)] : ["/", ...path.split(sep2)];
|
|
25930
|
+
return steps.filter((step) => step !== "").join(" \u203A ").slice(0, 255);
|
|
25931
|
+
}
|
|
25932
|
+
/** The harness's own set: what every agent, or every agent below a folder, reads beside its own. */
|
|
25933
|
+
sharedSpots() {
|
|
25934
|
+
const { places, kind: kind2 } = this;
|
|
25935
|
+
if (this.id === "codex") {
|
|
25936
|
+
const yours2 = [join6(places.codexHome, "AGENTS.override.md"), join6(places.codexHome, "AGENTS.md")].find(isFile);
|
|
25937
|
+
if (yours2 === void 0) return [];
|
|
25938
|
+
return [
|
|
25939
|
+
{
|
|
25940
|
+
path: yours2,
|
|
25941
|
+
name: this.crumbs(yours2),
|
|
25942
|
+
title: "For all your Codex",
|
|
25943
|
+
role: "instructions",
|
|
25944
|
+
about: this.tilde(yours2),
|
|
25945
|
+
editable: false,
|
|
25946
|
+
whyReadOnly: "Your own Codex reads it too.",
|
|
25947
|
+
id: "yours"
|
|
25948
|
+
}
|
|
25949
|
+
];
|
|
25950
|
+
}
|
|
25951
|
+
const spots = [];
|
|
25952
|
+
if (kind2.folder === void 0) {
|
|
25953
|
+
const path = join6(kind2.folders, "CLAUDE.md");
|
|
25954
|
+
spots.push({
|
|
25955
|
+
path,
|
|
25956
|
+
name: this.crumbs(path),
|
|
25957
|
+
title: `For every ${kind2.name} agent`.slice(0, 80),
|
|
25958
|
+
role: "instructions",
|
|
25959
|
+
about: this.tilde(path),
|
|
25960
|
+
editable: true,
|
|
25961
|
+
id: "every-agent",
|
|
25962
|
+
over: kind2.folders
|
|
25963
|
+
});
|
|
25964
|
+
}
|
|
25965
|
+
const yours = join6(places.claudeHome, "CLAUDE.md");
|
|
25966
|
+
for (const dir of upFrom(kind2.folder === void 0 ? kind2.folders : dirname4(kind2.folder))) {
|
|
25967
|
+
for (const path of claudeFilesIn(dir)) {
|
|
25968
|
+
if (path === yours || spots.some((spot) => spot.path === path) || !isFile(path)) continue;
|
|
25969
|
+
spots.push({
|
|
25970
|
+
path,
|
|
25971
|
+
name: this.crumbs(path),
|
|
25972
|
+
title: `From ${this.tilde(dir)}`.slice(0, 80),
|
|
25973
|
+
role: "instructions",
|
|
25974
|
+
about: this.tilde(path),
|
|
25975
|
+
editable: false,
|
|
25976
|
+
whyReadOnly: "It sits above the agents' folders.",
|
|
25977
|
+
id: `above-${hashOf(path).slice(0, 12)}`,
|
|
25978
|
+
over: dir
|
|
25979
|
+
});
|
|
25980
|
+
}
|
|
25981
|
+
}
|
|
25982
|
+
if (isFile(yours)) {
|
|
25983
|
+
spots.push({
|
|
25984
|
+
path: yours,
|
|
25985
|
+
name: this.crumbs(yours),
|
|
25986
|
+
title: "For all your Claude Code",
|
|
25987
|
+
role: "instructions",
|
|
25988
|
+
about: this.tilde(yours),
|
|
25989
|
+
editable: false,
|
|
25990
|
+
whyReadOnly: "Your own Claude Code reads it too.",
|
|
25991
|
+
id: "yours"
|
|
25992
|
+
});
|
|
25993
|
+
}
|
|
25994
|
+
return spots;
|
|
25995
|
+
}
|
|
25996
|
+
/** An agent's own files: its folder's, and for Claude Code its memory, last. */
|
|
25997
|
+
ownSpots(folder2) {
|
|
25998
|
+
if (this.id === "codex") {
|
|
25999
|
+
const override = join6(folder2, "AGENTS.override.md");
|
|
26000
|
+
const path = isFile(override) ? override : join6(folder2, "AGENTS.md");
|
|
26001
|
+
return [{ path, name: relative(folder2, path), title: "How it works", role: "instructions", editable: true }];
|
|
26002
|
+
}
|
|
26003
|
+
const spots = claudeFilesIn(folder2).filter((path, at) => at === 0 || isFile(path)).map((path) => {
|
|
26004
|
+
const where = relative(folder2, path);
|
|
26005
|
+
return { path, name: where.split(sep2).join(" \u203A "), title: ownTitle(where), role: "instructions", editable: true };
|
|
26006
|
+
});
|
|
26007
|
+
const memory = memoryPath(this.places.claudeHome, folder2);
|
|
26008
|
+
if (memory !== void 0 && memoryOn(settingsLayers(this.places.claudeHome, folder2))) {
|
|
26009
|
+
spots.push({
|
|
26010
|
+
path: memory,
|
|
26011
|
+
name: "MEMORY.md",
|
|
26012
|
+
title: "What it remembers",
|
|
26013
|
+
role: "memory",
|
|
26014
|
+
about: "Claude Code reads its first 200 lines, and writes to it too.",
|
|
26015
|
+
editable: true
|
|
26016
|
+
});
|
|
26017
|
+
}
|
|
26018
|
+
return spots;
|
|
26019
|
+
}
|
|
26020
|
+
/** The shared files an agent in `folder` reads. */
|
|
26021
|
+
readBy(folder2) {
|
|
26022
|
+
return this.sharedSpots().filter((spot) => spot.over === void 0 || within(folder2, spot.over));
|
|
26023
|
+
}
|
|
26024
|
+
/** An agent's copy: its own files and the shared ones it reads, eight at most, and when it reads them. */
|
|
26025
|
+
agentCopy(folder2) {
|
|
26026
|
+
const own2 = this.ownSpots(folder2);
|
|
26027
|
+
const memory = own2.filter((spot) => spot.role === "memory");
|
|
26028
|
+
const rows = [];
|
|
26029
|
+
const notShown = [];
|
|
26030
|
+
const add = (row, text) => {
|
|
26031
|
+
const named = { name: row["name"], title: row["title"] };
|
|
26032
|
+
if (text !== void 0 && contextBytes(text) > CONTEXT_FILE_BYTES) notShown.push({ ...named, reason: "too_large" });
|
|
26033
|
+
else if (rows.length >= CONTEXT_FILES_SHOWN) notShown.push({ ...named, reason: "count" });
|
|
26034
|
+
else rows.push(row);
|
|
26035
|
+
};
|
|
26036
|
+
const addOwn = (spot) => {
|
|
26037
|
+
const text = textOf(spot.path) ?? "";
|
|
26038
|
+
add(
|
|
26039
|
+
{
|
|
26040
|
+
name: spot.name,
|
|
26041
|
+
title: spot.title,
|
|
26042
|
+
role: spot.role,
|
|
26043
|
+
...spot.about === void 0 ? {} : { about: spot.about },
|
|
26044
|
+
text,
|
|
26045
|
+
hash: hashOf(text),
|
|
26046
|
+
editable: true
|
|
26047
|
+
},
|
|
26048
|
+
text
|
|
26049
|
+
);
|
|
26050
|
+
};
|
|
26051
|
+
for (const spot of own2) if (spot.role !== "memory") addOwn(spot);
|
|
26052
|
+
for (const spot of this.readBy(folder2)) {
|
|
26053
|
+
add({
|
|
26054
|
+
name: spot.name,
|
|
26055
|
+
title: spot.title,
|
|
26056
|
+
role: spot.role,
|
|
26057
|
+
...spot.about === void 0 ? {} : { about: spot.about },
|
|
26058
|
+
shared: spot.id,
|
|
26059
|
+
replaceable: false,
|
|
26060
|
+
editable: false
|
|
26061
|
+
});
|
|
26062
|
+
}
|
|
26063
|
+
for (const spot of memory) addOwn(spot);
|
|
26064
|
+
return {
|
|
26065
|
+
files: rows,
|
|
26066
|
+
...notShown.length === 0 ? {} : { not_shown: notShown },
|
|
26067
|
+
read_note: readNote2(this.id === "codex" ? "Codex" : "Claude Code")
|
|
26068
|
+
};
|
|
26069
|
+
}
|
|
26070
|
+
/** The harness's own set, each file with how many of its agents (in `folders`) read it. */
|
|
26071
|
+
harnessCopy(folders) {
|
|
26072
|
+
const shared = [];
|
|
26073
|
+
const notShown = [];
|
|
26074
|
+
for (const spot of this.sharedSpots()) {
|
|
26075
|
+
const text = textOf(spot.path) ?? "";
|
|
26076
|
+
const named = { name: spot.name, title: spot.title };
|
|
26077
|
+
if (contextBytes(text) > CONTEXT_FILE_BYTES) {
|
|
26078
|
+
notShown.push({ ...named, reason: "too_large" });
|
|
26079
|
+
continue;
|
|
26080
|
+
}
|
|
26081
|
+
if (shared.length >= CONTEXT_FILES_SHOWN) {
|
|
26082
|
+
notShown.push({ ...named, reason: "count" });
|
|
26083
|
+
continue;
|
|
26084
|
+
}
|
|
26085
|
+
const over = spot.over;
|
|
26086
|
+
shared.push({
|
|
26087
|
+
id: spot.id,
|
|
26088
|
+
name: spot.name,
|
|
26089
|
+
title: spot.title,
|
|
26090
|
+
role: spot.role,
|
|
26091
|
+
...spot.about === void 0 ? {} : { about: spot.about },
|
|
26092
|
+
text,
|
|
26093
|
+
hash: hashOf(text),
|
|
26094
|
+
editable: spot.editable,
|
|
26095
|
+
...spot.whyReadOnly === void 0 ? {} : { why_read_only: spot.whyReadOnly },
|
|
26096
|
+
used_by: over === void 0 ? folders.length : folders.filter((folder2) => within(folder2, over)).length
|
|
26097
|
+
});
|
|
26098
|
+
}
|
|
26099
|
+
return { shared, ...notShown.length === 0 ? {} : { not_shown: notShown } };
|
|
26100
|
+
}
|
|
26101
|
+
/**
|
|
26102
|
+
* A person's edit of one of an agent's files, saved where the agent reads it, only if it is still
|
|
26103
|
+
* the version they changed. Refused, with the copy as it is, for a file that isn't the agent's own
|
|
26104
|
+
* to change, for one Codex would not read whole, and as `changed` for one changed since.
|
|
26105
|
+
*/
|
|
26106
|
+
async saveAgent(folder2, edit) {
|
|
26107
|
+
const now = () => this.agentCopy(folder2);
|
|
26108
|
+
const spot = this.ownSpots(folder2).find((each) => each.name === edit.name);
|
|
26109
|
+
if (spot === void 0) {
|
|
26110
|
+
const shared = this.readBy(folder2).some((each) => each.name === edit.name);
|
|
26111
|
+
throw new Refuse(
|
|
26112
|
+
shared ? `Every agent reads this one. Change it on ${this.kind.name}'s page.` : `There is no file called ${edit.name} here.`,
|
|
26113
|
+
now(),
|
|
26114
|
+
"failed"
|
|
26115
|
+
);
|
|
26116
|
+
}
|
|
26117
|
+
if (edit.base_hash === null) {
|
|
26118
|
+
throw new Refuse("This file is the agent's own already.", now(), "failed");
|
|
26119
|
+
}
|
|
26120
|
+
if (this.id === "codex" && contextBytes(edit.text) > this.docBytes) {
|
|
26121
|
+
throw new Refuse(`Codex reads only the first ${Math.floor(this.docBytes / 1024)} KB of this file.`, now(), "failed");
|
|
26122
|
+
}
|
|
26123
|
+
await this.write(spot, edit, now);
|
|
26124
|
+
}
|
|
26125
|
+
/** A person's edit of one of the harness's own files, read by its agents beside their own. */
|
|
26126
|
+
async saveShared(folders, edit) {
|
|
26127
|
+
const now = () => this.harnessCopy(folders);
|
|
26128
|
+
const spot = this.sharedSpots().find((each) => each.name === edit.name);
|
|
26129
|
+
if (spot === void 0) throw new Refuse(`There is no file called ${edit.name} here.`, now(), "failed");
|
|
26130
|
+
if (!spot.editable) throw new Refuse(spot.whyReadOnly ?? "It can't be changed from Chips.", now(), "failed");
|
|
26131
|
+
if (edit.base_hash === null) {
|
|
26132
|
+
throw new Refuse("Every agent reads this file beside its own, so none can have its own in its place.", now(), "failed");
|
|
26133
|
+
}
|
|
26134
|
+
await this.write(spot, edit, now);
|
|
26135
|
+
}
|
|
26136
|
+
async write(spot, edit, now) {
|
|
26137
|
+
if (hashOf(textOf(spot.path) ?? "") !== edit.base_hash) throw new Refuse("", now(), "changed");
|
|
26138
|
+
try {
|
|
26139
|
+
await mkdir2(dirname4(spot.path), { recursive: true });
|
|
26140
|
+
await writeFile2(spot.path, edit.text, "utf8");
|
|
26141
|
+
} catch (error62) {
|
|
26142
|
+
throw new Refuse(`It couldn't be saved: ${error62 instanceof Error ? error62.message : String(error62)}`.slice(0, 300), now(), "failed");
|
|
26143
|
+
}
|
|
26144
|
+
}
|
|
26145
|
+
};
|
|
25686
26146
|
|
|
25687
26147
|
// src/kinds.ts
|
|
25688
26148
|
var KNOWN = [
|
|
@@ -25715,6 +26175,32 @@ var knownBy = (kind2) => {
|
|
|
25715
26175
|
const program = kind2.command[0]?.split("/").pop();
|
|
25716
26176
|
return KNOWN.find((each) => each.program === program);
|
|
25717
26177
|
};
|
|
26178
|
+
function knownIdOf(kind2) {
|
|
26179
|
+
return knownBy(kind2)?.id;
|
|
26180
|
+
}
|
|
26181
|
+
var CODEX_DOC_BYTES = 65536;
|
|
26182
|
+
function codexConfigOf(env2) {
|
|
26183
|
+
const raw = env2["CODEX_CONFIG"];
|
|
26184
|
+
if (raw === void 0 || raw.trim() === "") return void 0;
|
|
26185
|
+
try {
|
|
26186
|
+
const parsed = JSON.parse(raw);
|
|
26187
|
+
return typeof parsed === "object" && parsed !== null && !Array.isArray(parsed) ? parsed : void 0;
|
|
26188
|
+
} catch {
|
|
26189
|
+
return void 0;
|
|
26190
|
+
}
|
|
26191
|
+
}
|
|
26192
|
+
function adapterEnv(kind2, env2) {
|
|
26193
|
+
if (knownIdOf(kind2) !== "codex") return env2;
|
|
26194
|
+
const raw = env2["CODEX_CONFIG"];
|
|
26195
|
+
const config2 = codexConfigOf(env2);
|
|
26196
|
+
if (raw !== void 0 && raw.trim() !== "" && config2 === void 0) return env2;
|
|
26197
|
+
if (config2?.["project_doc_max_bytes"] !== void 0) return env2;
|
|
26198
|
+
return { ...env2, CODEX_CONFIG: JSON.stringify({ ...config2, project_doc_max_bytes: CODEX_DOC_BYTES }) };
|
|
26199
|
+
}
|
|
26200
|
+
function codexDocBytes(env2) {
|
|
26201
|
+
const said = codexConfigOf(env2)?.["project_doc_max_bytes"];
|
|
26202
|
+
return typeof said === "number" && Number.isFinite(said) && said > 0 ? said : 32768;
|
|
26203
|
+
}
|
|
25718
26204
|
function installWords(kind2) {
|
|
25719
26205
|
const known = knownBy(kind2);
|
|
25720
26206
|
return known === void 0 ? "install the agent's ACP adapter its own way, or name it by its path in the config" : `install it with \`npm install -g ${known.adapter}\``;
|
|
@@ -25742,6 +26228,98 @@ function signedOutStop(kind2) {
|
|
|
25742
26228
|
};
|
|
25743
26229
|
}
|
|
25744
26230
|
|
|
26231
|
+
// src/windows.ts
|
|
26232
|
+
var LIMITS = [50, 60, 70, 80, 90];
|
|
26233
|
+
var HEADROOM = 33e3;
|
|
26234
|
+
var LEAST_WINDOW = 1e5;
|
|
26235
|
+
var COMPACT_TITLE = "Compact conversation";
|
|
26236
|
+
var CODEX_COMPACTED = "*Context compacted to fit the model's context window.*";
|
|
26237
|
+
var ascending3 = (values) => [...new Set(values)].sort((a, b) => a - b);
|
|
26238
|
+
function percentOf(tokens2, window) {
|
|
26239
|
+
const at = Math.round((Math.min(tokens2, window) - HEADROOM) / window * 100);
|
|
26240
|
+
return Math.min(99, Math.max(1, at));
|
|
26241
|
+
}
|
|
26242
|
+
function tokensFor(percent2, window) {
|
|
26243
|
+
return Math.min(window, Math.max(LEAST_WINDOW, Math.round(percent2 / 100 * window) + HEADROOM));
|
|
26244
|
+
}
|
|
26245
|
+
function reachable(percent2, window) {
|
|
26246
|
+
const tokens2 = Math.round(percent2 / 100 * window) + HEADROOM;
|
|
26247
|
+
return tokens2 >= LEAST_WINDOW && tokens2 <= window;
|
|
26248
|
+
}
|
|
26249
|
+
function claudeOwn(env2, layers, model, window) {
|
|
26250
|
+
const fromEnv = autoCompactWindowFromEnv(env2);
|
|
26251
|
+
if (fromEnv !== void 0) return { at: percentOf(fromEnv, window), fixed: true };
|
|
26252
|
+
if (!autoCompactOn(layers)) return { at: null, fixed: false };
|
|
26253
|
+
return { at: percentOf(autoCompactWindowOf(layers, model) ?? window, window), fixed: false };
|
|
26254
|
+
}
|
|
26255
|
+
function claudeLimit(kept2, own2) {
|
|
26256
|
+
if (own2.fixed) {
|
|
26257
|
+
return {
|
|
26258
|
+
limit: { at: own2.at, choices: own2.at === null ? [] : [own2.at], default: own2.at, may_turn_off: false },
|
|
26259
|
+
editable: false,
|
|
26260
|
+
whyReadOnly: "CLAUDE_CODE_AUTO_COMPACT_WINDOW sets it for this harness."
|
|
26261
|
+
};
|
|
26262
|
+
}
|
|
26263
|
+
const at = kept2.limit !== void 0 ? kept2.limit : own2.at;
|
|
26264
|
+
const choices = ascending3([
|
|
26265
|
+
...LIMITS.filter((each) => reachable(each, kept2.window)),
|
|
26266
|
+
...own2.at === null ? [] : [own2.at],
|
|
26267
|
+
...typeof at === "number" ? [at] : []
|
|
26268
|
+
]);
|
|
26269
|
+
if (choices.length === 0) return { editable: false, whyReadOnly: "Its window is too small to pick a limit." };
|
|
26270
|
+
return { limit: { at, choices, default: own2.at, may_turn_off: true }, editable: true };
|
|
26271
|
+
}
|
|
26272
|
+
function bridgeLimit(kept2) {
|
|
26273
|
+
const at = kept2.limit ?? null;
|
|
26274
|
+
return {
|
|
26275
|
+
limit: { at, choices: ascending3([...LIMITS, ...typeof at === "number" ? [at] : []]), default: null, may_turn_off: true },
|
|
26276
|
+
editable: true
|
|
26277
|
+
};
|
|
26278
|
+
}
|
|
26279
|
+
function pastLimit(kept2) {
|
|
26280
|
+
return typeof kept2.limit === "number" && kept2.used / kept2.window * 100 >= kept2.limit;
|
|
26281
|
+
}
|
|
26282
|
+
function claudeSessionSettings(kept2) {
|
|
26283
|
+
if (kept2?.limit === void 0) return void 0;
|
|
26284
|
+
if (kept2.limit === null) return { autoCompactEnabled: false };
|
|
26285
|
+
return { autoCompactEnabled: true, autoCompactWindow: tokensFor(kept2.limit, kept2.window) };
|
|
26286
|
+
}
|
|
26287
|
+
function windowCopy(kept2, more) {
|
|
26288
|
+
return {
|
|
26289
|
+
used: Math.max(0, Math.round(kept2.used)),
|
|
26290
|
+
window: Math.max(1, Math.round(kept2.window)),
|
|
26291
|
+
...kept2.model === void 0 ? {} : { model: kept2.model.slice(0, 120) },
|
|
26292
|
+
as_of: kept2.asOf,
|
|
26293
|
+
...more.compacting === void 0 ? {} : { compacting: more.compacting },
|
|
26294
|
+
...kept2.last === void 0 ? {} : { last: kept2.last },
|
|
26295
|
+
...kept2.longTurn === void 0 ? {} : { long_turn: { ...kept2.longTurn, folds: Math.min(kept2.longTurn.folds, LONG_TURN_FOLDS_MAX) } },
|
|
26296
|
+
compacts: more.compacts,
|
|
26297
|
+
...more.compacts || more.whyNot === void 0 ? {} : { why_not: more.whyNot },
|
|
26298
|
+
...more.limit === void 0 ? {} : { limit: more.limit },
|
|
26299
|
+
editable: more.editable,
|
|
26300
|
+
...more.editable || more.whyReadOnly === void 0 ? {} : { why_read_only: more.whyReadOnly }
|
|
26301
|
+
};
|
|
26302
|
+
}
|
|
26303
|
+
function isCompaction(update) {
|
|
26304
|
+
if (update["title"] === COMPACT_TITLE) return true;
|
|
26305
|
+
const meta3 = update["_meta"];
|
|
26306
|
+
return meta3?.claudeCode?.toolName === "compact";
|
|
26307
|
+
}
|
|
26308
|
+
function compactionFacts(update) {
|
|
26309
|
+
const raw = update["rawOutput"];
|
|
26310
|
+
if (typeof raw !== "object" || raw === null) return {};
|
|
26311
|
+
const number4 = (value) => typeof value === "number" && Number.isFinite(value) && value >= 0 ? value : void 0;
|
|
26312
|
+
const from = number4(raw["preTokens"]);
|
|
26313
|
+
const to = number4(raw["postTokens"]);
|
|
26314
|
+
const trigger = raw["trigger"];
|
|
26315
|
+
const by = trigger === "manual" ? "asked" : trigger === "automatic" ? "itself" : void 0;
|
|
26316
|
+
return {
|
|
26317
|
+
...from === void 0 ? {} : { from },
|
|
26318
|
+
...to === void 0 ? {} : { to },
|
|
26319
|
+
...by === void 0 ? {} : { by }
|
|
26320
|
+
};
|
|
26321
|
+
}
|
|
26322
|
+
|
|
25745
26323
|
// src/bridge.ts
|
|
25746
26324
|
var VERSION = "1.0.0";
|
|
25747
26325
|
var QUIET_MS = 1500;
|
|
@@ -25757,9 +26335,13 @@ var Bridge = class {
|
|
|
25757
26335
|
this.known = new Promise((resolve5) => {
|
|
25758
26336
|
this.knew = resolve5;
|
|
25759
26337
|
});
|
|
26338
|
+
this.env = options.env ?? adapterEnv(options.kind, { ...process.env, ...options.kind.env });
|
|
26339
|
+
this.places = placesOf(this.env, options.home ?? homedir4());
|
|
26340
|
+
this.knownKind = knownIdOf(options.kind);
|
|
26341
|
+
this.files = this.knownKind === void 0 ? void 0 : new ContextFiles(this.knownKind, options.kind, this.places, codexDocBytes(this.env));
|
|
25760
26342
|
}
|
|
25761
26343
|
options;
|
|
25762
|
-
process = { live: /* @__PURE__ */ new Set(), stopping: false, failures: 0 };
|
|
26344
|
+
process = { live: /* @__PURE__ */ new Set(), stale: /* @__PURE__ */ new Set(), stopping: false, failures: 0 };
|
|
25763
26345
|
rooms = /* @__PURE__ */ new Map();
|
|
25764
26346
|
/** The cost each session has run up, as the agent last said. */
|
|
25765
26347
|
costs = /* @__PURE__ */ new Map();
|
|
@@ -25772,6 +26354,24 @@ var Bridge = class {
|
|
|
25772
26354
|
/** The feedback already answered, oldest first. */
|
|
25773
26355
|
answered = /* @__PURE__ */ new Set();
|
|
25774
26356
|
sweeper;
|
|
26357
|
+
/** The environment the agent runs in. */
|
|
26358
|
+
env;
|
|
26359
|
+
places;
|
|
26360
|
+
/** Claude Code or Codex, whose files and limits this bridge knows; nothing for any other kind. */
|
|
26361
|
+
knownKind;
|
|
26362
|
+
/** The files the agents are built from (Chips ADR 0134), for the two kinds this bridge knows. */
|
|
26363
|
+
files;
|
|
26364
|
+
/** Whether the agent said it takes `/compact` (`available_commands_update`): any kind but the two known. */
|
|
26365
|
+
offersCompact = false;
|
|
26366
|
+
/** Each session's last `used`, for where a compaction began. */
|
|
26367
|
+
sessionUsed = /* @__PURE__ */ new Map();
|
|
26368
|
+
compactions = /* @__PURE__ */ new Map();
|
|
26369
|
+
/** The bridge's own `/compact` turns, by session. */
|
|
26370
|
+
compactRuns = /* @__PURE__ */ new Map();
|
|
26371
|
+
/** Agents compacting now, by key: waiting for a turn to end, or under way. */
|
|
26372
|
+
compacting = /* @__PURE__ */ new Map();
|
|
26373
|
+
/** A window copy to send in a moment, by agent key: readings come in bursts. */
|
|
26374
|
+
windowTimers = /* @__PURE__ */ new Map();
|
|
25775
26375
|
/** Hear what Chips asks, learn the agents Chips has, run the agent, and close idle sessions. */
|
|
25776
26376
|
async start() {
|
|
25777
26377
|
const { chips: chips2 } = this.options;
|
|
@@ -25786,6 +26386,8 @@ var Bridge = class {
|
|
|
25786
26386
|
chips2.onSpaceAsked((asked) => after("a room from the +", () => this.claim(asked)));
|
|
25787
26387
|
await this.know(await chips2.agents.list(), { forget: true });
|
|
25788
26388
|
this.knew();
|
|
26389
|
+
await this.sendContexts();
|
|
26390
|
+
for (const record2 of this.records()) await this.sendWindow(record2);
|
|
25789
26391
|
await this.run();
|
|
25790
26392
|
const idleMs = this.options.idleMs ?? IDLE_MS;
|
|
25791
26393
|
this.sweeper = setInterval(() => void this.sweep(idleMs), Math.max(10, Math.min(6e4, idleMs / 2)));
|
|
@@ -25804,6 +26406,8 @@ var Bridge = class {
|
|
|
25804
26406
|
this.process.stopping = true;
|
|
25805
26407
|
this.process.client?.close();
|
|
25806
26408
|
clearInterval(this.sweeper);
|
|
26409
|
+
for (const timer of this.windowTimers.values()) clearTimeout(timer);
|
|
26410
|
+
this.windowTimers.clear();
|
|
25807
26411
|
}
|
|
25808
26412
|
// ------------------------------------------------------------------ the agents
|
|
25809
26413
|
records() {
|
|
@@ -25847,7 +26451,10 @@ var Bridge = class {
|
|
|
25847
26451
|
};
|
|
25848
26452
|
changed = true;
|
|
25849
26453
|
}
|
|
25850
|
-
if (changed)
|
|
26454
|
+
if (changed) {
|
|
26455
|
+
this.save();
|
|
26456
|
+
this.contextsChanged();
|
|
26457
|
+
}
|
|
25851
26458
|
});
|
|
25852
26459
|
if (!forget) return;
|
|
25853
26460
|
for (const record2 of this.records()) {
|
|
@@ -25879,15 +26486,15 @@ var Bridge = class {
|
|
|
25879
26486
|
async folderFor(name) {
|
|
25880
26487
|
const { kind: kind2 } = this.options;
|
|
25881
26488
|
if (kind2.folder !== void 0) {
|
|
25882
|
-
await
|
|
26489
|
+
await mkdir3(kind2.folder, { recursive: true });
|
|
25883
26490
|
return kind2.folder;
|
|
25884
26491
|
}
|
|
25885
26492
|
const base = slugOf(name).replace(/_/g, "-") || "agent";
|
|
25886
26493
|
const taken = new Set(this.records().map((record2) => record2.folder));
|
|
25887
26494
|
for (let n = 1; ; n += 1) {
|
|
25888
|
-
const folder2 =
|
|
25889
|
-
if (taken.has(folder2) ||
|
|
25890
|
-
await
|
|
26495
|
+
const folder2 = join7(kind2.folders, n === 1 ? base : `${base}-${n}`);
|
|
26496
|
+
if (taken.has(folder2) || existsSync6(folder2)) continue;
|
|
26497
|
+
await mkdir3(folder2, { recursive: true });
|
|
25891
26498
|
return folder2;
|
|
25892
26499
|
}
|
|
25893
26500
|
}
|
|
@@ -25904,6 +26511,7 @@ var Bridge = class {
|
|
|
25904
26511
|
record2.agentId = agent.agentId;
|
|
25905
26512
|
record2.name = agent.name;
|
|
25906
26513
|
this.save();
|
|
26514
|
+
this.contextsChanged();
|
|
25907
26515
|
}
|
|
25908
26516
|
/**
|
|
25909
26517
|
* A person asked for a new agent in a room (ADR 0108): a record and a folder of its own, then
|
|
@@ -26005,6 +26613,7 @@ var Bridge = class {
|
|
|
26005
26613
|
};
|
|
26006
26614
|
this.options.state.agents[key] = made;
|
|
26007
26615
|
this.save();
|
|
26616
|
+
this.contextsChanged();
|
|
26008
26617
|
return made;
|
|
26009
26618
|
});
|
|
26010
26619
|
this.log(`${agent.name} claimed ${spaceId}, in ${record2.folder}`);
|
|
@@ -26049,6 +26658,11 @@ var Bridge = class {
|
|
|
26049
26658
|
const record2 = state2.agents[key];
|
|
26050
26659
|
if (record2 === void 0) return;
|
|
26051
26660
|
delete state2.agents[key];
|
|
26661
|
+
delete state2.windows?.[key];
|
|
26662
|
+
this.compacting.delete(key);
|
|
26663
|
+
clearTimeout(this.windowTimers.get(key));
|
|
26664
|
+
this.windowTimers.delete(key);
|
|
26665
|
+
if (record2.agentId !== "") this.options.chips.settings.forget(record2.agentId);
|
|
26052
26666
|
for (const [id2, room] of this.rooms) {
|
|
26053
26667
|
if (room.record.key !== key) continue;
|
|
26054
26668
|
room.queue.length = 0;
|
|
@@ -26063,6 +26677,7 @@ var Bridge = class {
|
|
|
26063
26677
|
}
|
|
26064
26678
|
}
|
|
26065
26679
|
this.save();
|
|
26680
|
+
this.contextsChanged();
|
|
26066
26681
|
this.log(`${record2.name} deleted; its folder stays, ${record2.folder}`);
|
|
26067
26682
|
}
|
|
26068
26683
|
// ------------------------------------------------------------------ the agent's process
|
|
@@ -26070,6 +26685,7 @@ var Bridge = class {
|
|
|
26070
26685
|
const proc = this.process;
|
|
26071
26686
|
const { name } = this.options.kind;
|
|
26072
26687
|
proc.live.clear();
|
|
26688
|
+
proc.stale.clear();
|
|
26073
26689
|
proc.info = void 0;
|
|
26074
26690
|
let wire;
|
|
26075
26691
|
try {
|
|
@@ -26164,6 +26780,7 @@ var Bridge = class {
|
|
|
26164
26780
|
try {
|
|
26165
26781
|
await client.closeSession(sessionId);
|
|
26166
26782
|
live.delete(sessionId);
|
|
26783
|
+
this.process.stale.delete(sessionId);
|
|
26167
26784
|
this.log(`${room.record.name}'s session in ${room.spaceId} closed, quiet ${Math.round(idleMs / 6e4)} min`);
|
|
26168
26785
|
} catch (error62) {
|
|
26169
26786
|
this.log(`${room.record.name}'s session in ${room.spaceId} stays open: ${messageOf(error62)}`);
|
|
@@ -26235,6 +26852,22 @@ var Bridge = class {
|
|
|
26235
26852
|
}
|
|
26236
26853
|
async pump(room) {
|
|
26237
26854
|
if (room.busy) return;
|
|
26855
|
+
const compact = room.compact;
|
|
26856
|
+
if (compact !== void 0) {
|
|
26857
|
+
room.compact = void 0;
|
|
26858
|
+
room.busy = true;
|
|
26859
|
+
try {
|
|
26860
|
+
await this.compactIn(room, compact);
|
|
26861
|
+
} catch (error62) {
|
|
26862
|
+
this.compacting.delete(room.record.key);
|
|
26863
|
+
this.log(`${room.record.name} not compacted: ${messageOf(error62)}`);
|
|
26864
|
+
} finally {
|
|
26865
|
+
room.busy = false;
|
|
26866
|
+
room.usedAt = Date.now();
|
|
26867
|
+
void this.pump(room);
|
|
26868
|
+
}
|
|
26869
|
+
return;
|
|
26870
|
+
}
|
|
26238
26871
|
const asked = room.queue.shift();
|
|
26239
26872
|
if (asked === void 0) return;
|
|
26240
26873
|
room.busy = true;
|
|
@@ -26244,8 +26877,10 @@ var Bridge = class {
|
|
|
26244
26877
|
this.log(`a turn of ${room.record.name} went wrong: ${String(error62)}`);
|
|
26245
26878
|
} finally {
|
|
26246
26879
|
room.busy = false;
|
|
26880
|
+
const ended = room.turn;
|
|
26247
26881
|
room.turn = void 0;
|
|
26248
26882
|
room.usedAt = Date.now();
|
|
26883
|
+
if (ended !== void 0) this.turnEnded(room, ended);
|
|
26249
26884
|
void this.pump(room);
|
|
26250
26885
|
}
|
|
26251
26886
|
}
|
|
@@ -26267,7 +26902,9 @@ var Bridge = class {
|
|
|
26267
26902
|
saidAt: 0,
|
|
26268
26903
|
gaugeAt: 0,
|
|
26269
26904
|
steps: /* @__PURE__ */ new Map(),
|
|
26270
|
-
allowed: /* @__PURE__ */ new Map()
|
|
26905
|
+
allowed: /* @__PURE__ */ new Map(),
|
|
26906
|
+
peak: 0,
|
|
26907
|
+
folds: 0
|
|
26271
26908
|
};
|
|
26272
26909
|
room.turn = turn;
|
|
26273
26910
|
run2.on("cancel", () => {
|
|
@@ -26317,16 +26954,20 @@ ${files.join("\n")}`;
|
|
|
26317
26954
|
}
|
|
26318
26955
|
await this.finish(room, turn, stop2);
|
|
26319
26956
|
}
|
|
26320
|
-
/**
|
|
26957
|
+
/**
|
|
26958
|
+
* The room's session: the one it had, loaded once, or a new one, in the agent's folder. One a
|
|
26959
|
+
* change from Chips made stale is closed and loaded again first, so the agent reads what changed.
|
|
26960
|
+
*/
|
|
26321
26961
|
async sessionFor(record2, client, spaceId) {
|
|
26322
26962
|
const { state: state2 } = this.options;
|
|
26323
26963
|
const { live, info } = this.process;
|
|
26324
26964
|
const key = `${record2.key}|${spaceId}`;
|
|
26325
26965
|
const kept2 = state2.sessions[key];
|
|
26966
|
+
if (kept2 !== void 0 && live.has(kept2) && this.process.stale.has(kept2)) await this.reopen(client, record2, kept2);
|
|
26326
26967
|
if (kept2 !== void 0 && live.has(kept2)) return kept2;
|
|
26327
26968
|
if (kept2 !== void 0 && info?.loadSession === true) {
|
|
26328
26969
|
try {
|
|
26329
|
-
await client.loadSession(kept2, record2.folder);
|
|
26970
|
+
await client.loadSession(kept2, record2.folder, [], this.sessionMeta(record2));
|
|
26330
26971
|
live.add(kept2);
|
|
26331
26972
|
await this.moded(client, kept2);
|
|
26332
26973
|
return kept2;
|
|
@@ -26334,13 +26975,35 @@ ${files.join("\n")}`;
|
|
|
26334
26975
|
this.log(`${record2.name} couldn't load ${kept2}: ${messageOf(error62)}; starting afresh`);
|
|
26335
26976
|
}
|
|
26336
26977
|
}
|
|
26337
|
-
const made = await client.newSession(record2.folder);
|
|
26978
|
+
const made = await client.newSession(record2.folder, [], this.sessionMeta(record2));
|
|
26338
26979
|
live.add(made.sessionId);
|
|
26339
26980
|
await this.moded(client, made.sessionId);
|
|
26340
26981
|
state2.sessions[key] = made.sessionId;
|
|
26341
26982
|
this.save();
|
|
26342
26983
|
return made.sessionId;
|
|
26343
26984
|
}
|
|
26985
|
+
/**
|
|
26986
|
+
* A stale session closed, where the agent closes and loads them, so its next turn loads it again
|
|
26987
|
+
* and the agent reads its files and its settings afresh. Elsewhere it goes on as it is.
|
|
26988
|
+
*/
|
|
26989
|
+
async reopen(client, record2, sessionId) {
|
|
26990
|
+
const { info, live, stale } = this.process;
|
|
26991
|
+
stale.delete(sessionId);
|
|
26992
|
+
if (info?.closeSession !== true || !info.loadSession) return;
|
|
26993
|
+
try {
|
|
26994
|
+
await client.closeSession(sessionId);
|
|
26995
|
+
live.delete(sessionId);
|
|
26996
|
+
this.log(`${record2.name}'s session ${sessionId} closed, to start again with what changed`);
|
|
26997
|
+
} catch (error62) {
|
|
26998
|
+
this.log(`${record2.name}'s session ${sessionId} stays open: ${messageOf(error62)}`);
|
|
26999
|
+
}
|
|
27000
|
+
}
|
|
27001
|
+
/** What a session of the agent starts with beside its folder: Claude Code's settings for the limit a person picked. */
|
|
27002
|
+
sessionMeta(record2) {
|
|
27003
|
+
if (this.knownKind !== "claude-code" || this.claudeFixed()) return void 0;
|
|
27004
|
+
const settings = claudeSessionSettings(this.options.state.windows?.[record2.key]);
|
|
27005
|
+
return settings === void 0 ? void 0 : { claudeCode: { options: { settings } } };
|
|
27006
|
+
}
|
|
26344
27007
|
/** The session into the mode the config names, or left in its own when the agent won't. */
|
|
26345
27008
|
async moded(client, sessionId) {
|
|
26346
27009
|
const { mode, name } = this.options.kind;
|
|
@@ -26352,10 +27015,10 @@ ${files.join("\n")}`;
|
|
|
26352
27015
|
const lines2 = [];
|
|
26353
27016
|
for (const file3 of message.attachments ?? []) {
|
|
26354
27017
|
try {
|
|
26355
|
-
const folder2 =
|
|
26356
|
-
await
|
|
26357
|
-
const path =
|
|
26358
|
-
await
|
|
27018
|
+
const folder2 = join7(record2.folder, "chips-files", message.message_id);
|
|
27019
|
+
await mkdir3(folder2, { recursive: true });
|
|
27020
|
+
const path = join7(folder2, file3.filename.replace(/[/\\]/g, "_"));
|
|
27021
|
+
await writeFile3(path, await this.options.chips.download(file3));
|
|
26359
27022
|
lines2.push(`(${file3.filename} is saved at ${path})`);
|
|
26360
27023
|
} catch (error62) {
|
|
26361
27024
|
lines2.push(`(${file3.filename} could not be fetched: ${messageOf(error62)})`);
|
|
@@ -26455,14 +27118,18 @@ ${files.join("\n")}`;
|
|
|
26455
27118
|
}
|
|
26456
27119
|
updated(sessionId, update) {
|
|
26457
27120
|
if (update.sessionUpdate === "usage_update") this.costed(sessionId, update);
|
|
27121
|
+
this.watched(sessionId, update);
|
|
26458
27122
|
const turn = this.turnOf(sessionId);
|
|
26459
27123
|
if (turn === void 0) return;
|
|
26460
27124
|
switch (update.sessionUpdate) {
|
|
26461
|
-
case "agent_message_chunk":
|
|
26462
|
-
|
|
27125
|
+
case "agent_message_chunk": {
|
|
27126
|
+
const text = textOf2(update["content"]);
|
|
27127
|
+
if (text.trim() === CODEX_COMPACTED) return;
|
|
27128
|
+
turn.reply += text;
|
|
26463
27129
|
return;
|
|
27130
|
+
}
|
|
26464
27131
|
case "agent_thought_chunk":
|
|
26465
|
-
turn.thought +=
|
|
27132
|
+
turn.thought += textOf2(update["content"]);
|
|
26466
27133
|
this.sayThought(turn);
|
|
26467
27134
|
return;
|
|
26468
27135
|
case "tool_call":
|
|
@@ -26547,6 +27214,378 @@ ${files.join("\n")}`;
|
|
|
26547
27214
|
const steps = entries.filter((entry) => entry["status"] !== "completed").slice(0, 20).map((entry, index) => ({ stepId: `plan-${index + 1}`, title: String(entry["content"] ?? "").slice(0, 300) })).filter((step) => step.title !== "");
|
|
26548
27215
|
if (steps.length > 0) await turn.run.plan(steps).catch(() => void 0);
|
|
26549
27216
|
}
|
|
27217
|
+
// ------------------------------------------------------------------ what the agents read (Chips ADRs 0134, 0238)
|
|
27218
|
+
/** The folders of the agents Chips has, for how many of them read each shared file. */
|
|
27219
|
+
folders() {
|
|
27220
|
+
return this.records().filter((record2) => record2.agentId !== "").map((record2) => record2.folder);
|
|
27221
|
+
}
|
|
27222
|
+
/** The agents came or went: the copies sent again where they changed (Chips takes the same copy once). */
|
|
27223
|
+
contextsChanged() {
|
|
27224
|
+
if (this.files !== void 0) void this.sendContexts();
|
|
27225
|
+
}
|
|
27226
|
+
/** The harness's own set and each agent's files, as they are on disk now. */
|
|
27227
|
+
async sendContexts() {
|
|
27228
|
+
const files = this.files;
|
|
27229
|
+
if (files === void 0) return;
|
|
27230
|
+
await this.options.chips.settings.harnessContext(files.harnessCopy(this.folders())).catch((error62) => this.log(`${this.options.kind.name}'s shared files not sent: ${messageOf(error62)}`));
|
|
27231
|
+
for (const record2 of this.records()) await this.sendContext(record2);
|
|
27232
|
+
}
|
|
27233
|
+
async sendContext(record2) {
|
|
27234
|
+
if (this.files === void 0 || record2.agentId === "") return;
|
|
27235
|
+
await this.options.chips.settings.context(record2.agentId, this.files.agentCopy(record2.folder)).catch((error62) => this.log(`${record2.name}'s files not sent: ${messageOf(error62)}`));
|
|
27236
|
+
}
|
|
27237
|
+
/**
|
|
27238
|
+
* A person's edit of a file from Chips: saved where the agent reads it, and answered with the copy
|
|
27239
|
+
* as it is now. Each agent that reads it starts its sessions again before its next turn, so the
|
|
27240
|
+
* change applies from the next message: an agent and its copies share a folder, and every agent
|
|
27241
|
+
* reads the harness's own set.
|
|
27242
|
+
*/
|
|
27243
|
+
async contextEdited(edit) {
|
|
27244
|
+
const files = this.files;
|
|
27245
|
+
if (files === void 0) throw new Refuse(`${this.options.kind.name} keeps no files of its agents here.`);
|
|
27246
|
+
await this.known;
|
|
27247
|
+
if (edit.agent_id === void 0) {
|
|
27248
|
+
await files.saveShared(this.folders(), edit);
|
|
27249
|
+
this.log(`${this.options.kind.name}'s ${edit.name} saved from Chips`);
|
|
27250
|
+
this.reload(this.records());
|
|
27251
|
+
return files.harnessCopy(this.folders());
|
|
27252
|
+
}
|
|
27253
|
+
const record2 = await this.recordOf(edit.agent_id);
|
|
27254
|
+
if (record2 === void 0) throw new Refuse("This harness has no such agent.");
|
|
27255
|
+
await files.saveAgent(record2.folder, edit);
|
|
27256
|
+
this.log(`${record2.name}'s ${edit.name} saved from Chips`);
|
|
27257
|
+
const sharing = this.records().filter((each) => each.folder === record2.folder);
|
|
27258
|
+
this.reload(sharing);
|
|
27259
|
+
for (const each of sharing) if (each !== record2) void this.sendContext(each);
|
|
27260
|
+
return files.agentCopy(record2.folder);
|
|
27261
|
+
}
|
|
27262
|
+
/** The agents' live sessions marked to start again before their next turn. */
|
|
27263
|
+
reload(records) {
|
|
27264
|
+
const { live, stale } = this.process;
|
|
27265
|
+
for (const record2 of records) {
|
|
27266
|
+
for (const [id2, sessionId] of Object.entries(this.options.state.sessions)) {
|
|
27267
|
+
if (id2.startsWith(`${record2.key}|`) && live.has(sessionId)) stale.add(sessionId);
|
|
27268
|
+
}
|
|
27269
|
+
}
|
|
27270
|
+
}
|
|
27271
|
+
// ------------------------------------------------------------------ how full each agent is (Chips ADR 0146)
|
|
27272
|
+
/** The agent and room a session is. */
|
|
27273
|
+
placeOf(sessionId) {
|
|
27274
|
+
for (const [id2, each] of Object.entries(this.options.state.sessions)) {
|
|
27275
|
+
if (each !== sessionId) continue;
|
|
27276
|
+
const at = id2.indexOf("|");
|
|
27277
|
+
const record2 = this.options.state.agents[id2.slice(0, at)];
|
|
27278
|
+
if (record2 !== void 0) return { record: record2, spaceId: id2.slice(at + 1) };
|
|
27279
|
+
}
|
|
27280
|
+
return void 0;
|
|
27281
|
+
}
|
|
27282
|
+
kept() {
|
|
27283
|
+
this.options.state.windows ??= {};
|
|
27284
|
+
return this.options.state.windows;
|
|
27285
|
+
}
|
|
27286
|
+
/** Whether `CLAUDE_CODE_AUTO_COMPACT_WINDOW` sets Claude Code's limit, which nothing here beats. */
|
|
27287
|
+
claudeFixed() {
|
|
27288
|
+
return this.knownKind === "claude-code" && claudeOwn(this.env, [], void 0, 1e6).fixed;
|
|
27289
|
+
}
|
|
27290
|
+
/** Whether the bridge keeps the agents' limit and compacts past it: every kind but Claude Code, which keeps its own. */
|
|
27291
|
+
keepsLimit() {
|
|
27292
|
+
return this.knownKind === "codex" || this.knownKind === void 0 && this.offersCompact;
|
|
27293
|
+
}
|
|
27294
|
+
/** An agent's copy, from what it last said: nothing until it has said. */
|
|
27295
|
+
windowCopy(record2) {
|
|
27296
|
+
const kept2 = this.options.state.windows?.[record2.key];
|
|
27297
|
+
if (kept2 === void 0) return void 0;
|
|
27298
|
+
const compacts = this.knownKind !== void 0 || this.offersCompact;
|
|
27299
|
+
const limit = this.knownKind === "claude-code" ? claudeLimit(kept2, claudeOwn(this.env, settingsLayers(this.places.claudeHome, record2.folder), kept2.model, kept2.window)) : compacts ? bridgeLimit(kept2) : { editable: false };
|
|
27300
|
+
return windowCopy(kept2, {
|
|
27301
|
+
compacting: this.compacting.get(record2.key),
|
|
27302
|
+
compacts,
|
|
27303
|
+
whyNot: "This agent has no compact command.",
|
|
27304
|
+
...limit
|
|
27305
|
+
});
|
|
27306
|
+
}
|
|
27307
|
+
/** An agent's copy sent now, and kept with the bridge's agents. */
|
|
27308
|
+
async sendWindow(record2) {
|
|
27309
|
+
clearTimeout(this.windowTimers.get(record2.key));
|
|
27310
|
+
this.windowTimers.delete(record2.key);
|
|
27311
|
+
const copy = this.windowCopy(record2);
|
|
27312
|
+
if (copy === void 0 || record2.agentId === "") return;
|
|
27313
|
+
this.save();
|
|
27314
|
+
await this.options.chips.settings.contextWindow(record2.agentId, copy).catch((error62) => this.log(`${record2.name}'s context window not sent: ${messageOf(error62)}`));
|
|
27315
|
+
}
|
|
27316
|
+
/** An agent's copy sent in a moment: a turn says how full it is after each step. */
|
|
27317
|
+
windowSoon(record2) {
|
|
27318
|
+
if (this.windowTimers.has(record2.key)) return;
|
|
27319
|
+
const timer = setTimeout(() => {
|
|
27320
|
+
this.windowTimers.delete(record2.key);
|
|
27321
|
+
void this.sendWindow(record2);
|
|
27322
|
+
}, QUIET_MS);
|
|
27323
|
+
timer.unref();
|
|
27324
|
+
this.windowTimers.set(record2.key, timer);
|
|
27325
|
+
}
|
|
27326
|
+
/** What any session says of its window and its compactions, heard whether a turn of Chips's is going or not. */
|
|
27327
|
+
watched(sessionId, update) {
|
|
27328
|
+
switch (update.sessionUpdate) {
|
|
27329
|
+
case "usage_update":
|
|
27330
|
+
this.reading(sessionId, update);
|
|
27331
|
+
return;
|
|
27332
|
+
case "tool_call":
|
|
27333
|
+
case "tool_call_update":
|
|
27334
|
+
this.compactionStep(sessionId, update);
|
|
27335
|
+
return;
|
|
27336
|
+
case "agent_message_chunk": {
|
|
27337
|
+
const text = textOf2(update["content"]);
|
|
27338
|
+
const run2 = this.compactRuns.get(sessionId);
|
|
27339
|
+
if (run2 !== void 0) run2.words += text;
|
|
27340
|
+
if (text.trim() === CODEX_COMPACTED) this.saidCompacted(sessionId);
|
|
27341
|
+
return;
|
|
27342
|
+
}
|
|
27343
|
+
case "available_commands_update": {
|
|
27344
|
+
const commands = update["availableCommands"];
|
|
27345
|
+
if (Array.isArray(commands) && commands.some((each) => each?.name === "compact")) {
|
|
27346
|
+
this.offersCompact = true;
|
|
27347
|
+
}
|
|
27348
|
+
return;
|
|
27349
|
+
}
|
|
27350
|
+
default:
|
|
27351
|
+
return;
|
|
27352
|
+
}
|
|
27353
|
+
}
|
|
27354
|
+
/**
|
|
27355
|
+
* How full a session is: the turn's height, where a compaction came to, and the agent's reading.
|
|
27356
|
+
* Claude Code's `size` is its model's window once a turn has a result (the update with the cost);
|
|
27357
|
+
* before that it may be a guess, so its window is the one it said last.
|
|
27358
|
+
*/
|
|
27359
|
+
reading(sessionId, update) {
|
|
27360
|
+
const used = update["used"];
|
|
27361
|
+
const size = update["size"];
|
|
27362
|
+
if (typeof used !== "number" || typeof size !== "number" || !(used >= 0) || !(size > 0)) return;
|
|
27363
|
+
const turn = this.turnOf(sessionId);
|
|
27364
|
+
if (turn !== void 0) turn.peak = Math.max(turn.peak, used);
|
|
27365
|
+
this.sessionUsed.set(sessionId, used);
|
|
27366
|
+
const compaction = this.compactions.get(sessionId);
|
|
27367
|
+
if (compaction !== void 0 && compaction.finished === void 0) {
|
|
27368
|
+
if (!compaction.done) compaction.latest = used;
|
|
27369
|
+
else if (compaction.to === void 0) {
|
|
27370
|
+
compaction.to = used;
|
|
27371
|
+
this.compacted(sessionId, compaction);
|
|
27372
|
+
}
|
|
27373
|
+
}
|
|
27374
|
+
const record2 = this.placeOf(sessionId)?.record;
|
|
27375
|
+
if (record2 === void 0) return;
|
|
27376
|
+
const windows = this.kept();
|
|
27377
|
+
const kept2 = windows[record2.key];
|
|
27378
|
+
const trusted = this.knownKind !== "claude-code" || update["cost"] !== void 0;
|
|
27379
|
+
const window = trusted ? size : kept2?.window;
|
|
27380
|
+
if (window === void 0) return;
|
|
27381
|
+
const meta3 = update["_meta"];
|
|
27382
|
+
const model = typeof meta3?.["_claude/model"] === "string" ? meta3["_claude/model"] : kept2?.model;
|
|
27383
|
+
const before = kept2 === void 0 ? this.compactions.get(sessionId)?.finished : void 0;
|
|
27384
|
+
windows[record2.key] = {
|
|
27385
|
+
...before === void 0 ? {} : { last: before },
|
|
27386
|
+
...kept2,
|
|
27387
|
+
used: Math.round(used),
|
|
27388
|
+
window: Math.round(window),
|
|
27389
|
+
...model === void 0 ? {} : { model },
|
|
27390
|
+
asOf: (/* @__PURE__ */ new Date()).toISOString(),
|
|
27391
|
+
session: sessionId
|
|
27392
|
+
};
|
|
27393
|
+
this.windowSoon(record2);
|
|
27394
|
+
}
|
|
27395
|
+
/**
|
|
27396
|
+
* A tool call of a compaction: begun, where Claude Code says from how much and to how much
|
|
27397
|
+
* (`rawOutput`, after it says it completed), done. Another tool call is nothing here.
|
|
27398
|
+
*/
|
|
27399
|
+
compactionStep(sessionId, update) {
|
|
27400
|
+
const id2 = String(update["toolCallId"] ?? "");
|
|
27401
|
+
if (id2 === "") return;
|
|
27402
|
+
let compaction = this.compactions.get(sessionId);
|
|
27403
|
+
if (compaction?.id !== id2) {
|
|
27404
|
+
if (update.sessionUpdate !== "tool_call" || !isCompaction(update)) return;
|
|
27405
|
+
compaction = { id: id2, from: this.sessionUsed.get(sessionId), done: false };
|
|
27406
|
+
this.compactions.set(sessionId, compaction);
|
|
27407
|
+
}
|
|
27408
|
+
const facts = compactionFacts(update);
|
|
27409
|
+
if (facts.from !== void 0) compaction.from = facts.from;
|
|
27410
|
+
if (facts.to !== void 0) compaction.to = facts.to;
|
|
27411
|
+
if (facts.by !== void 0) compaction.by = facts.by;
|
|
27412
|
+
if (compaction.finished !== void 0) {
|
|
27413
|
+
if (facts.from !== void 0 || facts.to !== void 0) this.corrected(sessionId, compaction);
|
|
27414
|
+
return;
|
|
27415
|
+
}
|
|
27416
|
+
const status = update["status"];
|
|
27417
|
+
if (status === "failed") {
|
|
27418
|
+
this.compactions.delete(sessionId);
|
|
27419
|
+
return;
|
|
27420
|
+
}
|
|
27421
|
+
if (status === "completed") {
|
|
27422
|
+
compaction.done = true;
|
|
27423
|
+
compaction.to ??= compaction.latest;
|
|
27424
|
+
}
|
|
27425
|
+
if (compaction.done && compaction.to !== void 0) this.compacted(sessionId, compaction);
|
|
27426
|
+
}
|
|
27427
|
+
/** Codex's old way, its words that it compacted, with no tool call: one done, to what it says next. */
|
|
27428
|
+
saidCompacted(sessionId) {
|
|
27429
|
+
const last = this.compactions.get(sessionId);
|
|
27430
|
+
const lately = last?.finished !== void 0 && Date.now() - Date.parse(last.finished.at) < 5e3;
|
|
27431
|
+
if (last !== void 0 && (last.finished === void 0 || lately)) return;
|
|
27432
|
+
this.compactions.set(sessionId, { id: `said-${Date.now()}`, from: this.sessionUsed.get(sessionId), done: true });
|
|
27433
|
+
}
|
|
27434
|
+
/** A compaction done: its agent's last, counted in the turn it was in, and the copy sent. */
|
|
27435
|
+
compacted(sessionId, compaction) {
|
|
27436
|
+
const run2 = this.compactRuns.get(sessionId);
|
|
27437
|
+
const to = Math.round(compaction.to ?? 0);
|
|
27438
|
+
const last = {
|
|
27439
|
+
at: (/* @__PURE__ */ new Date()).toISOString(),
|
|
27440
|
+
from: Math.round(compaction.from ?? to),
|
|
27441
|
+
to,
|
|
27442
|
+
by: run2?.by ?? compaction.by ?? "itself"
|
|
27443
|
+
};
|
|
27444
|
+
compaction.finished = last;
|
|
27445
|
+
if (run2 !== void 0) run2.done = true;
|
|
27446
|
+
const turn = this.turnOf(sessionId);
|
|
27447
|
+
if (turn !== void 0 && last.by === "itself") turn.folds += 1;
|
|
27448
|
+
this.sessionUsed.set(sessionId, to);
|
|
27449
|
+
const record2 = this.placeOf(sessionId)?.record;
|
|
27450
|
+
const kept2 = record2 === void 0 ? void 0 : this.options.state.windows?.[record2.key];
|
|
27451
|
+
if (record2 === void 0 || kept2 === void 0) return;
|
|
27452
|
+
kept2.last = last;
|
|
27453
|
+
kept2.used = to;
|
|
27454
|
+
kept2.asOf = last.at;
|
|
27455
|
+
kept2.session = sessionId;
|
|
27456
|
+
this.log(`${record2.name} compacted (${last.by}), ${last.from} to ${last.to} tokens`);
|
|
27457
|
+
void this.sendWindow(record2);
|
|
27458
|
+
}
|
|
27459
|
+
/** Claude Code's own count of a compaction, heard after it said it was done: the last put right. */
|
|
27460
|
+
corrected(sessionId, compaction) {
|
|
27461
|
+
const before = compaction.finished;
|
|
27462
|
+
if (before === void 0) return;
|
|
27463
|
+
const last = {
|
|
27464
|
+
...before,
|
|
27465
|
+
from: Math.round(compaction.from ?? before.from),
|
|
27466
|
+
to: Math.round(compaction.to ?? before.to)
|
|
27467
|
+
};
|
|
27468
|
+
compaction.finished = last;
|
|
27469
|
+
const record2 = this.placeOf(sessionId)?.record;
|
|
27470
|
+
const kept2 = record2 === void 0 ? void 0 : this.options.state.windows?.[record2.key];
|
|
27471
|
+
if (record2 === void 0 || kept2?.last?.at !== before.at) return;
|
|
27472
|
+
kept2.last = last;
|
|
27473
|
+
void this.sendWindow(record2);
|
|
27474
|
+
}
|
|
27475
|
+
/**
|
|
27476
|
+
* A turn of Chips's ended: the agent's files read again, in case it changed them (Claude Code
|
|
27477
|
+
* writes its memory), how full it got if that passed half its window, and, where the bridge
|
|
27478
|
+
* keeps its limit, a compaction when it ended at or past it.
|
|
27479
|
+
*/
|
|
27480
|
+
turnEnded(room, turn) {
|
|
27481
|
+
const { record: record2 } = room;
|
|
27482
|
+
void this.sendContext(record2);
|
|
27483
|
+
const kept2 = this.options.state.windows?.[record2.key];
|
|
27484
|
+
if (kept2 === void 0) return;
|
|
27485
|
+
if (turn.peak > kept2.window / 2) {
|
|
27486
|
+
kept2.longTurn = {
|
|
27487
|
+
at: (/* @__PURE__ */ new Date()).toISOString(),
|
|
27488
|
+
peak: Math.round(turn.peak),
|
|
27489
|
+
folds: Math.min(turn.folds, LONG_TURN_FOLDS_MAX)
|
|
27490
|
+
};
|
|
27491
|
+
}
|
|
27492
|
+
const here2 = this.options.state.sessions[`${record2.key}|${room.spaceId}`] === kept2.session;
|
|
27493
|
+
if (here2 && room.compact === void 0 && !this.compacting.has(record2.key) && this.keepsLimit() && pastLimit(kept2)) {
|
|
27494
|
+
this.log(`${record2.name} is past its limit, ${kept2.used} of ${kept2.window} tokens: compacting`);
|
|
27495
|
+
room.compact = { by: "itself" };
|
|
27496
|
+
}
|
|
27497
|
+
void this.sendWindow(record2);
|
|
27498
|
+
}
|
|
27499
|
+
/**
|
|
27500
|
+
* A person's Compact now (Chips ADR 0146): taken at once, with the copy saying so; run in the
|
|
27501
|
+
* session the agent said it was in last, now, or once the turn going there ends.
|
|
27502
|
+
*/
|
|
27503
|
+
async windowCompact(ask2) {
|
|
27504
|
+
await this.known;
|
|
27505
|
+
const record2 = await this.recordOf(ask2.agent_id);
|
|
27506
|
+
if (record2 === void 0) throw new Refuse("This harness has no such agent.");
|
|
27507
|
+
const copy = this.windowCopy(record2);
|
|
27508
|
+
const kept2 = this.options.state.windows?.[record2.key];
|
|
27509
|
+
if (copy === void 0 || kept2 === void 0) throw new Refuse(`${record2.name} hasn't said how full it is yet.`);
|
|
27510
|
+
if (!copy.compacts) throw new Refuse(copy.why_not ?? "It doesn't compact from Chips.", copy);
|
|
27511
|
+
if (this.compacting.has(record2.key)) throw new Refuse("It is compacting already.", copy);
|
|
27512
|
+
const place = this.placeOf(kept2.session);
|
|
27513
|
+
if (place === void 0) throw new Refuse("The conversation it was in isn't open here any more.", copy);
|
|
27514
|
+
const room = this.roomOf(place.record, place.spaceId);
|
|
27515
|
+
this.compacting.set(record2.key, room.busy ? "queued" : "running");
|
|
27516
|
+
room.compact = { by: "asked", changeId: ask2.change_id };
|
|
27517
|
+
this.log(`${record2.name} compacts ${room.busy ? "when its turn ends" : "now"}, from Chips`);
|
|
27518
|
+
if (!room.busy) setImmediate(() => void this.pump(room));
|
|
27519
|
+
return this.windowCopy(record2) ?? copy;
|
|
27520
|
+
}
|
|
27521
|
+
/**
|
|
27522
|
+
* A person's limit (Chips ADR 0146): kept with the agent. Claude Code's sessions start again with
|
|
27523
|
+
* it before their next turn; for the others the bridge compacts past it after a turn. Picking the
|
|
27524
|
+
* harness's own clears what a person picked.
|
|
27525
|
+
*/
|
|
27526
|
+
async windowChange(ask2) {
|
|
27527
|
+
await this.known;
|
|
27528
|
+
const record2 = await this.recordOf(ask2.agent_id);
|
|
27529
|
+
if (record2 === void 0) throw new Refuse("This harness has no such agent.");
|
|
27530
|
+
const copy = this.windowCopy(record2);
|
|
27531
|
+
const kept2 = this.options.state.windows?.[record2.key];
|
|
27532
|
+
if (copy === void 0 || kept2 === void 0) throw new Refuse(`${record2.name} hasn't said how full it is yet.`);
|
|
27533
|
+
if (!copy.editable || copy.limit === void 0) {
|
|
27534
|
+
throw new Refuse(copy.why_read_only ?? "Its limit can't be changed from Chips.", copy);
|
|
27535
|
+
}
|
|
27536
|
+
const offered = ask2.at === null ? copy.limit.may_turn_off : copy.limit.choices.includes(ask2.at);
|
|
27537
|
+
if (!offered) throw new Refuse("That limit isn't one it offers.", copy);
|
|
27538
|
+
const before = kept2.limit;
|
|
27539
|
+
kept2.limit = ask2.at === copy.limit.default ? void 0 : ask2.at;
|
|
27540
|
+
this.save();
|
|
27541
|
+
if (this.knownKind === "claude-code" && kept2.limit !== before) this.reload([record2]);
|
|
27542
|
+
this.log(`${record2.name} compacts itself ${ask2.at === null ? "only when asked" : `at ${ask2.at}%`}, from Chips`);
|
|
27543
|
+
return this.windowCopy(record2) ?? copy;
|
|
27544
|
+
}
|
|
27545
|
+
/**
|
|
27546
|
+
* Compact a room's session now: `/compact`, said to the agent as a turn of its own, whose words go
|
|
27547
|
+
* nowhere. Done when the agent says it compacted; refused with its words when it doesn't.
|
|
27548
|
+
*/
|
|
27549
|
+
async compactIn(room, ask2) {
|
|
27550
|
+
const { record: record2 } = room;
|
|
27551
|
+
const { kind: kind2, chips: chips2 } = this.options;
|
|
27552
|
+
this.compacting.set(record2.key, "running");
|
|
27553
|
+
void this.sendWindow(record2);
|
|
27554
|
+
const notDone = async (why) => {
|
|
27555
|
+
this.compacting.delete(record2.key);
|
|
27556
|
+
this.log(`${record2.name} not compacted: ${why}`);
|
|
27557
|
+
if (ask2.changeId === void 0 || record2.agentId === "") {
|
|
27558
|
+
await this.sendWindow(record2);
|
|
27559
|
+
return;
|
|
27560
|
+
}
|
|
27561
|
+
await chips2.settings.contextWindowFailed(record2.agentId, ask2.changeId, why, this.windowCopy(record2)).catch((error62) => this.log(`${record2.name}'s context window not sent: ${messageOf(error62)}`));
|
|
27562
|
+
};
|
|
27563
|
+
const client = await this.running();
|
|
27564
|
+
if (client === void 0) return notDone(`${kind2.name} isn't running.`);
|
|
27565
|
+
let sessionId;
|
|
27566
|
+
try {
|
|
27567
|
+
sessionId = await this.sessionFor(record2, client, room.spaceId);
|
|
27568
|
+
} catch (error62) {
|
|
27569
|
+
return notDone(this.failure(record2, error62));
|
|
27570
|
+
}
|
|
27571
|
+
const run2 = { by: ask2.by, words: "", done: false };
|
|
27572
|
+
this.compactRuns.set(sessionId, run2);
|
|
27573
|
+
let failed;
|
|
27574
|
+
try {
|
|
27575
|
+
await client.prompt(sessionId, [{ type: "text", text: "/compact" }]);
|
|
27576
|
+
} catch (error62) {
|
|
27577
|
+
failed = this.failure(record2, error62);
|
|
27578
|
+
}
|
|
27579
|
+
const compaction = this.compactions.get(sessionId);
|
|
27580
|
+
if (!run2.done && compaction?.done === true && compaction.finished === void 0) {
|
|
27581
|
+
compaction.to ??= this.sessionUsed.get(sessionId);
|
|
27582
|
+
if (compaction.to !== void 0) this.compacted(sessionId, compaction);
|
|
27583
|
+
}
|
|
27584
|
+
this.compactRuns.delete(sessionId);
|
|
27585
|
+
if (!run2.done) return notDone(failed ?? (cut(run2.words.trim(), 300) || `${kind2.name} didn't compact.`));
|
|
27586
|
+
this.compacting.delete(record2.key);
|
|
27587
|
+
await this.sendWindow(record2);
|
|
27588
|
+
}
|
|
26550
27589
|
// ------------------------------------------------------------------ what the agent asks
|
|
26551
27590
|
async asked(request) {
|
|
26552
27591
|
switch (request.method) {
|
|
@@ -26607,6 +27646,20 @@ ${files.join("\n")}`;
|
|
|
26607
27646
|
return { action: "accept", content };
|
|
26608
27647
|
}
|
|
26609
27648
|
};
|
|
27649
|
+
function settingsFor(kind2, bridge2) {
|
|
27650
|
+
const active = () => {
|
|
27651
|
+
const running = bridge2();
|
|
27652
|
+
if (running === void 0) throw new Refuse("The harness is still starting.");
|
|
27653
|
+
return running;
|
|
27654
|
+
};
|
|
27655
|
+
return {
|
|
27656
|
+
...knownIdOf(kind2) === void 0 ? {} : { context: (edit) => active().contextEdited(edit) },
|
|
27657
|
+
contextWindows: {
|
|
27658
|
+
compact: (ask2) => active().windowCompact(ask2),
|
|
27659
|
+
change: (ask2) => active().windowChange(ask2)
|
|
27660
|
+
}
|
|
27661
|
+
};
|
|
27662
|
+
}
|
|
26610
27663
|
function messageOf(error62) {
|
|
26611
27664
|
if (error62 instanceof AcpError) return error62.message;
|
|
26612
27665
|
return error62 instanceof Error ? error62.message : String(error62);
|
|
@@ -26622,7 +27675,7 @@ function lookAgainPrompt(who, reply, note) {
|
|
|
26622
27675
|
\xAB${cut(reply.trim(), QUOTED)}\xBB`;
|
|
26623
27676
|
const wrong = note === void 0 ? "They didn't say what. Read your reply again and find what was wrong." : `What wasn't right: \xAB${note}\xBB`;
|
|
26624
27677
|
return [
|
|
26625
|
-
`${who} says your reply in this
|
|
27678
|
+
`${who} says your reply in this space wasn't right.`,
|
|
26626
27679
|
quoted2,
|
|
26627
27680
|
wrong,
|
|
26628
27681
|
"Look at it again and answer properly in its place. If it is not clear what was wrong, ask them in one short line. Say plainly what you changed."
|
|
@@ -26635,7 +27688,7 @@ function lookAgainGoal(note) {
|
|
|
26635
27688
|
function cut(text, most) {
|
|
26636
27689
|
return text.length <= most ? text : `${text.slice(0, most - 1)}\u2026`;
|
|
26637
27690
|
}
|
|
26638
|
-
function
|
|
27691
|
+
function textOf2(content) {
|
|
26639
27692
|
const block = content;
|
|
26640
27693
|
return block?.type === "text" && typeof block.text === "string" ? block.text : "";
|
|
26641
27694
|
}
|
|
@@ -26705,12 +27758,12 @@ function forkName(original) {
|
|
|
26705
27758
|
}
|
|
26706
27759
|
|
|
26707
27760
|
// src/keep.ts
|
|
26708
|
-
import { homedir as
|
|
26709
|
-
import { basename as basename3, join as
|
|
27761
|
+
import { homedir as homedir5 } from "node:os";
|
|
27762
|
+
import { basename as basename3, join as join8, resolve as resolve2 } from "node:path";
|
|
26710
27763
|
import { fileURLToPath as fileURLToPath2 } from "node:url";
|
|
26711
27764
|
var flags = process.argv.slice(2);
|
|
26712
27765
|
var words3 = flags.filter((word) => !word.startsWith("--"));
|
|
26713
|
-
var whole = (word) => resolve2(word.startsWith("~/") ?
|
|
27766
|
+
var whole = (word) => resolve2(word.startsWith("~/") ? join8(homedir5(), word.slice(2)) : word);
|
|
26714
27767
|
var here = fileURLToPath2(new URL("..", import.meta.url)).replace(/\/$/, "");
|
|
26715
27768
|
var self = fileURLToPath2(import.meta.url);
|
|
26716
27769
|
var run = self.endsWith(".js") ? [self] : ["--import", "tsx", "src/main.ts"];
|
|
@@ -26756,9 +27809,9 @@ function keepIfAsked(label2, url2, names, log2, before = () => void 0) {
|
|
|
26756
27809
|
}
|
|
26757
27810
|
|
|
26758
27811
|
// src/setup.ts
|
|
26759
|
-
import { accessSync as accessSync2, constants as constants2, existsSync as
|
|
26760
|
-
import { homedir as
|
|
26761
|
-
import { basename as basename4, delimiter as delimiter2, isAbsolute as isAbsolute2, join as
|
|
27812
|
+
import { accessSync as accessSync2, constants as constants2, existsSync as existsSync7, readFileSync as readFileSync7 } from "node:fs";
|
|
27813
|
+
import { homedir as homedir6 } from "node:os";
|
|
27814
|
+
import { basename as basename4, delimiter as delimiter2, isAbsolute as isAbsolute2, join as join9, resolve as resolve3 } from "node:path";
|
|
26762
27815
|
var SetupError = class extends Error {
|
|
26763
27816
|
constructor(message, words4 = {}) {
|
|
26764
27817
|
super(message);
|
|
@@ -26769,15 +27822,15 @@ var SetupError = class extends Error {
|
|
|
26769
27822
|
};
|
|
26770
27823
|
var STILL_GOOD = "The link is still good: run the same command again once that's done.";
|
|
26771
27824
|
var EXAMPLE = '{ "name": "Claude Code", "command": ["claude-agent-acp"], "folders": "~/chips-acp/claude-code" }';
|
|
26772
|
-
var home = (path) => path.startsWith("~/") ?
|
|
27825
|
+
var home = (path) => path.startsWith("~/") ? join9(homedir6(), path.slice(2)) : path;
|
|
26773
27826
|
function readConfig(path) {
|
|
26774
27827
|
const known = knownConfig(basename4(path, ".json"));
|
|
26775
|
-
if (!
|
|
27828
|
+
if (!existsSync7(path) && known === void 0) {
|
|
26776
27829
|
throw new SetupError(
|
|
26777
27830
|
`There is no config at ${path}. Write ${EXAMPLE} there, or name claude-code.json or codex.json, which need none. ${STILL_GOOD}`
|
|
26778
27831
|
);
|
|
26779
27832
|
}
|
|
26780
|
-
const raw =
|
|
27833
|
+
const raw = existsSync7(path) ? JSON.parse(readFileSync7(path, "utf8")) : known;
|
|
26781
27834
|
const name = raw["name"];
|
|
26782
27835
|
const command = raw["command"];
|
|
26783
27836
|
if (typeof name !== "string" || name.trim() === "" || !Array.isArray(command) || command.length === 0) {
|
|
@@ -26801,11 +27854,11 @@ var runnable = (path) => {
|
|
|
26801
27854
|
return false;
|
|
26802
27855
|
}
|
|
26803
27856
|
};
|
|
26804
|
-
function checkCommand(kind2,
|
|
27857
|
+
function checkCommand(kind2, env2 = process.env) {
|
|
26805
27858
|
const [program] = kind2.command;
|
|
26806
27859
|
if (program === void 0) throw new SetupError(`${kind2.name} has no command to run. ${STILL_GOOD}`);
|
|
26807
|
-
const path = { ...
|
|
26808
|
-
const found = program.includes("/") ? runnable(isAbsolute2(program) ? program : resolve3(home(program))) : path.split(delimiter2).some((dir) => dir !== "" && runnable(
|
|
27860
|
+
const path = { ...env2, ...kind2.env }["PATH"] ?? "";
|
|
27861
|
+
const found = program.includes("/") ? runnable(isAbsolute2(program) ? program : resolve3(home(program))) : path.split(delimiter2).some((dir) => dir !== "" && runnable(join9(dir, program)));
|
|
26809
27862
|
if (!found) {
|
|
26810
27863
|
throw new SetupError(
|
|
26811
27864
|
`${kind2.name}'s command, ${program}, isn't on this machine's PATH: ${installWords(kind2)}. ${STILL_GOOD}`,
|
|
@@ -26814,7 +27867,7 @@ function checkCommand(kind2, env = process.env) {
|
|
|
26814
27867
|
}
|
|
26815
27868
|
}
|
|
26816
27869
|
var MINUTE = 6e4;
|
|
26817
|
-
function
|
|
27870
|
+
function within2(promise2, ms, what) {
|
|
26818
27871
|
let timer;
|
|
26819
27872
|
const late = new Promise((_, reject) => {
|
|
26820
27873
|
timer = setTimeout(() => reject(new Error(what)), ms);
|
|
@@ -26843,7 +27896,7 @@ async function checkSignIn(kind2, wire, cwd, options = {}) {
|
|
|
26843
27896
|
try {
|
|
26844
27897
|
let info;
|
|
26845
27898
|
try {
|
|
26846
|
-
info = await
|
|
27899
|
+
info = await within2(client.initialize({ name: "chips-acp", version: "1.0.0" }), MINUTE, "it didn't answer within a minute");
|
|
26847
27900
|
} catch (error62) {
|
|
26848
27901
|
const last = options.stderr?.().slice(-3).join(" ") ?? "";
|
|
26849
27902
|
throw new SetupError(`${kind2.name} didn't start: ${wordsOf2(error62)}.${last === "" ? "" : ` It said: ${last}`} ${STILL_GOOD}`, {
|
|
@@ -26853,7 +27906,7 @@ async function checkSignIn(kind2, wire, cwd, options = {}) {
|
|
|
26853
27906
|
});
|
|
26854
27907
|
}
|
|
26855
27908
|
try {
|
|
26856
|
-
const { sessionId } = await
|
|
27909
|
+
const { sessionId } = await within2(client.newSession(cwd), MINUTE, "it didn't answer within a minute");
|
|
26857
27910
|
if (info.closeSession) await client.closeSession(sessionId).catch(() => void 0);
|
|
26858
27911
|
} catch (error62) {
|
|
26859
27912
|
if (isAuthRequired(error62)) throw new SetupError(`${signedOutWords(kind2, info)} ${STILL_GOOD}`, signedOutStop(kind2));
|
|
@@ -26862,7 +27915,7 @@ async function checkSignIn(kind2, wire, cwd, options = {}) {
|
|
|
26862
27915
|
says: `${kind2.name} couldn't open a session: ${wordsOf2(error62)}.`
|
|
26863
27916
|
});
|
|
26864
27917
|
}
|
|
26865
|
-
if (info.reportsAuth && status === void 0) await
|
|
27918
|
+
if (info.reportsAuth && status === void 0) await within2(said, options.waitMs ?? 6e3, "").catch(() => void 0);
|
|
26866
27919
|
if (status?.kind === "none") throw new SetupError(`${signedOutWords(kind2, info)} ${STILL_GOOD}`, signedOutStop(kind2));
|
|
26867
27920
|
} finally {
|
|
26868
27921
|
client.close();
|
|
@@ -26870,7 +27923,7 @@ async function checkSignIn(kind2, wire, cwd, options = {}) {
|
|
|
26870
27923
|
}
|
|
26871
27924
|
|
|
26872
27925
|
// src/main.ts
|
|
26873
|
-
var home2 = (path) => path.startsWith("~/") ?
|
|
27926
|
+
var home2 = (path) => path.startsWith("~/") ? join10(homedir7(), path.slice(2)) : path;
|
|
26874
27927
|
var link = process.env["CHIPS_JOIN_LINK"] || void 0;
|
|
26875
27928
|
var configPath = resolve4(home2(words3[0] ?? "~/.chips-acp/config.json"));
|
|
26876
27929
|
var LABEL = `chat.chips.acp.${basename5(configPath, ".json")}`;
|
|
@@ -26887,7 +27940,7 @@ try {
|
|
|
26887
27940
|
log(`checking that ${kind.name} starts and is signed in`);
|
|
26888
27941
|
const cwd = kind.folder ?? kind.folders;
|
|
26889
27942
|
const stderr = [];
|
|
26890
|
-
const wire = processWire(kind.command, cwd, { ...process.env, ...kind.env }, (line) => stderr.push(line));
|
|
27943
|
+
const wire = processWire(kind.command, cwd, adapterEnv(kind, { ...process.env, ...kind.env }), (line) => stderr.push(line));
|
|
26891
27944
|
await checkSignIn(kind, wire, cwd, { stderr: () => stderr });
|
|
26892
27945
|
reportStep("checked", { detail: `${kind.name} opened a session` });
|
|
26893
27946
|
}
|
|
@@ -26898,8 +27951,8 @@ try {
|
|
|
26898
27951
|
`);
|
|
26899
27952
|
process.exit(1);
|
|
26900
27953
|
}
|
|
26901
|
-
var folder =
|
|
26902
|
-
var statePath =
|
|
27954
|
+
var folder = join10(dirname5(configPath), basename5(configPath, ".json"));
|
|
27955
|
+
var statePath = join10(folder, "state.json");
|
|
26903
27956
|
mkdirSync4(folder, { recursive: true, mode: 448 });
|
|
26904
27957
|
var refused2 = (error62) => {
|
|
26905
27958
|
if (!(error62 instanceof JoinError)) throw error62;
|
|
@@ -26912,22 +27965,34 @@ var joined = await join3({
|
|
|
26912
27965
|
url: process.env["CHIPS_URL"],
|
|
26913
27966
|
name: kind.name,
|
|
26914
27967
|
software: "chips-acp 1.0.0",
|
|
26915
|
-
wants: [
|
|
27968
|
+
wants: [
|
|
27969
|
+
"agents",
|
|
27970
|
+
"new_spaces",
|
|
27971
|
+
"new_agents",
|
|
27972
|
+
"forks",
|
|
27973
|
+
"restarts",
|
|
27974
|
+
// Each agent's files, for the kinds whose files the bridge knows, and every agent's context window.
|
|
27975
|
+
...knownIdOf(kind) === void 0 ? [] : ["context_files"],
|
|
27976
|
+
"context_windows"
|
|
27977
|
+
],
|
|
26916
27978
|
onCode: (code) => log(`Allow this harness in Chips: ${code}`)
|
|
26917
27979
|
}).catch(refused2);
|
|
26918
27980
|
keepIfAsked(LABEL, joined.url, ["ANTHROPIC_API_KEY", "OPENAI_API_KEY", "CODEX_HOME", "CLAUDE_CONFIG_DIR"], log);
|
|
26919
|
-
var kept =
|
|
26920
|
-
var state = { sessions: kept.sessions ?? {}, agents: kept.agents ?? {} };
|
|
27981
|
+
var kept = existsSync8(statePath) ? JSON.parse(readFileSync8(statePath, "utf8")) : {};
|
|
27982
|
+
var state = { sessions: kept.sessions ?? {}, agents: kept.agents ?? {}, windows: kept.windows ?? {} };
|
|
27983
|
+
var env = adapterEnv(kind, { ...process.env, ...kind.env });
|
|
26921
27984
|
var bridge;
|
|
26922
27985
|
var chips = await connect({
|
|
26923
27986
|
url: joined.url,
|
|
26924
27987
|
token: joined.token,
|
|
26925
27988
|
client: { name: "chips-acp", version: "1.0.0" },
|
|
26926
|
-
store: fileStore(
|
|
27989
|
+
store: fileStore(join10(folder, "chips-state.json")),
|
|
26927
27990
|
onRestart: async () => {
|
|
26928
27991
|
log("a person asked for a restart");
|
|
26929
27992
|
await bridge?.restart();
|
|
26930
|
-
}
|
|
27993
|
+
},
|
|
27994
|
+
// An agent's files and its context window, changed from its page (Chips ADRs 0134, 0146).
|
|
27995
|
+
settings: settingsFor(kind, () => bridge)
|
|
26931
27996
|
});
|
|
26932
27997
|
var git = await checkGit();
|
|
26933
27998
|
if (!git.ok) log(`rooms' projects are off: ${git.why}`);
|
|
@@ -26938,19 +28003,15 @@ bridge = new Bridge({
|
|
|
26938
28003
|
state,
|
|
26939
28004
|
saveState: (next) => writeFileSync4(statePath, `${JSON.stringify(next, null, 2)}
|
|
26940
28005
|
`, { mode: 384 }),
|
|
26941
|
-
wire: () => processWire(
|
|
26942
|
-
|
|
26943
|
-
kind.folder ?? kind.folders,
|
|
26944
|
-
{ ...process.env, ...kind.env },
|
|
26945
|
-
(line) => log(`${kind.name}: ${line}`)
|
|
26946
|
-
),
|
|
28006
|
+
wire: () => processWire(kind.command, kind.folder ?? kind.folders, env, (line) => log(`${kind.name}: ${line}`)),
|
|
28007
|
+
env,
|
|
26947
28008
|
log
|
|
26948
28009
|
});
|
|
26949
28010
|
await bridge.start();
|
|
26950
28011
|
log(`connected as ${chips.harnessId} (${kind.name}), ${Object.keys(state.agents).length} agent(s)`);
|
|
26951
28012
|
await helloOnce(joined, {
|
|
26952
28013
|
name: kind.name,
|
|
26953
|
-
say: (spaceId) => chips.post({ spaceId, text: `Hi, ${kind.name} here, through chips-acp. Make me an agent from any
|
|
28014
|
+
say: (spaceId) => chips.post({ spaceId, text: `Hi, ${kind.name} here, through chips-acp. Make me an agent from any space, or ask me here.` })
|
|
26954
28015
|
}).catch((error62) => log(`hello not said: ${String(error62)}`));
|
|
26955
28016
|
var stop = () => {
|
|
26956
28017
|
bridge?.stop();
|