@akagilnc/pi-workflow-roles 0.1.3414 → 0.1.3439
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/archivist-record-entry.js +21 -12
- package/dist/archivist-record-topology.js +20 -0
- package/dist/auditor-dossier-tool.js +67 -76
- package/dist/canonical-json.js +66 -69
- package/dist/compliance-transport.js +99 -86
- package/dist/countersign-contracts.js +23 -25
- package/dist/doctor-contracts.js +169 -145
- package/dist/engine-detour-tool.js +83 -87
- package/dist/engine-detour.js +148 -183
- package/dist/evidence-child-executor.js +10 -1
- package/dist/exact-utf8.js +11 -10
- package/dist/git-object-id.js +10 -5
- package/dist/gleaner-left-contracts.js +33 -35
- package/dist/grok/production-host.js +229 -118
- package/dist/inspector-contracts.js +28 -31
- package/dist/institutional-resolution.js +101 -104
- package/dist/ledger-session-read.js +241 -0
- package/dist/merger-contracts.js +66 -56
- package/dist/notary-contracts.js +91 -100
- package/dist/open-tool-schema.js +32 -31
- package/dist/package-contracts/collector-output.js +56 -43
- package/dist/package-contracts/fixer-output.js +52 -50
- package/dist/package-contracts/fixer-packet.js +67 -64
- package/dist/package-contracts/gatekeeper-output.js +48 -56
- package/dist/package-contracts/judge-output.js +23 -20
- package/dist/package-contracts/navigator-output.js +35 -40
- package/dist/package-contracts/reviewer-output.js +94 -110
- package/dist/package-contracts/terminating-infrastructure.js +62 -90
- package/dist/package-contracts/worker-output.js +30 -11
- package/dist/package-resources/engine-material.js +58 -94
- package/dist/public-cli/config.js +420 -484
- package/dist/public-cli/main.js +1219 -524
- package/dist/public-cli/registry.js +107 -114
- package/dist/receipt-delivery-policy.js +74 -76
- package/dist/session-opening-materials.js +44 -47
- package/dist/sha256.js +5 -3
- package/dist/sitian-appender.js +204 -210
- package/dist/sitian-contracts.js +15 -19
- package/dist/sitian-facade.js +5 -10
- package/dist/sitian-reader.js +37 -46
- package/dist/stream-idle-guard.js +63 -71
- package/dist/ticket-seat-memory.js +244 -0
- package/package.json +1 -1
- package/scripts/build-package.mjs +41 -0
- package/src/analyst-gate-cycles-read.ts +152 -83
- package/src/analyst-ledger.ts +170 -43
- package/src/archivist-record-entry.ts +32 -11
- package/src/archivist-record-topology.ts +39 -0
- package/src/evidence-child-executor.ts +14 -1
- package/src/grok/production-host.ts +44 -9
- package/src/host-contracts.ts +18 -0
- package/src/host-transition-prior-native.ts +8 -1
- package/src/ledger-session-read.ts +56 -0
- package/src/pi/durable-principal.ts +6 -0
- package/src/public-cli/inspector-run.ts +21 -10
- package/src/public-cli/invocation.ts +4 -20
- package/src/public-cli/notary-run.ts +21 -4
- package/src/public-cli/post-admission.ts +333 -42
- package/src/public-cli/settlement.ts +266 -81
- package/src/session-opening-materials.ts +4 -2
- package/src/ticket-seat-memory.ts +454 -0
|
@@ -348,6 +348,26 @@ var init_activation_ledger_topology = __esm({
|
|
|
348
348
|
}
|
|
349
349
|
});
|
|
350
350
|
|
|
351
|
+
// src/archivist-record-topology.ts
|
|
352
|
+
import { createHash as createHash4 } from "node:crypto";
|
|
353
|
+
import { join as join5 } from "node:path";
|
|
354
|
+
function subjectKeyedRecordDirectory(input) {
|
|
355
|
+
const ledgerHome = input.parentSessionFile !== void 0 && input.parentSessionFile.length > 0 ? resolveActivationLedgerHomeForPath(input.parentSessionFile) : resolveActivationLedgerHome(input.home);
|
|
356
|
+
const digest = createHash4("sha256").update(input.subject).digest("hex").slice(0, 32);
|
|
357
|
+
return join5(
|
|
358
|
+
activationBookDirectory(ledgerHome, resolveBookKeyFromGit(input.cwd)),
|
|
359
|
+
input.kind,
|
|
360
|
+
digest
|
|
361
|
+
);
|
|
362
|
+
}
|
|
363
|
+
var init_archivist_record_topology = __esm({
|
|
364
|
+
"src/archivist-record-topology.ts"() {
|
|
365
|
+
"use strict";
|
|
366
|
+
init_activation_ledger_git();
|
|
367
|
+
init_activation_ledger_topology();
|
|
368
|
+
}
|
|
369
|
+
});
|
|
370
|
+
|
|
351
371
|
// src/upstream-error-testimony.ts
|
|
352
372
|
function isNonSuccessHttpStatus(status) {
|
|
353
373
|
return typeof status === "number" && (status < 200 || status >= 300);
|
|
@@ -373,14 +393,15 @@ var init_upstream_error_testimony = __esm({
|
|
|
373
393
|
var archivist_record_entry_exports = {};
|
|
374
394
|
__export(archivist_record_entry_exports, {
|
|
375
395
|
WORKER_SUBMISSION_GATE_KIND: () => WORKER_SUBMISSION_GATE_KIND,
|
|
376
|
-
createRecordSession: () => createRecordSession
|
|
396
|
+
createRecordSession: () => createRecordSession,
|
|
397
|
+
createRecordSessionOpen: () => createRecordSessionOpen,
|
|
398
|
+
subjectKeyedRecordDirectory: () => subjectKeyedRecordDirectory
|
|
377
399
|
});
|
|
378
|
-
import { createHash as createHash4 } from "node:crypto";
|
|
379
400
|
import { existsSync as existsSync5, readFileSync as readFileSync2, realpathSync as realpathSync2, writeFileSync as writeFileSync3 } from "node:fs";
|
|
380
|
-
import { dirname as dirname8, resolve as resolve6, join as
|
|
401
|
+
import { dirname as dirname8, resolve as resolve6, join as join12 } from "node:path";
|
|
381
402
|
import { SessionManager } from "@earendil-works/pi-coding-agent";
|
|
382
403
|
function readCurrentSession(sessionDir) {
|
|
383
|
-
const ledger =
|
|
404
|
+
const ledger = join12(sessionDir, CURRENT_SESSION_LEDGER);
|
|
384
405
|
try {
|
|
385
406
|
const value = JSON.parse(readFileSync2(ledger, "utf8"));
|
|
386
407
|
if (typeof value !== "object" || value === null || typeof value.sessionFile !== "string" || value.sessionFile.length === 0) {
|
|
@@ -395,7 +416,7 @@ function readCurrentSession(sessionDir) {
|
|
|
395
416
|
}
|
|
396
417
|
}
|
|
397
418
|
function writeCurrentSession(sessionDir, sessionFile) {
|
|
398
|
-
const ledger =
|
|
419
|
+
const ledger = join12(sessionDir, CURRENT_SESSION_LEDGER);
|
|
399
420
|
try {
|
|
400
421
|
writeFileSync3(ledger, `${JSON.stringify({ sessionFile })}
|
|
401
422
|
`, { flag: "wx" });
|
|
@@ -438,25 +459,25 @@ function assertRecentFinalFileUnderSessionDir(sessionDir, recentFile) {
|
|
|
438
459
|
);
|
|
439
460
|
}
|
|
440
461
|
}
|
|
441
|
-
function
|
|
462
|
+
function createRecordSessionOpen(options) {
|
|
442
463
|
const cwd = options.cwd;
|
|
443
464
|
const parentFile = options.parent?.getSessionFile();
|
|
444
465
|
const ledgerHome = resolveActivationLedgerHomeForPath(parentFile);
|
|
445
466
|
let sessionDir;
|
|
446
467
|
let parentSession;
|
|
447
468
|
if (options.subject !== void 0) {
|
|
448
|
-
|
|
449
|
-
|
|
450
|
-
|
|
451
|
-
options.
|
|
452
|
-
|
|
453
|
-
);
|
|
469
|
+
sessionDir = subjectKeyedRecordDirectory({
|
|
470
|
+
cwd,
|
|
471
|
+
kind: options.kind,
|
|
472
|
+
subject: options.subject,
|
|
473
|
+
...parentFile === void 0 || parentFile.length === 0 ? {} : { parentSessionFile: parentFile }
|
|
474
|
+
});
|
|
454
475
|
parentSession = parentFile && parentFile.length > 0 ? parentFile : void 0;
|
|
455
476
|
} else if (parentFile === void 0 || parentFile.length === 0) {
|
|
456
|
-
return SessionManager.inMemory(cwd);
|
|
477
|
+
return { session: SessionManager.inMemory(cwd), resumed: false };
|
|
457
478
|
} else {
|
|
458
479
|
const parentResolved = resolve6(parentFile);
|
|
459
|
-
sessionDir = physicallyContainedIn(ledgerHome, parentResolved) ?
|
|
480
|
+
sessionDir = physicallyContainedIn(ledgerHome, parentResolved) ? join12(dirname8(parentResolved), options.kind) : join12(activationBookDirectory(ledgerHome, resolveBookKeyFromGit(cwd)), options.kind);
|
|
460
481
|
parentSession = parentFile;
|
|
461
482
|
}
|
|
462
483
|
const nestAlreadyExists = existsSync5(sessionDir);
|
|
@@ -465,7 +486,10 @@ function createRecordSession(options) {
|
|
|
465
486
|
if (mayResumeSameNest && nestAlreadyExists) {
|
|
466
487
|
const recentFile = readCurrentSession(sessionDir);
|
|
467
488
|
assertRecentFinalFileUnderSessionDir(sessionDir, recentFile);
|
|
468
|
-
return
|
|
489
|
+
return {
|
|
490
|
+
session: SessionManager.open(recentFile, sessionDir, cwd),
|
|
491
|
+
resumed: true
|
|
492
|
+
};
|
|
469
493
|
}
|
|
470
494
|
const session = SessionManager.create(
|
|
471
495
|
cwd,
|
|
@@ -486,7 +510,10 @@ function createRecordSession(options) {
|
|
|
486
510
|
writeCurrentSession(sessionDir, file);
|
|
487
511
|
}
|
|
488
512
|
}
|
|
489
|
-
return session;
|
|
513
|
+
return { session, resumed: false };
|
|
514
|
+
}
|
|
515
|
+
function createRecordSession(options) {
|
|
516
|
+
return createRecordSessionOpen(options).session;
|
|
490
517
|
}
|
|
491
518
|
var CURRENT_SESSION_LEDGER, WORKER_SUBMISSION_GATE_KIND;
|
|
492
519
|
var init_archivist_record_entry = __esm({
|
|
@@ -494,6 +521,8 @@ var init_archivist_record_entry = __esm({
|
|
|
494
521
|
"use strict";
|
|
495
522
|
init_activation_ledger_git();
|
|
496
523
|
init_activation_ledger_topology();
|
|
524
|
+
init_archivist_record_topology();
|
|
525
|
+
init_archivist_record_topology();
|
|
497
526
|
CURRENT_SESSION_LEDGER = "current-session.json";
|
|
498
527
|
WORKER_SUBMISSION_GATE_KIND = "worker-submission-gate";
|
|
499
528
|
}
|
|
@@ -575,7 +604,7 @@ __export(in_process_session_exports, {
|
|
|
575
604
|
});
|
|
576
605
|
import { mkdtemp as mkdtemp2, rm as rm2 } from "node:fs/promises";
|
|
577
606
|
import { tmpdir as tmpdir2 } from "node:os";
|
|
578
|
-
import { join as
|
|
607
|
+
import { join as join13 } from "node:path";
|
|
579
608
|
import {
|
|
580
609
|
createAgentSession,
|
|
581
610
|
DefaultResourceLoader,
|
|
@@ -698,7 +727,7 @@ async function openPiInstitutionalSession(options) {
|
|
|
698
727
|
let scratchDir;
|
|
699
728
|
let resolvedAgentDir = options.agentDir;
|
|
700
729
|
if (resolvedAgentDir === void 0) {
|
|
701
|
-
scratchDir = await mkdtemp2(
|
|
730
|
+
scratchDir = await mkdtemp2(join13(options.credentialScratchParent ?? tmpdir2(), "ak-institutional-"));
|
|
702
731
|
resolvedAgentDir = scratchDir;
|
|
703
732
|
}
|
|
704
733
|
try {
|
|
@@ -1216,8 +1245,8 @@ var init_in_process_session = __esm({
|
|
|
1216
1245
|
});
|
|
1217
1246
|
|
|
1218
1247
|
// src/grok/production-host.ts
|
|
1219
|
-
import { readFile as
|
|
1220
|
-
import { join as
|
|
1248
|
+
import { readFile as readFile16, rm as rm6, writeFile as writeFile11 } from "node:fs/promises";
|
|
1249
|
+
import { join as join27 } from "node:path";
|
|
1221
1250
|
import { fileURLToPath as fileURLToPath3 } from "node:url";
|
|
1222
1251
|
|
|
1223
1252
|
// src/canonical-skill-binding.ts
|
|
@@ -3105,7 +3134,7 @@ import { Type as Type13 } from "typebox";
|
|
|
3105
3134
|
// src/evidence-child-executor.ts
|
|
3106
3135
|
import { mkdtemp as mkdtemp3, rm as rm3 } from "node:fs/promises";
|
|
3107
3136
|
import { tmpdir as tmpdir3 } from "node:os";
|
|
3108
|
-
import { join as
|
|
3137
|
+
import { join as join14 } from "node:path";
|
|
3109
3138
|
import "@earendil-works/pi-ai";
|
|
3110
3139
|
|
|
3111
3140
|
// src/sitian-appender.ts
|
|
@@ -3388,14 +3417,79 @@ function sitianReport(input) {
|
|
|
3388
3417
|
return appendSitianRecord(input);
|
|
3389
3418
|
}
|
|
3390
3419
|
|
|
3420
|
+
// src/ticket-seat-memory.ts
|
|
3421
|
+
import { readFile as readFile4, writeFile } from "node:fs/promises";
|
|
3422
|
+
import { join as join6 } from "node:path";
|
|
3423
|
+
init_activation_ledger_topology();
|
|
3424
|
+
init_archivist_record_topology();
|
|
3425
|
+
var TICKET_SEAT_MEMORY_KIND = "auditor-roles";
|
|
3426
|
+
var TICKET_SEAT_MEMORY_SEATS = ["inspector", "notary", "auditor"];
|
|
3427
|
+
function isTicketSeatMemorySeat(value) {
|
|
3428
|
+
return TICKET_SEAT_MEMORY_SEATS.includes(value);
|
|
3429
|
+
}
|
|
3430
|
+
function isEnoent(error) {
|
|
3431
|
+
return error instanceof Error && "code" in error && error.code === "ENOENT";
|
|
3432
|
+
}
|
|
3433
|
+
function ticketSeatMemorySubject(ticketNumber, seat) {
|
|
3434
|
+
if (!Number.isSafeInteger(ticketNumber) || ticketNumber < 1) {
|
|
3435
|
+
throw new Error(
|
|
3436
|
+
`ticket-seat memory subject requires a positive ticket number, got ${String(ticketNumber)}`
|
|
3437
|
+
);
|
|
3438
|
+
}
|
|
3439
|
+
return `${ticketNumber}:${seat}`;
|
|
3440
|
+
}
|
|
3441
|
+
async function readRunAdmittedPageFacts(runDirectory) {
|
|
3442
|
+
try {
|
|
3443
|
+
const raw = JSON.parse(
|
|
3444
|
+
await readFile4(join6(runDirectory, "admitted-request.json"), "utf8")
|
|
3445
|
+
);
|
|
3446
|
+
if (raw === null || typeof raw !== "object" || Array.isArray(raw)) {
|
|
3447
|
+
return {};
|
|
3448
|
+
}
|
|
3449
|
+
const record4 = raw;
|
|
3450
|
+
const ticketNumber = record4.ticketNumber;
|
|
3451
|
+
const projectRoot = record4.projectRoot;
|
|
3452
|
+
return {
|
|
3453
|
+
...typeof ticketNumber === "number" && Number.isSafeInteger(ticketNumber) && ticketNumber >= 1 ? { ticketNumber } : {},
|
|
3454
|
+
...typeof projectRoot === "string" ? { projectRoot } : {}
|
|
3455
|
+
};
|
|
3456
|
+
} catch (error) {
|
|
3457
|
+
if (isEnoent(error)) return {};
|
|
3458
|
+
throw error;
|
|
3459
|
+
}
|
|
3460
|
+
}
|
|
3461
|
+
async function readInvocationTicketNumber(runDirectory) {
|
|
3462
|
+
try {
|
|
3463
|
+
const raw = JSON.parse(
|
|
3464
|
+
await readFile4(join6(runDirectory, "invocation.json"), "utf8")
|
|
3465
|
+
);
|
|
3466
|
+
if (raw === null || typeof raw !== "object" || Array.isArray(raw)) {
|
|
3467
|
+
return void 0;
|
|
3468
|
+
}
|
|
3469
|
+
const ticketNumber = raw.ticketNumber;
|
|
3470
|
+
if (typeof ticketNumber === "number" && Number.isSafeInteger(ticketNumber) && ticketNumber >= 1) {
|
|
3471
|
+
return ticketNumber;
|
|
3472
|
+
}
|
|
3473
|
+
} catch (error) {
|
|
3474
|
+
if (isEnoent(error)) return void 0;
|
|
3475
|
+
throw error;
|
|
3476
|
+
}
|
|
3477
|
+
return void 0;
|
|
3478
|
+
}
|
|
3479
|
+
async function readRunTicketNumber(runDirectory) {
|
|
3480
|
+
const admitted = await readRunAdmittedPageFacts(runDirectory);
|
|
3481
|
+
if (admitted.ticketNumber !== void 0) return admitted.ticketNumber;
|
|
3482
|
+
return readInvocationTicketNumber(runDirectory);
|
|
3483
|
+
}
|
|
3484
|
+
|
|
3391
3485
|
// src/engine-detour-tool.ts
|
|
3392
3486
|
import { Type as Type11 } from "typebox";
|
|
3393
3487
|
|
|
3394
3488
|
// src/engine-detour.ts
|
|
3395
3489
|
import { spawn as spawn2 } from "node:child_process";
|
|
3396
|
-
import { mkdtemp, rm, writeFile } from "node:fs/promises";
|
|
3490
|
+
import { mkdtemp, rm, writeFile as writeFile2 } from "node:fs/promises";
|
|
3397
3491
|
import { tmpdir } from "node:os";
|
|
3398
|
-
import { join as
|
|
3492
|
+
import { join as join7 } from "node:path";
|
|
3399
3493
|
var ENGINE_DETOUR_TOOL_NAME = "ak_engine_detour";
|
|
3400
3494
|
var AK_ROLE_ENGINE_ENV = "AK_ROLE_ENGINE";
|
|
3401
3495
|
var ENGINE_DETOUR_STAGED_PROMPT_TOKEN = "<<ak-engine-staged-prompt>>";
|
|
@@ -3486,12 +3580,12 @@ async function runEngineDetourOnce(input) {
|
|
|
3486
3580
|
if (input.stagedPrompt === void 0) {
|
|
3487
3581
|
return spawnEngineDetourOnce(input);
|
|
3488
3582
|
}
|
|
3489
|
-
const stagingDir = await mkdtemp(
|
|
3490
|
-
const stagedPath =
|
|
3583
|
+
const stagingDir = await mkdtemp(join7(tmpdir(), "ak-engine-detour-"));
|
|
3584
|
+
const stagedPath = join7(stagingDir, "prompt.txt");
|
|
3491
3585
|
let result2;
|
|
3492
3586
|
let runError;
|
|
3493
3587
|
try {
|
|
3494
|
-
await
|
|
3588
|
+
await writeFile2(stagedPath, input.stagedPrompt, "utf8");
|
|
3495
3589
|
const argv = resolveArgvWithStagedPrompt(input.argv, stagedPath);
|
|
3496
3590
|
result2 = await spawnEngineDetourOnce({
|
|
3497
3591
|
argv,
|
|
@@ -3623,7 +3717,7 @@ function registerEngineDetourTool(roleHost, hostActions) {
|
|
|
3623
3717
|
|
|
3624
3718
|
// src/package-resources/engine-material.ts
|
|
3625
3719
|
import { existsSync as existsSync4, readdirSync } from "node:fs";
|
|
3626
|
-
import { join as
|
|
3720
|
+
import { join as join8 } from "node:path";
|
|
3627
3721
|
var ENGINE_MATERIAL_RELATIVE_ROOT = "resources/engines";
|
|
3628
3722
|
function isEngineNameSyntax(name) {
|
|
3629
3723
|
if (typeof name !== "string") return false;
|
|
@@ -3633,11 +3727,11 @@ function isEngineNameSyntax(name) {
|
|
|
3633
3727
|
return true;
|
|
3634
3728
|
}
|
|
3635
3729
|
function resolveEngineMaterialDirectory(packageRoot) {
|
|
3636
|
-
return
|
|
3730
|
+
return join8(packageRoot, ENGINE_MATERIAL_RELATIVE_ROOT);
|
|
3637
3731
|
}
|
|
3638
3732
|
function resolveEngineMaterialPath(packageRoot, name) {
|
|
3639
3733
|
const legal = assertLegalEngineName(name);
|
|
3640
|
-
return
|
|
3734
|
+
return join8(resolveEngineMaterialDirectory(packageRoot), `${legal}.md`);
|
|
3641
3735
|
}
|
|
3642
3736
|
function assertLegalEngineName(name) {
|
|
3643
3737
|
if (!isEngineNameSyntax(name)) {
|
|
@@ -3674,8 +3768,8 @@ function appendEngineSessionMaterial(lines, engineMaterial) {
|
|
|
3674
3768
|
}
|
|
3675
3769
|
|
|
3676
3770
|
// src/institutional-resolution.ts
|
|
3677
|
-
import { readFile as
|
|
3678
|
-
import { join as
|
|
3771
|
+
import { readFile as readFile5, writeFile as writeFile3 } from "node:fs/promises";
|
|
3772
|
+
import { join as join9 } from "node:path";
|
|
3679
3773
|
|
|
3680
3774
|
// src/public-cli/registry.ts
|
|
3681
3775
|
var PUBLIC_CALLABLE_ROLES = PACKAGED_ROLE_REGISTRY.map(
|
|
@@ -3705,10 +3799,10 @@ function cleanSelection(model) {
|
|
|
3705
3799
|
};
|
|
3706
3800
|
}
|
|
3707
3801
|
async function readInstitutionalSeatSelection(runDirectory, seat) {
|
|
3708
|
-
const filePath =
|
|
3802
|
+
const filePath = join9(runDirectory, INSTITUTIONAL_RESOLUTION_FILE);
|
|
3709
3803
|
let raw;
|
|
3710
3804
|
try {
|
|
3711
|
-
raw = await
|
|
3805
|
+
raw = await readFile5(filePath, "utf8");
|
|
3712
3806
|
} catch (error) {
|
|
3713
3807
|
throw new InstitutionalResolutionError(
|
|
3714
3808
|
`institutional resolution page is missing at ${filePath}`,
|
|
@@ -3750,9 +3844,9 @@ async function readInstitutionalSeatSelection(runDirectory, seat) {
|
|
|
3750
3844
|
}
|
|
3751
3845
|
|
|
3752
3846
|
// src/navigator-session-contracts.ts
|
|
3753
|
-
import { mkdir, readFile as
|
|
3847
|
+
import { mkdir, readFile as readFile6, writeFile as writeFile4 } from "node:fs/promises";
|
|
3754
3848
|
import { homedir as homedir2 } from "node:os";
|
|
3755
|
-
import { dirname as dirname7, join as
|
|
3849
|
+
import { dirname as dirname7, join as join10 } from "node:path";
|
|
3756
3850
|
import { Type as Type12 } from "typebox";
|
|
3757
3851
|
import { Value as Value2 } from "typebox/value";
|
|
3758
3852
|
var NAVIGATOR_PREPARE_TOOL_NAME = "ak_navigator_prepare";
|
|
@@ -3867,11 +3961,11 @@ var navigatorProviderFailureSchema = Type12.Object({
|
|
|
3867
3961
|
])
|
|
3868
3962
|
}, { additionalProperties: false });
|
|
3869
3963
|
function navigatorModelSettingPath() {
|
|
3870
|
-
return
|
|
3964
|
+
return join10(process.env.PI_CODING_AGENT_DIR ?? join10(homedir2(), ".pi", "agent"), "navigator-model.json");
|
|
3871
3965
|
}
|
|
3872
3966
|
async function readNavigatorModelSetting(path = navigatorModelSettingPath()) {
|
|
3873
3967
|
try {
|
|
3874
|
-
const raw = JSON.parse(await
|
|
3968
|
+
const raw = JSON.parse(await readFile6(path, "utf8"));
|
|
3875
3969
|
if (!exactRecord(raw) || typeof raw.model !== "string" || raw.model.trim() === "") {
|
|
3876
3970
|
throw new Error("Navigator model setting is malformed");
|
|
3877
3971
|
}
|
|
@@ -3998,11 +4092,11 @@ function createReceiptDeliveryPolicy() {
|
|
|
3998
4092
|
}
|
|
3999
4093
|
|
|
4000
4094
|
// src/typed-provider-http.ts
|
|
4001
|
-
import { readFile as
|
|
4002
|
-
import { join as
|
|
4095
|
+
import { readFile as readFile7, unlink, writeFile as writeFile5 } from "node:fs/promises";
|
|
4096
|
+
import { join as join11 } from "node:path";
|
|
4003
4097
|
var TYPED_HTTP_FILE = "typed-provider-http.json";
|
|
4004
4098
|
function typedProviderHttpPath(runDirectory) {
|
|
4005
|
-
return
|
|
4099
|
+
return join11(runDirectory, TYPED_HTTP_FILE);
|
|
4006
4100
|
}
|
|
4007
4101
|
async function clearTypedProviderHttpObservation(runDirectory) {
|
|
4008
4102
|
try {
|
|
@@ -4023,7 +4117,7 @@ async function recordTypedProviderHttpStatus(runDirectory, observation) {
|
|
|
4023
4117
|
httpStatus: observation.httpStatus,
|
|
4024
4118
|
provider: observation.provider
|
|
4025
4119
|
};
|
|
4026
|
-
await
|
|
4120
|
+
await writeFile5(
|
|
4027
4121
|
typedProviderHttpPath(runDirectory),
|
|
4028
4122
|
`${JSON.stringify(body)}
|
|
4029
4123
|
`,
|
|
@@ -4044,7 +4138,7 @@ async function buildEvidenceChildSystemPrompt(engineMaterial) {
|
|
|
4044
4138
|
return appendEngineSessionMaterial(materials, engineMaterial).join("\n");
|
|
4045
4139
|
}
|
|
4046
4140
|
async function withInProcessScratch(options, run) {
|
|
4047
|
-
const scratch = await mkdtemp3(
|
|
4141
|
+
const scratch = await mkdtemp3(join14(options.parentDirectory ?? tmpdir3(), options.prefix));
|
|
4048
4142
|
let failure2;
|
|
4049
4143
|
try {
|
|
4050
4144
|
return await run(scratch);
|
|
@@ -4324,9 +4418,12 @@ async function executeAuditorChild(options) {
|
|
|
4324
4418
|
const parentHeader = parentSessionManager?.getHeader?.();
|
|
4325
4419
|
const parentSessionFile = parentSessionManager?.getSessionFile?.();
|
|
4326
4420
|
const parentAttemptEntryId = parentSessionManager?.getLeafId?.();
|
|
4421
|
+
const ticketNumber = await readRunTicketNumber(runDirectory);
|
|
4422
|
+
const memorySubject = ticketNumber !== void 0 && isTicketSeatMemorySeat(seat) ? ticketSeatMemorySubject(ticketNumber, seat) : void 0;
|
|
4327
4423
|
const auditorSessionManager = createRecordSession2({
|
|
4328
4424
|
cwd,
|
|
4329
|
-
kind:
|
|
4425
|
+
kind: TICKET_SEAT_MEMORY_KIND,
|
|
4426
|
+
...memorySubject === void 0 ? {} : { subject: memorySubject },
|
|
4330
4427
|
...parentSessionManager === void 0 ? {} : { parent: parentSessionManager }
|
|
4331
4428
|
});
|
|
4332
4429
|
const { openPiInstitutionalSession: openPiInstitutionalSession2 } = await Promise.resolve().then(() => (init_in_process_session(), in_process_session_exports));
|
|
@@ -4985,7 +5082,7 @@ function createPiDoctorAuditor() {
|
|
|
4985
5082
|
}
|
|
4986
5083
|
|
|
4987
5084
|
// src/doctor-evidence.ts
|
|
4988
|
-
import { readdir, readFile as
|
|
5085
|
+
import { readdir, readFile as readFile8, realpath as realpath2, stat } from "node:fs/promises";
|
|
4989
5086
|
import { dirname as dirname9, relative as relative2, resolve as resolve8, sep as sep2 } from "node:path";
|
|
4990
5087
|
|
|
4991
5088
|
// src/audit-escalation.ts
|
|
@@ -5387,7 +5484,7 @@ async function loadDoctorCase(runsPath) {
|
|
|
5387
5484
|
const turns = { count: 0, sources: [] }, calls = { count: 0, sources: [] }, tokens = { count: 0, sources: [] };
|
|
5388
5485
|
for (const path of await discoverCaseFiles(root)) {
|
|
5389
5486
|
const id = relative2(root, path).split(sep2).join("/");
|
|
5390
|
-
const bytes = await
|
|
5487
|
+
const bytes = await readFile8(path);
|
|
5391
5488
|
const content = bytes.toString("utf8");
|
|
5392
5489
|
const kind = id.endsWith(".jsonl") ? "session" : "stderr";
|
|
5393
5490
|
evidence.push({ id, kind, byteLength: bytes.byteLength, contentLength: content.length, sha256: sha256Hex(bytes), content });
|
|
@@ -6398,23 +6495,23 @@ ${helpContext}
|
|
|
6398
6495
|
}
|
|
6399
6496
|
|
|
6400
6497
|
// src/navigator-work-context.ts
|
|
6401
|
-
import { readFile as
|
|
6498
|
+
import { readFile as readFile12 } from "node:fs/promises";
|
|
6402
6499
|
import { resolve as resolve13 } from "node:path";
|
|
6403
6500
|
|
|
6404
6501
|
// src/notary-source-run.ts
|
|
6405
6502
|
init_activation_ledger_git();
|
|
6406
6503
|
init_activation_ledger_topology();
|
|
6407
|
-
import { dirname as dirname11, isAbsolute as isAbsolute4, join as
|
|
6504
|
+
import { dirname as dirname11, isAbsolute as isAbsolute4, join as join18, resolve as resolve12, basename as basename5 } from "node:path";
|
|
6408
6505
|
import { lstat as lstat2, realpath as realpath4 } from "node:fs/promises";
|
|
6409
6506
|
|
|
6410
6507
|
// src/public-cli/run-lifecycle.ts
|
|
6411
6508
|
init_activation_ledger_topology();
|
|
6412
|
-
import { chmod, open, readdir as readdir2, readFile as
|
|
6413
|
-
import { join as
|
|
6509
|
+
import { chmod, open, readdir as readdir2, readFile as readFile11, unlink as unlink2, writeFile as writeFile7 } from "node:fs/promises";
|
|
6510
|
+
import { join as join17 } from "node:path";
|
|
6414
6511
|
|
|
6415
6512
|
// src/collector-config.ts
|
|
6416
6513
|
import { createHash as createHash6 } from "node:crypto";
|
|
6417
|
-
import { readFile as
|
|
6514
|
+
import { readFile as readFile9 } from "node:fs/promises";
|
|
6418
6515
|
var COLLECTOR_HOST = "github.com";
|
|
6419
6516
|
var COLLECTOR_OWNER_PATTERN = /^[A-Za-z0-9](?:[A-Za-z0-9-]{0,37}[A-Za-z0-9])?$/;
|
|
6420
6517
|
var COLLECTOR_REPO_PATTERN = /^[A-Za-z0-9](?:[A-Za-z0-9._-]{0,98}[A-Za-z0-9])?$/;
|
|
@@ -6461,7 +6558,7 @@ function emptyCollectorManifest() {
|
|
|
6461
6558
|
async function loadCollectorManifest(path) {
|
|
6462
6559
|
let bytes;
|
|
6463
6560
|
try {
|
|
6464
|
-
bytes = await
|
|
6561
|
+
bytes = await readFile9(path);
|
|
6465
6562
|
} catch (error) {
|
|
6466
6563
|
fail3(`Collector request manifest is unreadable at ${path}`, error);
|
|
6467
6564
|
}
|
|
@@ -6492,11 +6589,11 @@ init_activation_ledger_git();
|
|
|
6492
6589
|
import {
|
|
6493
6590
|
lstat,
|
|
6494
6591
|
mkdir as mkdir2,
|
|
6495
|
-
readFile as
|
|
6592
|
+
readFile as readFile10,
|
|
6496
6593
|
realpath as realpath3,
|
|
6497
|
-
writeFile as
|
|
6594
|
+
writeFile as writeFile6
|
|
6498
6595
|
} from "node:fs/promises";
|
|
6499
|
-
import { basename as basename4, isAbsolute as isAbsolute3, join as
|
|
6596
|
+
import { basename as basename4, isAbsolute as isAbsolute3, join as join16, resolve as resolve11, sep as sep3 } from "node:path";
|
|
6500
6597
|
|
|
6501
6598
|
// src/public-cli/option-definitions.ts
|
|
6502
6599
|
var SHARED_PROJECT_SEMANTICS = {
|
|
@@ -6959,7 +7056,7 @@ var PUBLIC_COMMAND_HELP = {
|
|
|
6959
7056
|
async function loadAdmittedJudgeRequest(runDirectory) {
|
|
6960
7057
|
try {
|
|
6961
7058
|
const raw = JSON.parse(
|
|
6962
|
-
await
|
|
7059
|
+
await readFile10(join16(runDirectory, "admitted-request.json"), "utf8")
|
|
6963
7060
|
);
|
|
6964
7061
|
if (raw === null || typeof raw !== "object" || Array.isArray(raw)) return void 0;
|
|
6965
7062
|
const record4 = raw;
|
|
@@ -6986,7 +7083,7 @@ function isV1ResumableProvider(provider) {
|
|
|
6986
7083
|
async function readRoleRunStateDisk(runDirectory) {
|
|
6987
7084
|
let raw;
|
|
6988
7085
|
try {
|
|
6989
|
-
raw = JSON.parse(await
|
|
7086
|
+
raw = JSON.parse(await readFile11(join17(runDirectory, RUN_STATE_FILE), "utf8"));
|
|
6990
7087
|
} catch {
|
|
6991
7088
|
return void 0;
|
|
6992
7089
|
}
|
|
@@ -7127,7 +7224,7 @@ function navigatorInputReference(getFlag, role) {
|
|
|
7127
7224
|
}
|
|
7128
7225
|
async function loadNavigatorWorkContext(options) {
|
|
7129
7226
|
const reference = navigatorInputReference(options.getFlag, options.role);
|
|
7130
|
-
const input = reference === void 0 || options.role === "doctor" || options.role === "notary" ? void 0 : await
|
|
7227
|
+
const input = reference === void 0 || options.role === "doctor" || options.role === "notary" ? void 0 : await readFile12(reference, "utf8");
|
|
7131
7228
|
const subjectRoot = subjectPath(reference ?? options.context.sessionManager.getSessionDir(), options.context.cwd);
|
|
7132
7229
|
let subjectKey = reference === void 0 ? subjectRoot : navigatorSubjectKeyForInput(subjectRoot, reference, options.context.cwd);
|
|
7133
7230
|
let subject = input ?? `work subject: ${subjectKey}`;
|
|
@@ -7184,7 +7281,7 @@ async function loadNavigatorWorkContext(options) {
|
|
|
7184
7281
|
let authorityMaterial;
|
|
7185
7282
|
for (const path of authorityFiles) {
|
|
7186
7283
|
try {
|
|
7187
|
-
const content = await
|
|
7284
|
+
const content = await readFile12(path, "utf8");
|
|
7188
7285
|
if (content.trim() !== "") {
|
|
7189
7286
|
authorityMaterial = content;
|
|
7190
7287
|
break;
|
|
@@ -7210,8 +7307,8 @@ import { dirname as dirname12 } from "node:path";
|
|
|
7210
7307
|
|
|
7211
7308
|
// src/package-resources/method-skill.ts
|
|
7212
7309
|
import { createHash as createHash7 } from "node:crypto";
|
|
7213
|
-
import { readFile as
|
|
7214
|
-
import { join as
|
|
7310
|
+
import { readFile as readFile13, realpath as realpath5 } from "node:fs/promises";
|
|
7311
|
+
import { join as join19 } from "node:path";
|
|
7215
7312
|
var PackagedMethodSkillUnavailableError = class extends Error {
|
|
7216
7313
|
constructor(skillName, path, cause) {
|
|
7217
7314
|
super(`Canonical ${skillName} Skill is unavailable at ${path}`, { cause });
|
|
@@ -7247,10 +7344,10 @@ function packagedMethodSkillRelativeDirectory(name) {
|
|
|
7247
7344
|
return `${METHOD_SKILL_RELATIVE_ROOT}/${name}`;
|
|
7248
7345
|
}
|
|
7249
7346
|
function resolvePackagedMethodSkillRoot(packageRoot, name) {
|
|
7250
|
-
return
|
|
7347
|
+
return join19(packageRoot, packagedMethodSkillRelativeDirectory(name));
|
|
7251
7348
|
}
|
|
7252
7349
|
function resolvePackagedMethodSkillPath(packageRoot, name) {
|
|
7253
|
-
return
|
|
7350
|
+
return join19(resolvePackagedMethodSkillRoot(packageRoot, name), "SKILL.md");
|
|
7254
7351
|
}
|
|
7255
7352
|
function isRecord11(value) {
|
|
7256
7353
|
return typeof value === "object" && value !== null && !Array.isArray(value);
|
|
@@ -7344,11 +7441,11 @@ function parseProvenance(raw, expectedName) {
|
|
|
7344
7441
|
}
|
|
7345
7442
|
async function loadPackagedMethodSkillMaterial(packageRoot, name) {
|
|
7346
7443
|
const rootDirectory = resolvePackagedMethodSkillRoot(packageRoot, name);
|
|
7347
|
-
const skillPathConfigured =
|
|
7348
|
-
const provenancePath =
|
|
7444
|
+
const skillPathConfigured = join19(rootDirectory, "SKILL.md");
|
|
7445
|
+
const provenancePath = join19(rootDirectory, "provenance.json");
|
|
7349
7446
|
let provenanceRaw;
|
|
7350
7447
|
try {
|
|
7351
|
-
provenanceRaw = await
|
|
7448
|
+
provenanceRaw = await readFile13(provenancePath, "utf8");
|
|
7352
7449
|
} catch (error) {
|
|
7353
7450
|
throw new PackagedMethodSkillUnavailableError(name, provenancePath, error);
|
|
7354
7451
|
}
|
|
@@ -7362,10 +7459,10 @@ async function loadPackagedMethodSkillMaterial(packageRoot, name) {
|
|
|
7362
7459
|
}
|
|
7363
7460
|
const provenance = parseProvenance(provenanceJson, name);
|
|
7364
7461
|
for (const [rel, expected] of Object.entries(provenance.files)) {
|
|
7365
|
-
const absolute =
|
|
7462
|
+
const absolute = join19(rootDirectory, rel);
|
|
7366
7463
|
let bytes;
|
|
7367
7464
|
try {
|
|
7368
|
-
bytes = await
|
|
7465
|
+
bytes = await readFile13(absolute);
|
|
7369
7466
|
} catch (error) {
|
|
7370
7467
|
throw new PackagedMethodSkillUnavailableError(name, absolute, error);
|
|
7371
7468
|
}
|
|
@@ -7381,7 +7478,7 @@ async function loadPackagedMethodSkillMaterial(packageRoot, name) {
|
|
|
7381
7478
|
let raw;
|
|
7382
7479
|
try {
|
|
7383
7480
|
skillPath = await realpath5(skillPathConfigured);
|
|
7384
|
-
raw = await
|
|
7481
|
+
raw = await readFile13(skillPath, "utf8");
|
|
7385
7482
|
} catch (error) {
|
|
7386
7483
|
throw new PackagedMethodSkillUnavailableError(name, skillPathConfigured, error);
|
|
7387
7484
|
}
|
|
@@ -7475,7 +7572,7 @@ async function executeReviewerChild(workspace, leg, context, options = {}) {
|
|
|
7475
7572
|
import { spawn as spawn3 } from "node:child_process";
|
|
7476
7573
|
import { mkdtemp as mkdtemp4, rm as rm4 } from "node:fs/promises";
|
|
7477
7574
|
import { tmpdir as tmpdir4 } from "node:os";
|
|
7478
|
-
import { join as
|
|
7575
|
+
import { join as join20 } from "node:path";
|
|
7479
7576
|
|
|
7480
7577
|
// src/reviewer-git-snapshot.ts
|
|
7481
7578
|
var REVIEW_REF_PREFIXES = ["refs/heads", "refs/tags", "refs/remotes"];
|
|
@@ -7576,8 +7673,8 @@ async function prepareSnapshot(accepted, signal, dependencies) {
|
|
|
7576
7673
|
if (!sameReviewerPinnedTarget({ repositoryRoot: accepted.repositoryRoot, objectFormat, targetHead }, accepted)) throw new Error("Accepted Reviewer target identity no longer matches the repository");
|
|
7577
7674
|
await git2(accepted.repositoryRoot, ["cat-file", "-e", `${targetHead}^{commit}`], signal);
|
|
7578
7675
|
dependencies.fault?.("mirror.before-create");
|
|
7579
|
-
mirrorRoot = await mkdtemp4(
|
|
7580
|
-
const mirrorPath =
|
|
7676
|
+
mirrorRoot = await mkdtemp4(join20(tmpdir4(), "ak-reviewer-snapshot-"));
|
|
7677
|
+
const mirrorPath = join20(mirrorRoot, "repository.git");
|
|
7581
7678
|
dependencies.fault?.("mirror.create");
|
|
7582
7679
|
await runCommand("git", ["init", "--bare", `--object-format=${accepted.objectFormat}`, mirrorPath], signal === void 0 ? {} : { signal });
|
|
7583
7680
|
await git2(mirrorPath, ["fetch", "--no-tags", accepted.repositoryRoot, targetHead], signal);
|
|
@@ -7594,7 +7691,7 @@ async function prepareClone(snapshot, signal, dependencies) {
|
|
|
7594
7691
|
const target = { repositoryRoot: snapshot.repositoryRoot, objectFormat: snapshot.objectFormat, targetHead: snapshot.targetHead, refs: { ...snapshot.refs } };
|
|
7595
7692
|
try {
|
|
7596
7693
|
dependencies.fault?.("workspace.before-create");
|
|
7597
|
-
workspace = await mkdtemp4(
|
|
7694
|
+
workspace = await mkdtemp4(join20(tmpdir4(), "ak-reviewer-leg-"));
|
|
7598
7695
|
dependencies.fault?.("workspace.init");
|
|
7599
7696
|
await git2(workspace, ["init", `--object-format=${snapshot.objectFormat}`, "--initial-branch=ak-reviewer-unborn"], signal);
|
|
7600
7697
|
dependencies.fault?.("workspace.fetch");
|
|
@@ -7776,7 +7873,7 @@ function stringEnum(values, options = {}) {
|
|
|
7776
7873
|
|
|
7777
7874
|
// src/public-cli/reviewer-dispatch-rejection.ts
|
|
7778
7875
|
import { writeFileSync as writeFileSync4 } from "node:fs";
|
|
7779
|
-
import { join as
|
|
7876
|
+
import { join as join21 } from "node:path";
|
|
7780
7877
|
|
|
7781
7878
|
// src/adr-path-refs.ts
|
|
7782
7879
|
var ADR_PATH_IN_BODY = /docs\/adr\/(?:[A-Za-z0-9][A-Za-z0-9._-]*\/)*[A-Za-z0-9][A-Za-z0-9._-]*\.md/g;
|
|
@@ -8375,7 +8472,7 @@ function createReviewerDispatcher(d) {
|
|
|
8375
8472
|
// src/public-cli/reviewer-dispatch-rejection.ts
|
|
8376
8473
|
var REVIEWER_DISPATCH_REJECTION_FILE = "typed-known-failure.json";
|
|
8377
8474
|
function reviewerDispatchRejectionPath(runDirectory) {
|
|
8378
|
-
return
|
|
8475
|
+
return join21(runDirectory, REVIEWER_DISPATCH_REJECTION_FILE);
|
|
8379
8476
|
}
|
|
8380
8477
|
function recordReviewerDispatchRejectionSync(runDirectory, rejection) {
|
|
8381
8478
|
writeFileSync4(
|
|
@@ -8543,7 +8640,7 @@ async function requireGatekeeperPass(options) {
|
|
|
8543
8640
|
}
|
|
8544
8641
|
|
|
8545
8642
|
// src/run-terminal-artifacts.ts
|
|
8546
|
-
import { basename as basename6, dirname as dirname13, join as
|
|
8643
|
+
import { basename as basename6, dirname as dirname13, join as join22 } from "node:path";
|
|
8547
8644
|
function runIdFromRunDirectory(runDirectory) {
|
|
8548
8645
|
const name = basename6(runDirectory);
|
|
8549
8646
|
const at = name.lastIndexOf("@");
|
|
@@ -13493,15 +13590,15 @@ function createRoleRuntimeExtension(dependencies) {
|
|
|
13493
13590
|
|
|
13494
13591
|
// src/grok/role-envelope.ts
|
|
13495
13592
|
import { randomUUID as randomUUID2 } from "node:crypto";
|
|
13496
|
-
import { mkdir as mkdir5, readFile as
|
|
13593
|
+
import { mkdir as mkdir5, readFile as readFile14, writeFile as writeFile9 } from "node:fs/promises";
|
|
13497
13594
|
import { createServer } from "node:net";
|
|
13498
|
-
import { basename as basename8, dirname as dirname16, join as
|
|
13595
|
+
import { basename as basename8, dirname as dirname16, join as join25 } from "node:path";
|
|
13499
13596
|
import { fileURLToPath as fileURLToPath2 } from "node:url";
|
|
13500
13597
|
|
|
13501
13598
|
// src/grok/role-turn-host.ts
|
|
13502
13599
|
import { execFile as execFile3, spawn as spawn4 } from "node:child_process";
|
|
13503
13600
|
import { copyFile, lstat as lstat3, mkdir as mkdir4, open as open2, realpath as realpath7, rm as rm5 } from "node:fs/promises";
|
|
13504
|
-
import { basename as basename7, dirname as dirname15, isAbsolute as isAbsolute7, join as
|
|
13601
|
+
import { basename as basename7, dirname as dirname15, isAbsolute as isAbsolute7, join as join24, relative as pathRelative } from "node:path";
|
|
13505
13602
|
import { createInterface } from "node:readline";
|
|
13506
13603
|
import { promisify as promisify3 } from "node:util";
|
|
13507
13604
|
|
|
@@ -13512,8 +13609,8 @@ function renderAgentStartMaterials(body, materials) {
|
|
|
13512
13609
|
}
|
|
13513
13610
|
|
|
13514
13611
|
// src/grok/bash-seatbelt.ts
|
|
13515
|
-
import { mkdir as mkdir3, writeFile as
|
|
13516
|
-
import { join as
|
|
13612
|
+
import { mkdir as mkdir3, writeFile as writeFile8 } from "node:fs/promises";
|
|
13613
|
+
import { join as join23 } from "node:path";
|
|
13517
13614
|
function renderGrokBashSeatbeltHookScript() {
|
|
13518
13615
|
const reasons = Object.fromEntries(
|
|
13519
13616
|
FIXER_BASH_FORBIDDEN_LITERALS.map((literal) => [literal, fixerBashSeatbeltDenyReason(literal)])
|
|
@@ -13541,12 +13638,12 @@ process.stdin.on("end", () => {
|
|
|
13541
13638
|
`;
|
|
13542
13639
|
}
|
|
13543
13640
|
async function installGrokPreToolUseDeny(controlledHome) {
|
|
13544
|
-
const hooksDir =
|
|
13641
|
+
const hooksDir = join23(controlledHome, "hooks");
|
|
13545
13642
|
await mkdir3(hooksDir, { recursive: true });
|
|
13546
13643
|
const scriptName = "ak-bash-seatbelt.mjs";
|
|
13547
|
-
const scriptPath =
|
|
13548
|
-
await
|
|
13549
|
-
await
|
|
13644
|
+
const scriptPath = join23(hooksDir, scriptName);
|
|
13645
|
+
await writeFile8(scriptPath, renderGrokBashSeatbeltHookScript(), { mode: 493 });
|
|
13646
|
+
await writeFile8(join23(hooksDir, "ak-bash-seatbelt.json"), `${JSON.stringify({
|
|
13550
13647
|
hooks: {
|
|
13551
13648
|
PreToolUse: [
|
|
13552
13649
|
{
|
|
@@ -13919,7 +14016,7 @@ async function resolveHeadTreePath(topLevel, relativePath) {
|
|
|
13919
14016
|
encoding: "utf8"
|
|
13920
14017
|
});
|
|
13921
14018
|
const needle = leaf.toLowerCase();
|
|
13922
|
-
const hits = listing.split("\n").map((name) => name.trim()).filter((name) => name !== "" && basename7(name).toLowerCase() === needle).map((name) => parent === "." ? basename7(name) :
|
|
14019
|
+
const hits = listing.split("\n").map((name) => name.trim()).filter((name) => name !== "" && basename7(name).toLowerCase() === needle).map((name) => parent === "." ? basename7(name) : join24(parent, basename7(name)));
|
|
13923
14020
|
return hits.length === 1 ? hits[0] : void 0;
|
|
13924
14021
|
}
|
|
13925
14022
|
async function isHeadMatchedProjectInstruction(repositoryCwd, absolutePath) {
|
|
@@ -13937,14 +14034,14 @@ async function isHeadMatchedProjectInstruction(repositoryCwd, absolutePath) {
|
|
|
13937
14034
|
if (parent === void 0) return false;
|
|
13938
14035
|
const leaf = basename7(absolutePath);
|
|
13939
14036
|
if (leaf === "" || leaf === "." || leaf === "..") return false;
|
|
13940
|
-
const candidate =
|
|
14037
|
+
const candidate = join24(parent, leaf);
|
|
13941
14038
|
const relative3 = pathRelative(topLevel, candidate);
|
|
13942
14039
|
if (relative3 === "" || relative3.startsWith("..") || isAbsolute7(relative3) || relative3.includes("\0")) {
|
|
13943
14040
|
return false;
|
|
13944
14041
|
}
|
|
13945
14042
|
const headRel = await resolveHeadTreePath(topLevel, relative3);
|
|
13946
14043
|
if (headRel === void 0) return false;
|
|
13947
|
-
const headFile =
|
|
14044
|
+
const headFile = join24(topLevel, headRel);
|
|
13948
14045
|
const { stdout: headBlobOut } = await execFileAsync3(
|
|
13949
14046
|
"git",
|
|
13950
14047
|
["rev-parse", "--verify", `HEAD:${headRel}`],
|
|
@@ -14043,20 +14140,20 @@ async function assertControlledGrokAuthIsNotSymlink(authPath) {
|
|
|
14043
14140
|
}
|
|
14044
14141
|
}
|
|
14045
14142
|
async function scrubAkBashSeatbeltHooks(controlledHome) {
|
|
14046
|
-
const hooksDir =
|
|
14143
|
+
const hooksDir = join24(controlledHome, "hooks");
|
|
14047
14144
|
for (const name of AK_BASH_SEATBELT_HOOK_FILES) {
|
|
14048
|
-
await rm5(
|
|
14145
|
+
await rm5(join24(hooksDir, name), { force: true });
|
|
14049
14146
|
}
|
|
14050
14147
|
}
|
|
14051
14148
|
async function prepareControlledGrokHome(sourceHome, controlledHome) {
|
|
14052
14149
|
await assertControlledGrokHomeIsRealDirectory(controlledHome);
|
|
14053
14150
|
await mkdir4(controlledHome, { recursive: true, mode: 448 });
|
|
14054
14151
|
await assertControlledGrokHomeIsRealDirectory(controlledHome);
|
|
14055
|
-
const authPath =
|
|
14152
|
+
const authPath = join24(controlledHome, "auth.json");
|
|
14056
14153
|
await assertControlledGrokAuthIsNotSymlink(authPath);
|
|
14057
14154
|
await rm5(authPath, { force: true });
|
|
14058
14155
|
await scrubAkBashSeatbeltHooks(controlledHome);
|
|
14059
|
-
await copyFile(
|
|
14156
|
+
await copyFile(join24(sourceHome, ".grok", "auth.json"), authPath);
|
|
14060
14157
|
}
|
|
14061
14158
|
async function inspectControlledGrok(options) {
|
|
14062
14159
|
const { stdout } = await execFileAsync3(options.binary, ["inspect", "--json"], {
|
|
@@ -14177,14 +14274,14 @@ async function prepareGrokRoleEnvelope(options) {
|
|
|
14177
14274
|
for (const method of request.methods) {
|
|
14178
14275
|
if (method.kind !== "skill") continue;
|
|
14179
14276
|
const name = basename8(dirname16(method.path));
|
|
14180
|
-
const raw = await
|
|
14277
|
+
const raw = await readFile14(method.path, "utf8");
|
|
14181
14278
|
methodSkills.set(name, { path: method.path, body: stripSkillFrontmatter(raw).trim() });
|
|
14182
14279
|
}
|
|
14183
|
-
let sessionFile = options.sessionFile ??
|
|
14280
|
+
let sessionFile = options.sessionFile ?? join25(request.runDirectory, "session", "session.jsonl");
|
|
14184
14281
|
await mkdir5(dirname16(sessionFile), { recursive: true });
|
|
14185
14282
|
if (request.continuation.kind !== "resume") {
|
|
14186
14283
|
try {
|
|
14187
|
-
await
|
|
14284
|
+
await writeFile9(
|
|
14188
14285
|
sessionFile,
|
|
14189
14286
|
`${JSON.stringify({
|
|
14190
14287
|
type: "session",
|
|
@@ -14592,7 +14689,7 @@ async function prepareGrokRoleEnvelope(options) {
|
|
|
14592
14689
|
message: { role: "user", content: prompt }
|
|
14593
14690
|
});
|
|
14594
14691
|
}
|
|
14595
|
-
const methodPrompt = (await Promise.all(request.methods.map(({ path }) =>
|
|
14692
|
+
const methodPrompt = (await Promise.all(request.methods.map(({ path }) => readFile14(path, "utf8")))).join("\n\n");
|
|
14596
14693
|
const promptResults = await emit("before_agent_start", {
|
|
14597
14694
|
prompt,
|
|
14598
14695
|
systemPrompt: methodPrompt,
|
|
@@ -14640,18 +14737,18 @@ async function prepareGrokRoleEnvelope(options) {
|
|
|
14640
14737
|
}
|
|
14641
14738
|
|
|
14642
14739
|
// src/grok/session-identity.ts
|
|
14643
|
-
import { mkdir as mkdir6, readFile as
|
|
14644
|
-
import { dirname as dirname17, join as
|
|
14740
|
+
import { mkdir as mkdir6, readFile as readFile15, rename, writeFile as writeFile10 } from "node:fs/promises";
|
|
14741
|
+
import { dirname as dirname17, join as join26 } from "node:path";
|
|
14645
14742
|
var GROK_ACP_SESSION_BINDING = "grok-acp-session.json";
|
|
14646
14743
|
function createGrokSessionIdentityAuthority(authority) {
|
|
14647
|
-
const bindingPath = (principal) =>
|
|
14744
|
+
const bindingPath = (principal) => join26(authority.decode(principal).sessionDirectory, GROK_ACP_SESSION_BINDING);
|
|
14648
14745
|
return {
|
|
14649
14746
|
resolveSessionFile(principal) {
|
|
14650
14747
|
return authority.decode(principal).sessionFile;
|
|
14651
14748
|
},
|
|
14652
14749
|
async load(principal) {
|
|
14653
14750
|
try {
|
|
14654
|
-
const value = JSON.parse(await
|
|
14751
|
+
const value = JSON.parse(await readFile15(bindingPath(principal), "utf8"));
|
|
14655
14752
|
if (typeof value !== "object" || value === null || typeof value.sessionId !== "string") {
|
|
14656
14753
|
throw new Error("durable Grok ACP session binding is invalid");
|
|
14657
14754
|
}
|
|
@@ -14665,7 +14762,7 @@ function createGrokSessionIdentityAuthority(authority) {
|
|
|
14665
14762
|
const target = bindingPath(principal);
|
|
14666
14763
|
await mkdir6(dirname17(target), { recursive: true });
|
|
14667
14764
|
const temporary = `${target}.${process.pid}.tmp`;
|
|
14668
|
-
await
|
|
14765
|
+
await writeFile10(temporary, `${JSON.stringify({ sessionId })}
|
|
14669
14766
|
`, { encoding: "utf8", mode: 384 });
|
|
14670
14767
|
await rename(temporary, target);
|
|
14671
14768
|
}
|
|
@@ -14674,7 +14771,7 @@ function createGrokSessionIdentityAuthority(authority) {
|
|
|
14674
14771
|
|
|
14675
14772
|
// src/grok/production-host.ts
|
|
14676
14773
|
function resolveGrokBinary(operatorHome) {
|
|
14677
|
-
return
|
|
14774
|
+
return join27(operatorHome, ".grok", "bin", "grok");
|
|
14678
14775
|
}
|
|
14679
14776
|
var NO_PRODUCTION_GROK_PRIMARY_FAILURE = {
|
|
14680
14777
|
present: false
|
|
@@ -14682,7 +14779,7 @@ var NO_PRODUCTION_GROK_PRIMARY_FAILURE = {
|
|
|
14682
14779
|
async function settleProductionGrokHomeCleanup(controlledHome, primaryFailure, concurrentMessage) {
|
|
14683
14780
|
try {
|
|
14684
14781
|
await assertControlledGrokHomeIsRealDirectory(controlledHome);
|
|
14685
|
-
const authPath =
|
|
14782
|
+
const authPath = join27(controlledHome, "auth.json");
|
|
14686
14783
|
await assertControlledGrokAuthIsNotSymlink(authPath);
|
|
14687
14784
|
await rm6(authPath, { force: true });
|
|
14688
14785
|
await scrubAkBashSeatbeltHooks(controlledHome);
|
|
@@ -14699,7 +14796,7 @@ async function settleProductionGrokHomeCleanup(controlledHome, primaryFailure, c
|
|
|
14699
14796
|
}
|
|
14700
14797
|
}
|
|
14701
14798
|
async function openProductionGrokHome(runDirectory, operatorHome) {
|
|
14702
|
-
const controlledHome =
|
|
14799
|
+
const controlledHome = join27(runDirectory, "grok-home");
|
|
14703
14800
|
try {
|
|
14704
14801
|
await prepareControlledGrokHome(operatorHome, controlledHome);
|
|
14705
14802
|
return controlledHome;
|
|
@@ -14727,12 +14824,13 @@ async function bindProductionGrokIsolation(runDirectory, operatorHome, packageRo
|
|
|
14727
14824
|
env: childEnv(controlledHome, packageRoot)
|
|
14728
14825
|
};
|
|
14729
14826
|
}
|
|
14730
|
-
async function withProductionGrokIsolation(runDirectory, operatorHome, packageRoot, run) {
|
|
14827
|
+
async function withProductionGrokIsolation(runDirectory, operatorHome, packageRoot, run, noteOpened) {
|
|
14731
14828
|
let binding;
|
|
14732
14829
|
let primaryFailure = NO_PRODUCTION_GROK_PRIMARY_FAILURE;
|
|
14733
14830
|
let value;
|
|
14734
14831
|
try {
|
|
14735
14832
|
binding = await bindProductionGrokIsolation(runDirectory, operatorHome, packageRoot);
|
|
14833
|
+
noteOpened?.(runDirectory);
|
|
14736
14834
|
value = await run(binding);
|
|
14737
14835
|
} catch (error) {
|
|
14738
14836
|
primaryFailure = { present: true, value: error };
|
|
@@ -14758,9 +14856,9 @@ function createGrokRoleRuntimeDependencies(packageRoot) {
|
|
|
14758
14856
|
return {
|
|
14759
14857
|
loadJudgeSoul: () => loadMainRoleSessionMaterials("judge"),
|
|
14760
14858
|
loadFixerSoul: () => loadMainRoleSessionMaterials("fixer"),
|
|
14761
|
-
loadFixPacket: (path) =>
|
|
14859
|
+
loadFixPacket: (path) => readFile16(path, "utf8"),
|
|
14762
14860
|
loadCoderSoul: () => loadMainRoleSessionMaterials("coder"),
|
|
14763
|
-
loadCoderTask: (path) =>
|
|
14861
|
+
loadCoderTask: (path) => readFile16(path, "utf8"),
|
|
14764
14862
|
loadReviewerSoul: () => loadMainRoleSessionMaterials("reviewer"),
|
|
14765
14863
|
createReviewerPinnedGitReader: () => createReviewerPinnedGitReader(),
|
|
14766
14864
|
createReviewerIssueFetcher: () => createGhIssueSoftFetcher(),
|
|
@@ -14776,7 +14874,7 @@ function createGrokRoleRuntimeDependencies(packageRoot) {
|
|
|
14776
14874
|
loadGleanerLeftSoul: () => loadMainRoleSessionMaterials("gleaner-left"),
|
|
14777
14875
|
loadNotarySourceRun: loadNotarySourceRunLocator,
|
|
14778
14876
|
loadMergerSoul: () => loadMainRoleSessionMaterials("merger"),
|
|
14779
|
-
loadMergerInput: async (path) => JSON.parse(await
|
|
14877
|
+
loadMergerInput: async (path) => JSON.parse(await readFile16(path, "utf8")),
|
|
14780
14878
|
createMergerGitState: (repositoryRoot) => createProductionMergerGitState(repositoryRoot),
|
|
14781
14879
|
async loadCanonicalSkillBinding(name) {
|
|
14782
14880
|
if (name === "tdd") {
|
|
@@ -14806,7 +14904,7 @@ function createGrokRoleRuntimeDependencies(packageRoot) {
|
|
|
14806
14904
|
authority: options.authority,
|
|
14807
14905
|
invocationId: options.invocationId,
|
|
14808
14906
|
loadSoul: () => loadMainRoleSessionMaterials("navigator"),
|
|
14809
|
-
loadRoutePlaybook: () =>
|
|
14907
|
+
loadRoutePlaybook: () => readFile16(navigatorRoutePlaybookPath, "utf8"),
|
|
14810
14908
|
loadRoleHelp: async (role) => formatNavigatorRoleHelp(role),
|
|
14811
14909
|
createSession: navigatorSessionFactory,
|
|
14812
14910
|
...options.contextError === void 0 ? {} : { contextError: options.contextError },
|
|
@@ -14815,13 +14913,19 @@ function createGrokRoleRuntimeDependencies(packageRoot) {
|
|
|
14815
14913
|
};
|
|
14816
14914
|
}
|
|
14817
14915
|
async function recordGrokCapabilities(request, declaration) {
|
|
14818
|
-
await
|
|
14819
|
-
|
|
14916
|
+
await writeFile11(
|
|
14917
|
+
join27(request.runDirectory, "grok-capabilities.json"),
|
|
14820
14918
|
`${JSON.stringify(declaration)}
|
|
14821
14919
|
`,
|
|
14822
14920
|
"utf8"
|
|
14823
14921
|
);
|
|
14824
14922
|
}
|
|
14923
|
+
function resolveProductionGrokIsolationRunDirectory(request) {
|
|
14924
|
+
if (request.continuation.kind === "resume" && typeof request.nativeHomeRunDirectory === "string" && request.nativeHomeRunDirectory.length > 0) {
|
|
14925
|
+
return request.nativeHomeRunDirectory;
|
|
14926
|
+
}
|
|
14927
|
+
return request.runDirectory;
|
|
14928
|
+
}
|
|
14825
14929
|
function createProductionGrokRoleTurnHost(options) {
|
|
14826
14930
|
const { packageRoot, principalAuthority } = options;
|
|
14827
14931
|
let turn;
|
|
@@ -14855,15 +14959,22 @@ function createProductionGrokRoleTurnHost(options) {
|
|
|
14855
14959
|
});
|
|
14856
14960
|
return {
|
|
14857
14961
|
executeTurn(request) {
|
|
14962
|
+
const isolationRunDirectory = resolveProductionGrokIsolationRunDirectory(request);
|
|
14858
14963
|
const execution = serial.then(
|
|
14859
|
-
() => withProductionGrokIsolation(
|
|
14860
|
-
|
|
14861
|
-
|
|
14862
|
-
|
|
14863
|
-
|
|
14864
|
-
turn =
|
|
14865
|
-
|
|
14866
|
-
|
|
14964
|
+
() => withProductionGrokIsolation(
|
|
14965
|
+
isolationRunDirectory,
|
|
14966
|
+
request.home,
|
|
14967
|
+
packageRoot,
|
|
14968
|
+
async (binding) => {
|
|
14969
|
+
turn = binding;
|
|
14970
|
+
try {
|
|
14971
|
+
return await inner.executeTurn({ ...request, home: binding.controlledHome });
|
|
14972
|
+
} finally {
|
|
14973
|
+
turn = void 0;
|
|
14974
|
+
}
|
|
14975
|
+
},
|
|
14976
|
+
request.noteNativeHomeOpened
|
|
14977
|
+
)
|
|
14867
14978
|
);
|
|
14868
14979
|
serial = execution.then(
|
|
14869
14980
|
() => void 0,
|