dsh-taskbridge 1.8.1 → 1.9.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +20 -0
- package/README.md +751 -733
- package/antigravity/agents/dsh-taskbridge.md +14 -12
- package/antigravity/skills/dsh-taskbridge/SKILL.md +32 -19
- package/bin/dsh-delegate-codex-agent.js +9 -4
- package/codex/skills/dsh-taskbridge/SKILL.md +131 -0
- package/codex/skills/dsh-taskbridge/rules-reference-96027c387cb9b7587efa4aa3836235d86db1108068e007dc08196e807ca25e5d.md +114 -0
- package/docs/INTRODUCTION.md +148 -122
- package/docs/INTRODUCTION.zh.md +151 -134
- package/docs/antigravity-integration.md +47 -42
- package/docs/assets/taskbridge-workflow.en.svg +72 -0
- package/docs/assets/taskbridge-workflow.zh.png +0 -0
- package/docs/claude-code.md +18 -18
- package/docs/codex-integration.md +139 -113
- package/docs/releases/1.8.0.zh.md +16 -16
- package/docs/releases/1.8.1.zh.md +24 -24
- package/docs/releases/1.9.0.zh.md +31 -0
- package/docs/runtime-compatibility.md +7 -9
- package/docs/silent-wait.md +17 -26
- package/docs/taskbridge-upgrade.md +4 -4
- package/lib/client.d.ts +2 -2
- package/lib/client.js +7 -7
- package/locale/en.json +7 -7
- package/locale/zh.json +7 -7
- package/package.json +10 -4
- package/src/antigravity/installer.js +1099 -1068
- package/src/antigravity/seam.js +142 -142
- package/src/client/api.js +135 -13
- package/src/client/index.jsx +19 -18
- package/src/codex/agent-ownership.js +72 -12
- package/src/codex/installer.js +688 -268
- package/src/http/execution-plane.js +17 -0
- package/src/http/user-plane.js +6 -0
- package/src/index.d.ts +9 -1
- package/src/index.js +86 -64
- package/src/jobs/engine.js +278 -5
- package/src/jobs/history.js +17 -1
- package/src/jobs/record-cleanup.js +715 -641
- package/src/mcp/server.js +241 -12
- package/src/runtime/permissions.js +18 -0
- package/src/runtime/worker-prompt.js +13 -9
- package/codex/dsh-taskbridge.toml +0 -181
package/src/codex/installer.js
CHANGED
|
@@ -1,13 +1,16 @@
|
|
|
1
|
-
// Codex integration: install the
|
|
2
|
-
// package's stdio MCP server in Codex
|
|
1
|
+
// Codex integration: install the native Codex skill and register this
|
|
2
|
+
// package's stdio MCP server in Codex, while safely retiring untouched
|
|
3
|
+
// legacy managed subagent files (`agents/dsh-taskbridge.toml` and
|
|
4
|
+
// `agents/dsh-delegate.toml`) from 0.1.6–1.8.x releases.
|
|
3
5
|
//
|
|
4
6
|
// Scope, stated once and enforced below
|
|
5
7
|
// -------------------------------------
|
|
6
|
-
// This module owns exactly two
|
|
8
|
+
// This module owns exactly two active targets in a Codex home:
|
|
7
9
|
//
|
|
8
|
-
// 1. `$CODEX_HOME/
|
|
9
|
-
// template `codex/dsh-taskbridge.
|
|
10
|
-
//
|
|
10
|
+
// 1. `$CODEX_HOME/skills/dsh-taskbridge/SKILL.md` — a *managed copy* of the shipped
|
|
11
|
+
// template `codex/skills/dsh-taskbridge/SKILL.md` and the reference it links to.
|
|
12
|
+
// Ownership is proved by content,
|
|
13
|
+
// never by the file name or a version marker alone:
|
|
11
14
|
// * a file that is the same text as the template this build would write is
|
|
12
15
|
// `installed` (and removable). "Same text" admits exactly one difference: CRLF
|
|
13
16
|
// versus LF line terminators (including a mixed spelling of the same lines).
|
|
@@ -81,7 +84,7 @@
|
|
|
81
84
|
// say what the file can and cannot guarantee.
|
|
82
85
|
|
|
83
86
|
import { lstatSync } from 'node:fs';
|
|
84
|
-
import { link, lstat, mkdir, open, readFile, readlink, realpath, stat, unlink } from 'node:fs/promises';
|
|
87
|
+
import { link, lstat, mkdir, open, readFile, readlink, realpath, rmdir, stat, unlink } from 'node:fs/promises';
|
|
85
88
|
import { execFile } from 'node:child_process';
|
|
86
89
|
import { createHash, randomBytes } from 'node:crypto';
|
|
87
90
|
import { homedir } from 'node:os';
|
|
@@ -89,7 +92,15 @@ import { basename, delimiter, dirname, isAbsolute, join, parse, resolve, sep } f
|
|
|
89
92
|
import { fileURLToPath } from 'node:url';
|
|
90
93
|
|
|
91
94
|
import { writeFileAtomic } from '../config/store.js';
|
|
92
|
-
import {
|
|
95
|
+
import {
|
|
96
|
+
chainPathsOf,
|
|
97
|
+
ownershipRecordPath,
|
|
98
|
+
recallSkillTemplateDigest,
|
|
99
|
+
recallTemplateDigest,
|
|
100
|
+
rememberSkillTemplateDigest,
|
|
101
|
+
skillOwnershipRecordPath,
|
|
102
|
+
digestLf,
|
|
103
|
+
} from './agent-ownership.js';
|
|
93
104
|
import {
|
|
94
105
|
TomlDocument,
|
|
95
106
|
TomlSyntaxError,
|
|
@@ -100,7 +111,12 @@ import {
|
|
|
100
111
|
tomlValueType,
|
|
101
112
|
} from './toml.js';
|
|
102
113
|
|
|
103
|
-
/**
|
|
114
|
+
/** Native Codex skill directory and file name inside `$CODEX_HOME/skills`. */
|
|
115
|
+
export const SKILL_DIR_NAME = 'dsh-taskbridge';
|
|
116
|
+
export const SKILL_FILENAME = 'SKILL.md';
|
|
117
|
+
export const SKILL_RELATIVE_PATH = join('skills', SKILL_DIR_NAME, SKILL_FILENAME);
|
|
118
|
+
|
|
119
|
+
/** Legacy retired subagent file names inside `$CODEX_HOME/agents` (recognised for safe cleanup). */
|
|
104
120
|
export const AGENT_FILENAME = 'dsh-taskbridge.toml';
|
|
105
121
|
export const LEGACY_AGENT_FILENAME = 'dsh-delegate.toml';
|
|
106
122
|
|
|
@@ -525,10 +541,44 @@ export const KNOWN_AGENT_TEMPLATES = [
|
|
|
525
541
|
// Published 1.8.0 companion before the 1.8.1 dual-client symmetry and Q&A boundary refinement, in LF and CRLF.
|
|
526
542
|
{ version: '1.8.0', sha256: 'ba3c964cad6b9ae395dbe0d74971a430795fd8927a4a5daeb6a45617823a9cab' },
|
|
527
543
|
{ version: '1.8.0', sha256: '6f732230068f3230f9ad1c6a92d30d677f717dd0b0ebd92abb73ed7578f956dd' },
|
|
544
|
+
// Published 1.8.1 companion before the 1.9.0 migration to native Codex Skill, in LF and CRLF.
|
|
545
|
+
{ version: '1.8.1', sha256: 'dc09680bcf6927ca1019554f1e841a176ac7035236f329ce008f45be06b9fb82' },
|
|
546
|
+
{ version: '1.8.1', sha256: 'addc76a5c9c47e64e2b7f30750e0bcbdfefe060dc6a2d5e3ebcf93252e072850' },
|
|
547
|
+
// Local 1.8.2-test2 companion before the 1.9.0 migration to native Codex Skill, in LF and CRLF.
|
|
548
|
+
{ version: '1.8.2-test2', sha256: '596177b7c3fe8fa446d50f670a546a2ae884a717c476eaaae63e637124b10d64' },
|
|
549
|
+
{ version: '1.8.2-test2', sha256: '6452e8672fd3628fe6a5650e21bb4bb9925e7ff0d090bae9330427325975d915' },
|
|
550
|
+
];
|
|
551
|
+
|
|
552
|
+
/** Exact shipped `skills/dsh-taskbridge/SKILL.md` files of earlier 1.9+ builds (SHA-256). */
|
|
553
|
+
export const KNOWN_SKILL_TEMPLATES = [
|
|
554
|
+
// Local 1.9.0-test1 native Codex skill before layered integrations/ refactor, in LF and CRLF.
|
|
555
|
+
{ version: '1.9.0-test1', sha256: '815ec71d75e8089dd1d726b5bb07cd7ad2e3a3dec444e7dca76b83cce064b565' },
|
|
556
|
+
{ version: '1.9.0-test1', sha256: '9777da3423c1a5c8d6cf50f0f161ab0f6e5b064708670f32abf6e6c4a4fffda0' },
|
|
557
|
+
// Local test packages with layered integration rules, in LF and CRLF.
|
|
558
|
+
{ version: '1.9.0-test2', sha256: '5ed46037522e854fb31c6bfb3ecefc751e85a4d1a445b2e0830cee40b0738d5b' },
|
|
559
|
+
{ version: '1.9.0-test2', sha256: '71b84788ab13749776f0ffa97d2be77e0b0296d1deff59b556eccdb95f681271' },
|
|
560
|
+
{ version: '1.9.0-test3', sha256: 'd381022187327e9aff453588239b1664f6b9b7fc2f895e11701d4148e1330b82' },
|
|
561
|
+
{ version: '1.9.0-test3', sha256: '5a0b5100b67a35600ead1c3b75d2e03a92e1fee10709e46e8ddd93661b59ddfc' },
|
|
562
|
+
{ version: '1.9.0-test4', sha256: 'f67b394705485d3dd3e7219bde9f05d7720410eeeaa234c5da6dc68f89e3c7ca' },
|
|
563
|
+
{ version: '1.9.0-test4', sha256: '7740c10f5f84f6fa309bdba67c10721dda6754b66f6b56236ca400ba6b9644af' },
|
|
564
|
+
{ version: '1.9.0-test5', sha256: '709e7c18aef5c54e371f6830ac9c837fbfcb5963b26e4019ef5f9e491864df24' },
|
|
565
|
+
{ version: '1.9.0-test5', sha256: '6e30655cb97200c3a3bbf6545ad90da1cc3e464363646e506f3075825cedf55d' },
|
|
566
|
+
{ version: '1.9.0-pre', sha256: 'd8878f88e60a4d46079f7fde93408d21c1e517c76d1bad86a7814d40603d729d' },
|
|
567
|
+
{ version: '1.9.0-pre', sha256: 'e2b8ec097cdedcbbbdf811870d566cb1fb36f6882d579db67a0f33f08c78da98' },
|
|
568
|
+
{ version: '1.9.0-pre', sha256: '64560e14664ab0b932c36a5e2560c35ef5acf7cdbf38acf522e87e8aefbd53b7' },
|
|
569
|
+
{ version: '1.9.0-pre', sha256: 'db1526280a0618a379db8dbe1c71840204a5957907a92b20bd3f43fd00971c0f' },
|
|
570
|
+
{ version: '1.9.0-test6', sha256: 'c2477b9233f4f9b4e36c59f8544f607249b2f96be0aeba0a013525e18c4eab38' },
|
|
571
|
+
{ version: '1.9.0-test6', sha256: '238366a0ebaa543d6b09fd1a94d5507a22d5ba0d19fee32539c429d1ded2182c' },
|
|
572
|
+
{ version: '1.9.0-preview', sha256: 'eefe1134216d3d73901ec8e279e8752b4281dd191343e180fb76c671055c4523' },
|
|
573
|
+
{ version: '1.9.0-preview', sha256: '0f28427153bda6e696fc6203d3ac885067ac22902b716e6ecbce6a2a0e693148' },
|
|
574
|
+
{ version: '1.9.0-preview2', sha256: 'bc1a1be12d5117efe52ed5c10e4d25cac4713b9746c41096cc6f5e75efada40d' },
|
|
575
|
+
{ version: '1.9.0-preview2', sha256: '6a2684b21762157edf3b32ddccea81d6327b117454cdb74e0c7260803f46d4be' },
|
|
576
|
+
{ version: '1.9.0-preview3', sha256: 'c3b3d6ad273f55ec822cde3f6635f875103c339d65821601d3baaddac85af4d7' },
|
|
577
|
+
{ version: '1.9.0-preview3', sha256: '1237d095f32a0c4ac1d5dde8f05f11b6edf17d863ff1bb67ab63a17f6ac2fe3b' },
|
|
528
578
|
];
|
|
529
579
|
|
|
530
|
-
/** The
|
|
531
|
-
const
|
|
580
|
+
/** The version provenance comment line inside a shipped Markdown Codex skill file. */
|
|
581
|
+
const SKILL_VERSION_LINE = /^<!-- dsh-taskbridge-version: ([^>\r\n]+) -->\r?$/mu;
|
|
532
582
|
|
|
533
583
|
/**
|
|
534
584
|
* Read agent text with CRLF terminators folded to LF.
|
|
@@ -578,29 +628,23 @@ function sameAgentText(contents, template) {
|
|
|
578
628
|
* Everything else still fails too: an added or removed line, a comment, a trailing space, a tab,
|
|
579
629
|
* a BOM, a changed version line or any other edit hashes to nothing in the table.
|
|
580
630
|
* @param {string} contents - installed file text.
|
|
581
|
-
* @param {object} [options] - `ignoreVersion`: compare with the version line masked, used only
|
|
582
|
-
* to explain *why* a file is `modified` in the status note. It never grants refresh or removal.
|
|
583
631
|
* @returns {boolean} true when the file is a known published build of this template.
|
|
584
632
|
*/
|
|
585
|
-
export function isKnownPriorTemplate(contents
|
|
633
|
+
export function isKnownPriorTemplate(contents) {
|
|
586
634
|
if (typeof contents !== 'string') return false;
|
|
587
|
-
const known = (text) =>
|
|
635
|
+
const known = (text) => {
|
|
636
|
+
const sha256 = digest(text);
|
|
637
|
+
return KNOWN_AGENT_TEMPLATES.some((entry) => entry.sha256 === sha256)
|
|
638
|
+
|| KNOWN_SKILL_TEMPLATES.some((entry) => entry.sha256 === sha256);
|
|
639
|
+
};
|
|
588
640
|
if (known(contents)) return true;
|
|
589
641
|
const lf = normalizeLineEndings(contents);
|
|
590
642
|
// A leftover `\r` means the file has a CR no spelling fold accounts for, so no equivalent
|
|
591
|
-
// digest may claim it.
|
|
592
|
-
|
|
593
|
-
if (
|
|
594
|
-
|
|
595
|
-
|
|
596
|
-
if (crlf !== contents && known(crlf)) return true;
|
|
597
|
-
}
|
|
598
|
-
if (!ignoreVersion) return false;
|
|
599
|
-
// Explanation-only path: the same body with the version line stripped still has to
|
|
600
|
-
// match a known build, which distinguishes "operator edited a managed file" from
|
|
601
|
-
// "this file was never ours".
|
|
602
|
-
const stripped = contents.replace(VERSION_LINE, 'version = "\u0000"');
|
|
603
|
-
return KNOWN_AGENT_TEMPLATES.some((entry) => entry.sha256 === digest(stripped));
|
|
643
|
+
// digest may claim it.
|
|
644
|
+
if (lf.includes('\r')) return false;
|
|
645
|
+
if (lf !== contents && known(lf)) return true;
|
|
646
|
+
const crlf = lf.replace(/\n/gu, '\r\n');
|
|
647
|
+
return crlf !== contents && known(crlf);
|
|
604
648
|
}
|
|
605
649
|
|
|
606
650
|
/** Stable states reported for the agent file. */
|
|
@@ -654,7 +698,8 @@ const PACKAGE_ROOT = resolve(dirname(fileURLToPath(import.meta.url)), '..', '..'
|
|
|
654
698
|
* declare before its entry point can be adopted by an automatic migration.
|
|
655
699
|
*/
|
|
656
700
|
const PACKAGE_NAME = 'dsh-taskbridge';
|
|
657
|
-
const TEMPLATE_PATH = join(PACKAGE_ROOT, 'codex',
|
|
701
|
+
const TEMPLATE_PATH = join(PACKAGE_ROOT, 'codex', 'skills', SKILL_DIR_NAME, SKILL_FILENAME);
|
|
702
|
+
const SKILL_REFERENCE_LINK = /\]\((rules-reference-([0-9a-f]{64})\.md)\)/u;
|
|
658
703
|
const PACKAGE_MANIFEST_PATH = join(PACKAGE_ROOT, 'package.json');
|
|
659
704
|
|
|
660
705
|
/** Bound on a Codex config document this module is willing to edit. */
|
|
@@ -1105,25 +1150,65 @@ async function inspectFile(path) {
|
|
|
1105
1150
|
* `unknown` means the platform could not say whether the directory is a link.
|
|
1106
1151
|
*/
|
|
1107
1152
|
export async function inspectDirectory(path) {
|
|
1108
|
-
|
|
1109
|
-
|
|
1110
|
-
|
|
1111
|
-
|
|
1112
|
-
|
|
1113
|
-
|
|
1114
|
-
|
|
1153
|
+
const results = await inspectDirectories([path]);
|
|
1154
|
+
return results.get(path) ?? { kind: 'unknown' };
|
|
1155
|
+
}
|
|
1156
|
+
|
|
1157
|
+
/**
|
|
1158
|
+
* Inspect multiple directory paths in ONE batched platform attribute call on Windows.
|
|
1159
|
+
* @param {string[]} paths - directory paths to inspect.
|
|
1160
|
+
* @returns {Promise<Map<string, { kind: 'missing' | 'directory' | 'link' | 'other' | 'unknown', target?: string }>>}
|
|
1161
|
+
*/
|
|
1162
|
+
export async function inspectDirectories(paths) {
|
|
1163
|
+
const unique = [];
|
|
1164
|
+
const seen = new Set();
|
|
1165
|
+
for (const path of paths) {
|
|
1166
|
+
if (typeof path === 'string' && path !== '' && !seen.has(path)) {
|
|
1167
|
+
seen.add(path);
|
|
1168
|
+
unique.push(path);
|
|
1169
|
+
}
|
|
1115
1170
|
}
|
|
1116
|
-
|
|
1117
|
-
|
|
1118
|
-
const
|
|
1119
|
-
|
|
1120
|
-
|
|
1121
|
-
|
|
1122
|
-
|
|
1123
|
-
|
|
1124
|
-
|
|
1125
|
-
|
|
1126
|
-
|
|
1171
|
+
const results = new Map();
|
|
1172
|
+
const toCheck = [];
|
|
1173
|
+
for (const path of unique) {
|
|
1174
|
+
let info;
|
|
1175
|
+
try {
|
|
1176
|
+
info = await lstat(path);
|
|
1177
|
+
} catch (error) {
|
|
1178
|
+
if (error?.code === 'ENOENT') {
|
|
1179
|
+
results.set(path, { kind: 'missing' });
|
|
1180
|
+
continue;
|
|
1181
|
+
}
|
|
1182
|
+
if (error?.code === 'ENOTDIR') {
|
|
1183
|
+
results.set(path, { kind: 'other' });
|
|
1184
|
+
continue;
|
|
1185
|
+
}
|
|
1186
|
+
throw error;
|
|
1187
|
+
}
|
|
1188
|
+
if (info.isSymbolicLink()) {
|
|
1189
|
+
results.set(path, { kind: 'link', target: await readLinkTarget(path) });
|
|
1190
|
+
continue;
|
|
1191
|
+
}
|
|
1192
|
+
if (!info.isDirectory()) {
|
|
1193
|
+
results.set(path, { kind: 'other' });
|
|
1194
|
+
continue;
|
|
1195
|
+
}
|
|
1196
|
+
toCheck.push(path);
|
|
1197
|
+
}
|
|
1198
|
+
if (toCheck.length > 0) {
|
|
1199
|
+
const kinds = await windowsDirectoryKinds(toCheck);
|
|
1200
|
+
for (const path of toCheck) {
|
|
1201
|
+
const kind = kinds.get(path);
|
|
1202
|
+
// A junction is reported by Node as a plain directory; only the attribute proves it.
|
|
1203
|
+
// `unknown` (the platform could not answer) is reported as itself: callers must
|
|
1204
|
+
// refuse, and must not describe it as a link they never saw.
|
|
1205
|
+
if (kind === 'missing') results.set(path, { kind: 'missing' });
|
|
1206
|
+
else if (kind === 'unknown') results.set(path, { kind: 'unknown' });
|
|
1207
|
+
else if (kind !== 'directory') results.set(path, { kind: 'link', target: await readLinkTarget(path) });
|
|
1208
|
+
else results.set(path, { kind: 'directory' });
|
|
1209
|
+
}
|
|
1210
|
+
}
|
|
1211
|
+
return results;
|
|
1127
1212
|
}
|
|
1128
1213
|
|
|
1129
1214
|
/**
|
|
@@ -1340,19 +1425,60 @@ async function readAgentState(path, template, recordedDigest = null) {
|
|
|
1340
1425
|
if (existing.kind === 'missing') return { state: AGENT_STATES.missing, present: false, reason: null, contents: null };
|
|
1341
1426
|
if (existing.kind === 'other') return { state: AGENT_STATES.conflict, present: true, reason: 'not-a-regular-file', contents: null };
|
|
1342
1427
|
const contents = existing.contents;
|
|
1343
|
-
|
|
1344
|
-
|
|
1345
|
-
|
|
1346
|
-
|
|
1347
|
-
|
|
1428
|
+
const current = sameAgentText(contents, template);
|
|
1429
|
+
const known = !current && isKnownPriorTemplate(contents);
|
|
1430
|
+
const recorded = !current && !known && recordedDigest !== null && digestLf(contents) === recordedDigest;
|
|
1431
|
+
if (current || known || recorded) {
|
|
1432
|
+
const reference = skillReference(path, contents);
|
|
1433
|
+
if (reference !== null) {
|
|
1434
|
+
const installed = await inspectFile(reference.path);
|
|
1435
|
+
if (installed.kind === 'missing' && current) {
|
|
1436
|
+
return { state: AGENT_STATES.outdated, present: true, reason: 'reference-missing', contents };
|
|
1437
|
+
}
|
|
1438
|
+
if (referenceConflicts(reference, installed)) {
|
|
1439
|
+
return { state: AGENT_STATES.modified, present: true, reason: 'reference-operator-owned', contents };
|
|
1440
|
+
}
|
|
1441
|
+
}
|
|
1442
|
+
const state = current ? AGENT_STATES.installed : AGENT_STATES.outdated;
|
|
1443
|
+
return { state, present: true, reason: null, contents, recorded };
|
|
1444
|
+
}
|
|
1445
|
+
const normalizedContents = normalizeLineEndings(contents);
|
|
1446
|
+
const normalizedTemplate = normalizeLineEndings(template);
|
|
1447
|
+
const sameBodyDifferentVersion = !normalizedContents.includes('\r')
|
|
1448
|
+
&& normalizedContents.replace(SKILL_VERSION_LINE, '<!-- dsh-taskbridge-version: \u0000 -->')
|
|
1449
|
+
=== normalizedTemplate.replace(SKILL_VERSION_LINE, '<!-- dsh-taskbridge-version: \u0000 -->');
|
|
1348
1450
|
return {
|
|
1349
1451
|
state: AGENT_STATES.modified,
|
|
1350
1452
|
present: true,
|
|
1351
|
-
reason:
|
|
1453
|
+
reason: sameBodyDifferentVersion ? 'edited' : 'unknown-content',
|
|
1352
1454
|
contents,
|
|
1353
1455
|
};
|
|
1354
1456
|
}
|
|
1355
1457
|
|
|
1458
|
+
function createBatchedKindClassifier(cache = new Map()) {
|
|
1459
|
+
const classifyMany = async (paths) => {
|
|
1460
|
+
const missing = [];
|
|
1461
|
+
for (const path of paths) {
|
|
1462
|
+
if (typeof path === 'string' && path !== '' && !cache.has(path)) missing.push(path);
|
|
1463
|
+
}
|
|
1464
|
+
if (missing.length > 0) {
|
|
1465
|
+
const inspected = await inspectDirectories(missing);
|
|
1466
|
+
for (const [path, info] of inspected.entries()) {
|
|
1467
|
+
cache.set(path, info.kind);
|
|
1468
|
+
}
|
|
1469
|
+
}
|
|
1470
|
+
const out = new Map();
|
|
1471
|
+
for (const path of paths) out.set(path, cache.get(path) ?? 'unknown');
|
|
1472
|
+
return out;
|
|
1473
|
+
};
|
|
1474
|
+
const classify = async (path) => {
|
|
1475
|
+
if (cache.has(path)) return cache.get(path);
|
|
1476
|
+
const out = await classifyMany([path]);
|
|
1477
|
+
return out.get(path) ?? 'unknown';
|
|
1478
|
+
};
|
|
1479
|
+
return { classify, classifyMany, cache };
|
|
1480
|
+
}
|
|
1481
|
+
|
|
1356
1482
|
/**
|
|
1357
1483
|
* The template digest this plugin last proved it wrote into one Codex home, or null.
|
|
1358
1484
|
*
|
|
@@ -1361,22 +1487,78 @@ async function readAgentState(path, template, recordedDigest = null) {
|
|
|
1361
1487
|
* file is classified. Nothing is created and nothing is written here.
|
|
1362
1488
|
* @param {string} home - the REAL, pinned Codex home.
|
|
1363
1489
|
* @param {Record<string, string | undefined>} env - environment (for `DSH_HOME`).
|
|
1490
|
+
* @param {{ classify: Function, classifyMany: Function }} [batch] - optional shared classifier cache.
|
|
1364
1491
|
* @returns {Promise<string | null>} LF digest, or null.
|
|
1365
1492
|
*/
|
|
1366
|
-
async function recallRecordedTemplate(home, env) {
|
|
1493
|
+
async function recallRecordedTemplate(home, env, batch = createBatchedKindClassifier()) {
|
|
1367
1494
|
if (typeof home !== 'string' || home.trim() === '' || !isAbsolute(home)) return null;
|
|
1368
1495
|
try {
|
|
1369
|
-
return await recallTemplateDigest({
|
|
1496
|
+
return await recallTemplateDigest({
|
|
1497
|
+
codexHome: home,
|
|
1498
|
+
env,
|
|
1499
|
+
classify: batch.classify,
|
|
1500
|
+
classifyMany: batch.classifyMany,
|
|
1501
|
+
});
|
|
1502
|
+
} catch {
|
|
1503
|
+
return null;
|
|
1504
|
+
}
|
|
1505
|
+
}
|
|
1506
|
+
|
|
1507
|
+
async function recallRecordedSkillTemplate(home, env, batch = createBatchedKindClassifier()) {
|
|
1508
|
+
if (typeof home !== 'string' || home.trim() === '' || !isAbsolute(home)) return null;
|
|
1509
|
+
try {
|
|
1510
|
+
return await recallSkillTemplateDigest({
|
|
1511
|
+
codexHome: home,
|
|
1512
|
+
env,
|
|
1513
|
+
classify: batch.classify,
|
|
1514
|
+
classifyMany: batch.classifyMany,
|
|
1515
|
+
});
|
|
1370
1516
|
} catch {
|
|
1371
1517
|
return null;
|
|
1372
1518
|
}
|
|
1373
1519
|
}
|
|
1374
1520
|
|
|
1375
1521
|
/**
|
|
1376
|
-
*
|
|
1522
|
+
* Inspect legacy Codex subagent files (`agents/dsh-taskbridge.toml` and `agents/dsh-delegate.toml`)
|
|
1523
|
+
* so untouched prior installs can be migrated to the native skill and safely retired, while
|
|
1524
|
+
* operator-edited files are preserved untouched and surfaced as notes.
|
|
1525
|
+
*/
|
|
1526
|
+
async function inspectLegacyAgents(home, recordedAgentDigest = null) {
|
|
1527
|
+
const filenames = [AGENT_FILENAME, LEGACY_AGENT_FILENAME];
|
|
1528
|
+
const entries = [];
|
|
1529
|
+
for (const filename of filenames) {
|
|
1530
|
+
const filePath = join(home, 'agents', filename);
|
|
1531
|
+
const inspected = await inspectFile(filePath);
|
|
1532
|
+
if (inspected.kind === 'missing') continue;
|
|
1533
|
+
if (inspected.kind === 'other') {
|
|
1534
|
+
entries.push({ filename, path: filePath, state: 'conflict', expect: null });
|
|
1535
|
+
continue;
|
|
1536
|
+
}
|
|
1537
|
+
const contents = inspected.contents;
|
|
1538
|
+
const isManaged = isKnownPriorTemplate(contents)
|
|
1539
|
+
|| (typeof recordedAgentDigest === 'string' && recordedAgentDigest !== '' && digestLf(contents) === recordedAgentDigest);
|
|
1540
|
+
entries.push({
|
|
1541
|
+
filename,
|
|
1542
|
+
path: filePath,
|
|
1543
|
+
state: isManaged ? 'managed-legacy' : 'modified-legacy',
|
|
1544
|
+
expect: isManaged ? contents : null,
|
|
1545
|
+
});
|
|
1546
|
+
}
|
|
1547
|
+
const state = entries.some((entry) => entry.state === 'managed-legacy')
|
|
1548
|
+
? 'managed-legacy'
|
|
1549
|
+
: entries.some((entry) => entry.state === 'modified-legacy')
|
|
1550
|
+
? 'modified-legacy'
|
|
1551
|
+
: entries.some((entry) => entry.state === 'conflict')
|
|
1552
|
+
? 'conflict'
|
|
1553
|
+
: 'absent';
|
|
1554
|
+
return { state, entries };
|
|
1555
|
+
}
|
|
1556
|
+
|
|
1557
|
+
/**
|
|
1558
|
+
* Record the skill template digest after a write this action just made, proved against the file.
|
|
1377
1559
|
*
|
|
1378
1560
|
* Called only from `install` and from the startup `refreshKnownAgentTemplate`, and only after the
|
|
1379
|
-
* write reported success: it re-reads the
|
|
1561
|
+
* write reported success: it re-reads the skill file, requires it to be exactly the rendered
|
|
1380
1562
|
* template, and records the digest of THOSE bytes. `repair`, `remove` and `status` never reach
|
|
1381
1563
|
* this. A failed record is a lost proof for the next release, never a failed install.
|
|
1382
1564
|
* @param {object} before - the status the write was planned from.
|
|
@@ -1386,99 +1568,177 @@ async function recordAgentTemplate(before) {
|
|
|
1386
1568
|
const env = before[INTERNAL_ENV];
|
|
1387
1569
|
if (env === undefined) return;
|
|
1388
1570
|
try {
|
|
1389
|
-
|
|
1571
|
+
const classify = (path) => inspectDirectory(path).then((info) => info.kind);
|
|
1572
|
+
const classifyMany = async (paths) => {
|
|
1573
|
+
const inspected = await inspectDirectories(paths);
|
|
1574
|
+
const out = new Map();
|
|
1575
|
+
for (const path of paths) out.set(path, inspected.get(path)?.kind ?? 'unknown');
|
|
1576
|
+
return out;
|
|
1577
|
+
};
|
|
1578
|
+
await rememberSkillTemplateDigest({
|
|
1390
1579
|
codexHome: before.codexHome,
|
|
1391
1580
|
env,
|
|
1392
1581
|
template: renderAgentFile(await readAgentTemplate(), before.packageVersion),
|
|
1393
|
-
|
|
1582
|
+
skillPath: before.agent.path,
|
|
1394
1583
|
readFile: async (path) => (await inspectFile(path)).contents,
|
|
1395
1584
|
writeFileAtomic,
|
|
1396
1585
|
mkdir,
|
|
1397
|
-
classify
|
|
1586
|
+
classify,
|
|
1587
|
+
classifyMany,
|
|
1398
1588
|
});
|
|
1399
1589
|
} catch {
|
|
1400
1590
|
// A proof that cannot be recorded must never fail the install that produced it, and a
|
|
1401
|
-
// refused record (a linked ancestor, a damaged file) is no record: the
|
|
1591
|
+
// refused record (a linked ancestor, a damaged file) is no record: the skill file stays
|
|
1402
1592
|
// classified by its own content.
|
|
1403
1593
|
}
|
|
1404
1594
|
}
|
|
1405
1595
|
|
|
1406
|
-
|
|
1407
|
-
|
|
1408
|
-
|
|
1409
|
-
|
|
1410
|
-
|
|
1411
|
-
|
|
1412
|
-
|
|
1413
|
-
|
|
1414
|
-
|
|
1415
|
-
* A directory whose identity cannot be established (`unknown`) is refused too: the
|
|
1416
|
-
* alternative is to assume it is safe, and an assumption is what this check exists to
|
|
1417
|
-
* remove. Both paths are inspected in one batch, so a normal Windows home costs one
|
|
1418
|
-
* child process, not two.
|
|
1419
|
-
* @param {string} home - resolved Codex home.
|
|
1420
|
-
* @returns {Promise<{
|
|
1421
|
-
* blocked: boolean,
|
|
1422
|
-
* link: 'codex-home' | 'agents' | null,
|
|
1423
|
-
* unknown: boolean,
|
|
1424
|
-
* home: { kind: string, target?: string },
|
|
1425
|
-
* agents: { kind: string, target?: string },
|
|
1426
|
-
* }>} boundary state.
|
|
1427
|
-
*/
|
|
1596
|
+
async function isLstatPlainDirectory(path) {
|
|
1597
|
+
try {
|
|
1598
|
+
const info = await lstat(path);
|
|
1599
|
+
return !info.isSymbolicLink() && info.isDirectory();
|
|
1600
|
+
} catch {
|
|
1601
|
+
return false;
|
|
1602
|
+
}
|
|
1603
|
+
}
|
|
1604
|
+
|
|
1428
1605
|
export async function inspectCodexBoundary(home) {
|
|
1606
|
+
const skillsPath = join(home, 'skills');
|
|
1607
|
+
const skillDirPath = join(skillsPath, SKILL_DIR_NAME);
|
|
1429
1608
|
const agentsPath = join(home, 'agents');
|
|
1430
|
-
const
|
|
1609
|
+
const candidates = [home];
|
|
1610
|
+
if (await isLstatPlainDirectory(home)) {
|
|
1611
|
+
candidates.push(skillsPath, agentsPath);
|
|
1612
|
+
if (await isLstatPlainDirectory(skillsPath)) {
|
|
1613
|
+
candidates.push(skillDirPath);
|
|
1614
|
+
}
|
|
1615
|
+
}
|
|
1616
|
+
const inspected = await inspectDirectories(candidates);
|
|
1617
|
+
const homeInfo = inspected.get(home) ?? { kind: 'unknown' };
|
|
1431
1618
|
if (homeInfo.kind === 'link') {
|
|
1432
|
-
|
|
1433
|
-
|
|
1434
|
-
|
|
1435
|
-
|
|
1436
|
-
|
|
1437
|
-
|
|
1619
|
+
return {
|
|
1620
|
+
blocked: true,
|
|
1621
|
+
link: 'codex-home',
|
|
1622
|
+
unknown: false,
|
|
1623
|
+
home: homeInfo,
|
|
1624
|
+
skills: { kind: 'unchecked' },
|
|
1625
|
+
skillDir: { kind: 'unchecked' },
|
|
1626
|
+
agents: { kind: 'unchecked' },
|
|
1627
|
+
};
|
|
1628
|
+
}
|
|
1629
|
+
const skillsInfo = homeInfo.kind === 'directory'
|
|
1630
|
+
? (inspected.get(skillsPath) ?? { kind: 'unknown' })
|
|
1631
|
+
: { kind: 'unchecked' };
|
|
1632
|
+
if (skillsInfo.kind === 'link') {
|
|
1633
|
+
return {
|
|
1634
|
+
blocked: true,
|
|
1635
|
+
link: 'skills',
|
|
1636
|
+
unknown: false,
|
|
1637
|
+
home: homeInfo,
|
|
1638
|
+
skills: skillsInfo,
|
|
1639
|
+
skillDir: { kind: 'unchecked' },
|
|
1640
|
+
agents: { kind: 'unchecked' },
|
|
1641
|
+
};
|
|
1642
|
+
}
|
|
1643
|
+
const skillDirInfo = skillsInfo.kind === 'directory'
|
|
1644
|
+
? (inspected.get(skillDirPath) ?? { kind: 'unknown' })
|
|
1645
|
+
: { kind: 'unchecked' };
|
|
1646
|
+
if (skillDirInfo.kind === 'link') {
|
|
1647
|
+
return {
|
|
1648
|
+
blocked: true,
|
|
1649
|
+
link: 'skill-dir',
|
|
1650
|
+
unknown: false,
|
|
1651
|
+
home: homeInfo,
|
|
1652
|
+
skills: skillsInfo,
|
|
1653
|
+
skillDir: skillDirInfo,
|
|
1654
|
+
agents: { kind: 'unchecked' },
|
|
1655
|
+
};
|
|
1438
1656
|
}
|
|
1439
1657
|
const agentsInfo = homeInfo.kind === 'directory'
|
|
1440
|
-
?
|
|
1658
|
+
? (inspected.get(agentsPath) ?? { kind: 'unknown' })
|
|
1441
1659
|
: { kind: 'unchecked' };
|
|
1442
1660
|
if (agentsInfo.kind === 'link') {
|
|
1443
|
-
return {
|
|
1661
|
+
return {
|
|
1662
|
+
blocked: true,
|
|
1663
|
+
link: 'agents',
|
|
1664
|
+
unknown: false,
|
|
1665
|
+
home: homeInfo,
|
|
1666
|
+
skills: skillsInfo,
|
|
1667
|
+
skillDir: skillDirInfo,
|
|
1668
|
+
agents: agentsInfo,
|
|
1669
|
+
};
|
|
1444
1670
|
}
|
|
1445
|
-
|
|
1446
|
-
|
|
1447
|
-
|
|
1448
|
-
|
|
1671
|
+
if (
|
|
1672
|
+
homeInfo.kind === 'unknown'
|
|
1673
|
+
|| skillsInfo.kind === 'unknown'
|
|
1674
|
+
|| skillDirInfo.kind === 'unknown'
|
|
1675
|
+
|| agentsInfo.kind === 'unknown'
|
|
1676
|
+
) {
|
|
1677
|
+
return {
|
|
1678
|
+
blocked: true,
|
|
1679
|
+
link: null,
|
|
1680
|
+
unknown: true,
|
|
1681
|
+
home: homeInfo,
|
|
1682
|
+
skills: skillsInfo,
|
|
1683
|
+
skillDir: skillDirInfo,
|
|
1684
|
+
agents: agentsInfo,
|
|
1685
|
+
};
|
|
1449
1686
|
}
|
|
1450
|
-
return {
|
|
1687
|
+
return {
|
|
1688
|
+
blocked: false,
|
|
1689
|
+
link: null,
|
|
1690
|
+
unknown: false,
|
|
1691
|
+
home: homeInfo,
|
|
1692
|
+
skills: skillsInfo,
|
|
1693
|
+
skillDir: skillDirInfo,
|
|
1694
|
+
agents: agentsInfo,
|
|
1695
|
+
};
|
|
1451
1696
|
}
|
|
1452
1697
|
|
|
1453
|
-
/**
|
|
1454
|
-
* Does a link stand between the Codex home and the managed files?
|
|
1455
|
-
*
|
|
1456
|
-
* The status document carries the answer (`boundary.blocked`) because it is read with
|
|
1457
|
-
* exactly the same inspect call; this turns that fact into a refusal in the shape
|
|
1458
|
-
* every action reports. Re-reading the status is what makes the check current: it is
|
|
1459
|
-
* re-done at the start of every writing action.
|
|
1460
|
-
* @param {object} status - a status document from {@link readCodexStatus}.
|
|
1461
|
-
* @returns {{ target: string, code: string, message: string, path: string, reason: string }} refusal.
|
|
1462
|
-
*/
|
|
1463
1698
|
function linkedBoundaryRefusal(status) {
|
|
1464
1699
|
if (status.boundary?.unknown === true) {
|
|
1465
1700
|
return {
|
|
1466
1701
|
target: 'agent',
|
|
1467
1702
|
code: 'AGENT_PATH_CONFLICT',
|
|
1468
|
-
message: 'the Codex home or agents directory could not be verified as a real directory and was not written',
|
|
1469
|
-
path: join(status.codexHome, '
|
|
1703
|
+
message: 'the Codex home, skills or agents directory could not be verified as a real directory and was not written',
|
|
1704
|
+
path: join(status.codexHome, 'skills'),
|
|
1470
1705
|
reason: 'boundary-unverified',
|
|
1471
1706
|
};
|
|
1472
1707
|
}
|
|
1473
|
-
const
|
|
1708
|
+
const linkKind = status.boundary?.link;
|
|
1709
|
+
if (linkKind === 'codex-home') {
|
|
1710
|
+
return {
|
|
1711
|
+
target: 'agent',
|
|
1712
|
+
code: 'AGENT_PATH_CONFLICT',
|
|
1713
|
+
message: 'the Codex home is a link or reparse point, so nothing below it is written or removed',
|
|
1714
|
+
path: status.codexHome,
|
|
1715
|
+
reason: 'codex-home-is-link',
|
|
1716
|
+
};
|
|
1717
|
+
}
|
|
1718
|
+
if (linkKind === 'skills') {
|
|
1719
|
+
return {
|
|
1720
|
+
target: 'agent',
|
|
1721
|
+
code: 'AGENT_PATH_CONFLICT',
|
|
1722
|
+
message: 'the skills directory is a link or reparse point, so nothing inside it is written or removed',
|
|
1723
|
+
path: join(status.codexHome, 'skills'),
|
|
1724
|
+
reason: 'skills-dir-is-link',
|
|
1725
|
+
};
|
|
1726
|
+
}
|
|
1727
|
+
if (linkKind === 'skill-dir') {
|
|
1728
|
+
return {
|
|
1729
|
+
target: 'agent',
|
|
1730
|
+
code: 'AGENT_PATH_CONFLICT',
|
|
1731
|
+
message: 'the skills/dsh-taskbridge directory is a link or reparse point, so nothing inside it is written or removed',
|
|
1732
|
+
path: join(status.codexHome, 'skills', SKILL_DIR_NAME),
|
|
1733
|
+
reason: 'skill-dir-is-link',
|
|
1734
|
+
};
|
|
1735
|
+
}
|
|
1474
1736
|
return {
|
|
1475
1737
|
target: 'agent',
|
|
1476
1738
|
code: 'AGENT_PATH_CONFLICT',
|
|
1477
|
-
message:
|
|
1478
|
-
|
|
1479
|
-
|
|
1480
|
-
path: isHome ? status.codexHome : join(status.codexHome, 'agents'),
|
|
1481
|
-
reason: isHome ? 'codex-home-is-link' : 'agents-dir-is-link',
|
|
1739
|
+
message: 'the agents directory is a link or reparse point, so nothing inside it is written or removed',
|
|
1740
|
+
path: join(status.codexHome, 'agents'),
|
|
1741
|
+
reason: 'agents-dir-is-link',
|
|
1482
1742
|
};
|
|
1483
1743
|
}
|
|
1484
1744
|
|
|
@@ -2697,8 +2957,14 @@ export function removeMcpEntry(document) {
|
|
|
2697
2957
|
* @returns {string} file contents, LF-terminated.
|
|
2698
2958
|
*/
|
|
2699
2959
|
export function renderAgentFile(template, version) {
|
|
2700
|
-
const marker = `version = ${renderString(version)}`;
|
|
2701
2960
|
const text = normalizeLineEndings(template);
|
|
2961
|
+
if (SKILL_VERSION_LINE.test(text)) {
|
|
2962
|
+
return text.replace(SKILL_VERSION_LINE, `<!-- dsh-taskbridge-version: ${version} -->`);
|
|
2963
|
+
}
|
|
2964
|
+
if (/^---\n[\s\S]*?\n---\n/u.test(text)) {
|
|
2965
|
+
return text.replace(/^(---\n[\s\S]*?\n---\n)/u, `$1<!-- dsh-taskbridge-version: ${version} -->\n`);
|
|
2966
|
+
}
|
|
2967
|
+
const marker = `version = ${renderString(version)}`;
|
|
2702
2968
|
if (/^version = ".*"$/mu.test(text)) return text.replace(/^version = ".*"$/mu, marker);
|
|
2703
2969
|
// Keep the provenance header first, then the version marker, then the rest.
|
|
2704
2970
|
const lines = text.split('\n');
|
|
@@ -2708,6 +2974,8 @@ export function renderAgentFile(template, version) {
|
|
|
2708
2974
|
return lines.join('\n');
|
|
2709
2975
|
}
|
|
2710
2976
|
|
|
2977
|
+
export { renderAgentFile as renderSkillFile };
|
|
2978
|
+
|
|
2711
2979
|
/**
|
|
2712
2980
|
* Read and parse the Codex config, or return an empty document.
|
|
2713
2981
|
* @param {string} configPath - config file path.
|
|
@@ -2757,30 +3025,60 @@ export async function readCodexStatus({
|
|
|
2757
3025
|
// against that real path.
|
|
2758
3026
|
const pinned = await pinCodexHome(selected);
|
|
2759
3027
|
const home = pinned.real;
|
|
2760
|
-
const
|
|
3028
|
+
const skillPath = join(home, 'skills', SKILL_DIR_NAME, SKILL_FILENAME);
|
|
2761
3029
|
const configPath = join(home, 'config.toml');
|
|
2762
3030
|
const packageVersionValue = version ?? await readPackageVersion();
|
|
2763
3031
|
const template = renderAgentFile(await readAgentTemplate(), packageVersionValue);
|
|
2764
|
-
// The boundary first: a link at the Codex home or at `agents` means the agent path
|
|
2765
|
-
// does not name a file this plugin may touch, whatever `lstat` would say about it.
|
|
2766
3032
|
const boundary = pinned.error === null
|
|
2767
3033
|
? await inspectCodexBoundary(home)
|
|
2768
|
-
|
|
2769
|
-
|
|
2770
|
-
|
|
2771
|
-
|
|
3034
|
+
: {
|
|
3035
|
+
blocked: true,
|
|
3036
|
+
link: null,
|
|
3037
|
+
unknown: false,
|
|
3038
|
+
home: { kind: 'link' },
|
|
3039
|
+
skills: { kind: 'unchecked' },
|
|
3040
|
+
skillDir: { kind: 'unchecked' },
|
|
3041
|
+
agents: { kind: 'unchecked' },
|
|
3042
|
+
};
|
|
3043
|
+
const boundaryReason = boundary.unknown === true
|
|
3044
|
+
? 'boundary-unverified'
|
|
3045
|
+
: (pinned.error?.reason ?? (
|
|
3046
|
+
boundary.link === 'codex-home' ? 'codex-home-is-link'
|
|
3047
|
+
: boundary.link === 'skills' ? 'skills-dir-is-link'
|
|
3048
|
+
: boundary.link === 'skill-dir' ? 'skill-dir-is-link'
|
|
3049
|
+
: 'agents-dir-is-link'
|
|
3050
|
+
));
|
|
3051
|
+
const skillPathBlocked = !boundary.blocked && (boundary.skills?.kind === 'other' || boundary.skillDir?.kind === 'other');
|
|
3052
|
+
const ownershipBatch = createBatchedKindClassifier();
|
|
3053
|
+
const needSkillRecord = !boundary.blocked && !skillPathBlocked;
|
|
3054
|
+
const needAgentRecord = !boundary.blocked && boundary.agents?.kind === 'directory';
|
|
3055
|
+
if (needSkillRecord || needAgentRecord) {
|
|
3056
|
+
const primeDirs = [];
|
|
3057
|
+
const skillRecPath = needSkillRecord ? skillOwnershipRecordPath(home, env) : null;
|
|
3058
|
+
const agentRecPath = needAgentRecord ? ownershipRecordPath(home, env) : null;
|
|
3059
|
+
for (const recPath of [skillRecPath, agentRecPath]) {
|
|
3060
|
+
if (recPath !== null) primeDirs.push(...chainPathsOf(dirname(recPath)));
|
|
3061
|
+
}
|
|
3062
|
+
if (primeDirs.length > 0) await ownershipBatch.classifyMany(primeDirs);
|
|
3063
|
+
}
|
|
2772
3064
|
const agent = boundary.blocked
|
|
2773
3065
|
? {
|
|
2774
3066
|
state: AGENT_STATES.conflict,
|
|
2775
3067
|
present: false,
|
|
2776
|
-
reason:
|
|
2777
|
-
? 'boundary-unverified'
|
|
2778
|
-
// A selected ROOT that could not be pinned reports WHY (missing target, not a
|
|
2779
|
-
// directory) instead of the generic "is a link".
|
|
2780
|
-
: (pinned.error?.reason ?? (boundary.link === 'codex-home' ? 'codex-home-is-link' : 'agents-dir-is-link')),
|
|
3068
|
+
reason: boundaryReason,
|
|
2781
3069
|
contents: null,
|
|
2782
3070
|
}
|
|
2783
|
-
:
|
|
3071
|
+
: skillPathBlocked
|
|
3072
|
+
? {
|
|
3073
|
+
state: AGENT_STATES.conflict,
|
|
3074
|
+
present: true,
|
|
3075
|
+
reason: 'not-a-regular-file',
|
|
3076
|
+
contents: null,
|
|
3077
|
+
}
|
|
3078
|
+
: await readAgentState(skillPath, template, await recallRecordedSkillTemplate(home, env, ownershipBatch));
|
|
3079
|
+
const legacyAgents = needAgentRecord
|
|
3080
|
+
? await inspectLegacyAgents(home, await recallRecordedTemplate(home, env, ownershipBatch))
|
|
3081
|
+
: { state: 'absent', entries: [] };
|
|
2784
3082
|
// A READ never writes: this function classifies the files and records nothing. The template
|
|
2785
3083
|
// digest is recorded only by `install` and by the startup `refreshKnownAgentTemplate`, after
|
|
2786
3084
|
// those actions themselves wrote and re-proved the file.
|
|
@@ -2823,16 +3121,10 @@ export async function readCodexStatus({
|
|
|
2823
3121
|
*/
|
|
2824
3122
|
let configFingerprint = null;
|
|
2825
3123
|
if (boundary.blocked) {
|
|
2826
|
-
// A link (or an unverifiable directory) at `$CODEX_HOME` or `$CODEX_HOME/agents`
|
|
2827
|
-
// bounds EVERY write this module makes, not only the agent file. The MCP entry is
|
|
2828
|
-
// described by the same verdict instead of by a read-through of the link: reporting
|
|
2829
|
-
// it as `outdated` from inside the linked tree, and then refusing to write, is how a
|
|
2830
|
-
// link would have been followed for a READ. Nothing below the boundary is examined.
|
|
2831
3124
|
mcp = {
|
|
2832
3125
|
state: MCP_STATES.conflict,
|
|
2833
3126
|
previous: null,
|
|
2834
|
-
reason:
|
|
2835
|
-
: (boundary.link === 'codex-home' ? 'codex-home-is-link' : 'agents-dir-is-link'),
|
|
3127
|
+
reason: boundaryReason,
|
|
2836
3128
|
ownedValues: {},
|
|
2837
3129
|
marked: false,
|
|
2838
3130
|
drift: null,
|
|
@@ -2872,10 +3164,11 @@ export async function readCodexStatus({
|
|
|
2872
3164
|
codexHomeSelected: pinned.selected,
|
|
2873
3165
|
codexHomeLinked: pinned.linked,
|
|
2874
3166
|
codexHomeLinkTarget: pinned.linkTarget,
|
|
2875
|
-
agentPath,
|
|
3167
|
+
agentPath: skillPath,
|
|
2876
3168
|
configPath,
|
|
2877
3169
|
packageVersionValue,
|
|
2878
3170
|
agent,
|
|
3171
|
+
legacyAgents,
|
|
2879
3172
|
mcp,
|
|
2880
3173
|
desired,
|
|
2881
3174
|
script,
|
|
@@ -2920,6 +3213,7 @@ function buildStatus({
|
|
|
2920
3213
|
configPath,
|
|
2921
3214
|
packageVersionValue,
|
|
2922
3215
|
agent,
|
|
3216
|
+
legacyAgents = { state: 'absent', entries: [] },
|
|
2923
3217
|
mcp,
|
|
2924
3218
|
desired,
|
|
2925
3219
|
script,
|
|
@@ -2933,43 +3227,36 @@ function buildStatus({
|
|
|
2933
3227
|
}) {
|
|
2934
3228
|
const agentOk = agent.state === AGENT_STATES.installed;
|
|
2935
3229
|
const mcpOk = mcp.state === MCP_STATES.configured;
|
|
3230
|
+
const skillTarget = {
|
|
3231
|
+
kind: 'skill',
|
|
3232
|
+
path: agentPath,
|
|
3233
|
+
state: agent.state,
|
|
3234
|
+
installed: agentOk,
|
|
3235
|
+
managed: agent.state !== AGENT_STATES.conflict && agent.state !== AGENT_STATES.modified,
|
|
3236
|
+
reason: agent.reason ?? null,
|
|
3237
|
+
expect: agent.contents ?? null,
|
|
3238
|
+
recorded: agent.recorded === true,
|
|
3239
|
+
};
|
|
2936
3240
|
return {
|
|
2937
3241
|
codexHome,
|
|
2938
|
-
// The selected spelling and whether it was a root link, kept beside the REAL path so
|
|
2939
|
-
// an operator who configured a junction recognises the answer without guessing.
|
|
2940
3242
|
codexHomeSelected: codexHomeSelected ?? codexHome,
|
|
2941
3243
|
codexHomeLinked: codexHomeLinked === true,
|
|
2942
3244
|
codexHomeLinkTarget,
|
|
2943
3245
|
packageVersion: packageVersionValue,
|
|
2944
|
-
// Whether the two directories that bound every write are real directories. A link
|
|
2945
|
-
// at either one is a stable diagnosis, not an installation state: install, repair
|
|
2946
|
-
// and remove all refuse while `blocked` is true.
|
|
2947
3246
|
boundary: boundary === null
|
|
2948
|
-
? { blocked: false, link: null, unknown: false, home: 'unknown', agents: 'unknown' }
|
|
3247
|
+
? { blocked: false, link: null, unknown: false, home: 'unknown', skills: 'unknown', skillDir: 'unknown', agents: 'unknown' }
|
|
2949
3248
|
: {
|
|
2950
3249
|
blocked: boundary.blocked === true,
|
|
2951
3250
|
link: boundary.blocked === true ? boundary.link : null,
|
|
2952
3251
|
unknown: boundary.unknown === true,
|
|
2953
3252
|
home: boundary.home.kind,
|
|
3253
|
+
skills: boundary.skills?.kind ?? 'unknown',
|
|
3254
|
+
skillDir: boundary.skillDir?.kind ?? 'unknown',
|
|
2954
3255
|
agents: boundary.agents.kind,
|
|
2955
3256
|
},
|
|
2956
|
-
|
|
2957
|
-
|
|
2958
|
-
|
|
2959
|
-
// Stated once here so no caller has to infer it from a state name.
|
|
2960
|
-
installed: agentOk,
|
|
2961
|
-
managed: agent.state !== AGENT_STATES.conflict && agent.state !== AGENT_STATES.modified,
|
|
2962
|
-
reason: agent.reason ?? null,
|
|
2963
|
-
// The exact bytes a refresh is allowed to replace. Internal: `installManaged`
|
|
2964
|
-
// re-reads the file and compares against this immediately before its rename, so
|
|
2965
|
-
// a file edited between the status read and the write is never replaced.
|
|
2966
|
-
expect: agent.contents ?? null,
|
|
2967
|
-
// True when this file was recognised through the template digest recorded for THIS home
|
|
2968
|
-
// rather than through the enumerated published history. It never reaches a response
|
|
2969
|
-
// (`publicCodexStatus` strips it) and it never makes a state: an unproved file is still
|
|
2970
|
-
// `modified`.
|
|
2971
|
-
recorded: agent.recorded === true,
|
|
2972
|
-
},
|
|
3257
|
+
skill: skillTarget,
|
|
3258
|
+
agent: skillTarget,
|
|
3259
|
+
legacyAgents,
|
|
2973
3260
|
mcp: {
|
|
2974
3261
|
path: configPath,
|
|
2975
3262
|
exists: configPathInfo.exists === true,
|
|
@@ -2978,28 +3265,15 @@ function buildStatus({
|
|
|
2978
3265
|
configured: mcpOk,
|
|
2979
3266
|
previous: mcp.previous,
|
|
2980
3267
|
reason: mcp.reason,
|
|
2981
|
-
// WHICH owned facts are stale, as a list of stable names (`tool_timeout_sec`,
|
|
2982
|
-
// `args`, `command`, `env`) — or null when nothing is stale. A state name alone
|
|
2983
|
-
// ("outdated") does not tell an operator, or the panel, what would change.
|
|
2984
3268
|
drift: mcp.drift ?? null,
|
|
2985
|
-
// The digest of the whole config this classification was derived from. It travels
|
|
2986
|
-
// with the status only so the write path can prove the file has not changed since;
|
|
2987
|
-
// `publicCodexStatus` strips it, and it is a hash, never the text.
|
|
2988
3269
|
fingerprint: configFingerprint,
|
|
2989
|
-
// True only when the entry carries the plugin marker, i.e. when a later
|
|
2990
|
-
// `remove` may delete it. Values alone never establish ownership.
|
|
2991
3270
|
marked: mcp.marked === true,
|
|
2992
|
-
// `null` when no Node.js executable could be proved; `resolved: false` says so
|
|
2993
|
-
// explicitly so a consumer never has to test for `null` alone.
|
|
2994
3271
|
desired,
|
|
2995
3272
|
node,
|
|
2996
3273
|
nodeResolved: node !== null,
|
|
2997
|
-
// Why the executable could not be resolved (`MCP_EXECUTABLE_UNRESOLVED`), or
|
|
2998
|
-
// null. The app executable is never substituted for it.
|
|
2999
3274
|
nodeError,
|
|
3000
3275
|
script: script.script,
|
|
3001
3276
|
scriptExists: script.exists,
|
|
3002
|
-
// Only written to the file when DSH uses a non-default location.
|
|
3003
3277
|
discoveryFile: discovery.path,
|
|
3004
3278
|
discoveryPinned: discovery.pin,
|
|
3005
3279
|
},
|
|
@@ -3007,45 +3281,60 @@ function buildStatus({
|
|
|
3007
3281
|
? { readable: true, error: null }
|
|
3008
3282
|
: { readable: false, error: configError },
|
|
3009
3283
|
ready: agentOk && mcpOk && configError === null && node !== null,
|
|
3010
|
-
|
|
3011
|
-
notes: buildNotes({ agent, mcp, script, configError, nodeError }),
|
|
3284
|
+
notes: buildNotes({ agent, legacyAgents, mcp, script, configError, nodeError }),
|
|
3012
3285
|
};
|
|
3013
3286
|
}
|
|
3014
3287
|
|
|
3015
|
-
|
|
3016
|
-
* Operator-facing limitations of the current state.
|
|
3017
|
-
* @param {object} parts - collected facts.
|
|
3018
|
-
* @returns {object[]} `[{ code, text }]`.
|
|
3019
|
-
*/
|
|
3020
|
-
function buildNotes({ agent, mcp, script, configError, nodeError = null }) {
|
|
3288
|
+
function buildNotes({ agent, legacyAgents = { state: 'absent', entries: [] }, mcp, script, configError, nodeError = null }) {
|
|
3021
3289
|
const notes = [];
|
|
3022
3290
|
if (agent.state === AGENT_STATES.modified) {
|
|
3023
3291
|
notes.push({
|
|
3024
3292
|
code: 'AGENT_USER_MODIFIED',
|
|
3025
|
-
text:
|
|
3026
|
-
|
|
3027
|
-
|
|
3028
|
-
|
|
3029
|
-
|
|
3030
|
-
|
|
3031
|
-
: '它不是本插件发布过的模板,因此插件不会把它当作自己的文件;由你继续管理即可。'),
|
|
3293
|
+
text: agent.reason === 'reference-operator-owned'
|
|
3294
|
+
? 'Codex 技能的规则附页与发布内容不同。插件将保留入口和附页,由你继续管理。'
|
|
3295
|
+
: `已存在内容不同的 skills/${SKILL_DIR_NAME}/${SKILL_FILENAME},本插件不会覆盖或删除它。`
|
|
3296
|
+
+ (agent.reason === 'edited'
|
|
3297
|
+
? '它与本插件发布过的某个技能模板只在个别字节上不同(可能只改了版本注释或加了你自己的说明);改回该发布版本的原样内容后,本插件会自动更新它,否则由你继续管理。'
|
|
3298
|
+
: '它不是本插件发布过的技能模板,因此插件不会把它当作自己的文件;由你继续管理即可。'),
|
|
3032
3299
|
});
|
|
3033
3300
|
}
|
|
3034
3301
|
if (agent.state === AGENT_STATES.conflict) {
|
|
3035
|
-
// `AGENT_PATH_CONFLICT` covers two different physical situations, and the
|
|
3036
|
-
// operator needs to know which one: a link on the way to the file (home or
|
|
3037
|
-
// `agents/`), or a final path that is not a regular file (a link, a directory).
|
|
3038
3302
|
const text = agent.reason === 'codex-home-is-link'
|
|
3039
|
-
? `Codex home 本身是链接(符号链接或 Windows reparse point/junction),本插件不会穿过它写入或删除
|
|
3040
|
-
: agent.reason === '
|
|
3041
|
-
? `
|
|
3042
|
-
: agent.reason === '
|
|
3043
|
-
?
|
|
3044
|
-
:
|
|
3303
|
+
? `Codex home 本身是链接(符号链接或 Windows reparse point/junction),本插件不会穿过它写入或删除 skills/${SKILL_DIR_NAME}/${SKILL_FILENAME}。`
|
|
3304
|
+
: agent.reason === 'skills-dir-is-link'
|
|
3305
|
+
? `skills 目录是链接(符号链接或 Windows reparse point/junction),本插件不会穿过它写入或删除 ${SKILL_DIR_NAME}/${SKILL_FILENAME}。`
|
|
3306
|
+
: agent.reason === 'skill-dir-is-link'
|
|
3307
|
+
? `skills/${SKILL_DIR_NAME} 目录是链接(符号链接或 Windows reparse point/junction),本插件不会穿过它写入或删除 ${SKILL_FILENAME}。`
|
|
3308
|
+
: agent.reason === 'agents-dir-is-link'
|
|
3309
|
+
? `agents 目录是链接(符号链接或 Windows reparse point/junction),本插件不会穿过它写入或删除任何文件。`
|
|
3310
|
+
: agent.reason === 'boundary-unverified'
|
|
3311
|
+
? 'Codex home、skills 或 agents 目录无法确认是真实目录(可能缺少 Windows PowerShell),本插件不会写入或删除任何文件。'
|
|
3312
|
+
: `skills/${SKILL_DIR_NAME}/${SKILL_FILENAME} 不是普通文件(可能是链接或目录),本插件不会改动它。`;
|
|
3045
3313
|
notes.push({ code: 'AGENT_PATH_CONFLICT', text });
|
|
3046
3314
|
}
|
|
3047
3315
|
if (agent.state === AGENT_STATES.outdated) {
|
|
3048
|
-
notes.push({
|
|
3316
|
+
notes.push({
|
|
3317
|
+
code: 'AGENT_OUTDATED',
|
|
3318
|
+
text: agent.reason === 'reference-missing'
|
|
3319
|
+
? 'Codex 技能缺少规则附页。插件启动时会补齐,也可以点「安装 / 更新 TaskBridge 技能」恢复。'
|
|
3320
|
+
: '已安装的技能文件是旧版本(与某个已发布版本逐字节相同)。插件下次启动时会自动刷新为当前版本;也可以点「安装 / 更新 TaskBridge 技能」立即更新。',
|
|
3321
|
+
});
|
|
3322
|
+
}
|
|
3323
|
+
const managedLegacy = legacyAgents.entries.filter((entry) => entry.state === 'managed-legacy');
|
|
3324
|
+
if (managedLegacy.length > 0) {
|
|
3325
|
+
const list = managedLegacy.map((entry) => `agents/${entry.filename}`).join('、');
|
|
3326
|
+
notes.push({
|
|
3327
|
+
code: 'LEGACY_AGENT_MIGRATION_PENDING',
|
|
3328
|
+
text: `检测到旧版托管子智能体(${list})。1.9.0 起 Codex 改用原生技能 skills/${SKILL_DIR_NAME}/${SKILL_FILENAME} 在当前会话单链直等(避免 spawn_agent + wait_agent 短轮询);插件下次启动或点「安装 / 更新 TaskBridge 技能」时会自动迁移并移除未修改的旧子智能体文件。`,
|
|
3329
|
+
});
|
|
3330
|
+
}
|
|
3331
|
+
const modifiedLegacy = legacyAgents.entries.filter((entry) => entry.state === 'modified-legacy');
|
|
3332
|
+
if (modifiedLegacy.length > 0) {
|
|
3333
|
+
const list = modifiedLegacy.map((entry) => `agents/${entry.filename}`).join('、');
|
|
3334
|
+
notes.push({
|
|
3335
|
+
code: 'LEGACY_AGENT_USER_MODIFIED',
|
|
3336
|
+
text: `检测到已被手动修改的旧子智能体文件(${list}),本插件已原样保留不删。若你不希望 Codex 在主会话中派生旧子智能体触发 wait_agent 轮询,可手动将其移走或删除,改用原生技能 skills/${SKILL_DIR_NAME}/${SKILL_FILENAME}。`,
|
|
3337
|
+
});
|
|
3049
3338
|
}
|
|
3050
3339
|
if (mcp.state === MCP_STATES.conflict) {
|
|
3051
3340
|
notes.push({
|
|
@@ -3053,9 +3342,9 @@ function buildNotes({ agent, mcp, script, configError, nodeError = null }) {
|
|
|
3053
3342
|
text: mcp.reason === 'unmanaged-entry'
|
|
3054
3343
|
? `config.toml 中已有同名的 mcp_servers.${MCP_SERVER_NAME} 条目,但没有本插件的托管标记注释,视为你自己写的:本插件不会更新或删除它;请自行删除或改名后再点安装。`
|
|
3055
3344
|
: (mcp.reason === UNMANAGED_EXACT_REASON
|
|
3056
|
-
? `config.toml 中已有同名的 mcp_servers.${MCP_SERVER_NAME} 条目,内容与当前插件应写入的条目完全一致(命令、入口脚本、参数、超时与环境项都相同),只缺托管标记注释。点「仅修复 MCP 配置」只会补上这一行标记,不改动其他内容;「安装 / 更新
|
|
3345
|
+
? `config.toml 中已有同名的 mcp_servers.${MCP_SERVER_NAME} 条目,内容与当前插件应写入的条目完全一致(命令、入口脚本、参数、超时与环境项都相同),只缺托管标记注释。点「仅修复 MCP 配置」只会补上这一行标记,不改动其他内容;「安装 / 更新 TaskBridge 技能」不会替你接管它。`
|
|
3057
3346
|
: (mcp.reason === 'args-shape-not-ours'
|
|
3058
|
-
? `config.toml 中已有的 mcp_servers.${MCP_SERVER_NAME} 条目带托管标记,但入口脚本与当前安装不同。若那是本插件的另一处真实安装,点「安装 / 更新
|
|
3347
|
+
? `config.toml 中已有的 mcp_servers.${MCP_SERVER_NAME} 条目带托管标记,但入口脚本与当前安装不同。若那是本插件的另一处真实安装,点「安装 / 更新 TaskBridge 技能」或「仅修复 MCP 配置」会在证明后采纳;否则本插件不会替换它。`
|
|
3059
3348
|
: `config.toml 中已有同名的 mcp_servers.${MCP_SERVER_NAME} 条目,但内容不是本插件写入的形态(${mcp.reason ?? 'unknown'})。本插件不会替换它;请自行删除或改名后再点安装。`)),
|
|
3060
3349
|
});
|
|
3061
3350
|
}
|
|
@@ -3075,7 +3364,7 @@ function buildNotes({ agent, mcp, script, configError, nodeError = null }) {
|
|
|
3075
3364
|
if (drift.includes('env')) reasons.push(`其 env.${DISCOVERY_ENV_VAR} 与当前发现文件不一致`);
|
|
3076
3365
|
notes.push({
|
|
3077
3366
|
code: 'MCP_ENTRY_OUTDATED',
|
|
3078
|
-
text: `已安装的 mcp_servers.${MCP_SERVER_NAME} 是本插件写入的托管条目,但已经过期:${reasons.length === 0 ? '需要更新' : reasons.join(';')}。插件下次启动时会自动在原地更新它;也可以点「安装 / 更新
|
|
3367
|
+
text: `已安装的 mcp_servers.${MCP_SERVER_NAME} 是本插件写入的托管条目,但已经过期:${reasons.length === 0 ? '需要更新' : reasons.join(';')}。插件下次启动时会自动在原地更新它;也可以点「安装 / 更新 TaskBridge 技能」立即更新。`,
|
|
3079
3368
|
});
|
|
3080
3369
|
}
|
|
3081
3370
|
if (configError !== null) {
|
|
@@ -3209,11 +3498,29 @@ async function installManaged(before, outcome) {
|
|
|
3209
3498
|
await installMcpEntry(before, outcome);
|
|
3210
3499
|
}
|
|
3211
3500
|
|
|
3212
|
-
/**
|
|
3501
|
+
/**
|
|
3502
|
+
* Safely retire untouched legacy Codex subagent files (`agents/dsh-taskbridge.toml` and
|
|
3503
|
+
* `agents/dsh-delegate.toml`) after migrating to the native skill `skills/dsh-taskbridge/SKILL.md`.
|
|
3504
|
+
* User-modified files are NEVER deleted; every unlink re-proves byte-exact ownership immediately
|
|
3505
|
+
* before deleting.
|
|
3506
|
+
*/
|
|
3213
3507
|
async function migrateLegacyAgent(before, outcome, { removeOnly = false } = {}) {
|
|
3214
|
-
|
|
3215
|
-
const
|
|
3216
|
-
if (
|
|
3508
|
+
if (before.boundary?.blocked === true) return;
|
|
3509
|
+
const managedEntries = (before.legacyAgents?.entries ?? []).filter((entry) => entry.state === 'managed-legacy');
|
|
3510
|
+
if (managedEntries.length === 0) return;
|
|
3511
|
+
|
|
3512
|
+
// Re-prove at least one legacy managed file STILL matches its exact inspected bytes
|
|
3513
|
+
// before creating or updating the native skill, so a concurrent user edit between
|
|
3514
|
+
// `plan` and migration never triggers an unwanted skill creation or file deletion.
|
|
3515
|
+
const liveEntries = [];
|
|
3516
|
+
for (const entry of managedEntries) {
|
|
3517
|
+
const currentLegacy = await inspectFile(entry.path);
|
|
3518
|
+
if (currentLegacy.kind === 'file' && typeof entry.expect === 'string' && currentLegacy.contents === entry.expect) {
|
|
3519
|
+
liveEntries.push(entry);
|
|
3520
|
+
}
|
|
3521
|
+
}
|
|
3522
|
+
if (liveEntries.length === 0) return;
|
|
3523
|
+
|
|
3217
3524
|
if (!removeOnly) {
|
|
3218
3525
|
if (before.agent.state === AGENT_STATES.missing) {
|
|
3219
3526
|
const current = await inspectFile(before.agent.path);
|
|
@@ -3221,12 +3528,28 @@ async function migrateLegacyAgent(before, outcome, { removeOnly = false } = {})
|
|
|
3221
3528
|
}
|
|
3222
3529
|
const template = renderAgentFile(await readAgentTemplate(), before.packageVersion);
|
|
3223
3530
|
const current = await inspectFile(before.agent.path);
|
|
3224
|
-
|
|
3531
|
+
const reference = skillReference(before.agent.path, template);
|
|
3532
|
+
const installed = reference === null ? null : await inspectFile(reference.path);
|
|
3533
|
+
const referenceReady = installed === null
|
|
3534
|
+
|| (installed.kind === 'file' && !referenceConflicts(reference, installed));
|
|
3535
|
+
const skillReady = current.kind === 'file'
|
|
3536
|
+
&& ((sameAgentText(current.contents, template) && referenceReady)
|
|
3537
|
+
|| before.agent.state === AGENT_STATES.modified);
|
|
3538
|
+
if (!skillReady) return;
|
|
3539
|
+
}
|
|
3540
|
+
|
|
3541
|
+
for (const entry of liveEntries) {
|
|
3542
|
+
const currentLegacy = await inspectFile(entry.path);
|
|
3543
|
+
if (currentLegacy.kind !== 'file' || typeof entry.expect !== 'string' || currentLegacy.contents !== entry.expect) {
|
|
3544
|
+
continue;
|
|
3545
|
+
}
|
|
3546
|
+
try {
|
|
3547
|
+
await unlink(entry.path);
|
|
3548
|
+
if (!outcome.changed.includes('legacyAgent')) outcome.changed.push('legacyAgent');
|
|
3549
|
+
} catch (error) {
|
|
3550
|
+
if (error?.code !== 'ENOENT') throw error;
|
|
3551
|
+
}
|
|
3225
3552
|
}
|
|
3226
|
-
const currentLegacy = await inspectFile(legacyPath);
|
|
3227
|
-
if (currentLegacy.kind !== 'file' || currentLegacy.contents !== legacy.contents) return;
|
|
3228
|
-
await unlink(legacyPath);
|
|
3229
|
-
if (!outcome.changed.includes('agent')) outcome.changed.push('agent');
|
|
3230
3553
|
}
|
|
3231
3554
|
|
|
3232
3555
|
/**
|
|
@@ -3290,6 +3613,51 @@ export async function refreshKnownAgentTemplate(options = {}) {
|
|
|
3290
3613
|
return { changed, refused, status };
|
|
3291
3614
|
}
|
|
3292
3615
|
|
|
3616
|
+
function skillReference(entryPath, entry) {
|
|
3617
|
+
const match = entry?.match(SKILL_REFERENCE_LINK);
|
|
3618
|
+
if (!match) return null;
|
|
3619
|
+
const [, name, sha256] = match;
|
|
3620
|
+
return { name, sha256, path: join(dirname(entryPath), name) };
|
|
3621
|
+
}
|
|
3622
|
+
|
|
3623
|
+
function referenceConflicts(reference, inspected) {
|
|
3624
|
+
return inspected.kind !== 'missing'
|
|
3625
|
+
&& (inspected.kind !== 'file' || digestLf(inspected.contents) !== reference.sha256);
|
|
3626
|
+
}
|
|
3627
|
+
|
|
3628
|
+
function skillReferenceRefusal(path, reason) {
|
|
3629
|
+
return {
|
|
3630
|
+
target: 'agent',
|
|
3631
|
+
code: reason === 'reference-operator-owned' ? 'AGENT_USER_MODIFIED' : 'AGENT_PATH_CONFLICT',
|
|
3632
|
+
path,
|
|
3633
|
+
reason,
|
|
3634
|
+
message: 'the Codex skill reference could not be installed or removed safely',
|
|
3635
|
+
};
|
|
3636
|
+
}
|
|
3637
|
+
|
|
3638
|
+
// Publish a new reference alongside any older one. Replacing the entry switches versions;
|
|
3639
|
+
// Codex sessions which already loaded the old entry can still read their reference.
|
|
3640
|
+
async function installSkillReference(reference, outcome) {
|
|
3641
|
+
if (reference === null) return 'unchanged';
|
|
3642
|
+
const packaged = await inspectFile(join(dirname(TEMPLATE_PATH), reference.name));
|
|
3643
|
+
if (packaged.kind !== 'file' || digestLf(packaged.contents) !== reference.sha256) {
|
|
3644
|
+
outcome.refused.push(skillReferenceRefusal(reference.path,
|
|
3645
|
+
packaged.kind === 'missing' ? 'reference-not-packaged' : 'reference-template-mismatch'));
|
|
3646
|
+
return 'refused';
|
|
3647
|
+
}
|
|
3648
|
+
const current = await inspectFile(reference.path);
|
|
3649
|
+
if (referenceConflicts(reference, current)) {
|
|
3650
|
+
outcome.refused.push(skillReferenceRefusal(reference.path, 'reference-operator-owned'));
|
|
3651
|
+
return 'refused';
|
|
3652
|
+
}
|
|
3653
|
+
if (current.kind === 'file') return 'unchanged';
|
|
3654
|
+
if (await createFileExclusive(reference.path, packaged.contents) === 'created') return 'created';
|
|
3655
|
+
const raced = await inspectFile(reference.path);
|
|
3656
|
+
if (raced.kind === 'file' && !referenceConflicts(reference, raced)) return 'unchanged';
|
|
3657
|
+
outcome.refused.push(skillReferenceRefusal(reference.path, 'reference-created-concurrently'));
|
|
3658
|
+
return 'refused';
|
|
3659
|
+
}
|
|
3660
|
+
|
|
3293
3661
|
/**
|
|
3294
3662
|
* Install or refresh the managed agent file without touching the MCP entry.
|
|
3295
3663
|
*
|
|
@@ -3299,51 +3667,80 @@ export async function refreshKnownAgentTemplate(options = {}) {
|
|
|
3299
3667
|
*/
|
|
3300
3668
|
async function installManagedAgent(before, outcome) {
|
|
3301
3669
|
const { agent } = before;
|
|
3302
|
-
if (agent.state === AGENT_STATES.
|
|
3303
|
-
|
|
3304
|
-
|
|
3305
|
-
|
|
3306
|
-
|
|
3307
|
-
// and this write belongs to whoever created it, and is reported, not replaced.
|
|
3308
|
-
const created = await createFileExclusive(agent.path, template);
|
|
3309
|
-
if (created === 'exists') {
|
|
3310
|
-
outcome.refused.push({
|
|
3311
|
-
target: 'agent',
|
|
3312
|
-
code: 'AGENT_PATH_CONFLICT',
|
|
3313
|
-
message: 'an agent file appeared while installing and was left untouched',
|
|
3314
|
-
path: agent.path,
|
|
3315
|
-
reason: 'created-concurrently',
|
|
3316
|
-
});
|
|
3317
|
-
return;
|
|
3318
|
-
}
|
|
3319
|
-
await recordAgentTemplate(before);
|
|
3320
|
-
outcome.changed.push('agent');
|
|
3321
|
-
} else {
|
|
3322
|
-
// A refresh replaces a byte-exact known build of our own file. Re-check right
|
|
3323
|
-
// before writing: if the file changed in the meantime it is no longer that
|
|
3324
|
-
// known build, and the rename must not overwrite it.
|
|
3325
|
-
const current = await inspectFile(agent.path);
|
|
3326
|
-
if (current.kind !== 'file' || current.contents !== before.agent.expect) {
|
|
3327
|
-
outcome.refused.push({
|
|
3328
|
-
target: 'agent',
|
|
3329
|
-
code: 'AGENT_USER_MODIFIED',
|
|
3330
|
-
message: 'the agent file changed while updating and was left untouched',
|
|
3331
|
-
path: agent.path,
|
|
3332
|
-
});
|
|
3333
|
-
return;
|
|
3334
|
-
}
|
|
3335
|
-
await writeFileAtomic(agent.path, template);
|
|
3336
|
-
await recordAgentTemplate(before);
|
|
3337
|
-
outcome.changed.push('agent');
|
|
3670
|
+
if (agent.state === AGENT_STATES.installed) return;
|
|
3671
|
+
if (agent.state === AGENT_STATES.modified || agent.state === AGENT_STATES.conflict) {
|
|
3672
|
+
if (agent.reason === 'reference-operator-owned') {
|
|
3673
|
+
outcome.refused.push(skillReferenceRefusal(skillReference(agent.path, agent.expect).path, agent.reason));
|
|
3674
|
+
return;
|
|
3338
3675
|
}
|
|
3339
|
-
} else if (agent.state === AGENT_STATES.modified || agent.state === AGENT_STATES.conflict) {
|
|
3340
3676
|
outcome.refused.push({
|
|
3341
3677
|
target: 'agent',
|
|
3342
3678
|
code: agent.state === AGENT_STATES.modified ? 'AGENT_USER_MODIFIED' : 'AGENT_PATH_CONFLICT',
|
|
3343
3679
|
message: 'an agent file with different contents already exists and was left untouched',
|
|
3344
3680
|
path: agent.path,
|
|
3345
3681
|
});
|
|
3682
|
+
return;
|
|
3683
|
+
}
|
|
3684
|
+
|
|
3685
|
+
const boundary = await inspectCodexBoundary(before.codexHome);
|
|
3686
|
+
if (boundary.blocked) {
|
|
3687
|
+
outcome.refused.push(linkedBoundaryRefusal({ ...before, boundary }));
|
|
3688
|
+
return;
|
|
3689
|
+
}
|
|
3690
|
+
if (boundary.skills.kind === 'other' || boundary.skillDir.kind === 'other') {
|
|
3691
|
+
outcome.refused.push(skillReferenceRefusal(agent.path, 'reference-boundary-changed'));
|
|
3692
|
+
return;
|
|
3346
3693
|
}
|
|
3694
|
+
if (boundary.skillDir.kind !== 'directory') {
|
|
3695
|
+
await mkdir(dirname(agent.path), { recursive: true, mode: 0o700 });
|
|
3696
|
+
const liveBoundary = await inspectCodexBoundary(before.codexHome);
|
|
3697
|
+
if (liveBoundary.blocked || liveBoundary.skillDir.kind !== 'directory') {
|
|
3698
|
+
outcome.refused.push(skillReferenceRefusal(agent.path, 'reference-boundary-changed'));
|
|
3699
|
+
return;
|
|
3700
|
+
}
|
|
3701
|
+
}
|
|
3702
|
+
|
|
3703
|
+
const template = renderAgentFile(await readAgentTemplate(), before.packageVersion);
|
|
3704
|
+
const previous = skillReference(agent.path, agent.expect);
|
|
3705
|
+
const reference = await installSkillReference(skillReference(agent.path, template), outcome);
|
|
3706
|
+
if (reference === 'refused') return;
|
|
3707
|
+
|
|
3708
|
+
if (agent.state === AGENT_STATES.missing) {
|
|
3709
|
+
const created = await createFileExclusive(agent.path, template);
|
|
3710
|
+
if (created === 'exists') {
|
|
3711
|
+
outcome.refused.push({
|
|
3712
|
+
target: 'agent',
|
|
3713
|
+
code: 'AGENT_PATH_CONFLICT',
|
|
3714
|
+
message: 'an agent file appeared while installing and was left untouched',
|
|
3715
|
+
path: agent.path,
|
|
3716
|
+
reason: 'created-concurrently',
|
|
3717
|
+
});
|
|
3718
|
+
return;
|
|
3719
|
+
}
|
|
3720
|
+
} else {
|
|
3721
|
+
if (previous !== null && referenceConflicts(previous, await inspectFile(previous.path))) {
|
|
3722
|
+
outcome.refused.push(skillReferenceRefusal(previous.path, 'reference-operator-owned'));
|
|
3723
|
+
return;
|
|
3724
|
+
}
|
|
3725
|
+
const current = await inspectFile(agent.path);
|
|
3726
|
+
if (current.kind !== 'file' || current.contents !== agent.expect) {
|
|
3727
|
+
outcome.refused.push({
|
|
3728
|
+
target: 'agent',
|
|
3729
|
+
code: 'AGENT_USER_MODIFIED',
|
|
3730
|
+
message: 'the agent file changed while updating and was left untouched',
|
|
3731
|
+
path: agent.path,
|
|
3732
|
+
});
|
|
3733
|
+
return;
|
|
3734
|
+
}
|
|
3735
|
+
if (sameAgentText(current.contents, template)) {
|
|
3736
|
+
// Restored a missing reference for the current entry. Its ownership record still applies.
|
|
3737
|
+
if (reference === 'created') outcome.changed.push('agent');
|
|
3738
|
+
return;
|
|
3739
|
+
}
|
|
3740
|
+
await writeFileAtomic(agent.path, template);
|
|
3741
|
+
}
|
|
3742
|
+
await recordAgentTemplate(before);
|
|
3743
|
+
outcome.changed.push('agent');
|
|
3347
3744
|
}
|
|
3348
3745
|
|
|
3349
3746
|
/**
|
|
@@ -3582,7 +3979,7 @@ async function upgradeOutdatedMcpEntry(before, outcome, options = {}) {
|
|
|
3582
3979
|
);
|
|
3583
3980
|
if (gate.owned !== true) {
|
|
3584
3981
|
refuse('MCP_ENTRY_CONFLICT',
|
|
3585
|
-
'the stale mcp_servers.dsh-delegate entry
|
|
3982
|
+
'the stale mcp_servers.dsh-delegate entry could not be verified as owned and was left untouched. 安装 / 更新 TaskBridge 技能 can update entries from a verifiable previous installation',
|
|
3586
3983
|
{ reason: gate.reason });
|
|
3587
3984
|
return;
|
|
3588
3985
|
}
|
|
@@ -3890,6 +4287,7 @@ export async function removeManagedAgentFile(agent) {
|
|
|
3890
4287
|
}
|
|
3891
4288
|
try {
|
|
3892
4289
|
await unlink(agent.path);
|
|
4290
|
+
await rmdir(dirname(agent.path)).catch(() => {});
|
|
3893
4291
|
} catch (error) {
|
|
3894
4292
|
if (error?.code === 'ENOENT') {
|
|
3895
4293
|
// Raced away between the read and the unlink; still not a change of ours.
|
|
@@ -3924,16 +4322,33 @@ export async function removeManagedAgentFile(agent) {
|
|
|
3924
4322
|
async function removeManaged(before, outcome) {
|
|
3925
4323
|
const { agent, mcp } = before;
|
|
3926
4324
|
if (agent.state === AGENT_STATES.installed || agent.state === AGENT_STATES.outdated) {
|
|
3927
|
-
const
|
|
3928
|
-
|
|
3929
|
-
|
|
4325
|
+
const reference = skillReference(agent.path, agent.expect);
|
|
4326
|
+
const verdict = reference !== null && referenceConflicts(reference, await inspectFile(reference.path))
|
|
4327
|
+
? skillReferenceRefusal(reference.path, 'reference-operator-owned')
|
|
4328
|
+
: await removeManagedAgentFile(agent);
|
|
4329
|
+
if (verdict.code === null) {
|
|
4330
|
+
outcome.changed.push('agent');
|
|
4331
|
+
if (reference !== null) {
|
|
4332
|
+
const current = await inspectFile(reference.path);
|
|
4333
|
+
if (referenceConflicts(reference, current)) {
|
|
4334
|
+
outcome.refused.push(skillReferenceRefusal(reference.path, 'reference-operator-owned'));
|
|
4335
|
+
} else if (current.kind === 'file') {
|
|
4336
|
+
const removed = await removeManagedAgentFile({ path: reference.path, expect: current.contents });
|
|
4337
|
+
if (removed.code !== null) outcome.refused.push(removed);
|
|
4338
|
+
}
|
|
4339
|
+
}
|
|
4340
|
+
} else outcome.refused.push(verdict);
|
|
3930
4341
|
} else if (agent.state === AGENT_STATES.modified) {
|
|
3931
|
-
|
|
3932
|
-
|
|
3933
|
-
|
|
3934
|
-
|
|
3935
|
-
|
|
3936
|
-
|
|
4342
|
+
if (agent.reason === 'reference-operator-owned') {
|
|
4343
|
+
outcome.refused.push(skillReferenceRefusal(skillReference(agent.path, agent.expect).path, agent.reason));
|
|
4344
|
+
} else {
|
|
4345
|
+
outcome.refused.push({
|
|
4346
|
+
target: 'agent',
|
|
4347
|
+
code: 'AGENT_USER_MODIFIED',
|
|
4348
|
+
message: 'the agent file differs from the managed template and was left untouched',
|
|
4349
|
+
path: agent.path,
|
|
4350
|
+
});
|
|
4351
|
+
}
|
|
3937
4352
|
} else if (agent.state === AGENT_STATES.conflict) {
|
|
3938
4353
|
outcome.refused.push({
|
|
3939
4354
|
target: 'agent',
|
|
@@ -3996,24 +4411,29 @@ async function removeManaged(before, outcome) {
|
|
|
3996
4411
|
export function publicCodexStatus(status) {
|
|
3997
4412
|
if (status === null || typeof status !== 'object') return status;
|
|
3998
4413
|
const { expect: _ignored, recorded: _record, ...agent } = status.agent ?? {};
|
|
3999
|
-
|
|
4000
|
-
|
|
4001
|
-
|
|
4414
|
+
const { expect: _skillIgnored, recorded: _skillRecord, ...skill } = status.skill ?? agent;
|
|
4415
|
+
const legacyAgents = status.legacyAgents && typeof status.legacyAgents === 'object'
|
|
4416
|
+
? {
|
|
4417
|
+
state: status.legacyAgents.state ?? 'absent',
|
|
4418
|
+
entries: Array.isArray(status.legacyAgents.entries)
|
|
4419
|
+
? status.legacyAgents.entries.map(({ expect: _legacyExpect, ...entry }) => entry)
|
|
4420
|
+
: [],
|
|
4421
|
+
}
|
|
4422
|
+
: { state: 'absent', entries: [] };
|
|
4002
4423
|
const { fingerprint: _receipt, ...mcp } = status.mcp ?? {};
|
|
4003
|
-
return { ...status, agent, mcp };
|
|
4424
|
+
return { ...status, skill, agent, legacyAgents, mcp };
|
|
4004
4425
|
}
|
|
4005
4426
|
|
|
4006
4427
|
/**
|
|
4007
|
-
* Load the shipped
|
|
4008
|
-
*
|
|
4009
|
-
* Exported so a test can assert the shipped dispatch rules independently of the
|
|
4010
|
-
* installed copy.
|
|
4011
|
-
* @returns {Promise<{ text: string, instructions: string }>} template text and its developer instructions.
|
|
4428
|
+
* Load the shipped Codex skill template (or legacy TOML template) and its instruction body.
|
|
4429
|
+
* @returns {Promise<{ text: string, instructions: string }>} template text and instructions.
|
|
4012
4430
|
*/
|
|
4013
4431
|
export async function readAgentInstructions() {
|
|
4014
4432
|
const text = await readAgentTemplate();
|
|
4015
|
-
const
|
|
4016
|
-
return { text, instructions:
|
|
4433
|
+
const tomlMatch = /developer_instructions = """([\s\S]*?)"""/u.exec(text);
|
|
4434
|
+
if (tomlMatch !== null) return { text, instructions: tomlMatch[1] };
|
|
4435
|
+
const stripped = normalizeLineEndings(text).replace(/^---\n[\s\S]*?\n---\n/u, '');
|
|
4436
|
+
return { text, instructions: stripped };
|
|
4017
4437
|
}
|
|
4018
4438
|
|
|
4019
4439
|
/**
|