@integrity-labs/agt-cli 0.28.677 → 0.28.679
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/bin/agt.js +5 -5
- package/dist/{chunk-HTLUHAKN.js → chunk-CLNFPTVG.js} +551 -397
- package/dist/chunk-CLNFPTVG.js.map +1 -0
- package/dist/{chunk-GYYEUNTD.js → chunk-GDT7JHV6.js} +24 -1
- package/dist/chunk-GDT7JHV6.js.map +1 -0
- package/dist/{chunk-F6CUSDJ6.js → chunk-HLJKOJVJ.js} +2 -2
- package/dist/{claude-pair-runtime-MY5LMJVT.js → claude-pair-runtime-5UDCBIB7.js} +2 -2
- package/dist/lib/manager-worker.js +15 -13
- package/dist/lib/manager-worker.js.map +1 -1
- package/dist/mcp/direct-chat-channel.js +23 -0
- package/dist/mcp/index.js +107 -0
- package/dist/mcp/origami.js +23 -0
- package/dist/mcp/slack-channel.js +23 -0
- package/dist/mcp/telegram-channel.js +23 -0
- package/dist/{persistent-session-TMOTEVV6.js → persistent-session-GQZQWMJU.js} +3 -3
- package/dist/{responsiveness-probe-ZHE7S6G4.js → responsiveness-probe-QKKOHDHF.js} +3 -3
- package/dist/{session-auth-dead-JCKENEY5.js → session-auth-dead-CUEBDRZU.js} +2 -2
- package/package.json +1 -1
- package/dist/chunk-GYYEUNTD.js.map +0 -1
- package/dist/chunk-HTLUHAKN.js.map +0 -1
- /package/dist/{chunk-F6CUSDJ6.js.map → chunk-HLJKOJVJ.js.map} +0 -0
- /package/dist/{claude-pair-runtime-MY5LMJVT.js.map → claude-pair-runtime-5UDCBIB7.js.map} +0 -0
- /package/dist/{persistent-session-TMOTEVV6.js.map → persistent-session-GQZQWMJU.js.map} +0 -0
- /package/dist/{responsiveness-probe-ZHE7S6G4.js.map → responsiveness-probe-QKKOHDHF.js.map} +0 -0
- /package/dist/{session-auth-dead-JCKENEY5.js.map → session-auth-dead-CUEBDRZU.js.map} +0 -0
|
@@ -12,7 +12,7 @@ import {
|
|
|
12
12
|
parseEnvFileEntries,
|
|
13
13
|
parseEnvIntegrations,
|
|
14
14
|
shellQuote
|
|
15
|
-
} from "./chunk-
|
|
15
|
+
} from "./chunk-HLJKOJVJ.js";
|
|
16
16
|
import {
|
|
17
17
|
BIND_FAILURE_QUARANTINE_THRESHOLD,
|
|
18
18
|
INTEGRATIONS_SECTION_END,
|
|
@@ -59,7 +59,7 @@ import {
|
|
|
59
59
|
resolveConnectivityProbe,
|
|
60
60
|
worseConnectivityOutcome,
|
|
61
61
|
wrapScheduledTaskPrompt
|
|
62
|
-
} from "./chunk-
|
|
62
|
+
} from "./chunk-GDT7JHV6.js";
|
|
63
63
|
import {
|
|
64
64
|
parsePsRows
|
|
65
65
|
} from "./chunk-XWVM4KPK.js";
|
|
@@ -369,6 +369,144 @@ function formatMirrorMismatch(m) {
|
|
|
369
369
|
return `[mcp-mirror] [parity-violation] server=${m.server} field=${m.field} location=${m.location} reason=${m.reason}`;
|
|
370
370
|
}
|
|
371
371
|
|
|
372
|
+
// ../../packages/core/dist/provisioning/secret-file-tmpfs.js
|
|
373
|
+
import { statfsSync, accessSync, constants as fsConstants, lstatSync, readlinkSync, readFileSync as readFileSync2, writeFileSync as writeFileSync2, mkdirSync, chmodSync as chmodSync2, rmSync, symlinkSync } from "fs";
|
|
374
|
+
import { dirname, join } from "path";
|
|
375
|
+
var SECRET_FILE_MODE = 384;
|
|
376
|
+
var TMPFS_MAGIC = 16914836;
|
|
377
|
+
var DEFAULT_TMPFS_CANDIDATES = ["/dev/shm", "/run"];
|
|
378
|
+
var TMPFS_SECRETS_SUBDIR = "augmented-secrets";
|
|
379
|
+
var backingEnabled = false;
|
|
380
|
+
var cachedBase;
|
|
381
|
+
var baseOverride;
|
|
382
|
+
function setSecretFileTmpfsBacking(enabled) {
|
|
383
|
+
backingEnabled = enabled;
|
|
384
|
+
}
|
|
385
|
+
function isSecretFileTmpfsBackingEnabled() {
|
|
386
|
+
return backingEnabled;
|
|
387
|
+
}
|
|
388
|
+
function resolveTmpfsBase(candidates = DEFAULT_TMPFS_CANDIDATES) {
|
|
389
|
+
if (baseOverride !== void 0)
|
|
390
|
+
return baseOverride;
|
|
391
|
+
if (cachedBase !== void 0)
|
|
392
|
+
return cachedBase;
|
|
393
|
+
cachedBase = null;
|
|
394
|
+
for (const cand of candidates) {
|
|
395
|
+
try {
|
|
396
|
+
if (Number(statfsSync(cand).type) !== TMPFS_MAGIC)
|
|
397
|
+
continue;
|
|
398
|
+
accessSync(cand, fsConstants.W_OK);
|
|
399
|
+
cachedBase = cand;
|
|
400
|
+
break;
|
|
401
|
+
} catch {
|
|
402
|
+
}
|
|
403
|
+
}
|
|
404
|
+
return cachedBase;
|
|
405
|
+
}
|
|
406
|
+
function ensureSafeSecretsRoot(base) {
|
|
407
|
+
const root = join(base, TMPFS_SECRETS_SUBDIR);
|
|
408
|
+
try {
|
|
409
|
+
mkdirSync(root, { recursive: true, mode: 448 });
|
|
410
|
+
} catch {
|
|
411
|
+
return null;
|
|
412
|
+
}
|
|
413
|
+
let st;
|
|
414
|
+
try {
|
|
415
|
+
st = lstatSync(root);
|
|
416
|
+
} catch {
|
|
417
|
+
return null;
|
|
418
|
+
}
|
|
419
|
+
if (st.isSymbolicLink() || !st.isDirectory())
|
|
420
|
+
return null;
|
|
421
|
+
const uid = typeof process.getuid === "function" ? process.getuid() : void 0;
|
|
422
|
+
if (uid !== void 0 && st.uid !== uid)
|
|
423
|
+
return null;
|
|
424
|
+
if ((st.mode & 63) !== 0) {
|
|
425
|
+
try {
|
|
426
|
+
chmodSync2(root, 448);
|
|
427
|
+
if ((lstatSync(root).mode & 63) !== 0)
|
|
428
|
+
return null;
|
|
429
|
+
} catch {
|
|
430
|
+
return null;
|
|
431
|
+
}
|
|
432
|
+
}
|
|
433
|
+
return root;
|
|
434
|
+
}
|
|
435
|
+
function ensureSecretFileTmpfsBacked(persistentPath, tmpfsTarget, mode = SECRET_FILE_MODE) {
|
|
436
|
+
mkdirSync(dirname(tmpfsTarget), { recursive: true, mode: 448 });
|
|
437
|
+
let migratedContent = null;
|
|
438
|
+
try {
|
|
439
|
+
const st = lstatSync(persistentPath);
|
|
440
|
+
if (st.isSymbolicLink()) {
|
|
441
|
+
if (readlinkSync(persistentPath) === tmpfsTarget) {
|
|
442
|
+
return { backed: true, migrated: false };
|
|
443
|
+
}
|
|
444
|
+
rmSync(persistentPath, { force: true });
|
|
445
|
+
} else {
|
|
446
|
+
try {
|
|
447
|
+
migratedContent = readFileSync2(persistentPath, "utf-8");
|
|
448
|
+
} catch {
|
|
449
|
+
migratedContent = null;
|
|
450
|
+
}
|
|
451
|
+
rmSync(persistentPath, { force: true });
|
|
452
|
+
}
|
|
453
|
+
} catch {
|
|
454
|
+
}
|
|
455
|
+
if (migratedContent !== null) {
|
|
456
|
+
let targetEmpty = true;
|
|
457
|
+
try {
|
|
458
|
+
targetEmpty = readFileSync2(tmpfsTarget, "utf-8").length === 0;
|
|
459
|
+
} catch {
|
|
460
|
+
targetEmpty = true;
|
|
461
|
+
}
|
|
462
|
+
if (targetEmpty)
|
|
463
|
+
writeFileSync2(tmpfsTarget, migratedContent, { mode });
|
|
464
|
+
}
|
|
465
|
+
mkdirSync(dirname(persistentPath), { recursive: true });
|
|
466
|
+
symlinkSync(tmpfsTarget, persistentPath);
|
|
467
|
+
return { backed: true, migrated: migratedContent !== null };
|
|
468
|
+
}
|
|
469
|
+
function ensureSecretFileNotTmpfsBacked(persistentPath) {
|
|
470
|
+
let st;
|
|
471
|
+
try {
|
|
472
|
+
st = lstatSync(persistentPath);
|
|
473
|
+
} catch {
|
|
474
|
+
return false;
|
|
475
|
+
}
|
|
476
|
+
if (!st.isSymbolicLink())
|
|
477
|
+
return false;
|
|
478
|
+
let ramTarget = null;
|
|
479
|
+
try {
|
|
480
|
+
ramTarget = readlinkSync(persistentPath);
|
|
481
|
+
} catch {
|
|
482
|
+
ramTarget = null;
|
|
483
|
+
}
|
|
484
|
+
rmSync(persistentPath, { force: true });
|
|
485
|
+
if (ramTarget !== null) {
|
|
486
|
+
try {
|
|
487
|
+
rmSync(ramTarget, { force: true });
|
|
488
|
+
} catch {
|
|
489
|
+
}
|
|
490
|
+
}
|
|
491
|
+
return true;
|
|
492
|
+
}
|
|
493
|
+
function ensureAgentSecretFilesTmpfsBacked(agentDir, projectDir, agentKey) {
|
|
494
|
+
const base = resolveTmpfsBase();
|
|
495
|
+
if (base === null)
|
|
496
|
+
return false;
|
|
497
|
+
const root = ensureSafeSecretsRoot(base);
|
|
498
|
+
if (root === null)
|
|
499
|
+
return false;
|
|
500
|
+
const agentRamDir = join(root, agentKey);
|
|
501
|
+
ensureSecretFileTmpfsBacked(join(agentDir, ".env.integrations"), join(agentRamDir, "env.integrations"));
|
|
502
|
+
ensureSecretFileTmpfsBacked(join(projectDir, ".env.integrations"), join(agentRamDir, "project.env.integrations"));
|
|
503
|
+
return true;
|
|
504
|
+
}
|
|
505
|
+
function ensureAgentSecretFilesNotTmpfsBacked(agentDir, projectDir) {
|
|
506
|
+
ensureSecretFileNotTmpfsBacked(join(agentDir, ".env.integrations"));
|
|
507
|
+
ensureSecretFileNotTmpfsBacked(join(projectDir, ".env.integrations"));
|
|
508
|
+
}
|
|
509
|
+
|
|
372
510
|
// ../../packages/core/dist/provisioning/hook-env.js
|
|
373
511
|
function augmentedHookPath(currentPath) {
|
|
374
512
|
const extras = [
|
|
@@ -409,15 +547,15 @@ function extractCommandNotFound(stderr) {
|
|
|
409
547
|
}
|
|
410
548
|
|
|
411
549
|
// ../../packages/core/dist/provisioning/frameworks/claudecode/index.js
|
|
412
|
-
import { readFileSync as
|
|
413
|
-
import { join as
|
|
550
|
+
import { readFileSync as readFileSync5, writeFileSync as writeFileSync5, mkdirSync as mkdirSync4, existsSync as existsSync4, chmodSync as chmodSync5, readdirSync, rmSync as rmSync3, copyFileSync, lstatSync as lstatSync2, realpathSync, symlinkSync as symlinkSync2, readlinkSync as readlinkSync2, renameSync as renameSync4, opendirSync } from "fs";
|
|
551
|
+
import { join as join4, relative, dirname as dirname4, basename } from "path";
|
|
414
552
|
import { homedir as homedir3 } from "os";
|
|
415
553
|
import { execFile } from "child_process";
|
|
416
554
|
|
|
417
555
|
// ../../packages/core/dist/integrations/xurl-config.js
|
|
418
|
-
import { chmodSync as
|
|
556
|
+
import { chmodSync as chmodSync3, existsSync as existsSync2, mkdirSync as mkdirSync2, readFileSync as readFileSync3, renameSync as renameSync2, unlinkSync as unlinkSync2, writeFileSync as writeFileSync3 } from "fs";
|
|
419
557
|
import { homedir } from "os";
|
|
420
|
-
import { dirname, join } from "path";
|
|
558
|
+
import { dirname as dirname2, join as join2 } from "path";
|
|
421
559
|
import { parse as parseYaml, stringify as stringifyYaml } from "yaml";
|
|
422
560
|
var XURL_FILE_MODE = 384;
|
|
423
561
|
var XURL_AGT_APP_PREFIX = "agt-";
|
|
@@ -536,7 +674,7 @@ function buildAgtXurlApps(integrations) {
|
|
|
536
674
|
}
|
|
537
675
|
function getXurlStorePath() {
|
|
538
676
|
const home = process.env["HOME"] ?? process.env["USERPROFILE"] ?? homedir();
|
|
539
|
-
return
|
|
677
|
+
return join2(home, ".xurl");
|
|
540
678
|
}
|
|
541
679
|
function writeXurlStoreForIntegrations(integrations, filePath = getXurlStorePath()) {
|
|
542
680
|
const agtApps = buildAgtXurlApps(integrations);
|
|
@@ -546,7 +684,7 @@ function writeXurlStoreForIntegrations(integrations, filePath = getXurlStorePath
|
|
|
546
684
|
if (existsSync2(filePath)) {
|
|
547
685
|
let raw;
|
|
548
686
|
try {
|
|
549
|
-
raw =
|
|
687
|
+
raw = readFileSync3(filePath, "utf-8");
|
|
550
688
|
} catch {
|
|
551
689
|
return null;
|
|
552
690
|
}
|
|
@@ -557,9 +695,9 @@ function writeXurlStoreForIntegrations(integrations, filePath = getXurlStorePath
|
|
|
557
695
|
existing = parsed;
|
|
558
696
|
}
|
|
559
697
|
const merged = mergeXurlStore(existing, agtApps);
|
|
560
|
-
|
|
698
|
+
mkdirSync2(dirname2(filePath), { recursive: true });
|
|
561
699
|
const tmpPath = `${filePath}.tmp-${process.pid}-${Date.now()}`;
|
|
562
|
-
|
|
700
|
+
writeFileSync3(tmpPath, serializeXurlStore(merged), { mode: XURL_FILE_MODE });
|
|
563
701
|
try {
|
|
564
702
|
renameSync2(tmpPath, filePath);
|
|
565
703
|
} catch (err) {
|
|
@@ -570,16 +708,16 @@ function writeXurlStoreForIntegrations(integrations, filePath = getXurlStorePath
|
|
|
570
708
|
throw err;
|
|
571
709
|
}
|
|
572
710
|
try {
|
|
573
|
-
|
|
711
|
+
chmodSync3(filePath, XURL_FILE_MODE);
|
|
574
712
|
} catch {
|
|
575
713
|
}
|
|
576
714
|
return filePath;
|
|
577
715
|
}
|
|
578
716
|
|
|
579
717
|
// ../../packages/core/dist/integrations/framer-credentials.js
|
|
580
|
-
import { chmodSync as
|
|
718
|
+
import { chmodSync as chmodSync4, existsSync as existsSync3, mkdirSync as mkdirSync3, readFileSync as readFileSync4, renameSync as renameSync3, rmSync as rmSync2, statSync, unlinkSync as unlinkSync3, writeFileSync as writeFileSync4 } from "fs";
|
|
581
719
|
import { homedir as homedir2 } from "os";
|
|
582
|
-
import { dirname as
|
|
720
|
+
import { dirname as dirname3, join as join3 } from "path";
|
|
583
721
|
var FRAMER_PROJECTS_CONFIG_VERSION = 2;
|
|
584
722
|
var BARE_PROJECT_ID = /^[A-Za-z0-9]{20}$/u;
|
|
585
723
|
var SLUGGED_PROJECT_ID = /^.+--([A-Za-z0-9]+)/u;
|
|
@@ -678,11 +816,11 @@ function mergeFramerProjectsConfig(existing, inputs, options = {}) {
|
|
|
678
816
|
var FRAMER_FILE_MODE = 384;
|
|
679
817
|
var MANAGED_SIDECAR_NAME = ".augmented-managed-projects.json";
|
|
680
818
|
function sidecarPathFor(projectsPath) {
|
|
681
|
-
return
|
|
819
|
+
return join3(dirname3(projectsPath), MANAGED_SIDECAR_NAME);
|
|
682
820
|
}
|
|
683
821
|
function readManagedIds(projectsPath) {
|
|
684
822
|
try {
|
|
685
|
-
const raw =
|
|
823
|
+
const raw = readFileSync4(sidecarPathFor(projectsPath), "utf-8");
|
|
686
824
|
const parsed = JSON.parse(raw);
|
|
687
825
|
if (!Array.isArray(parsed))
|
|
688
826
|
return [];
|
|
@@ -701,7 +839,7 @@ function writeManagedIds(projectsPath, ids) {
|
|
|
701
839
|
}
|
|
702
840
|
return;
|
|
703
841
|
}
|
|
704
|
-
|
|
842
|
+
writeFileSync4(target, `${JSON.stringify([...ids].sort(), null, " ")}
|
|
705
843
|
`, {
|
|
706
844
|
mode: FRAMER_FILE_MODE
|
|
707
845
|
});
|
|
@@ -714,18 +852,18 @@ var LOCK_MAX_ATTEMPTS = 50;
|
|
|
714
852
|
function withStoreLock(projectsPath, fn) {
|
|
715
853
|
const lockDir = `${projectsPath}.lock`;
|
|
716
854
|
try {
|
|
717
|
-
|
|
855
|
+
mkdirSync3(dirname3(projectsPath), { recursive: true, mode: 448 });
|
|
718
856
|
} catch {
|
|
719
857
|
}
|
|
720
858
|
let held = false;
|
|
721
859
|
for (let attempt = 0; attempt < LOCK_MAX_ATTEMPTS && !held; attempt++) {
|
|
722
860
|
try {
|
|
723
|
-
|
|
861
|
+
mkdirSync3(lockDir);
|
|
724
862
|
held = true;
|
|
725
863
|
} catch {
|
|
726
864
|
try {
|
|
727
865
|
if (Date.now() - statSync(lockDir).mtimeMs > LOCK_STALE_MS) {
|
|
728
|
-
|
|
866
|
+
rmSync2(lockDir, { recursive: true, force: true });
|
|
729
867
|
continue;
|
|
730
868
|
}
|
|
731
869
|
} catch {
|
|
@@ -743,7 +881,7 @@ function withStoreLock(projectsPath, fn) {
|
|
|
743
881
|
return { acquired: true, value: fn() };
|
|
744
882
|
} finally {
|
|
745
883
|
try {
|
|
746
|
-
|
|
884
|
+
rmSync2(lockDir, { recursive: true, force: true });
|
|
747
885
|
} catch {
|
|
748
886
|
}
|
|
749
887
|
}
|
|
@@ -754,9 +892,9 @@ function asString2(value) {
|
|
|
754
892
|
function getFramerProjectsPath() {
|
|
755
893
|
const xdg = process.env["XDG_CONFIG_HOME"];
|
|
756
894
|
if (xdg)
|
|
757
|
-
return
|
|
895
|
+
return join3(xdg, "framer", "projects.json");
|
|
758
896
|
const home = process.env["HOME"] ?? process.env["USERPROFILE"] ?? homedir2();
|
|
759
|
-
return
|
|
897
|
+
return join3(home, ".config", "framer", "projects.json");
|
|
760
898
|
}
|
|
761
899
|
function buildFramerCredentialInputs(integrations) {
|
|
762
900
|
const inputs = [];
|
|
@@ -787,7 +925,7 @@ function writeFramerStoreForIntegrations(integrations, filePath = getFramerProje
|
|
|
787
925
|
let existing = null;
|
|
788
926
|
if (existsSync3(filePath)) {
|
|
789
927
|
try {
|
|
790
|
-
existing =
|
|
928
|
+
existing = readFileSync4(filePath, "utf-8");
|
|
791
929
|
} catch {
|
|
792
930
|
return null;
|
|
793
931
|
}
|
|
@@ -799,9 +937,9 @@ function writeFramerStoreForIntegrations(integrations, filePath = getFramerProje
|
|
|
799
937
|
}
|
|
800
938
|
if (!content)
|
|
801
939
|
return null;
|
|
802
|
-
|
|
940
|
+
mkdirSync3(dirname3(filePath), { recursive: true, mode: 448 });
|
|
803
941
|
const tmpPath = `${filePath}.tmp-${process.pid}-${Date.now()}`;
|
|
804
|
-
|
|
942
|
+
writeFileSync4(tmpPath, content, { mode: FRAMER_FILE_MODE });
|
|
805
943
|
try {
|
|
806
944
|
renameSync3(tmpPath, filePath);
|
|
807
945
|
} catch (err) {
|
|
@@ -812,7 +950,7 @@ function writeFramerStoreForIntegrations(integrations, filePath = getFramerProje
|
|
|
812
950
|
throw err;
|
|
813
951
|
}
|
|
814
952
|
try {
|
|
815
|
-
|
|
953
|
+
chmodSync4(filePath, FRAMER_FILE_MODE);
|
|
816
954
|
} catch {
|
|
817
955
|
}
|
|
818
956
|
writeManagedIds(filePath, written);
|
|
@@ -1511,30 +1649,45 @@ main().catch((err) => fail(err && err.message ? err.message : String(err)));
|
|
|
1511
1649
|
|
|
1512
1650
|
// ../../packages/core/dist/provisioning/frameworks/claudecode/index.js
|
|
1513
1651
|
var VALID_CODE_NAME = /^[a-z0-9]+(?:-[a-z0-9]+)*$/;
|
|
1514
|
-
var
|
|
1652
|
+
var SECRET_FILE_MODE2 = 384;
|
|
1515
1653
|
function writeEnvIntegrationsForAgent(codeName, args) {
|
|
1516
1654
|
const agentDir = getAgentDir(codeName);
|
|
1517
|
-
const envPath =
|
|
1655
|
+
const envPath = join4(agentDir, ".env.integrations");
|
|
1518
1656
|
let existing = null;
|
|
1519
1657
|
try {
|
|
1520
|
-
existing =
|
|
1658
|
+
existing = readFileSync5(envPath, "utf-8");
|
|
1521
1659
|
} catch {
|
|
1522
1660
|
}
|
|
1523
1661
|
if (existing === null && Object.keys(args.updates).length === 0)
|
|
1524
1662
|
return;
|
|
1663
|
+
if (isSecretFileTmpfsBackingEnabled()) {
|
|
1664
|
+
try {
|
|
1665
|
+
ensureAgentSecretFilesTmpfsBacked(agentDir, join4(agentDir, "project"), basename(agentDir));
|
|
1666
|
+
} catch (err) {
|
|
1667
|
+
process.stderr.write(`[env-integrations] [tmpfs-backing-failed] agent=${codeName} error=${err.message}
|
|
1668
|
+
`);
|
|
1669
|
+
}
|
|
1670
|
+
} else {
|
|
1671
|
+
try {
|
|
1672
|
+
ensureAgentSecretFilesNotTmpfsBacked(agentDir, join4(agentDir, "project"));
|
|
1673
|
+
} catch (err) {
|
|
1674
|
+
process.stderr.write(`[env-integrations] [tmpfs-revert-failed] agent=${codeName} error=${err.message}
|
|
1675
|
+
`);
|
|
1676
|
+
}
|
|
1677
|
+
}
|
|
1525
1678
|
const content = mergeEnvIntegrationsContent(existing, args);
|
|
1526
|
-
|
|
1679
|
+
writeFileSync5(envPath, content, { mode: SECRET_FILE_MODE2 });
|
|
1527
1680
|
try {
|
|
1528
|
-
|
|
1681
|
+
chmodSync5(envPath, SECRET_FILE_MODE2);
|
|
1529
1682
|
} catch {
|
|
1530
1683
|
}
|
|
1531
1684
|
try {
|
|
1532
1685
|
const projectDir = getProjectDir(codeName);
|
|
1533
|
-
|
|
1534
|
-
const dest =
|
|
1535
|
-
|
|
1686
|
+
mkdirSync4(projectDir, { recursive: true });
|
|
1687
|
+
const dest = join4(projectDir, ".env.integrations");
|
|
1688
|
+
writeFileSync5(dest, content, { mode: SECRET_FILE_MODE2 });
|
|
1536
1689
|
try {
|
|
1537
|
-
|
|
1690
|
+
chmodSync5(dest, SECRET_FILE_MODE2);
|
|
1538
1691
|
} catch {
|
|
1539
1692
|
}
|
|
1540
1693
|
} catch (err) {
|
|
@@ -1552,16 +1705,16 @@ var MIGRATABLE_FIELD_TO_ENV_VAR = {
|
|
|
1552
1705
|
AGT_API_KEY: "AGT_API_KEY"
|
|
1553
1706
|
};
|
|
1554
1707
|
function migrateExistingLiteralSecrets(codeName) {
|
|
1555
|
-
const mcpJsonPath =
|
|
1708
|
+
const mcpJsonPath = join4(getAgentDir(codeName), "provision", ".mcp.json");
|
|
1556
1709
|
let config;
|
|
1557
1710
|
try {
|
|
1558
|
-
config = JSON.parse(
|
|
1711
|
+
config = JSON.parse(readFileSync5(mcpJsonPath, "utf-8"));
|
|
1559
1712
|
} catch {
|
|
1560
1713
|
return;
|
|
1561
1714
|
}
|
|
1562
1715
|
let existingEnvKeys = /* @__PURE__ */ new Set();
|
|
1563
1716
|
try {
|
|
1564
|
-
existingEnvKeys = new Set(parseEnvFileEntries(
|
|
1717
|
+
existingEnvKeys = new Set(parseEnvFileEntries(readFileSync5(join4(getAgentDir(codeName), ".env.integrations"), "utf-8")).keys());
|
|
1565
1718
|
} catch {
|
|
1566
1719
|
}
|
|
1567
1720
|
const updates = {};
|
|
@@ -1649,7 +1802,7 @@ function assertValidAgentId(agentId) {
|
|
|
1649
1802
|
}
|
|
1650
1803
|
function resolveRealAgentPath(codeNamePath) {
|
|
1651
1804
|
try {
|
|
1652
|
-
if (
|
|
1805
|
+
if (lstatSync2(codeNamePath).isSymbolicLink()) {
|
|
1653
1806
|
return realpathSync(codeNamePath);
|
|
1654
1807
|
}
|
|
1655
1808
|
} catch {
|
|
@@ -1660,11 +1813,11 @@ function ensureIdKeyedLayout(codeName, agentId) {
|
|
|
1660
1813
|
assertValidCodeName(codeName);
|
|
1661
1814
|
assertValidAgentId(agentId);
|
|
1662
1815
|
const home = getHomeDir();
|
|
1663
|
-
const codeNamePath =
|
|
1664
|
-
const idPath =
|
|
1816
|
+
const codeNamePath = join4(home, ".augmented", codeName);
|
|
1817
|
+
const idPath = join4(home, ".augmented", agentId);
|
|
1665
1818
|
let state;
|
|
1666
1819
|
try {
|
|
1667
|
-
state =
|
|
1820
|
+
state = lstatSync2(codeNamePath).isSymbolicLink() ? "symlink" : "realdir";
|
|
1668
1821
|
} catch {
|
|
1669
1822
|
state = "absent";
|
|
1670
1823
|
}
|
|
@@ -1672,30 +1825,30 @@ function ensureIdKeyedLayout(codeName, agentId) {
|
|
|
1672
1825
|
return codeNamePath;
|
|
1673
1826
|
}
|
|
1674
1827
|
if (state === "symlink") {
|
|
1675
|
-
const target =
|
|
1828
|
+
const target = readlinkSync2(codeNamePath);
|
|
1676
1829
|
if (target !== agentId) {
|
|
1677
1830
|
throw new Error(`Codename symlink ${codeNamePath} points at "${target}", expected "${agentId}"; refusing to provision over a mismatched id-keyed layout.`);
|
|
1678
1831
|
}
|
|
1679
|
-
|
|
1832
|
+
mkdirSync4(idPath, { recursive: true });
|
|
1680
1833
|
return idPath;
|
|
1681
1834
|
}
|
|
1682
|
-
|
|
1683
|
-
|
|
1835
|
+
mkdirSync4(idPath, { recursive: true });
|
|
1836
|
+
symlinkSync2(agentId, codeNamePath);
|
|
1684
1837
|
return idPath;
|
|
1685
1838
|
}
|
|
1686
1839
|
function stagedMigrationLinkPath(home, codeName) {
|
|
1687
|
-
return
|
|
1840
|
+
return join4(home, ".augmented", `.${codeName}.migrating`);
|
|
1688
1841
|
}
|
|
1689
1842
|
function cleanupStaleStagedLink(staged) {
|
|
1690
1843
|
try {
|
|
1691
|
-
if (
|
|
1692
|
-
|
|
1844
|
+
if (lstatSync2(staged).isSymbolicLink())
|
|
1845
|
+
rmSync3(staged, { force: true });
|
|
1693
1846
|
} catch {
|
|
1694
1847
|
}
|
|
1695
1848
|
}
|
|
1696
1849
|
function isSymlinkTo(path, target) {
|
|
1697
1850
|
try {
|
|
1698
|
-
return
|
|
1851
|
+
return lstatSync2(path).isSymbolicLink() && readlinkSync2(path) === target;
|
|
1699
1852
|
} catch {
|
|
1700
1853
|
return false;
|
|
1701
1854
|
}
|
|
@@ -1704,18 +1857,18 @@ function migrateAgentDirToIdKeyed(codeName, agentId, opts = {}) {
|
|
|
1704
1857
|
assertValidCodeName(codeName);
|
|
1705
1858
|
assertValidAgentId(agentId);
|
|
1706
1859
|
const home = opts.home ?? getHomeDir();
|
|
1707
|
-
const codeNamePath =
|
|
1708
|
-
const idPath =
|
|
1860
|
+
const codeNamePath = join4(home, ".augmented", codeName);
|
|
1861
|
+
const idPath = join4(home, ".augmented", agentId);
|
|
1709
1862
|
const staged = stagedMigrationLinkPath(home, codeName);
|
|
1710
1863
|
let codeNameKind;
|
|
1711
1864
|
try {
|
|
1712
|
-
codeNameKind =
|
|
1865
|
+
codeNameKind = lstatSync2(codeNamePath).isSymbolicLink() ? "symlink" : "realdir";
|
|
1713
1866
|
} catch {
|
|
1714
1867
|
codeNameKind = "absent";
|
|
1715
1868
|
}
|
|
1716
1869
|
const idExists = existsSync4(idPath);
|
|
1717
1870
|
if (codeNameKind === "symlink") {
|
|
1718
|
-
const target =
|
|
1871
|
+
const target = readlinkSync2(codeNamePath);
|
|
1719
1872
|
if (target !== agentId) {
|
|
1720
1873
|
throw new Error(`Codename symlink ${codeNamePath} points at "${target}", expected "${agentId}"; refusing to migrate.`);
|
|
1721
1874
|
}
|
|
@@ -1726,7 +1879,7 @@ function migrateAgentDirToIdKeyed(codeName, agentId, opts = {}) {
|
|
|
1726
1879
|
renameSync4(staged, codeNamePath);
|
|
1727
1880
|
} else {
|
|
1728
1881
|
cleanupStaleStagedLink(staged);
|
|
1729
|
-
|
|
1882
|
+
symlinkSync2(agentId, codeNamePath);
|
|
1730
1883
|
}
|
|
1731
1884
|
return "recovered";
|
|
1732
1885
|
}
|
|
@@ -1736,21 +1889,21 @@ function migrateAgentDirToIdKeyed(codeName, agentId, opts = {}) {
|
|
|
1736
1889
|
return "conflict";
|
|
1737
1890
|
}
|
|
1738
1891
|
cleanupStaleStagedLink(staged);
|
|
1739
|
-
|
|
1892
|
+
symlinkSync2(agentId, staged);
|
|
1740
1893
|
renameSync4(codeNamePath, idPath);
|
|
1741
1894
|
renameSync4(staged, codeNamePath);
|
|
1742
1895
|
return "migrated";
|
|
1743
1896
|
}
|
|
1744
1897
|
function getAgentDir(codeName) {
|
|
1745
1898
|
assertValidCodeName(codeName);
|
|
1746
|
-
return resolveRealAgentPath(
|
|
1899
|
+
return resolveRealAgentPath(join4(getHomeDir(), ".augmented", codeName));
|
|
1747
1900
|
}
|
|
1748
1901
|
var migratedCodeNames = /* @__PURE__ */ new Set();
|
|
1749
1902
|
function migrateLegacyClaudecodeDir(codeName, log2) {
|
|
1750
1903
|
assertValidCodeName(codeName);
|
|
1751
1904
|
if (migratedCodeNames.has(codeName))
|
|
1752
1905
|
return;
|
|
1753
|
-
const legacyRoot =
|
|
1906
|
+
const legacyRoot = join4(getHomeDir(), ".augmented", codeName, "claudecode");
|
|
1754
1907
|
if (!existsSync4(legacyRoot)) {
|
|
1755
1908
|
migratedCodeNames.add(codeName);
|
|
1756
1909
|
return;
|
|
@@ -1761,20 +1914,20 @@ function migrateLegacyClaudecodeDir(codeName, log2) {
|
|
|
1761
1914
|
};
|
|
1762
1915
|
try {
|
|
1763
1916
|
const walkAndMigrate = (srcDir, destDir) => {
|
|
1764
|
-
|
|
1917
|
+
mkdirSync4(destDir, { recursive: true });
|
|
1765
1918
|
for (const entry of readdirSync(srcDir, { withFileTypes: true })) {
|
|
1766
|
-
const src =
|
|
1767
|
-
const dest =
|
|
1919
|
+
const src = join4(srcDir, entry.name);
|
|
1920
|
+
const dest = join4(destDir, entry.name);
|
|
1768
1921
|
if (entry.isDirectory()) {
|
|
1769
1922
|
walkAndMigrate(src, dest);
|
|
1770
1923
|
continue;
|
|
1771
1924
|
}
|
|
1772
1925
|
if (entry.name === ".mcp.json" && existsSync4(dest)) {
|
|
1773
1926
|
try {
|
|
1774
|
-
const oldCfg = JSON.parse(
|
|
1775
|
-
const newCfg = JSON.parse(
|
|
1927
|
+
const oldCfg = JSON.parse(readFileSync5(src, "utf-8"));
|
|
1928
|
+
const newCfg = JSON.parse(readFileSync5(dest, "utf-8"));
|
|
1776
1929
|
const merged = { mcpServers: { ...oldCfg.mcpServers ?? {}, ...newCfg.mcpServers ?? {} } };
|
|
1777
|
-
|
|
1930
|
+
writeFileSync5(dest, JSON.stringify(merged, null, 2));
|
|
1778
1931
|
emit(`[migrate] '${codeName}' merged .mcp.json (${Object.keys(merged.mcpServers).length} servers)`);
|
|
1779
1932
|
} catch (err) {
|
|
1780
1933
|
throw new Error(`Failed merging .mcp.json (${src} \u2192 ${dest}): ${err.message}`);
|
|
@@ -1786,8 +1939,8 @@ function migrateLegacyClaudecodeDir(codeName, log2) {
|
|
|
1786
1939
|
continue;
|
|
1787
1940
|
}
|
|
1788
1941
|
try {
|
|
1789
|
-
const srcStat =
|
|
1790
|
-
const destStat =
|
|
1942
|
+
const srcStat = readFileSync5(src);
|
|
1943
|
+
const destStat = readFileSync5(dest);
|
|
1791
1944
|
if (!srcStat.equals(destStat)) {
|
|
1792
1945
|
}
|
|
1793
1946
|
} catch (err) {
|
|
@@ -1796,7 +1949,7 @@ function migrateLegacyClaudecodeDir(codeName, log2) {
|
|
|
1796
1949
|
}
|
|
1797
1950
|
};
|
|
1798
1951
|
walkAndMigrate(legacyRoot, newRoot);
|
|
1799
|
-
|
|
1952
|
+
rmSync3(legacyRoot, { recursive: true, force: true });
|
|
1800
1953
|
emit(`[migrate] '${codeName}': collapsed ~/.augmented/${codeName}/claudecode/ into ~/.augmented/${codeName}/`);
|
|
1801
1954
|
migratedCodeNames.add(codeName);
|
|
1802
1955
|
} catch (err) {
|
|
@@ -1804,25 +1957,25 @@ function migrateLegacyClaudecodeDir(codeName, log2) {
|
|
|
1804
1957
|
}
|
|
1805
1958
|
}
|
|
1806
1959
|
function syncGitHubBrokerCredentialTooling(projectDir, enabled) {
|
|
1807
|
-
const binDir =
|
|
1960
|
+
const binDir = join4(projectDir, GITHUB_BROKER_BIN_DIR);
|
|
1808
1961
|
if (!enabled) {
|
|
1809
|
-
|
|
1962
|
+
rmSync3(binDir, { recursive: true, force: true });
|
|
1810
1963
|
return {};
|
|
1811
1964
|
}
|
|
1812
|
-
const helperPath =
|
|
1813
|
-
const shimPath =
|
|
1814
|
-
|
|
1815
|
-
|
|
1816
|
-
|
|
1817
|
-
|
|
1818
|
-
|
|
1965
|
+
const helperPath = join4(binDir, GIT_CREDENTIAL_HELPER_BASENAME);
|
|
1966
|
+
const shimPath = join4(binDir, GH_SHIM_BASENAME);
|
|
1967
|
+
mkdirSync4(binDir, { recursive: true });
|
|
1968
|
+
writeFileSync5(helperPath, renderGitCredentialHelper(), { mode: BROKER_SCRIPT_MODE });
|
|
1969
|
+
chmodSync5(helperPath, BROKER_SCRIPT_MODE);
|
|
1970
|
+
writeFileSync5(shimPath, renderGhShim(), { mode: BROKER_SCRIPT_MODE });
|
|
1971
|
+
chmodSync5(shimPath, BROKER_SCRIPT_MODE);
|
|
1819
1972
|
return buildGitCredentialEnv(helperPath);
|
|
1820
1973
|
}
|
|
1821
1974
|
function getProjectDir(codeName) {
|
|
1822
|
-
return
|
|
1975
|
+
return join4(getAgentDir(codeName), "project");
|
|
1823
1976
|
}
|
|
1824
1977
|
function getScratchDir(codeName) {
|
|
1825
|
-
return
|
|
1978
|
+
return join4(getAgentDir(codeName), "scratch");
|
|
1826
1979
|
}
|
|
1827
1980
|
function getAgentTmpDir(codeName) {
|
|
1828
1981
|
return agentTmpDirFor(getAgentDir(codeName));
|
|
@@ -1838,11 +1991,11 @@ function sweepScratchDir(codeName, now = Date.now()) {
|
|
|
1838
1991
|
}
|
|
1839
1992
|
const cutoff = now - SCRATCH_RETENTION_DAYS * 24 * 60 * 60 * 1e3;
|
|
1840
1993
|
for (const entry of entries) {
|
|
1841
|
-
const full =
|
|
1994
|
+
const full = join4(scratchDir, entry);
|
|
1842
1995
|
try {
|
|
1843
1996
|
if (isFreshWithin(full, cutoff))
|
|
1844
1997
|
continue;
|
|
1845
|
-
|
|
1998
|
+
rmSync3(full, { recursive: true, force: true });
|
|
1846
1999
|
removed += 1;
|
|
1847
2000
|
} catch {
|
|
1848
2001
|
}
|
|
@@ -1859,7 +2012,7 @@ function isFreshWithin(path, cutoff) {
|
|
|
1859
2012
|
const current = queue.pop();
|
|
1860
2013
|
let stat;
|
|
1861
2014
|
try {
|
|
1862
|
-
stat =
|
|
2015
|
+
stat = lstatSync2(current);
|
|
1863
2016
|
} catch {
|
|
1864
2017
|
return true;
|
|
1865
2018
|
}
|
|
@@ -1878,7 +2031,7 @@ function isFreshWithin(path, cutoff) {
|
|
|
1878
2031
|
const child = dir.readSync();
|
|
1879
2032
|
if (child === null)
|
|
1880
2033
|
break;
|
|
1881
|
-
queue.push(
|
|
2034
|
+
queue.push(join4(current, child.name));
|
|
1882
2035
|
budget -= 1;
|
|
1883
2036
|
}
|
|
1884
2037
|
} catch {
|
|
@@ -1895,18 +2048,18 @@ function isFreshWithin(path, cutoff) {
|
|
|
1895
2048
|
function syncMcpToProject(codeName) {
|
|
1896
2049
|
const agentDir = getAgentDir(codeName);
|
|
1897
2050
|
const projectDir = getProjectDir(codeName);
|
|
1898
|
-
const provisionMcpPath =
|
|
1899
|
-
const projectMcpPath =
|
|
2051
|
+
const provisionMcpPath = join4(agentDir, "provision", ".mcp.json");
|
|
2052
|
+
const projectMcpPath = join4(projectDir, ".mcp.json");
|
|
1900
2053
|
try {
|
|
1901
|
-
const content =
|
|
1902
|
-
|
|
1903
|
-
|
|
2054
|
+
const content = readFileSync5(provisionMcpPath, "utf-8");
|
|
2055
|
+
mkdirSync4(projectDir, { recursive: true });
|
|
2056
|
+
writeFileSync5(projectMcpPath, content, { mode: MCP_FILE_MODE });
|
|
1904
2057
|
try {
|
|
1905
|
-
|
|
2058
|
+
chmodSync5(projectMcpPath, MCP_FILE_MODE);
|
|
1906
2059
|
} catch {
|
|
1907
2060
|
}
|
|
1908
2061
|
try {
|
|
1909
|
-
const mismatches = mcpMirrorParityErrors(JSON.parse(content), JSON.parse(
|
|
2062
|
+
const mismatches = mcpMirrorParityErrors(JSON.parse(content), JSON.parse(readFileSync5(projectMcpPath, "utf-8")));
|
|
1910
2063
|
for (const m of mismatches) {
|
|
1911
2064
|
process.stderr.write(`${formatMirrorMismatch(m)} agent=${codeName}
|
|
1912
2065
|
`);
|
|
@@ -1920,19 +2073,19 @@ function syncMcpToProject(codeName) {
|
|
|
1920
2073
|
}
|
|
1921
2074
|
var INTEGRATIONS_SUMMARY_FILE = "integrations-summary.json";
|
|
1922
2075
|
function integrationsSummaryPath(codeName) {
|
|
1923
|
-
return
|
|
2076
|
+
return join4(getAgentDir(codeName), "provision", INTEGRATIONS_SUMMARY_FILE);
|
|
1924
2077
|
}
|
|
1925
2078
|
function writeIntegrationsSummaryForAgent(codeName, summaries) {
|
|
1926
2079
|
const target = integrationsSummaryPath(codeName);
|
|
1927
2080
|
try {
|
|
1928
|
-
|
|
1929
|
-
|
|
2081
|
+
mkdirSync4(dirname4(target), { recursive: true });
|
|
2082
|
+
writeFileSync5(target, JSON.stringify(summaries, null, 2));
|
|
1930
2083
|
} catch {
|
|
1931
2084
|
}
|
|
1932
2085
|
}
|
|
1933
2086
|
function readIntegrationsSummaryForAgent(codeName) {
|
|
1934
2087
|
try {
|
|
1935
|
-
const raw =
|
|
2088
|
+
const raw = readFileSync5(integrationsSummaryPath(codeName), "utf-8");
|
|
1936
2089
|
const parsed = JSON.parse(raw);
|
|
1937
2090
|
return Array.isArray(parsed) ? parsed : [];
|
|
1938
2091
|
} catch {
|
|
@@ -1942,10 +2095,10 @@ function readIntegrationsSummaryForAgent(codeName) {
|
|
|
1942
2095
|
function renderChannelMessageHandlerForAgent(codeName) {
|
|
1943
2096
|
const agentDir = getAgentDir(codeName);
|
|
1944
2097
|
const projectDir = getProjectDir(codeName);
|
|
1945
|
-
const provisionMcpPath =
|
|
2098
|
+
const provisionMcpPath = join4(agentDir, "provision", ".mcp.json");
|
|
1946
2099
|
let mcpServerKeys;
|
|
1947
2100
|
try {
|
|
1948
|
-
const config = JSON.parse(
|
|
2101
|
+
const config = JSON.parse(readFileSync5(provisionMcpPath, "utf-8"));
|
|
1949
2102
|
mcpServerKeys = Object.keys(config.mcpServers ?? {});
|
|
1950
2103
|
} catch {
|
|
1951
2104
|
return;
|
|
@@ -1953,10 +2106,10 @@ function renderChannelMessageHandlerForAgent(codeName) {
|
|
|
1953
2106
|
const integrations = readIntegrationsSummaryForAgent(codeName);
|
|
1954
2107
|
const content = buildChannelMessageHandlerAgent({ mcpServerKeys, integrations });
|
|
1955
2108
|
for (const baseDir of [agentDir, projectDir]) {
|
|
1956
|
-
const target =
|
|
2109
|
+
const target = join4(baseDir, ".claude", "agents", "channel-message-handler.md");
|
|
1957
2110
|
try {
|
|
1958
|
-
|
|
1959
|
-
|
|
2111
|
+
mkdirSync4(dirname4(target), { recursive: true });
|
|
2112
|
+
writeFileSync5(target, content);
|
|
1960
2113
|
} catch {
|
|
1961
2114
|
}
|
|
1962
2115
|
}
|
|
@@ -1971,9 +2124,9 @@ function writeMcpJsonGuarded(codeName, path, config) {
|
|
|
1971
2124
|
return true;
|
|
1972
2125
|
}
|
|
1973
2126
|
function readExistingMcpEnvVar(codeName, serverId, envKey) {
|
|
1974
|
-
const mcpJsonPath =
|
|
2127
|
+
const mcpJsonPath = join4(getAgentDir(codeName), "provision", ".mcp.json");
|
|
1975
2128
|
try {
|
|
1976
|
-
const raw =
|
|
2129
|
+
const raw = readFileSync5(mcpJsonPath, "utf-8");
|
|
1977
2130
|
const config = JSON.parse(raw);
|
|
1978
2131
|
const server = config.mcpServers?.[serverId];
|
|
1979
2132
|
if (!server || typeof server !== "object")
|
|
@@ -2002,10 +2155,10 @@ function resolveBrokerAgentId(codeName, fallback) {
|
|
|
2002
2155
|
}
|
|
2003
2156
|
function deployArtifactsToProject(codeName, provisionDir) {
|
|
2004
2157
|
const projectDir = getProjectDir(codeName);
|
|
2005
|
-
|
|
2158
|
+
mkdirSync4(projectDir, { recursive: true });
|
|
2006
2159
|
try {
|
|
2007
|
-
|
|
2008
|
-
|
|
2160
|
+
mkdirSync4(getScratchDir(codeName), { recursive: true });
|
|
2161
|
+
mkdirSync4(getAgentTmpDir(codeName), { recursive: true });
|
|
2009
2162
|
sweepScratchDir(codeName);
|
|
2010
2163
|
} catch (err) {
|
|
2011
2164
|
process.stderr.write(`[scratch] [ensure-or-sweep-failed] agent=${codeName} error=${err.message}
|
|
@@ -2015,42 +2168,42 @@ function deployArtifactsToProject(codeName, provisionDir) {
|
|
|
2015
2168
|
const SKILLS_START = "<!-- AGT:SKILLS_INDEX_START -->";
|
|
2016
2169
|
const SKILLS_END = "<!-- AGT:SKILLS_INDEX_END -->";
|
|
2017
2170
|
for (const file of artifactFiles) {
|
|
2018
|
-
const src =
|
|
2019
|
-
const dest =
|
|
2171
|
+
const src = join4(provisionDir, file);
|
|
2172
|
+
const dest = join4(projectDir, file);
|
|
2020
2173
|
try {
|
|
2021
|
-
const srcContent =
|
|
2174
|
+
const srcContent = readFileSync5(src, "utf-8");
|
|
2022
2175
|
if (file === "CLAUDE.md" && existsSync4(dest)) {
|
|
2023
|
-
const destContent =
|
|
2176
|
+
const destContent = readFileSync5(dest, "utf-8");
|
|
2024
2177
|
const stripIndex = (s) => s.replace(new RegExp(`${SKILLS_START}[\\s\\S]*?${SKILLS_END}`), "").trimEnd();
|
|
2025
2178
|
if (stripIndex(srcContent) === stripIndex(destContent))
|
|
2026
2179
|
continue;
|
|
2027
2180
|
const indexMatch = destContent.match(new RegExp(`${SKILLS_START}[\\s\\S]*?${SKILLS_END}`));
|
|
2028
2181
|
if (indexMatch) {
|
|
2029
|
-
|
|
2182
|
+
writeFileSync5(dest, srcContent.trimEnd() + "\n\n" + indexMatch[0] + "\n");
|
|
2030
2183
|
continue;
|
|
2031
2184
|
}
|
|
2032
2185
|
}
|
|
2033
2186
|
if (file === ".mcp.json") {
|
|
2034
|
-
|
|
2187
|
+
writeFileSync5(dest, srcContent, { mode: MCP_FILE_MODE });
|
|
2035
2188
|
try {
|
|
2036
|
-
|
|
2189
|
+
chmodSync5(dest, MCP_FILE_MODE);
|
|
2037
2190
|
} catch {
|
|
2038
2191
|
}
|
|
2039
2192
|
} else {
|
|
2040
|
-
|
|
2193
|
+
writeFileSync5(dest, srcContent);
|
|
2041
2194
|
}
|
|
2042
2195
|
} catch {
|
|
2043
2196
|
}
|
|
2044
2197
|
}
|
|
2045
|
-
const skillsDir =
|
|
2046
|
-
const destSkillsDir =
|
|
2198
|
+
const skillsDir = join4(provisionDir, ".claude", "skills");
|
|
2199
|
+
const destSkillsDir = join4(projectDir, ".claude", "skills");
|
|
2047
2200
|
try {
|
|
2048
2201
|
if (existsSync4(destSkillsDir)) {
|
|
2049
2202
|
const srcFolders = existsSync4(skillsDir) ? new Set(readdirSync(skillsDir)) : /* @__PURE__ */ new Set();
|
|
2050
2203
|
for (const folder of readdirSync(destSkillsDir)) {
|
|
2051
2204
|
if (folder.startsWith("knowledge-") || folder === "core-knowledge" && !srcFolders.has(folder)) {
|
|
2052
2205
|
try {
|
|
2053
|
-
|
|
2206
|
+
rmSync3(join4(destSkillsDir, folder), { recursive: true });
|
|
2054
2207
|
} catch {
|
|
2055
2208
|
}
|
|
2056
2209
|
}
|
|
@@ -2058,25 +2211,25 @@ function deployArtifactsToProject(codeName, provisionDir) {
|
|
|
2058
2211
|
}
|
|
2059
2212
|
if (existsSync4(skillsDir)) {
|
|
2060
2213
|
for (const skillFolder of readdirSync(skillsDir)) {
|
|
2061
|
-
const srcSkillFile =
|
|
2214
|
+
const srcSkillFile = join4(skillsDir, skillFolder, "SKILL.md");
|
|
2062
2215
|
if (!existsSync4(srcSkillFile))
|
|
2063
2216
|
continue;
|
|
2064
|
-
const destFolder =
|
|
2065
|
-
const destFile =
|
|
2066
|
-
const srcContent =
|
|
2217
|
+
const destFolder = join4(destSkillsDir, skillFolder);
|
|
2218
|
+
const destFile = join4(destFolder, "SKILL.md");
|
|
2219
|
+
const srcContent = readFileSync5(srcSkillFile, "utf-8");
|
|
2067
2220
|
try {
|
|
2068
|
-
if (existsSync4(destFile) &&
|
|
2221
|
+
if (existsSync4(destFile) && readFileSync5(destFile, "utf-8") === srcContent)
|
|
2069
2222
|
continue;
|
|
2070
2223
|
} catch {
|
|
2071
2224
|
}
|
|
2072
|
-
|
|
2073
|
-
|
|
2225
|
+
mkdirSync4(destFolder, { recursive: true });
|
|
2226
|
+
writeFileSync5(destFile, srcContent);
|
|
2074
2227
|
}
|
|
2075
2228
|
}
|
|
2076
2229
|
} catch {
|
|
2077
2230
|
}
|
|
2078
|
-
const agentsDir =
|
|
2079
|
-
const destAgentsDir =
|
|
2231
|
+
const agentsDir = join4(provisionDir, ".claude", "agents");
|
|
2232
|
+
const destAgentsDir = join4(projectDir, ".claude", "agents");
|
|
2080
2233
|
try {
|
|
2081
2234
|
if (existsSync4(agentsDir)) {
|
|
2082
2235
|
const sourceAgentFiles = new Set(readdirSync(agentsDir).filter((f) => f.endsWith(".md")));
|
|
@@ -2087,28 +2240,28 @@ function deployArtifactsToProject(codeName, provisionDir) {
|
|
|
2087
2240
|
if (sourceAgentFiles.has(destFile))
|
|
2088
2241
|
continue;
|
|
2089
2242
|
try {
|
|
2090
|
-
|
|
2243
|
+
rmSync3(join4(destAgentsDir, destFile));
|
|
2091
2244
|
} catch {
|
|
2092
2245
|
}
|
|
2093
2246
|
}
|
|
2094
2247
|
}
|
|
2095
2248
|
for (const agentFile of sourceAgentFiles) {
|
|
2096
|
-
const srcPath =
|
|
2097
|
-
const destPath =
|
|
2098
|
-
const srcContent =
|
|
2249
|
+
const srcPath = join4(agentsDir, agentFile);
|
|
2250
|
+
const destPath = join4(destAgentsDir, agentFile);
|
|
2251
|
+
const srcContent = readFileSync5(srcPath, "utf-8");
|
|
2099
2252
|
try {
|
|
2100
|
-
if (existsSync4(destPath) &&
|
|
2253
|
+
if (existsSync4(destPath) && readFileSync5(destPath, "utf-8") === srcContent)
|
|
2101
2254
|
continue;
|
|
2102
2255
|
} catch {
|
|
2103
2256
|
}
|
|
2104
|
-
|
|
2105
|
-
|
|
2257
|
+
mkdirSync4(destAgentsDir, { recursive: true });
|
|
2258
|
+
writeFileSync5(destPath, srcContent);
|
|
2106
2259
|
}
|
|
2107
2260
|
}
|
|
2108
2261
|
} catch {
|
|
2109
2262
|
}
|
|
2110
|
-
const workflowsDir =
|
|
2111
|
-
const destWorkflowsDir =
|
|
2263
|
+
const workflowsDir = join4(provisionDir, ".claude", "workflows");
|
|
2264
|
+
const destWorkflowsDir = join4(projectDir, ".claude", "workflows");
|
|
2112
2265
|
try {
|
|
2113
2266
|
const sourceWorkflowFiles = existsSync4(workflowsDir) ? new Set(readdirSync(workflowsDir).filter((f) => f.endsWith(".js"))) : /* @__PURE__ */ new Set();
|
|
2114
2267
|
if (existsSync4(destWorkflowsDir)) {
|
|
@@ -2118,32 +2271,32 @@ function deployArtifactsToProject(codeName, provisionDir) {
|
|
|
2118
2271
|
if (sourceWorkflowFiles.has(destFile))
|
|
2119
2272
|
continue;
|
|
2120
2273
|
try {
|
|
2121
|
-
|
|
2274
|
+
rmSync3(join4(destWorkflowsDir, destFile));
|
|
2122
2275
|
} catch {
|
|
2123
2276
|
}
|
|
2124
2277
|
}
|
|
2125
2278
|
}
|
|
2126
2279
|
for (const workflowFile of sourceWorkflowFiles) {
|
|
2127
|
-
const srcPath =
|
|
2128
|
-
const destPath =
|
|
2129
|
-
const srcContent =
|
|
2280
|
+
const srcPath = join4(workflowsDir, workflowFile);
|
|
2281
|
+
const destPath = join4(destWorkflowsDir, workflowFile);
|
|
2282
|
+
const srcContent = readFileSync5(srcPath, "utf-8");
|
|
2130
2283
|
try {
|
|
2131
|
-
if (existsSync4(destPath) &&
|
|
2284
|
+
if (existsSync4(destPath) && readFileSync5(destPath, "utf-8") === srcContent)
|
|
2132
2285
|
continue;
|
|
2133
2286
|
} catch {
|
|
2134
2287
|
}
|
|
2135
|
-
|
|
2136
|
-
|
|
2288
|
+
mkdirSync4(destWorkflowsDir, { recursive: true });
|
|
2289
|
+
writeFileSync5(destPath, srcContent);
|
|
2137
2290
|
}
|
|
2138
2291
|
} catch {
|
|
2139
2292
|
}
|
|
2140
|
-
const agentMcpPath =
|
|
2141
|
-
const projectMcpPath =
|
|
2293
|
+
const agentMcpPath = join4(getAgentDir(codeName), "provision", ".mcp.json");
|
|
2294
|
+
const projectMcpPath = join4(projectDir, ".mcp.json");
|
|
2142
2295
|
try {
|
|
2143
|
-
const agentMcp = JSON.parse(
|
|
2296
|
+
const agentMcp = JSON.parse(readFileSync5(agentMcpPath, "utf-8"));
|
|
2144
2297
|
let projectMcp;
|
|
2145
2298
|
try {
|
|
2146
|
-
projectMcp = JSON.parse(
|
|
2299
|
+
projectMcp = JSON.parse(readFileSync5(projectMcpPath, "utf-8"));
|
|
2147
2300
|
} catch {
|
|
2148
2301
|
projectMcp = { mcpServers: {} };
|
|
2149
2302
|
}
|
|
@@ -2154,9 +2307,9 @@ function deployArtifactsToProject(codeName, provisionDir) {
|
|
|
2154
2307
|
return !(entry && typeof entry["url"] === "string" && entry["url"].startsWith("/"));
|
|
2155
2308
|
}));
|
|
2156
2309
|
projectMcp["mcpServers"] = { ...stripRelativeUrls(projectServers), ...stripRelativeUrls(agentServers) };
|
|
2157
|
-
|
|
2310
|
+
writeFileSync5(projectMcpPath, JSON.stringify(projectMcp, null, 2), { mode: MCP_FILE_MODE });
|
|
2158
2311
|
try {
|
|
2159
|
-
|
|
2312
|
+
chmodSync5(projectMcpPath, MCP_FILE_MODE);
|
|
2160
2313
|
} catch {
|
|
2161
2314
|
}
|
|
2162
2315
|
} catch {
|
|
@@ -2164,37 +2317,37 @@ function deployArtifactsToProject(codeName, provisionDir) {
|
|
|
2164
2317
|
const agentDir = getAgentDir(codeName);
|
|
2165
2318
|
for (const envFile of [".env", ".env.integrations"]) {
|
|
2166
2319
|
try {
|
|
2167
|
-
const content =
|
|
2168
|
-
const envDest =
|
|
2169
|
-
|
|
2320
|
+
const content = readFileSync5(join4(agentDir, envFile), "utf-8");
|
|
2321
|
+
const envDest = join4(projectDir, envFile);
|
|
2322
|
+
writeFileSync5(envDest, content, { mode: SECRET_FILE_MODE2 });
|
|
2170
2323
|
try {
|
|
2171
|
-
|
|
2324
|
+
chmodSync5(envDest, SECRET_FILE_MODE2);
|
|
2172
2325
|
} catch {
|
|
2173
2326
|
}
|
|
2174
2327
|
} catch {
|
|
2175
2328
|
}
|
|
2176
2329
|
}
|
|
2177
2330
|
try {
|
|
2178
|
-
const gitDir =
|
|
2179
|
-
const hookSrc =
|
|
2331
|
+
const gitDir = join4(projectDir, ".git");
|
|
2332
|
+
const hookSrc = join4(provisionDir, ".git-hooks", "pre-commit");
|
|
2180
2333
|
if (existsSync4(gitDir) && existsSync4(hookSrc)) {
|
|
2181
|
-
const hooksDir =
|
|
2182
|
-
|
|
2183
|
-
const hookDest =
|
|
2184
|
-
const srcContent =
|
|
2185
|
-
const upToDate = existsSync4(hookDest) &&
|
|
2334
|
+
const hooksDir = join4(gitDir, "hooks");
|
|
2335
|
+
mkdirSync4(hooksDir, { recursive: true });
|
|
2336
|
+
const hookDest = join4(hooksDir, "pre-commit");
|
|
2337
|
+
const srcContent = readFileSync5(hookSrc, "utf-8");
|
|
2338
|
+
const upToDate = existsSync4(hookDest) && readFileSync5(hookDest, "utf-8") === srcContent;
|
|
2186
2339
|
if (!upToDate)
|
|
2187
|
-
|
|
2188
|
-
|
|
2340
|
+
writeFileSync5(hookDest, srcContent);
|
|
2341
|
+
chmodSync5(hookDest, 493);
|
|
2189
2342
|
}
|
|
2190
2343
|
} catch {
|
|
2191
2344
|
}
|
|
2192
2345
|
}
|
|
2193
2346
|
function provisionStopHook(codeName) {
|
|
2194
2347
|
const projectDir = getProjectDir(codeName);
|
|
2195
|
-
const claudeDir =
|
|
2196
|
-
|
|
2197
|
-
const hookScriptPath =
|
|
2348
|
+
const claudeDir = join4(projectDir, ".claude");
|
|
2349
|
+
mkdirSync4(claudeDir, { recursive: true });
|
|
2350
|
+
const hookScriptPath = join4(claudeDir, "agt-stop-hook.sh");
|
|
2198
2351
|
const hookScript = [
|
|
2199
2352
|
"#!/bin/bash",
|
|
2200
2353
|
"# Auto-generated by Augmented \u2014 captures persistent session task results.",
|
|
@@ -2225,8 +2378,8 @@ function provisionStopHook(codeName) {
|
|
|
2225
2378
|
"esac",
|
|
2226
2379
|
"exit 0"
|
|
2227
2380
|
].join("\n") + "\n";
|
|
2228
|
-
|
|
2229
|
-
const ghostHookPath =
|
|
2381
|
+
writeFileSync5(hookScriptPath, hookScript, { mode: 493 });
|
|
2382
|
+
const ghostHookPath = join4(claudeDir, "agt-ghost-reply-hook.sh");
|
|
2230
2383
|
const jqNormalizeContent = '(.message.content // .content // []) | if type == "string" then [{type: "text", text: .}] elif type == "array" then . else [] end';
|
|
2231
2384
|
const ghostHookScript = [
|
|
2232
2385
|
"#!/bin/bash",
|
|
@@ -3098,12 +3251,12 @@ function provisionStopHook(codeName) {
|
|
|
3098
3251
|
"fi",
|
|
3099
3252
|
"exit 0"
|
|
3100
3253
|
].join("\n") + "\n";
|
|
3101
|
-
|
|
3254
|
+
writeFileSync5(ghostHookPath, ghostHookScript, { mode: 493 });
|
|
3102
3255
|
const backlogHookPath = provisionBacklogPullHook(codeName);
|
|
3103
|
-
const settingsPath =
|
|
3256
|
+
const settingsPath = join4(claudeDir, "settings.local.json");
|
|
3104
3257
|
let settings = {};
|
|
3105
3258
|
try {
|
|
3106
|
-
settings = JSON.parse(
|
|
3259
|
+
settings = JSON.parse(readFileSync5(settingsPath, "utf-8"));
|
|
3107
3260
|
} catch {
|
|
3108
3261
|
}
|
|
3109
3262
|
const hooks = settings["hooks"] ?? {};
|
|
@@ -3117,21 +3270,21 @@ function provisionStopHook(codeName) {
|
|
|
3117
3270
|
}
|
|
3118
3271
|
];
|
|
3119
3272
|
settings["hooks"] = hooks;
|
|
3120
|
-
|
|
3273
|
+
writeFileSync5(settingsPath, JSON.stringify(settings, null, 2));
|
|
3121
3274
|
}
|
|
3122
3275
|
function provisionIsolationHook(codeName, agentId) {
|
|
3123
3276
|
const projectDir = getProjectDir(codeName);
|
|
3124
|
-
const claudeDir =
|
|
3125
|
-
|
|
3277
|
+
const claudeDir = join4(projectDir, ".claude");
|
|
3278
|
+
mkdirSync4(claudeDir, { recursive: true });
|
|
3126
3279
|
const hasAgentId = agentId !== void 0;
|
|
3127
3280
|
if (hasAgentId)
|
|
3128
3281
|
assertValidAgentId(agentId);
|
|
3129
3282
|
const homeDir = getHomeDir();
|
|
3130
|
-
const augmentedBase =
|
|
3283
|
+
const augmentedBase = join4(homeDir, ".augmented");
|
|
3131
3284
|
const ownAgentDir = getAgentDir(codeName);
|
|
3132
|
-
const logFile =
|
|
3285
|
+
const logFile = join4(ownAgentDir, "isolation.log");
|
|
3133
3286
|
const idAllowClause = hasAgentId ? ` && [ "$AGENT_DIR" != "${agentId}" ]` : "";
|
|
3134
|
-
const hookScriptPath =
|
|
3287
|
+
const hookScriptPath = join4(claudeDir, "agt-isolation-hook.sh");
|
|
3135
3288
|
const hookScript = [
|
|
3136
3289
|
"#!/bin/bash",
|
|
3137
3290
|
"# Auto-generated by Augmented \u2014 prevents cross-agent file access.",
|
|
@@ -3184,11 +3337,11 @@ function provisionIsolationHook(codeName, agentId) {
|
|
|
3184
3337
|
"",
|
|
3185
3338
|
"exit 0"
|
|
3186
3339
|
].join("\n") + "\n";
|
|
3187
|
-
|
|
3188
|
-
const settingsPath =
|
|
3340
|
+
writeFileSync5(hookScriptPath, hookScript, { mode: 493 });
|
|
3341
|
+
const settingsPath = join4(claudeDir, "settings.local.json");
|
|
3189
3342
|
let settings = {};
|
|
3190
3343
|
try {
|
|
3191
|
-
settings = JSON.parse(
|
|
3344
|
+
settings = JSON.parse(readFileSync5(settingsPath, "utf-8"));
|
|
3192
3345
|
} catch {
|
|
3193
3346
|
}
|
|
3194
3347
|
const hooks = settings["hooks"] ?? {};
|
|
@@ -3203,13 +3356,13 @@ function provisionIsolationHook(codeName, agentId) {
|
|
|
3203
3356
|
}
|
|
3204
3357
|
];
|
|
3205
3358
|
settings["hooks"] = hooks;
|
|
3206
|
-
|
|
3359
|
+
writeFileSync5(settingsPath, JSON.stringify(settings, null, 2));
|
|
3207
3360
|
}
|
|
3208
3361
|
function provisionBacklogPullHook(codeName) {
|
|
3209
3362
|
const projectDir = getProjectDir(codeName);
|
|
3210
|
-
const claudeDir =
|
|
3211
|
-
|
|
3212
|
-
const hookScriptPath =
|
|
3363
|
+
const claudeDir = join4(projectDir, ".claude");
|
|
3364
|
+
mkdirSync4(claudeDir, { recursive: true });
|
|
3365
|
+
const hookScriptPath = join4(claudeDir, "agt-backlog-pull-hook.sh");
|
|
3213
3366
|
const hookScript = `#!/usr/bin/env bash
|
|
3214
3367
|
# Auto-generated by Augmented (CS-1549) \u2014 Stop hook: don't end a turn idle
|
|
3215
3368
|
# beside a non-empty backlog. Fail-open on every path; blocks at most once per
|
|
@@ -3334,14 +3487,14 @@ If you genuinely should not pull it, say so in one line and why (it is deliberat
|
|
|
3334
3487
|
jq -cn --arg r "$REASON" '{decision:"block", reason:$r}'
|
|
3335
3488
|
exit 0
|
|
3336
3489
|
`;
|
|
3337
|
-
|
|
3490
|
+
writeFileSync5(hookScriptPath, hookScript, { mode: 493 });
|
|
3338
3491
|
return hookScriptPath;
|
|
3339
3492
|
}
|
|
3340
3493
|
function provisionAutoKanbanProgressHook(codeName) {
|
|
3341
3494
|
const projectDir = getProjectDir(codeName);
|
|
3342
|
-
const claudeDir =
|
|
3343
|
-
|
|
3344
|
-
const hookScriptPath =
|
|
3495
|
+
const claudeDir = join4(projectDir, ".claude");
|
|
3496
|
+
mkdirSync4(claudeDir, { recursive: true });
|
|
3497
|
+
const hookScriptPath = join4(claudeDir, "agt-auto-kanban-progress-hook.sh");
|
|
3345
3498
|
const hookScript = `#!/usr/bin/env bash
|
|
3346
3499
|
# Auto-generated by Augmented (ENG-6179 / ENG-6241) \u2014 PostToolUse auto-progress.
|
|
3347
3500
|
# Maps the agent's latest tool action onto its active in-thread kanban progress
|
|
@@ -3449,11 +3602,11 @@ BODY="$(jq -nc --arg a "$AGENT_ID" --arg s "$STEP" '{agent_id:$a, step:$s}' 2>/d
|
|
|
3449
3602
|
|
|
3450
3603
|
exit 0
|
|
3451
3604
|
`;
|
|
3452
|
-
|
|
3453
|
-
const settingsPath =
|
|
3605
|
+
writeFileSync5(hookScriptPath, hookScript, { mode: 493 });
|
|
3606
|
+
const settingsPath = join4(claudeDir, "settings.local.json");
|
|
3454
3607
|
let settings = {};
|
|
3455
3608
|
try {
|
|
3456
|
-
settings = JSON.parse(
|
|
3609
|
+
settings = JSON.parse(readFileSync5(settingsPath, "utf-8"));
|
|
3457
3610
|
} catch {
|
|
3458
3611
|
}
|
|
3459
3612
|
const hooks = settings["hooks"] ?? {};
|
|
@@ -3465,13 +3618,13 @@ exit 0
|
|
|
3465
3618
|
}
|
|
3466
3619
|
];
|
|
3467
3620
|
settings["hooks"] = hooks;
|
|
3468
|
-
|
|
3621
|
+
writeFileSync5(settingsPath, JSON.stringify(settings, null, 2));
|
|
3469
3622
|
}
|
|
3470
3623
|
function provisionChannelProgressHook(codeName) {
|
|
3471
3624
|
const projectDir = getProjectDir(codeName);
|
|
3472
|
-
const claudeDir =
|
|
3473
|
-
|
|
3474
|
-
const hookScriptPath =
|
|
3625
|
+
const claudeDir = join4(projectDir, ".claude");
|
|
3626
|
+
mkdirSync4(claudeDir, { recursive: true });
|
|
3627
|
+
const hookScriptPath = join4(claudeDir, "agt-channel-progress-hook.sh");
|
|
3475
3628
|
const hookScript = `#!/usr/bin/env bash
|
|
3476
3629
|
# Auto-generated by Augmented (ENG-6567 Phase 2) \u2014 PostToolUse channel-progress
|
|
3477
3630
|
# heartbeat. Writes a throttled local {step, updated_at_ms} the channel MCP reads
|
|
@@ -3538,11 +3691,11 @@ else
|
|
|
3538
3691
|
fi
|
|
3539
3692
|
exit 0
|
|
3540
3693
|
`;
|
|
3541
|
-
|
|
3542
|
-
const settingsPath =
|
|
3694
|
+
writeFileSync5(hookScriptPath, hookScript, { mode: 493 });
|
|
3695
|
+
const settingsPath = join4(claudeDir, "settings.local.json");
|
|
3543
3696
|
let settings = {};
|
|
3544
3697
|
try {
|
|
3545
|
-
settings = JSON.parse(
|
|
3698
|
+
settings = JSON.parse(readFileSync5(settingsPath, "utf-8"));
|
|
3546
3699
|
} catch {
|
|
3547
3700
|
}
|
|
3548
3701
|
const hooks = settings["hooks"] ?? {};
|
|
@@ -3558,14 +3711,14 @@ exit 0
|
|
|
3558
3711
|
}
|
|
3559
3712
|
hooks["PostToolUse"] = groups;
|
|
3560
3713
|
settings["hooks"] = hooks;
|
|
3561
|
-
|
|
3714
|
+
writeFileSync5(settingsPath, JSON.stringify(settings, null, 2));
|
|
3562
3715
|
}
|
|
3563
3716
|
function provisionOrientHook(codeName) {
|
|
3564
3717
|
const projectDir = getProjectDir(codeName);
|
|
3565
|
-
const claudeDir =
|
|
3566
|
-
|
|
3718
|
+
const claudeDir = join4(projectDir, ".claude");
|
|
3719
|
+
mkdirSync4(claudeDir, { recursive: true });
|
|
3567
3720
|
const agentDir = getAgentDir(codeName);
|
|
3568
|
-
const hookScriptPath =
|
|
3721
|
+
const hookScriptPath = join4(claudeDir, "agt-orient-hook.sh");
|
|
3569
3722
|
const hookScript = [
|
|
3570
3723
|
"#!/bin/bash",
|
|
3571
3724
|
"# Auto-generated by Augmented (ENG-5397) \u2014 SessionStart orientation hook.",
|
|
@@ -3715,11 +3868,11 @@ function provisionOrientHook(codeName) {
|
|
|
3715
3868
|
"fi",
|
|
3716
3869
|
"exit 0"
|
|
3717
3870
|
].join("\n") + "\n";
|
|
3718
|
-
|
|
3719
|
-
const settingsPath =
|
|
3871
|
+
writeFileSync5(hookScriptPath, hookScript, { mode: 493 });
|
|
3872
|
+
const settingsPath = join4(claudeDir, "settings.local.json");
|
|
3720
3873
|
let settings = {};
|
|
3721
3874
|
try {
|
|
3722
|
-
settings = JSON.parse(
|
|
3875
|
+
settings = JSON.parse(readFileSync5(settingsPath, "utf-8"));
|
|
3723
3876
|
} catch {
|
|
3724
3877
|
}
|
|
3725
3878
|
const hooks = settings["hooks"] ?? {};
|
|
@@ -3739,15 +3892,15 @@ function provisionOrientHook(codeName) {
|
|
|
3739
3892
|
}
|
|
3740
3893
|
hooks["SessionStart"] = existingSessionStart;
|
|
3741
3894
|
settings["hooks"] = hooks;
|
|
3742
|
-
|
|
3895
|
+
writeFileSync5(settingsPath, JSON.stringify(settings, null, 2));
|
|
3743
3896
|
}
|
|
3744
3897
|
function provisionPreCompactHook(codeName) {
|
|
3745
3898
|
const projectDir = getProjectDir(codeName);
|
|
3746
|
-
const claudeDir =
|
|
3747
|
-
|
|
3899
|
+
const claudeDir = join4(projectDir, ".claude");
|
|
3900
|
+
mkdirSync4(claudeDir, { recursive: true });
|
|
3748
3901
|
const agentDir = getAgentDir(codeName);
|
|
3749
3902
|
const jqNormalizeContent = '(.message.content // .content // []) | if type == "string" then [{type: "text", text: .}] elif type == "array" then . else [] end';
|
|
3750
|
-
const hookScriptPath =
|
|
3903
|
+
const hookScriptPath = join4(claudeDir, "agt-pre-compact-hook.sh");
|
|
3751
3904
|
const hookScript = [
|
|
3752
3905
|
"#!/bin/bash",
|
|
3753
3906
|
"# Auto-generated by Augmented (ENG-7339) - PreCompact courtesy notice.",
|
|
@@ -3851,12 +4004,12 @@ function provisionPreCompactHook(codeName) {
|
|
|
3851
4004
|
'if [ "$WROTE" = "1" ]; then date +%s > "$NOTICE_MARKER" 2>/dev/null || true; fi',
|
|
3852
4005
|
"exit 0"
|
|
3853
4006
|
].join("\n") + "\n";
|
|
3854
|
-
|
|
3855
|
-
|
|
3856
|
-
const settingsPath =
|
|
4007
|
+
writeFileSync5(hookScriptPath, hookScript, { mode: 493 });
|
|
4008
|
+
chmodSync5(hookScriptPath, 493);
|
|
4009
|
+
const settingsPath = join4(claudeDir, "settings.local.json");
|
|
3857
4010
|
let settings = {};
|
|
3858
4011
|
try {
|
|
3859
|
-
settings = JSON.parse(
|
|
4012
|
+
settings = JSON.parse(readFileSync5(settingsPath, "utf-8"));
|
|
3860
4013
|
} catch {
|
|
3861
4014
|
}
|
|
3862
4015
|
const hooks = settings["hooks"] ?? {};
|
|
@@ -3876,14 +4029,14 @@ function provisionPreCompactHook(codeName) {
|
|
|
3876
4029
|
}
|
|
3877
4030
|
hooks["PreCompact"] = existingPreCompact;
|
|
3878
4031
|
settings["hooks"] = hooks;
|
|
3879
|
-
|
|
4032
|
+
writeFileSync5(settingsPath, JSON.stringify(settings, null, 2));
|
|
3880
4033
|
}
|
|
3881
4034
|
function provisionSessionStateHook(codeName) {
|
|
3882
4035
|
const projectDir = getProjectDir(codeName);
|
|
3883
|
-
const claudeDir =
|
|
3884
|
-
|
|
4036
|
+
const claudeDir = join4(projectDir, ".claude");
|
|
4037
|
+
mkdirSync4(claudeDir, { recursive: true });
|
|
3885
4038
|
const agentDir = getAgentDir(codeName);
|
|
3886
|
-
const hookScriptPath =
|
|
4039
|
+
const hookScriptPath = join4(claudeDir, "agt-session-state-hook.sh");
|
|
3887
4040
|
const hookScript = `#!/usr/bin/env bash
|
|
3888
4041
|
# Auto-generated by Augmented (ENG-6233 / ENG-6268) \u2014 SessionStart session-state
|
|
3889
4042
|
# recorder. Writes the model + session origin (which only the agent's own
|
|
@@ -3960,11 +4113,11 @@ fi
|
|
|
3960
4113
|
|
|
3961
4114
|
exit 0
|
|
3962
4115
|
`;
|
|
3963
|
-
|
|
3964
|
-
const settingsPath =
|
|
4116
|
+
writeFileSync5(hookScriptPath, hookScript, { mode: 493 });
|
|
4117
|
+
const settingsPath = join4(claudeDir, "settings.local.json");
|
|
3965
4118
|
let settings = {};
|
|
3966
4119
|
try {
|
|
3967
|
-
settings = JSON.parse(
|
|
4120
|
+
settings = JSON.parse(readFileSync5(settingsPath, "utf-8"));
|
|
3968
4121
|
} catch {
|
|
3969
4122
|
}
|
|
3970
4123
|
const hooks = settings["hooks"] ?? {};
|
|
@@ -3980,13 +4133,13 @@ exit 0
|
|
|
3980
4133
|
}
|
|
3981
4134
|
hooks["SessionStart"] = existingSessionStart;
|
|
3982
4135
|
settings["hooks"] = hooks;
|
|
3983
|
-
|
|
4136
|
+
writeFileSync5(settingsPath, JSON.stringify(settings, null, 2));
|
|
3984
4137
|
}
|
|
3985
4138
|
function modifyJsonConfig(filePath, fn) {
|
|
3986
4139
|
let originalContent;
|
|
3987
4140
|
let config;
|
|
3988
4141
|
try {
|
|
3989
|
-
originalContent =
|
|
4142
|
+
originalContent = readFileSync5(filePath, "utf-8");
|
|
3990
4143
|
config = JSON.parse(originalContent);
|
|
3991
4144
|
} catch {
|
|
3992
4145
|
return;
|
|
@@ -3997,7 +4150,7 @@ function modifyJsonConfig(filePath, fn) {
|
|
|
3997
4150
|
const newContent = JSON.stringify(config, null, 2);
|
|
3998
4151
|
if (newContent === originalContent)
|
|
3999
4152
|
return;
|
|
4000
|
-
|
|
4153
|
+
writeFileSync5(filePath, newContent);
|
|
4001
4154
|
}
|
|
4002
4155
|
var SECRETS_DENY_PERMISSIONS = [
|
|
4003
4156
|
// Read blocks
|
|
@@ -4095,7 +4248,7 @@ function buildSettingsJson(input) {
|
|
|
4095
4248
|
const projectDir = getProjectDir(agent.code_name);
|
|
4096
4249
|
const agentDir = getAgentDir(agent.code_name);
|
|
4097
4250
|
const homeDir = getHomeDir();
|
|
4098
|
-
const codenameAliasDir =
|
|
4251
|
+
const codenameAliasDir = join4(homeDir, ".augmented", agent.code_name);
|
|
4099
4252
|
settings["allowedDirectories"] = [
|
|
4100
4253
|
.../* @__PURE__ */ new Set([
|
|
4101
4254
|
projectDir,
|
|
@@ -4104,7 +4257,7 @@ function buildSettingsJson(input) {
|
|
|
4104
4257
|
// Agent's config dir (.env, schedules, registration)
|
|
4105
4258
|
codenameAliasDir,
|
|
4106
4259
|
// Codename symlink alias (== agentDir for legacy agents)
|
|
4107
|
-
|
|
4260
|
+
join4(homeDir, ".augmented", "_mcp"),
|
|
4108
4261
|
// Shared MCP binaries
|
|
4109
4262
|
"/tmp"
|
|
4110
4263
|
// Temp files
|
|
@@ -4222,10 +4375,10 @@ ${integrationsBlock}`;
|
|
|
4222
4375
|
function renderAugmentedWorkerForAgent(codeName) {
|
|
4223
4376
|
const agentDir = getAgentDir(codeName);
|
|
4224
4377
|
const projectDir = getProjectDir(codeName);
|
|
4225
|
-
const provisionMcpPath =
|
|
4378
|
+
const provisionMcpPath = join4(agentDir, "provision", ".mcp.json");
|
|
4226
4379
|
let mcpServerKeys;
|
|
4227
4380
|
try {
|
|
4228
|
-
const config = JSON.parse(
|
|
4381
|
+
const config = JSON.parse(readFileSync5(provisionMcpPath, "utf-8"));
|
|
4229
4382
|
mcpServerKeys = Object.keys(config.mcpServers ?? {});
|
|
4230
4383
|
} catch {
|
|
4231
4384
|
return;
|
|
@@ -4233,10 +4386,10 @@ function renderAugmentedWorkerForAgent(codeName) {
|
|
|
4233
4386
|
const integrations = readIntegrationsSummaryForAgent(codeName);
|
|
4234
4387
|
const content = buildAugmentedWorkerAgent({ mcpServerKeys, integrations });
|
|
4235
4388
|
for (const baseDir of [agentDir, projectDir]) {
|
|
4236
|
-
const target =
|
|
4389
|
+
const target = join4(baseDir, ".claude", "agents", "augmented-worker.md");
|
|
4237
4390
|
try {
|
|
4238
|
-
|
|
4239
|
-
|
|
4391
|
+
mkdirSync4(dirname4(target), { recursive: true });
|
|
4392
|
+
writeFileSync5(target, content);
|
|
4240
4393
|
} catch {
|
|
4241
4394
|
}
|
|
4242
4395
|
}
|
|
@@ -4262,8 +4415,8 @@ function buildPostizMcpEntry(integration) {
|
|
|
4262
4415
|
}
|
|
4263
4416
|
function buildMcpJson(input) {
|
|
4264
4417
|
const mcpServers = {};
|
|
4265
|
-
const turnInitiatorFile =
|
|
4266
|
-
const localMcpPath =
|
|
4418
|
+
const turnInitiatorFile = join4(getAgentDir(input.agent.code_name), ".current-turn-initiator.json");
|
|
4419
|
+
const localMcpPath = join4(getHomeDir(), ".augmented", "_mcp", "index.js");
|
|
4267
4420
|
mcpServers["augmented"] = {
|
|
4268
4421
|
command: "node",
|
|
4269
4422
|
args: [localMcpPath],
|
|
@@ -4315,7 +4468,7 @@ function buildMcpJson(input) {
|
|
|
4315
4468
|
const xeroIntegration = input.integrations?.find((i) => i.definition_id === "xero");
|
|
4316
4469
|
if (xeroIntegration) {
|
|
4317
4470
|
const brokerMode = Boolean(xeroIntegration.id);
|
|
4318
|
-
const localXeroMcpPath =
|
|
4471
|
+
const localXeroMcpPath = join4(getHomeDir(), ".augmented", "_mcp", "xero.js");
|
|
4319
4472
|
mcpServers["xero"] = {
|
|
4320
4473
|
command: "node",
|
|
4321
4474
|
args: [localXeroMcpPath],
|
|
@@ -4355,7 +4508,7 @@ function buildMcpJson(input) {
|
|
|
4355
4508
|
// getProjectDir (the ADR-0049 seam), not the MCP child's inherited
|
|
4356
4509
|
// cwd, so the path stays correct if Claude Code ever spawns the
|
|
4357
4510
|
// server from somewhere else.
|
|
4358
|
-
XERO_EXPORT_DIR:
|
|
4511
|
+
XERO_EXPORT_DIR: join4(getProjectDir(input.agent.code_name), "xero-exports"),
|
|
4359
4512
|
PATH: process.env["PATH"] ?? "",
|
|
4360
4513
|
HOME: process.env["HOME"] ?? ""
|
|
4361
4514
|
}
|
|
@@ -4366,8 +4519,8 @@ function buildMcpJson(input) {
|
|
|
4366
4519
|
mcpServers["postiz"] = buildPostizMcpEntry(postizIntegration);
|
|
4367
4520
|
}
|
|
4368
4521
|
const remoteOAuthProxyPaths = {
|
|
4369
|
-
proxyPath:
|
|
4370
|
-
tokenFile:
|
|
4522
|
+
proxyPath: join4(getHomeDir(), ".augmented", "_mcp", "remote-oauth-proxy.js"),
|
|
4523
|
+
tokenFile: join4(getProjectDir(input.agent.code_name), ".env.integrations")
|
|
4371
4524
|
};
|
|
4372
4525
|
for (const integration of input.integrations ?? []) {
|
|
4373
4526
|
const connectionKey = integration.connection_key;
|
|
@@ -4433,7 +4586,7 @@ function buildMcpJson(input) {
|
|
|
4433
4586
|
}
|
|
4434
4587
|
const hasAdminDebug = input.integrations?.some((i) => i.definition_id === "augmented-admin") ?? false;
|
|
4435
4588
|
if (hasAdminDebug) {
|
|
4436
|
-
const localAdminMcpPath =
|
|
4589
|
+
const localAdminMcpPath = join4(getHomeDir(), ".augmented", "_mcp", "augmented-admin.js");
|
|
4437
4590
|
mcpServers["augmented-admin"] = {
|
|
4438
4591
|
command: "node",
|
|
4439
4592
|
args: [localAdminMcpPath],
|
|
@@ -4447,7 +4600,7 @@ function buildMcpJson(input) {
|
|
|
4447
4600
|
}
|
|
4448
4601
|
const hasSupport = input.integrations?.some((i) => i.definition_id === "augmented-support") ?? false;
|
|
4449
4602
|
if (hasSupport) {
|
|
4450
|
-
const localSupportMcpPath =
|
|
4603
|
+
const localSupportMcpPath = join4(getHomeDir(), ".augmented", "_mcp", "augmented-support.js");
|
|
4451
4604
|
mcpServers["augmented-support"] = {
|
|
4452
4605
|
command: "node",
|
|
4453
4606
|
args: [localSupportMcpPath],
|
|
@@ -4461,7 +4614,7 @@ function buildMcpJson(input) {
|
|
|
4461
4614
|
}
|
|
4462
4615
|
const hasHelpKb = input.integrations?.some((i) => i.definition_id === "augmented-help-kb") ?? false;
|
|
4463
4616
|
if (hasHelpKb) {
|
|
4464
|
-
const localHelpKbMcpPath =
|
|
4617
|
+
const localHelpKbMcpPath = join4(getHomeDir(), ".augmented", "_mcp", "augmented-help-kb.js");
|
|
4465
4618
|
mcpServers["augmented-help-kb"] = {
|
|
4466
4619
|
command: "node",
|
|
4467
4620
|
args: [localHelpKbMcpPath],
|
|
@@ -4475,7 +4628,7 @@ function buildMcpJson(input) {
|
|
|
4475
4628
|
}
|
|
4476
4629
|
const origamiIntegration = input.integrations?.find((i) => i.definition_id === "origami");
|
|
4477
4630
|
if (origamiIntegration?.stdioMcp === true && origamiIntegration.id) {
|
|
4478
|
-
const localOrigamiMcpPath =
|
|
4631
|
+
const localOrigamiMcpPath = join4(getHomeDir(), ".augmented", "_mcp", "origami.js");
|
|
4479
4632
|
mcpServers["origami"] = {
|
|
4480
4633
|
command: "node",
|
|
4481
4634
|
args: [localOrigamiMcpPath],
|
|
@@ -4719,27 +4872,27 @@ ${sections}`
|
|
|
4719
4872
|
},
|
|
4720
4873
|
async getRegisteredAgents(_profile) {
|
|
4721
4874
|
const homeDir = getHomeDir();
|
|
4722
|
-
const augDir =
|
|
4875
|
+
const augDir = join4(homeDir, ".augmented");
|
|
4723
4876
|
const agents = /* @__PURE__ */ new Set();
|
|
4724
4877
|
try {
|
|
4725
4878
|
const entries = readdirSync(augDir);
|
|
4726
4879
|
for (const entry of entries) {
|
|
4727
4880
|
if (entry.startsWith("_") || entry.startsWith("."))
|
|
4728
4881
|
continue;
|
|
4729
|
-
const agentRoot =
|
|
4882
|
+
const agentRoot = join4(augDir, entry);
|
|
4730
4883
|
let st;
|
|
4731
4884
|
try {
|
|
4732
|
-
st =
|
|
4885
|
+
st = lstatSync2(agentRoot);
|
|
4733
4886
|
} catch {
|
|
4734
4887
|
continue;
|
|
4735
4888
|
}
|
|
4736
4889
|
if (st.isSymbolicLink() || !st.isDirectory())
|
|
4737
4890
|
continue;
|
|
4738
|
-
if (!existsSync4(
|
|
4891
|
+
if (!existsSync4(join4(agentRoot, "registration.json")))
|
|
4739
4892
|
continue;
|
|
4740
4893
|
let codeName = entry;
|
|
4741
4894
|
try {
|
|
4742
|
-
const reg = JSON.parse(
|
|
4895
|
+
const reg = JSON.parse(readFileSync5(join4(agentRoot, "registration.json"), "utf8"));
|
|
4743
4896
|
if (reg && typeof reg.code_name === "string" && reg.code_name) {
|
|
4744
4897
|
codeName = reg.code_name;
|
|
4745
4898
|
}
|
|
@@ -4758,9 +4911,9 @@ ${sections}`
|
|
|
4758
4911
|
}
|
|
4759
4912
|
const agentDir = getAgentDir(codeName);
|
|
4760
4913
|
const projectDir = getProjectDir(codeName);
|
|
4761
|
-
|
|
4762
|
-
|
|
4763
|
-
|
|
4914
|
+
mkdirSync4(agentDir, { recursive: true });
|
|
4915
|
+
mkdirSync4(projectDir, { recursive: true });
|
|
4916
|
+
writeFileSync5(join4(agentDir, "registration.json"), JSON.stringify({
|
|
4764
4917
|
code_name: codeName,
|
|
4765
4918
|
agent_id: agentId ?? null,
|
|
4766
4919
|
team_dir: teamDir,
|
|
@@ -4779,7 +4932,7 @@ ${sections}`
|
|
|
4779
4932
|
async deregisterAgent(codeName) {
|
|
4780
4933
|
try {
|
|
4781
4934
|
const agentDir = getAgentDir(codeName);
|
|
4782
|
-
const regFile =
|
|
4935
|
+
const regFile = join4(agentDir, "registration.json");
|
|
4783
4936
|
if (existsSync4(regFile)) {
|
|
4784
4937
|
const { unlinkSync: unlinkSync5 } = await import("fs");
|
|
4785
4938
|
unlinkSync5(regFile);
|
|
@@ -4791,7 +4944,7 @@ ${sections}`
|
|
|
4791
4944
|
},
|
|
4792
4945
|
writeAuthProfiles(codeName, profiles) {
|
|
4793
4946
|
const agentDir = getAgentDir(codeName);
|
|
4794
|
-
|
|
4947
|
+
mkdirSync4(agentDir, { recursive: true });
|
|
4795
4948
|
const envLines = ["# Augmented auth profiles \u2014 auto-generated, do not edit"];
|
|
4796
4949
|
for (const p of profiles) {
|
|
4797
4950
|
if (!p.api_key)
|
|
@@ -4805,9 +4958,9 @@ ${sections}`
|
|
|
4805
4958
|
}
|
|
4806
4959
|
}
|
|
4807
4960
|
if (envLines.length > 1) {
|
|
4808
|
-
const envPath =
|
|
4809
|
-
|
|
4810
|
-
|
|
4961
|
+
const envPath = join4(agentDir, ".env");
|
|
4962
|
+
writeFileSync5(envPath, envLines.join("\n") + "\n");
|
|
4963
|
+
chmodSync5(envPath, SECRET_FILE_MODE2);
|
|
4811
4964
|
}
|
|
4812
4965
|
},
|
|
4813
4966
|
// Claude Code has no gateway process — methods intentionally omitted
|
|
@@ -4840,7 +4993,7 @@ ${sections}`
|
|
|
4840
4993
|
const senderPolicyInternalOnly = options?.senderPolicy?.internal_only === true;
|
|
4841
4994
|
const senderPolicyEnv = senderPolicyTeamId ? { AGT_TEAM_ID: senderPolicyTeamId } : {};
|
|
4842
4995
|
const agentDir = getAgentDir(codeName);
|
|
4843
|
-
|
|
4996
|
+
mkdirSync4(agentDir, { recursive: true });
|
|
4844
4997
|
const persistChannelSecrets = options?.channelSecretDelivery !== "spawn-env";
|
|
4845
4998
|
const channelSecretUpdates = (updates, fullKeySet) => {
|
|
4846
4999
|
if (persistChannelSecrets)
|
|
@@ -4854,7 +5007,7 @@ ${sections}`
|
|
|
4854
5007
|
if (!botToken)
|
|
4855
5008
|
return;
|
|
4856
5009
|
const allowedChats = config["allowed_chats"];
|
|
4857
|
-
const localTelegramChannel =
|
|
5010
|
+
const localTelegramChannel = join4(getHomeDir(), ".augmented", "_mcp", "telegram-channel.js");
|
|
4858
5011
|
const resolvedAgtHostForTelegram = process.env["AGT_HOST"]?.trim() || "https://api.augmented.team";
|
|
4859
5012
|
const resolvedAgtApiKeyForTelegram = process.env["AGT_API_KEY"]?.trim();
|
|
4860
5013
|
writeEnvIntegrationsForAgent(codeName, {
|
|
@@ -4869,7 +5022,7 @@ ${sections}`
|
|
|
4869
5022
|
...options?.agentId ? { AGT_AGENT_ID: options.agentId } : {},
|
|
4870
5023
|
...tzEnv,
|
|
4871
5024
|
// ENG-6582 (D16): stamp the verified turn initiator for broker MCPs.
|
|
4872
|
-
AGT_TURN_INITIATOR_FILE:
|
|
5025
|
+
AGT_TURN_INITIATOR_FILE: join4(getAgentDir(codeName), ".current-turn-initiator.json")
|
|
4873
5026
|
};
|
|
4874
5027
|
if (allowedChats && allowedChats.length > 0) {
|
|
4875
5028
|
telegramEnv.TELEGRAM_ALLOWED_CHATS = allowedChats.join(",");
|
|
@@ -4929,11 +5082,11 @@ ${sections}`
|
|
|
4929
5082
|
args: [localTelegramChannel],
|
|
4930
5083
|
env: telegramEnv
|
|
4931
5084
|
};
|
|
4932
|
-
const provisionMcpPath =
|
|
4933
|
-
|
|
5085
|
+
const provisionMcpPath = join4(agentDir, "provision", ".mcp.json");
|
|
5086
|
+
mkdirSync4(dirname4(provisionMcpPath), { recursive: true });
|
|
4934
5087
|
let mcpConfig2 = { mcpServers: {} };
|
|
4935
5088
|
try {
|
|
4936
|
-
mcpConfig2 = JSON.parse(
|
|
5089
|
+
mcpConfig2 = JSON.parse(readFileSync5(provisionMcpPath, "utf-8"));
|
|
4937
5090
|
if (!mcpConfig2.mcpServers)
|
|
4938
5091
|
mcpConfig2.mcpServers = {};
|
|
4939
5092
|
} catch {
|
|
@@ -4946,13 +5099,13 @@ ${sections}`
|
|
|
4946
5099
|
return;
|
|
4947
5100
|
}
|
|
4948
5101
|
if (isPersistent && (channelId === "discord" || channelId === "slack")) {
|
|
4949
|
-
const channelDir =
|
|
5102
|
+
const channelDir = join4(getHomeDir(), ".claude", "channels", channelId);
|
|
4950
5103
|
if (channelId === "discord")
|
|
4951
|
-
|
|
5104
|
+
mkdirSync4(channelDir, { recursive: true });
|
|
4952
5105
|
if (channelId === "discord") {
|
|
4953
5106
|
const botToken = config["bot_token"];
|
|
4954
5107
|
if (botToken) {
|
|
4955
|
-
|
|
5108
|
+
writeFileSync5(join4(channelDir, ".env"), `DISCORD_BOT_TOKEN=${botToken}
|
|
4956
5109
|
`);
|
|
4957
5110
|
}
|
|
4958
5111
|
} else if (channelId === "slack") {
|
|
@@ -5018,7 +5171,7 @@ ${sections}`
|
|
|
5018
5171
|
...appToken ? { SLACK_APP_TOKEN: appToken } : {}
|
|
5019
5172
|
}, ["SLACK_BOT_TOKEN", "SLACK_APP_TOKEN"])
|
|
5020
5173
|
});
|
|
5021
|
-
const localSlackChannel =
|
|
5174
|
+
const localSlackChannel = join4(getHomeDir(), ".augmented", "_mcp", "slack-channel.js");
|
|
5022
5175
|
const slackAvatarEnvUrl = resolveAvatarEnvUrl(options?.agentAvatarUrl).url;
|
|
5023
5176
|
const slackEntry = {
|
|
5024
5177
|
command: existsSync4(localSlackChannel) ? "node" : "npx",
|
|
@@ -5104,14 +5257,14 @@ ${sections}`
|
|
|
5104
5257
|
...pingAllowedUsers.length > 0 ? { SLACK_PING_ALLOWED_USERS: pingAllowedUsers.join(",") } : {},
|
|
5105
5258
|
// ENG-6563 (D16): stamp the verified turn initiator so broker MCPs
|
|
5106
5259
|
// can forward it when the agent files an approval mid-turn.
|
|
5107
|
-
AGT_TURN_INITIATOR_FILE:
|
|
5260
|
+
AGT_TURN_INITIATOR_FILE: join4(agentDir, ".current-turn-initiator.json")
|
|
5108
5261
|
}
|
|
5109
5262
|
};
|
|
5110
|
-
const provisionMcpPath =
|
|
5111
|
-
|
|
5263
|
+
const provisionMcpPath = join4(agentDir, "provision", ".mcp.json");
|
|
5264
|
+
mkdirSync4(dirname4(provisionMcpPath), { recursive: true });
|
|
5112
5265
|
let mcpConfig2 = { mcpServers: {} };
|
|
5113
5266
|
try {
|
|
5114
|
-
mcpConfig2 = JSON.parse(
|
|
5267
|
+
mcpConfig2 = JSON.parse(readFileSync5(provisionMcpPath, "utf-8"));
|
|
5115
5268
|
if (!mcpConfig2.mcpServers)
|
|
5116
5269
|
mcpConfig2.mcpServers = {};
|
|
5117
5270
|
} catch {
|
|
@@ -5121,10 +5274,10 @@ ${sections}`
|
|
|
5121
5274
|
return;
|
|
5122
5275
|
}
|
|
5123
5276
|
syncMcpToProject(codeName);
|
|
5124
|
-
const staleChannelsPath =
|
|
5277
|
+
const staleChannelsPath = join4(getProjectDir(codeName), ".mcp-channels.json");
|
|
5125
5278
|
if (existsSync4(staleChannelsPath)) {
|
|
5126
5279
|
try {
|
|
5127
|
-
|
|
5280
|
+
rmSync3(staleChannelsPath, { force: true });
|
|
5128
5281
|
} catch {
|
|
5129
5282
|
}
|
|
5130
5283
|
}
|
|
@@ -5132,11 +5285,11 @@ ${sections}`
|
|
|
5132
5285
|
}
|
|
5133
5286
|
return;
|
|
5134
5287
|
}
|
|
5135
|
-
const mcpJsonPath =
|
|
5136
|
-
|
|
5288
|
+
const mcpJsonPath = join4(agentDir, "provision", ".mcp.json");
|
|
5289
|
+
mkdirSync4(dirname4(mcpJsonPath), { recursive: true });
|
|
5137
5290
|
let mcpConfig;
|
|
5138
5291
|
try {
|
|
5139
|
-
mcpConfig = JSON.parse(
|
|
5292
|
+
mcpConfig = JSON.parse(readFileSync5(mcpJsonPath, "utf-8"));
|
|
5140
5293
|
} catch {
|
|
5141
5294
|
mcpConfig = { mcpServers: {} };
|
|
5142
5295
|
}
|
|
@@ -5155,7 +5308,7 @@ ${sections}`
|
|
|
5155
5308
|
const appToken = config["app_token"];
|
|
5156
5309
|
if (!botToken)
|
|
5157
5310
|
return;
|
|
5158
|
-
const localSlackChannel =
|
|
5311
|
+
const localSlackChannel = join4(getHomeDir(), ".augmented", "_mcp", "slack-channel.js");
|
|
5159
5312
|
const slackThreadAutoFollow = config["thread_auto_follow"];
|
|
5160
5313
|
const slackAutoFollowEnv = slackThreadAutoFollow && slackThreadAutoFollow !== "off" ? { SLACK_THREAD_AUTO_FOLLOW: slackThreadAutoFollow } : {};
|
|
5161
5314
|
const slackChannelResponseMode = config["channel_response_mode"];
|
|
@@ -5248,7 +5401,7 @@ ${sections}`
|
|
|
5248
5401
|
...slackAgtAuthEnv,
|
|
5249
5402
|
...tzEnv,
|
|
5250
5403
|
// ENG-6563 (D16): stamp the verified turn initiator for broker MCPs.
|
|
5251
|
-
AGT_TURN_INITIATOR_FILE:
|
|
5404
|
+
AGT_TURN_INITIATOR_FILE: join4(getAgentDir(codeName), ".current-turn-initiator.json"),
|
|
5252
5405
|
// ENG-6155: avatar URL → bot Slack profile photo (see persistent
|
|
5253
5406
|
// branch above). Mirrored here so oneshot-mode agents get it too.
|
|
5254
5407
|
// ENG-6245: slackAvatarEnvUrl is null for data-URI / oversized values.
|
|
@@ -5273,7 +5426,7 @@ ${sections}`
|
|
|
5273
5426
|
...slackAgtAuthEnv,
|
|
5274
5427
|
...tzEnv,
|
|
5275
5428
|
// ENG-6563 (D16): stamp the verified turn initiator for broker MCPs.
|
|
5276
|
-
AGT_TURN_INITIATOR_FILE:
|
|
5429
|
+
AGT_TURN_INITIATOR_FILE: join4(getAgentDir(codeName), ".current-turn-initiator.json"),
|
|
5277
5430
|
// ENG-6155: avatar URL → bot Slack profile photo (see persistent
|
|
5278
5431
|
// branch above). Mirrored here so oneshot-mode agents get it too.
|
|
5279
5432
|
// ENG-6245: slackAvatarEnvUrl is null for data-URI / oversized values.
|
|
@@ -5286,12 +5439,12 @@ ${sections}`
|
|
|
5286
5439
|
const clientSecret = config["client_secret"];
|
|
5287
5440
|
if (!appId || !clientSecret)
|
|
5288
5441
|
return;
|
|
5289
|
-
const localTeamsChannel =
|
|
5442
|
+
const localTeamsChannel = join4(getHomeDir(), ".augmented", "_mcp", "teams-channel.js");
|
|
5290
5443
|
const agentDirMs = getAgentDir(codeName);
|
|
5291
5444
|
try {
|
|
5292
|
-
|
|
5293
|
-
|
|
5294
|
-
|
|
5445
|
+
mkdirSync4(join4(agentDirMs, "msteams-pending-inbound", ".markers"), { recursive: true });
|
|
5446
|
+
mkdirSync4(join4(agentDirMs, "msteams-pending-interactions"), { recursive: true });
|
|
5447
|
+
mkdirSync4(join4(agentDirMs, "msteams-recovery-outbox"), { recursive: true });
|
|
5295
5448
|
} catch {
|
|
5296
5449
|
}
|
|
5297
5450
|
const tenantId = config["tenant_id"] ?? "common";
|
|
@@ -5369,7 +5522,7 @@ ${sections}`
|
|
|
5369
5522
|
}
|
|
5370
5523
|
if (channelId === "whatsapp") {
|
|
5371
5524
|
const provider = config["provider"] ?? "kapso";
|
|
5372
|
-
const localWhatsappChannel =
|
|
5525
|
+
const localWhatsappChannel = join4(getHomeDir(), ".augmented", "_mcp", "whatsapp-channel.js");
|
|
5373
5526
|
if (provider === "baileys") {
|
|
5374
5527
|
mcpServers["whatsapp"] = {
|
|
5375
5528
|
command: "node",
|
|
@@ -5388,7 +5541,7 @@ ${sections}`
|
|
|
5388
5541
|
const phoneNumberId = config["phone_number_id"];
|
|
5389
5542
|
if (projectApiKey && phoneNumberId) {
|
|
5390
5543
|
try {
|
|
5391
|
-
|
|
5544
|
+
mkdirSync4(join4(getAgentDir(codeName), "whatsapp-pending-inbound"), { recursive: true });
|
|
5392
5545
|
} catch {
|
|
5393
5546
|
}
|
|
5394
5547
|
writeEnvIntegrationsForAgent(codeName, {
|
|
@@ -5416,11 +5569,11 @@ ${sections}`
|
|
|
5416
5569
|
}
|
|
5417
5570
|
},
|
|
5418
5571
|
hasChannelCredentials(codeName, channelId) {
|
|
5419
|
-
const provisionMcpPath =
|
|
5572
|
+
const provisionMcpPath = join4(getAgentDir(codeName), "provision", ".mcp.json");
|
|
5420
5573
|
if (!existsSync4(provisionMcpPath))
|
|
5421
5574
|
return false;
|
|
5422
5575
|
try {
|
|
5423
|
-
const parsed = JSON.parse(
|
|
5576
|
+
const parsed = JSON.parse(readFileSync5(provisionMcpPath, "utf-8"));
|
|
5424
5577
|
return Boolean(parsed.mcpServers?.[channelId]);
|
|
5425
5578
|
} catch {
|
|
5426
5579
|
return false;
|
|
@@ -5428,7 +5581,7 @@ ${sections}`
|
|
|
5428
5581
|
},
|
|
5429
5582
|
removeChannelCredentials(codeName, channelId) {
|
|
5430
5583
|
const agentDir = getAgentDir(codeName);
|
|
5431
|
-
const mcpJsonPath =
|
|
5584
|
+
const mcpJsonPath = join4(agentDir, "provision", ".mcp.json");
|
|
5432
5585
|
modifyJsonConfig(mcpJsonPath, (config) => {
|
|
5433
5586
|
const mcpServers = config["mcpServers"];
|
|
5434
5587
|
if (!mcpServers || !(channelId in mcpServers))
|
|
@@ -5440,7 +5593,7 @@ ${sections}`
|
|
|
5440
5593
|
},
|
|
5441
5594
|
async updateAgentModel(codeName, model) {
|
|
5442
5595
|
const agentDir = getAgentDir(codeName);
|
|
5443
|
-
const settingsPath =
|
|
5596
|
+
const settingsPath = join4(agentDir, "provision", "settings.json");
|
|
5444
5597
|
let changed = false;
|
|
5445
5598
|
modifyJsonConfig(settingsPath, (config) => {
|
|
5446
5599
|
config["model"] = model;
|
|
@@ -5458,20 +5611,20 @@ ${sections}`
|
|
|
5458
5611
|
seedProfileConfig(codeName) {
|
|
5459
5612
|
const agentDir = getAgentDir(codeName);
|
|
5460
5613
|
const projectDir = getProjectDir(codeName);
|
|
5461
|
-
|
|
5462
|
-
|
|
5614
|
+
mkdirSync4(join4(agentDir, "provision"), { recursive: true });
|
|
5615
|
+
mkdirSync4(projectDir, { recursive: true });
|
|
5463
5616
|
},
|
|
5464
5617
|
syncScheduledTasks(codeName, tasks) {
|
|
5465
5618
|
const agentDir = getAgentDir(codeName);
|
|
5466
|
-
const schedulesPath =
|
|
5619
|
+
const schedulesPath = join4(agentDir, "schedules.json");
|
|
5467
5620
|
const mapped = mapScheduledTasks(tasks);
|
|
5468
|
-
|
|
5469
|
-
|
|
5621
|
+
mkdirSync4(agentDir, { recursive: true });
|
|
5622
|
+
writeFileSync5(schedulesPath, JSON.stringify({ schedules: mapped }, null, 2));
|
|
5470
5623
|
return Promise.resolve();
|
|
5471
5624
|
},
|
|
5472
5625
|
writeIntegrations(codeName, integrations, agentId, options) {
|
|
5473
5626
|
const agentDir = getAgentDir(codeName);
|
|
5474
|
-
|
|
5627
|
+
mkdirSync4(agentDir, { recursive: true });
|
|
5475
5628
|
const summariesForSidecar = integrations.map((i) => {
|
|
5476
5629
|
const def = INTEGRATION_REGISTRY.find((d) => d.id === i.definition_id);
|
|
5477
5630
|
return {
|
|
@@ -5588,7 +5741,7 @@ ${sections}`
|
|
|
5588
5741
|
xeroEnv.AGT_AGENT_ID = agentId;
|
|
5589
5742
|
xeroEnv.AGT_INTEGRATION_ID = xeroIntegration.id;
|
|
5590
5743
|
}
|
|
5591
|
-
const localXeroMcpPath =
|
|
5744
|
+
const localXeroMcpPath = join4(getHomeDir(), ".augmented", "_mcp", "xero.js");
|
|
5592
5745
|
this.writeMcpServer(codeName, "xero", {
|
|
5593
5746
|
command: "node",
|
|
5594
5747
|
args: [localXeroMcpPath],
|
|
@@ -5600,8 +5753,8 @@ ${sections}`
|
|
|
5600
5753
|
this.writeMcpServer(codeName, "postiz", buildPostizMcpEntry(postizIntegration));
|
|
5601
5754
|
}
|
|
5602
5755
|
const remoteOAuthProxyPaths = {
|
|
5603
|
-
proxyPath:
|
|
5604
|
-
tokenFile:
|
|
5756
|
+
proxyPath: join4(getHomeDir(), ".augmented", "_mcp", "remote-oauth-proxy.js"),
|
|
5757
|
+
tokenFile: join4(getProjectDir(codeName), ".env.integrations")
|
|
5605
5758
|
};
|
|
5606
5759
|
for (const integration of integrations) {
|
|
5607
5760
|
const connectionKey = integration.connection_key;
|
|
@@ -5642,7 +5795,7 @@ ${sections}`
|
|
|
5642
5795
|
// ENG-6586 (D16): keep incremental cloud-broker wiring in sync with
|
|
5643
5796
|
// buildMcpJson so agents that add cloud-broker post-provision still
|
|
5644
5797
|
// forward the per-turn initiator.
|
|
5645
|
-
AGT_TURN_INITIATOR_FILE:
|
|
5798
|
+
AGT_TURN_INITIATOR_FILE: join4(getAgentDir(codeName), ".current-turn-initiator.json"),
|
|
5646
5799
|
PATH: process.env["PATH"] ?? "",
|
|
5647
5800
|
HOME: process.env["HOME"] ?? ""
|
|
5648
5801
|
}
|
|
@@ -5666,7 +5819,7 @@ ${sections}`
|
|
|
5666
5819
|
// ENG-6563 (D16): keep incremental xero-broker wiring in sync with
|
|
5667
5820
|
// buildMcpJson so agents that add xero-broker post-provision still
|
|
5668
5821
|
// forward the per-turn initiator.
|
|
5669
|
-
AGT_TURN_INITIATOR_FILE:
|
|
5822
|
+
AGT_TURN_INITIATOR_FILE: join4(getAgentDir(codeName), ".current-turn-initiator.json"),
|
|
5670
5823
|
PATH: process.env["PATH"] ?? "",
|
|
5671
5824
|
HOME: process.env["HOME"] ?? ""
|
|
5672
5825
|
}
|
|
@@ -5675,7 +5828,7 @@ ${sections}`
|
|
|
5675
5828
|
}
|
|
5676
5829
|
const hasAdminDebug = integrations.some((i) => i.definition_id === "augmented-admin");
|
|
5677
5830
|
if (hasAdminDebug) {
|
|
5678
|
-
const localAdminMcpPath =
|
|
5831
|
+
const localAdminMcpPath = join4(getHomeDir(), ".augmented", "_mcp", "augmented-admin.js");
|
|
5679
5832
|
this.writeMcpServer(codeName, "augmented-admin", {
|
|
5680
5833
|
command: "node",
|
|
5681
5834
|
args: [localAdminMcpPath],
|
|
@@ -5689,7 +5842,7 @@ ${sections}`
|
|
|
5689
5842
|
}
|
|
5690
5843
|
const hasSupport = integrations.some((i) => i.definition_id === "augmented-support");
|
|
5691
5844
|
if (hasSupport) {
|
|
5692
|
-
const localSupportMcpPath =
|
|
5845
|
+
const localSupportMcpPath = join4(getHomeDir(), ".augmented", "_mcp", "augmented-support.js");
|
|
5693
5846
|
this.writeMcpServer(codeName, "augmented-support", {
|
|
5694
5847
|
command: "node",
|
|
5695
5848
|
args: [localSupportMcpPath],
|
|
@@ -5703,7 +5856,7 @@ ${sections}`
|
|
|
5703
5856
|
}
|
|
5704
5857
|
const hasHelpKb = integrations.some((i) => i.definition_id === "augmented-help-kb");
|
|
5705
5858
|
if (hasHelpKb) {
|
|
5706
|
-
const localHelpKbMcpPath =
|
|
5859
|
+
const localHelpKbMcpPath = join4(getHomeDir(), ".augmented", "_mcp", "augmented-help-kb.js");
|
|
5707
5860
|
this.writeMcpServer(codeName, "augmented-help-kb", {
|
|
5708
5861
|
command: "node",
|
|
5709
5862
|
args: [localHelpKbMcpPath],
|
|
@@ -5719,7 +5872,7 @@ ${sections}`
|
|
|
5719
5872
|
const origamiStdioAgentId = resolveBrokerAgentId(codeName) ?? agentId;
|
|
5720
5873
|
const origamiStdioExpected = Boolean(origamiStdio?.stdioMcp === true && origamiStdio.id);
|
|
5721
5874
|
if (origamiStdioExpected && origamiStdioAgentId) {
|
|
5722
|
-
const localOrigamiMcpPath =
|
|
5875
|
+
const localOrigamiMcpPath = join4(getHomeDir(), ".augmented", "_mcp", "origami.js");
|
|
5723
5876
|
this.writeMcpServer(codeName, "origami", {
|
|
5724
5877
|
command: "node",
|
|
5725
5878
|
args: [localOrigamiMcpPath],
|
|
@@ -5836,9 +5989,9 @@ ${sections}`
|
|
|
5836
5989
|
}
|
|
5837
5990
|
}
|
|
5838
5991
|
const projectDir = getProjectDir(codeName);
|
|
5839
|
-
const claudeMdPath =
|
|
5992
|
+
const claudeMdPath = join4(projectDir, "CLAUDE.md");
|
|
5840
5993
|
try {
|
|
5841
|
-
const existing =
|
|
5994
|
+
const existing = readFileSync5(claudeMdPath, "utf-8");
|
|
5842
5995
|
const renderSection = options?.renderClaudeMdSection === true;
|
|
5843
5996
|
const newSection = renderSection ? buildIntegrationsSection(summariesForSidecar) : "";
|
|
5844
5997
|
const sentinelStart = INTEGRATIONS_SECTION_START.replace(/[.*+?^${}()|[\]\\]/g, "\\$&");
|
|
@@ -5855,15 +6008,15 @@ ${sections}`
|
|
|
5855
6008
|
updated = existing;
|
|
5856
6009
|
}
|
|
5857
6010
|
if (updated !== existing)
|
|
5858
|
-
|
|
6011
|
+
writeFileSync5(claudeMdPath, updated);
|
|
5859
6012
|
const agentDir2 = getAgentDir(codeName);
|
|
5860
|
-
const envSrc =
|
|
6013
|
+
const envSrc = join4(agentDir2, ".env.integrations");
|
|
5861
6014
|
try {
|
|
5862
|
-
const envContent =
|
|
5863
|
-
const envDest =
|
|
5864
|
-
|
|
6015
|
+
const envContent = readFileSync5(envSrc, "utf-8");
|
|
6016
|
+
const envDest = join4(projectDir, ".env.integrations");
|
|
6017
|
+
writeFileSync5(envDest, envContent, { mode: SECRET_FILE_MODE2 });
|
|
5865
6018
|
try {
|
|
5866
|
-
|
|
6019
|
+
chmodSync5(envDest, SECRET_FILE_MODE2);
|
|
5867
6020
|
} catch {
|
|
5868
6021
|
}
|
|
5869
6022
|
} catch {
|
|
@@ -5875,11 +6028,11 @@ ${sections}`
|
|
|
5875
6028
|
},
|
|
5876
6029
|
writeMcpServer(codeName, serverId, config) {
|
|
5877
6030
|
const agentDir = getAgentDir(codeName);
|
|
5878
|
-
const mcpJsonPath =
|
|
5879
|
-
|
|
6031
|
+
const mcpJsonPath = join4(agentDir, "provision", ".mcp.json");
|
|
6032
|
+
mkdirSync4(join4(agentDir, "provision"), { recursive: true });
|
|
5880
6033
|
let mcpConfig;
|
|
5881
6034
|
try {
|
|
5882
|
-
mcpConfig = JSON.parse(
|
|
6035
|
+
mcpConfig = JSON.parse(readFileSync5(mcpJsonPath, "utf-8"));
|
|
5883
6036
|
} catch {
|
|
5884
6037
|
mcpConfig = { mcpServers: {} };
|
|
5885
6038
|
}
|
|
@@ -5923,7 +6076,7 @@ ${sections}`
|
|
|
5923
6076
|
}
|
|
5924
6077
|
},
|
|
5925
6078
|
getMcpPath(codeName) {
|
|
5926
|
-
return
|
|
6079
|
+
return join4(getAgentDir(codeName), "provision", ".mcp.json");
|
|
5927
6080
|
},
|
|
5928
6081
|
/**
|
|
5929
6082
|
* ENG-7994: the declared servers from `provision/.mcp.json`. Mirrors what the
|
|
@@ -5934,7 +6087,7 @@ ${sections}`
|
|
|
5934
6087
|
readMcpServers(codeName) {
|
|
5935
6088
|
let parsed;
|
|
5936
6089
|
try {
|
|
5937
|
-
parsed = JSON.parse(
|
|
6090
|
+
parsed = JSON.parse(readFileSync5(join4(getAgentDir(codeName), "provision", ".mcp.json"), "utf-8"));
|
|
5938
6091
|
} catch {
|
|
5939
6092
|
return {};
|
|
5940
6093
|
}
|
|
@@ -5947,10 +6100,10 @@ ${sections}`
|
|
|
5947
6100
|
},
|
|
5948
6101
|
removeMcpServer(codeName, serverId) {
|
|
5949
6102
|
const agentDir = getAgentDir(codeName);
|
|
5950
|
-
const mcpJsonPath =
|
|
6103
|
+
const mcpJsonPath = join4(agentDir, "provision", ".mcp.json");
|
|
5951
6104
|
let mcpConfig;
|
|
5952
6105
|
try {
|
|
5953
|
-
mcpConfig = JSON.parse(
|
|
6106
|
+
mcpConfig = JSON.parse(readFileSync5(mcpJsonPath, "utf-8"));
|
|
5954
6107
|
} catch {
|
|
5955
6108
|
return;
|
|
5956
6109
|
}
|
|
@@ -5969,27 +6122,27 @@ ${sections}`
|
|
|
5969
6122
|
const READ_WRITE_MODE = 420;
|
|
5970
6123
|
const agentDir = getAgentDir(codeName);
|
|
5971
6124
|
const projectDir = getProjectDir(codeName);
|
|
5972
|
-
for (const baseDir of [
|
|
5973
|
-
const skillDir =
|
|
5974
|
-
|
|
6125
|
+
for (const baseDir of [join4(agentDir, "skills"), join4(projectDir, ".claude", "skills")]) {
|
|
6126
|
+
const skillDir = join4(baseDir, skillId);
|
|
6127
|
+
mkdirSync4(skillDir, { recursive: true });
|
|
5975
6128
|
for (const file of files) {
|
|
5976
6129
|
assertSafeRelativePath(file.relativePath);
|
|
5977
|
-
const filePath =
|
|
6130
|
+
const filePath = join4(skillDir, file.relativePath);
|
|
5978
6131
|
const rel = relative(skillDir, filePath);
|
|
5979
6132
|
if (rel.startsWith("..") || rel === "") {
|
|
5980
6133
|
throw new Error(`Path traversal detected: ${file.relativePath} resolves outside ${skillDir}`);
|
|
5981
6134
|
}
|
|
5982
|
-
|
|
6135
|
+
mkdirSync4(join4(filePath, ".."), { recursive: true });
|
|
5983
6136
|
if (isPluginManaged && existsSync4(filePath)) {
|
|
5984
6137
|
try {
|
|
5985
|
-
|
|
6138
|
+
chmodSync5(filePath, READ_WRITE_MODE);
|
|
5986
6139
|
} catch {
|
|
5987
6140
|
}
|
|
5988
6141
|
}
|
|
5989
|
-
|
|
6142
|
+
writeFileSync5(filePath, file.content);
|
|
5990
6143
|
if (isPluginManaged) {
|
|
5991
6144
|
try {
|
|
5992
|
-
|
|
6145
|
+
chmodSync5(filePath, READ_ONLY_MODE);
|
|
5993
6146
|
} catch {
|
|
5994
6147
|
}
|
|
5995
6148
|
}
|
|
@@ -5998,11 +6151,11 @@ ${sections}`
|
|
|
5998
6151
|
},
|
|
5999
6152
|
installPlugin(codeName, pluginId, pluginPath, pluginConfig) {
|
|
6000
6153
|
const agentDir = getAgentDir(codeName);
|
|
6001
|
-
const pluginsJsonPath =
|
|
6002
|
-
|
|
6154
|
+
const pluginsJsonPath = join4(agentDir, "plugins.json");
|
|
6155
|
+
mkdirSync4(agentDir, { recursive: true });
|
|
6003
6156
|
let pluginsConfig;
|
|
6004
6157
|
try {
|
|
6005
|
-
pluginsConfig = JSON.parse(
|
|
6158
|
+
pluginsConfig = JSON.parse(readFileSync5(pluginsJsonPath, "utf-8"));
|
|
6006
6159
|
} catch {
|
|
6007
6160
|
pluginsConfig = { plugins: {} };
|
|
6008
6161
|
}
|
|
@@ -6015,7 +6168,7 @@ ${sections}`
|
|
|
6015
6168
|
installed_at: (/* @__PURE__ */ new Date()).toISOString(),
|
|
6016
6169
|
...pluginConfig ? { config: pluginConfig } : {}
|
|
6017
6170
|
};
|
|
6018
|
-
|
|
6171
|
+
writeFileSync5(pluginsJsonPath, JSON.stringify(pluginsConfig, null, 2));
|
|
6019
6172
|
},
|
|
6020
6173
|
/**
|
|
6021
6174
|
* Full plugin provisioning: install scripts, register hooks, apply permissions,
|
|
@@ -6031,11 +6184,11 @@ ${sections}`
|
|
|
6031
6184
|
assertValidCodeName(codeName);
|
|
6032
6185
|
assertValidCodeName(plugin.slug);
|
|
6033
6186
|
const projectDir = getProjectDir(codeName);
|
|
6034
|
-
const claudeDir =
|
|
6035
|
-
|
|
6187
|
+
const claudeDir = join4(projectDir, ".claude");
|
|
6188
|
+
mkdirSync4(claudeDir, { recursive: true });
|
|
6036
6189
|
const sourceSpec = options?.scriptSource ?? `augmented-plugin:${plugin.slug}`;
|
|
6037
6190
|
this.installPlugin(codeName, plugin.slug, sourceSpec, contextValues);
|
|
6038
|
-
const installedDir =
|
|
6191
|
+
const installedDir = join4(projectDir, ".claude", "plugins", plugin.slug);
|
|
6039
6192
|
for (const skill of plugin.skills) {
|
|
6040
6193
|
const skillId = skill.id;
|
|
6041
6194
|
assertValidCodeName(skillId);
|
|
@@ -6047,10 +6200,10 @@ ${sections}`
|
|
|
6047
6200
|
}
|
|
6048
6201
|
const scriptsConfig = plugin.scripts;
|
|
6049
6202
|
if (scriptsConfig?.hooks) {
|
|
6050
|
-
const settingsPath =
|
|
6203
|
+
const settingsPath = join4(claudeDir, "settings.local.json");
|
|
6051
6204
|
let settings = {};
|
|
6052
6205
|
try {
|
|
6053
|
-
settings = JSON.parse(
|
|
6206
|
+
settings = JSON.parse(readFileSync5(settingsPath, "utf-8"));
|
|
6054
6207
|
} catch {
|
|
6055
6208
|
}
|
|
6056
6209
|
const existingHooks = settings["hooks"] ?? {};
|
|
@@ -6084,13 +6237,13 @@ ${sections}`
|
|
|
6084
6237
|
}
|
|
6085
6238
|
}
|
|
6086
6239
|
settings["hooks"] = existingHooks;
|
|
6087
|
-
|
|
6240
|
+
writeFileSync5(settingsPath, JSON.stringify(settings, null, 2));
|
|
6088
6241
|
}
|
|
6089
6242
|
if (plugin.allowed_tools.length > 0) {
|
|
6090
|
-
const settingsPath =
|
|
6243
|
+
const settingsPath = join4(claudeDir, "settings.local.json");
|
|
6091
6244
|
let settings = {};
|
|
6092
6245
|
try {
|
|
6093
|
-
settings = JSON.parse(
|
|
6246
|
+
settings = JSON.parse(readFileSync5(settingsPath, "utf-8"));
|
|
6094
6247
|
} catch {
|
|
6095
6248
|
}
|
|
6096
6249
|
const existingPerms = settings["permissions"] ?? {};
|
|
@@ -6102,20 +6255,20 @@ ${sections}`
|
|
|
6102
6255
|
}
|
|
6103
6256
|
existingPerms["allow"] = allowList;
|
|
6104
6257
|
settings["permissions"] = existingPerms;
|
|
6105
|
-
|
|
6258
|
+
writeFileSync5(settingsPath, JSON.stringify(settings, null, 2));
|
|
6106
6259
|
}
|
|
6107
6260
|
if (contextValues && Object.keys(contextValues).length > 0) {
|
|
6108
|
-
const configDir =
|
|
6109
|
-
|
|
6110
|
-
|
|
6261
|
+
const configDir = join4(projectDir, `.${plugin.slug}`);
|
|
6262
|
+
mkdirSync4(configDir, { recursive: true });
|
|
6263
|
+
writeFileSync5(join4(configDir, "config.json"), JSON.stringify(contextValues, null, 2));
|
|
6111
6264
|
}
|
|
6112
6265
|
},
|
|
6113
6266
|
executePluginHook(ctx) {
|
|
6114
6267
|
assertValidCodeName(ctx.codeName);
|
|
6115
|
-
const agentRootDir =
|
|
6268
|
+
const agentRootDir = join4(getHomeDir(), ".augmented", ctx.codeName);
|
|
6116
6269
|
const projectDir = getProjectDir(ctx.codeName);
|
|
6117
|
-
|
|
6118
|
-
|
|
6270
|
+
mkdirSync4(agentRootDir, { recursive: true });
|
|
6271
|
+
mkdirSync4(projectDir, { recursive: true });
|
|
6119
6272
|
const startedAt = Date.now();
|
|
6120
6273
|
return new Promise((resolve) => {
|
|
6121
6274
|
const child = execFile("bash", ["-c", ctx.script], {
|
|
@@ -6151,7 +6304,7 @@ ${sections}`
|
|
|
6151
6304
|
},
|
|
6152
6305
|
writeTokenFile(codeName, integrations) {
|
|
6153
6306
|
const agentDir = getAgentDir(codeName);
|
|
6154
|
-
|
|
6307
|
+
mkdirSync4(agentDir, { recursive: true });
|
|
6155
6308
|
const tokens = {};
|
|
6156
6309
|
for (const integration of integrations) {
|
|
6157
6310
|
if (integration.auth_type !== "oauth2" && integration.auth_type !== "github_app")
|
|
@@ -6168,9 +6321,9 @@ ${sections}`
|
|
|
6168
6321
|
}
|
|
6169
6322
|
if (Object.keys(tokens).length === 0)
|
|
6170
6323
|
return;
|
|
6171
|
-
const tokenPath =
|
|
6172
|
-
|
|
6173
|
-
|
|
6324
|
+
const tokenPath = join4(agentDir, ".tokens.json");
|
|
6325
|
+
writeFileSync5(tokenPath, JSON.stringify(tokens, null, 2));
|
|
6326
|
+
chmodSync5(tokenPath, SECRET_FILE_MODE2);
|
|
6174
6327
|
}
|
|
6175
6328
|
};
|
|
6176
6329
|
registerFramework(claudeCodeAdapter);
|
|
@@ -6192,14 +6345,14 @@ function jsonOutput(data) {
|
|
|
6192
6345
|
}
|
|
6193
6346
|
|
|
6194
6347
|
// src/lib/config.ts
|
|
6195
|
-
import { readFileSync as
|
|
6196
|
-
import { join as
|
|
6348
|
+
import { readFileSync as readFileSync6, writeFileSync as writeFileSync6, mkdirSync as mkdirSync5, existsSync as existsSync5 } from "fs";
|
|
6349
|
+
import { join as join5 } from "path";
|
|
6197
6350
|
import { homedir as homedir4 } from "os";
|
|
6198
|
-
var AUGMENTED_DIR =
|
|
6199
|
-
var CONFIG_PATH =
|
|
6351
|
+
var AUGMENTED_DIR = join5(homedir4(), ".augmented");
|
|
6352
|
+
var CONFIG_PATH = join5(AUGMENTED_DIR, "config.json");
|
|
6200
6353
|
function ensureAugmentedDir() {
|
|
6201
6354
|
if (!existsSync5(AUGMENTED_DIR)) {
|
|
6202
|
-
|
|
6355
|
+
mkdirSync5(AUGMENTED_DIR, { recursive: true });
|
|
6203
6356
|
}
|
|
6204
6357
|
}
|
|
6205
6358
|
function reloadFromShellProfile() {
|
|
@@ -6209,10 +6362,10 @@ function loadFromShellProfile(force = false) {
|
|
|
6209
6362
|
if (!force && process.env["AGT_HOST"] && process.env["AGT_API_KEY"]) return;
|
|
6210
6363
|
const shell = process.env["SHELL"] ?? "";
|
|
6211
6364
|
const home = homedir4();
|
|
6212
|
-
const candidates = shell.includes("zsh") ? [
|
|
6365
|
+
const candidates = shell.includes("zsh") ? [join5(home, ".zshrc"), join5(home, ".zprofile")] : shell.includes("fish") ? [join5(home, ".config", "fish", "config.fish")] : [join5(home, ".bashrc"), join5(home, ".bash_profile")];
|
|
6213
6366
|
for (const profile of candidates) {
|
|
6214
6367
|
try {
|
|
6215
|
-
const content =
|
|
6368
|
+
const content = readFileSync6(profile, "utf-8");
|
|
6216
6369
|
for (const key of ["AGT_HOST", "AGT_API_KEY", "AGT_TEAM"]) {
|
|
6217
6370
|
if (!force && process.env[key]) continue;
|
|
6218
6371
|
const match = content.split(/\r?\n/).map((line) => line.trim()).filter((line) => line.length > 0 && !line.startsWith("#")).map(
|
|
@@ -6237,7 +6390,7 @@ function getApiKey() {
|
|
|
6237
6390
|
}
|
|
6238
6391
|
function getConfig() {
|
|
6239
6392
|
try {
|
|
6240
|
-
const raw =
|
|
6393
|
+
const raw = readFileSync6(CONFIG_PATH, "utf-8");
|
|
6241
6394
|
return JSON.parse(raw);
|
|
6242
6395
|
} catch {
|
|
6243
6396
|
return {};
|
|
@@ -6245,7 +6398,7 @@ function getConfig() {
|
|
|
6245
6398
|
}
|
|
6246
6399
|
function saveConfig(config) {
|
|
6247
6400
|
ensureAugmentedDir();
|
|
6248
|
-
|
|
6401
|
+
writeFileSync6(CONFIG_PATH, JSON.stringify(config, null, 2));
|
|
6249
6402
|
}
|
|
6250
6403
|
function getActiveTeam() {
|
|
6251
6404
|
const envTeam = process.env["AGT_TEAM"];
|
|
@@ -6292,7 +6445,7 @@ function exchangeFailureKind(err) {
|
|
|
6292
6445
|
}
|
|
6293
6446
|
|
|
6294
6447
|
// src/lib/api-client.ts
|
|
6295
|
-
var agtCliVersion = true ? "0.28.
|
|
6448
|
+
var agtCliVersion = true ? "0.28.679" : "dev";
|
|
6296
6449
|
var lastConfigHash = null;
|
|
6297
6450
|
function setConfigHash(hash) {
|
|
6298
6451
|
lastConfigHash = hash && hash.length > 0 ? hash : null;
|
|
@@ -6542,13 +6695,13 @@ async function getHostId() {
|
|
|
6542
6695
|
}
|
|
6543
6696
|
|
|
6544
6697
|
// src/lib/atomic-write.ts
|
|
6545
|
-
import { closeSync, fsyncSync, openSync, writeSync, renameSync as renameSync5, mkdirSync as
|
|
6546
|
-
import { dirname as
|
|
6698
|
+
import { closeSync, fsyncSync, openSync, writeSync, renameSync as renameSync5, mkdirSync as mkdirSync6 } from "fs";
|
|
6699
|
+
import { dirname as dirname5 } from "path";
|
|
6547
6700
|
function atomicWriteFileSync(path, data) {
|
|
6548
|
-
const dirPath =
|
|
6701
|
+
const dirPath = dirname5(path);
|
|
6549
6702
|
const tmpPath = `${path}.tmp.${process.pid}.${Math.random().toString(36).slice(2, 8)}`;
|
|
6550
6703
|
try {
|
|
6551
|
-
|
|
6704
|
+
mkdirSync6(dirPath, { recursive: true });
|
|
6552
6705
|
} catch {
|
|
6553
6706
|
}
|
|
6554
6707
|
const fd = openSync(tmpPath, "w", 420);
|
|
@@ -6574,15 +6727,15 @@ function atomicWriteFileSync(path, data) {
|
|
|
6574
6727
|
}
|
|
6575
6728
|
|
|
6576
6729
|
// src/lib/feature-flags-host.ts
|
|
6577
|
-
import { existsSync as existsSync6, readFileSync as
|
|
6578
|
-
import { join as
|
|
6730
|
+
import { existsSync as existsSync6, readFileSync as readFileSync7, statSync as statSync2 } from "fs";
|
|
6731
|
+
import { join as join6 } from "path";
|
|
6579
6732
|
function defaultFlagsCachePath(configDir) {
|
|
6580
|
-
return
|
|
6733
|
+
return join6(configDir, "flags-cache.json");
|
|
6581
6734
|
}
|
|
6582
6735
|
function readFlagsCache(path) {
|
|
6583
6736
|
try {
|
|
6584
6737
|
if (!existsSync6(path)) return null;
|
|
6585
|
-
const parsed = JSON.parse(
|
|
6738
|
+
const parsed = JSON.parse(readFileSync7(path, "utf8"));
|
|
6586
6739
|
if (!parsed || typeof parsed !== "object") return null;
|
|
6587
6740
|
const obj = parsed;
|
|
6588
6741
|
const flags = obj["flags"];
|
|
@@ -7047,16 +7200,16 @@ function buildArgvMatchersForEntry(key, entry) {
|
|
|
7047
7200
|
const tail = "(?![A-Za-z0-9_-])";
|
|
7048
7201
|
if (/^@?[a-z0-9]([a-z0-9._-]*\/)?[a-z0-9._-]+$/i.test(stripped)) {
|
|
7049
7202
|
patterns.push(new RegExp(`${escapeRe(stripped)}${tail}`));
|
|
7050
|
-
const
|
|
7051
|
-
if (
|
|
7052
|
-
patterns.push(new RegExp(`${escapeRe(
|
|
7203
|
+
const basename2 = stripped.split("/").pop();
|
|
7204
|
+
if (basename2 && basename2 !== stripped) {
|
|
7205
|
+
patterns.push(new RegExp(`${escapeRe(basename2)}${tail}`));
|
|
7053
7206
|
}
|
|
7054
7207
|
break;
|
|
7055
7208
|
}
|
|
7056
7209
|
if (stripped.includes("/")) {
|
|
7057
|
-
const
|
|
7058
|
-
if (
|
|
7059
|
-
patterns.push(new RegExp(`${escapeRe(
|
|
7210
|
+
const basename2 = stripped.split("/").pop();
|
|
7211
|
+
if (basename2) {
|
|
7212
|
+
patterns.push(new RegExp(`${escapeRe(basename2)}${tail}`));
|
|
7060
7213
|
break;
|
|
7061
7214
|
}
|
|
7062
7215
|
}
|
|
@@ -8208,8 +8361,8 @@ function verdictForUnavailableMcpConfig(cause, ctx) {
|
|
|
8208
8361
|
}
|
|
8209
8362
|
|
|
8210
8363
|
// src/lib/connectivity-probe-context.ts
|
|
8211
|
-
import { delimiter as pathDelimiter, join as
|
|
8212
|
-
import { existsSync as existsSync7, readFileSync as
|
|
8364
|
+
import { delimiter as pathDelimiter, join as join7 } from "path";
|
|
8365
|
+
import { existsSync as existsSync7, readFileSync as readFileSync8 } from "fs";
|
|
8213
8366
|
|
|
8214
8367
|
// src/lib/mcp-stdio-probe.ts
|
|
8215
8368
|
import { spawn } from "child_process";
|
|
@@ -8720,7 +8873,7 @@ function resolveHttpServerEntry(entry, env) {
|
|
|
8720
8873
|
function readMcpHttpServerConfig(projectDir, serverKey, env) {
|
|
8721
8874
|
let servers;
|
|
8722
8875
|
try {
|
|
8723
|
-
const raw =
|
|
8876
|
+
const raw = readFileSync8(join7(projectDir, ".mcp.json"), "utf-8");
|
|
8724
8877
|
servers = JSON.parse(raw).mcpServers ?? {};
|
|
8725
8878
|
} catch {
|
|
8726
8879
|
return { ok: false, cause: "file-unreadable" };
|
|
@@ -8732,7 +8885,7 @@ function readMcpHttpServerConfig(projectDir, serverKey, env) {
|
|
|
8732
8885
|
}
|
|
8733
8886
|
function resolveDeclaredServerKey(projectDir, definitionId, derivedKey) {
|
|
8734
8887
|
try {
|
|
8735
|
-
const raw =
|
|
8888
|
+
const raw = readFileSync8(join7(projectDir, ".mcp.json"), "utf-8");
|
|
8736
8889
|
const servers = JSON.parse(raw).mcpServers ?? {};
|
|
8737
8890
|
const declared = Object.keys(servers);
|
|
8738
8891
|
if (derivedKey !== definitionId && derivedKey !== sanitizeServerKey(definitionId)) {
|
|
@@ -8774,7 +8927,7 @@ function resolveStdioServerEntry(entry, env) {
|
|
|
8774
8927
|
function readMcpStdioServerConfig(projectDir, serverKey, env) {
|
|
8775
8928
|
let servers;
|
|
8776
8929
|
try {
|
|
8777
|
-
const raw =
|
|
8930
|
+
const raw = readFileSync8(join7(projectDir, ".mcp.json"), "utf-8");
|
|
8778
8931
|
servers = JSON.parse(raw).mcpServers ?? {};
|
|
8779
8932
|
} catch {
|
|
8780
8933
|
return { ok: false, cause: "file-unreadable" };
|
|
@@ -8800,9 +8953,9 @@ function deriveMcpServerKey(input) {
|
|
|
8800
8953
|
function buildProbeEnv(projectDir, agentId) {
|
|
8801
8954
|
const probeEnv = { ...process.env };
|
|
8802
8955
|
try {
|
|
8803
|
-
const envIntPath =
|
|
8956
|
+
const envIntPath = join7(projectDir, ".env.integrations");
|
|
8804
8957
|
if (existsSync7(envIntPath)) {
|
|
8805
|
-
Object.assign(probeEnv, parseEnvIntegrations(
|
|
8958
|
+
Object.assign(probeEnv, parseEnvIntegrations(readFileSync8(envIntPath, "utf-8")));
|
|
8806
8959
|
}
|
|
8807
8960
|
} catch {
|
|
8808
8961
|
}
|
|
@@ -8810,7 +8963,7 @@ function buildProbeEnv(projectDir, agentId) {
|
|
|
8810
8963
|
probeEnv.AGT_AGENT_ID = agentId.trim();
|
|
8811
8964
|
}
|
|
8812
8965
|
try {
|
|
8813
|
-
const agentBinDir =
|
|
8966
|
+
const agentBinDir = join7(projectDir, ".claude", "agt-bin");
|
|
8814
8967
|
if (existsSync7(agentBinDir)) {
|
|
8815
8968
|
probeEnv.PATH = probeEnv.PATH ? `${agentBinDir}${pathDelimiter}${probeEnv.PATH}` : agentBinDir;
|
|
8816
8969
|
}
|
|
@@ -8947,9 +9100,9 @@ function buildConnectivityProbeDeps(projectDir, probeEnv) {
|
|
|
8947
9100
|
|
|
8948
9101
|
// src/lib/session-tool-bind-probe-host.ts
|
|
8949
9102
|
import { execFileSync as syncExecFile } from "child_process";
|
|
8950
|
-
import { readFileSync as
|
|
8951
|
-
import { join as
|
|
8952
|
-
import { dirname as
|
|
9103
|
+
import { readFileSync as readFileSync9 } from "fs";
|
|
9104
|
+
import { join as join8 } from "path";
|
|
9105
|
+
import { dirname as dirname6 } from "path";
|
|
8953
9106
|
function deliveryFields(i) {
|
|
8954
9107
|
const keys = ["source_type", "provider", "mcp_command", "mcp_url", "cli_binary", "cli_package"];
|
|
8955
9108
|
const out = {};
|
|
@@ -8962,7 +9115,7 @@ async function gatherSessionToolBindProbe(agent, integrations, projectDir, opts)
|
|
|
8962
9115
|
if (integrations.length === 0) return null;
|
|
8963
9116
|
let mcpRaw = null;
|
|
8964
9117
|
try {
|
|
8965
|
-
mcpRaw =
|
|
9118
|
+
mcpRaw = readFileSync9(join8(projectDir, ".mcp.json"), "utf-8");
|
|
8966
9119
|
} catch {
|
|
8967
9120
|
mcpRaw = null;
|
|
8968
9121
|
}
|
|
@@ -9055,7 +9208,7 @@ var SLACK_MCP_SERVER_KEY = "slack";
|
|
|
9055
9208
|
function readSlackTransportDownKeys(projectDir) {
|
|
9056
9209
|
const none = /* @__PURE__ */ new Set();
|
|
9057
9210
|
try {
|
|
9058
|
-
const raw =
|
|
9211
|
+
const raw = readFileSync9(join8(dirname6(projectDir), SLACK_SOCKET_STATE_FILENAME), "utf-8");
|
|
9059
9212
|
const state = parseSlackSocketState(raw, Date.now());
|
|
9060
9213
|
return isSlackInboundTransportDown(state, SLACK_TRANSPORT_DOWN_AFTER_MS) ? /* @__PURE__ */ new Set([SLACK_MCP_SERVER_KEY]) : none;
|
|
9061
9214
|
} catch {
|
|
@@ -9172,34 +9325,34 @@ function decidePin(opts) {
|
|
|
9172
9325
|
// src/commands/manager.ts
|
|
9173
9326
|
import chalk3 from "chalk";
|
|
9174
9327
|
import { existsSync as existsSync9, realpathSync as realpathSync2 } from "fs";
|
|
9175
|
-
import { join as
|
|
9328
|
+
import { join as join10 } from "path";
|
|
9176
9329
|
import { homedir as homedir5, userInfo } from "os";
|
|
9177
9330
|
import { spawn as spawn3 } from "child_process";
|
|
9178
9331
|
|
|
9179
9332
|
// src/lib/watchdog.ts
|
|
9180
|
-
import { readFileSync as
|
|
9181
|
-
import { join as
|
|
9333
|
+
import { readFileSync as readFileSync10, writeFileSync as writeFileSync7, unlinkSync as unlinkSync4, existsSync as existsSync8, mkdirSync as mkdirSync7, openSync as openSync2, closeSync as closeSync2, chmodSync as chmodSync6 } from "fs";
|
|
9334
|
+
import { join as join9 } from "path";
|
|
9182
9335
|
import { spawn as spawn2, execFileSync as execFileSync3 } from "child_process";
|
|
9183
|
-
var DEFAULT_CONFIG_DIR =
|
|
9336
|
+
var DEFAULT_CONFIG_DIR = join9(process.env["HOME"] ?? "/tmp", ".augmented");
|
|
9184
9337
|
function getManagerPaths(configDir) {
|
|
9185
9338
|
return {
|
|
9186
|
-
pidFile:
|
|
9187
|
-
stateFile:
|
|
9188
|
-
logFile:
|
|
9339
|
+
pidFile: join9(configDir, "manager.pid"),
|
|
9340
|
+
stateFile: join9(configDir, "manager-state.json"),
|
|
9341
|
+
logFile: join9(configDir, "manager.log")
|
|
9189
9342
|
};
|
|
9190
9343
|
}
|
|
9191
9344
|
function ensureDir(configDir) {
|
|
9192
9345
|
if (!existsSync8(configDir)) {
|
|
9193
|
-
|
|
9346
|
+
mkdirSync7(configDir, { recursive: true });
|
|
9194
9347
|
}
|
|
9195
9348
|
}
|
|
9196
9349
|
function writePidFile(configDir, pid) {
|
|
9197
9350
|
ensureDir(configDir);
|
|
9198
|
-
|
|
9351
|
+
writeFileSync7(getManagerPaths(configDir).pidFile, String(pid), { mode: 384 });
|
|
9199
9352
|
}
|
|
9200
9353
|
function readPidFile(configDir) {
|
|
9201
9354
|
try {
|
|
9202
|
-
const raw =
|
|
9355
|
+
const raw = readFileSync10(getManagerPaths(configDir).pidFile, "utf-8").trim();
|
|
9203
9356
|
const pid = parseInt(raw, 10);
|
|
9204
9357
|
return isNaN(pid) ? null : pid;
|
|
9205
9358
|
} catch {
|
|
@@ -9245,7 +9398,7 @@ function defaultPgrep() {
|
|
|
9245
9398
|
}
|
|
9246
9399
|
function readStateFile(configDir) {
|
|
9247
9400
|
try {
|
|
9248
|
-
const raw =
|
|
9401
|
+
const raw = readFileSync10(getManagerPaths(configDir).stateFile, "utf-8");
|
|
9249
9402
|
return JSON.parse(raw);
|
|
9250
9403
|
} catch {
|
|
9251
9404
|
return null;
|
|
@@ -9279,7 +9432,7 @@ function startWatchdog(opts) {
|
|
|
9279
9432
|
const { logFile } = getManagerPaths(configDir);
|
|
9280
9433
|
const logFd = openSync2(logFile, "a", 384);
|
|
9281
9434
|
try {
|
|
9282
|
-
|
|
9435
|
+
chmodSync6(logFile, 384);
|
|
9283
9436
|
} catch {
|
|
9284
9437
|
}
|
|
9285
9438
|
const intervalSec = String(Math.max(Math.floor(opts.intervalMs / 1e3), 5));
|
|
@@ -9441,7 +9594,7 @@ function managerStartCommand(opts) {
|
|
|
9441
9594
|
process.exitCode = 1;
|
|
9442
9595
|
return;
|
|
9443
9596
|
}
|
|
9444
|
-
const configDir = opts.configDir ??
|
|
9597
|
+
const configDir = opts.configDir ?? join10(homedir5(), ".augmented");
|
|
9445
9598
|
if (opts.supervise) {
|
|
9446
9599
|
if (json) {
|
|
9447
9600
|
jsonOutput({ ok: false, error: "--supervise is not supported with --json" });
|
|
@@ -9537,7 +9690,7 @@ function runSupervisorLoop(intervalSec, configDir) {
|
|
|
9537
9690
|
}
|
|
9538
9691
|
async function managerStopCommand(opts = {}) {
|
|
9539
9692
|
const json = isJsonMode();
|
|
9540
|
-
const configDir = opts.configDir ??
|
|
9693
|
+
const configDir = opts.configDir ?? join10(homedir5(), ".augmented");
|
|
9541
9694
|
try {
|
|
9542
9695
|
const result = await stopWatchdog(configDir);
|
|
9543
9696
|
if (!result.stopped && !result.pid) {
|
|
@@ -9565,7 +9718,7 @@ async function managerStopCommand(opts = {}) {
|
|
|
9565
9718
|
}
|
|
9566
9719
|
function managerStatusCommand(opts = {}) {
|
|
9567
9720
|
const json = isJsonMode();
|
|
9568
|
-
const configDir = opts.configDir ??
|
|
9721
|
+
const configDir = opts.configDir ?? join10(homedir5(), ".augmented");
|
|
9569
9722
|
const status = getManagerStatus(configDir);
|
|
9570
9723
|
if (!status) {
|
|
9571
9724
|
if (json) {
|
|
@@ -9657,7 +9810,7 @@ async function managerInstallCommand(opts = {}) {
|
|
|
9657
9810
|
process.exitCode = 1;
|
|
9658
9811
|
return;
|
|
9659
9812
|
}
|
|
9660
|
-
const configDir = opts.configDir ??
|
|
9813
|
+
const configDir = opts.configDir ?? join10(homedir5(), ".augmented");
|
|
9661
9814
|
const rawAgtBin = process.argv[1];
|
|
9662
9815
|
if (!rawAgtBin) {
|
|
9663
9816
|
const msg = "Could not resolve the agt binary path from argv. Re-run via the installed `agt` command.";
|
|
@@ -9670,7 +9823,7 @@ async function managerInstallCommand(opts = {}) {
|
|
|
9670
9823
|
if (process.platform === "darwin") {
|
|
9671
9824
|
const home = homedir5();
|
|
9672
9825
|
const protectedRoots = ["Documents", "Downloads", "Desktop", "Movies", "Music", "Pictures"];
|
|
9673
|
-
const offending = protectedRoots.map((r) =>
|
|
9826
|
+
const offending = protectedRoots.map((r) => join10(home, r)).find((p) => agtBin === p || agtBin.startsWith(`${p}/`));
|
|
9674
9827
|
if (offending) {
|
|
9675
9828
|
const msg = `agt binary at ${agtBin} sits inside a macOS TCC-protected folder (${offending}). launchd-spawned processes cannot read files there and the manager would EPERM on startup. Either install agt globally (\`npm install -g @integrity-labs/agt-cli\`) or copy the dist outside protected folders before running this command.`;
|
|
9676
9829
|
if (json) jsonOutput({ ok: false, error: msg });
|
|
@@ -9739,7 +9892,7 @@ async function managerInstallSystemUnitCommand(opts = {}) {
|
|
|
9739
9892
|
return;
|
|
9740
9893
|
}
|
|
9741
9894
|
const user = opts.user ?? "root";
|
|
9742
|
-
const configDir = opts.configDir ?? (user === "root" ? "/root/.augmented" :
|
|
9895
|
+
const configDir = opts.configDir ?? (user === "root" ? "/root/.augmented" : join10("/home", user, ".augmented"));
|
|
9743
9896
|
const rawAgtBin = process.argv[1];
|
|
9744
9897
|
if (!rawAgtBin) {
|
|
9745
9898
|
const msg = "Could not resolve the agt binary path from argv. Re-run via the installed `agt` command.";
|
|
@@ -9951,6 +10104,7 @@ function withEvidence(outcome, evidence) {
|
|
|
9951
10104
|
export {
|
|
9952
10105
|
LITERAL_SECRET_PATTERNS,
|
|
9953
10106
|
safeWriteJsonAtomic,
|
|
10107
|
+
setSecretFileTmpfsBacking,
|
|
9954
10108
|
extractCommandNotFound,
|
|
9955
10109
|
migrateAgentDirToIdKeyed,
|
|
9956
10110
|
provisionStopHook,
|
|
@@ -10033,4 +10187,4 @@ export {
|
|
|
10033
10187
|
managerInstallSystemUnitCommand,
|
|
10034
10188
|
managerUninstallSystemUnitCommand
|
|
10035
10189
|
};
|
|
10036
|
-
//# sourceMappingURL=chunk-
|
|
10190
|
+
//# sourceMappingURL=chunk-CLNFPTVG.js.map
|