@shuind/dsh-codex-harness 0.2.15 → 0.2.16
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +9 -3
- package/docs/preset-library.md +21 -0
- package/lib/client.js +4583 -515
- package/lib/index.js +379 -4
- package/lib/types/client/index.d.ts +31 -20
- package/lib/types/client/index.js +63 -185
- package/lib/types/client/preset-copy.d.ts +30 -0
- package/lib/types/client/preset-copy.js +57 -0
- package/lib/types/client/preset-manager.d.ts +22 -0
- package/lib/types/client/preset-manager.js +156 -0
- package/lib/types/index.d.ts +11 -0
- package/lib/types/index.js +44 -1
- package/lib/types/preset-contract.d.ts +58 -0
- package/lib/types/preset-contract.js +22 -0
- package/lib/types/preset-editor-remote.d.ts +30 -0
- package/lib/types/preset-editor-remote.js +36 -0
- package/lib/types/preset-editor.d.ts +58 -0
- package/lib/types/preset-editor.js +332 -0
- package/lib/types/preset-templates.d.ts +36 -0
- package/lib/types/preset-templates.js +12 -0
- package/package.json +39 -20
package/lib/index.js
CHANGED
|
@@ -1,13 +1,16 @@
|
|
|
1
1
|
import z from "@deepseek-ai/schemastery";
|
|
2
2
|
import { defineTool } from "@deepseek-ai/dsh-tools";
|
|
3
|
-
import { randomBytes, randomUUID } from "node:crypto";
|
|
4
|
-
import { join, resolve } from "node:path";
|
|
3
|
+
import { createHash, randomBytes, randomUUID } from "node:crypto";
|
|
4
|
+
import { dirname, isAbsolute, join, relative, resolve } from "node:path";
|
|
5
5
|
import { credentialRef } from "@deepseek-ai/dsh-credentials";
|
|
6
6
|
import { AsyncLocalStorage } from "node:async_hooks";
|
|
7
7
|
import { mkdirSync, writeFileSync } from "node:fs";
|
|
8
8
|
import { homedir } from "node:os";
|
|
9
9
|
import { z as z$1 } from "zod";
|
|
10
10
|
import BasicCompactionEngine from "@deepseek-ai/dsh-compaction-basic";
|
|
11
|
+
import { readFile, realpath, stat, unlink } from "node:fs/promises";
|
|
12
|
+
import { Remote, TypertRemoteService } from "@deepseek-ai/dsh-typert-protocol";
|
|
13
|
+
import { Scalar, YAMLMap, isMap, isScalar, isSeq, parseDocument } from "yaml";
|
|
11
14
|
//#region lib/types/patch.js
|
|
12
15
|
/** Parser and line-oriented applicator for Codex's `apply_patch` language. */
|
|
13
16
|
const APPLY_PATCH_DESCRIPTION = "Edits files using Codex patch syntax with Begin/End Patch markers and file update directives. In hunk lines, the first character is the operation marker; repeat a source-leading marker when the source line itself starts with one.";
|
|
@@ -1379,6 +1382,339 @@ function withDurableContextCapacity(llm, ctx, activeSession) {
|
|
|
1379
1382
|
}
|
|
1380
1383
|
});
|
|
1381
1384
|
//#endregion
|
|
1385
|
+
//#region lib/types/preset-editor.js
|
|
1386
|
+
let atomicWriteModule;
|
|
1387
|
+
function loadAtomicWrite() {
|
|
1388
|
+
return atomicWriteModule ??= import("@deepseek-ai/dsh-atomic-write");
|
|
1389
|
+
}
|
|
1390
|
+
const PRESET_ID = /^[A-Za-z0-9][A-Za-z0-9_-]{0,63}$/;
|
|
1391
|
+
const DEFAULT_CODEX_PRESET_OPTIONS = {
|
|
1392
|
+
promptEnabled: true,
|
|
1393
|
+
terminalToolsEnabled: true,
|
|
1394
|
+
patchToolEnabled: true,
|
|
1395
|
+
planToolEnabled: true,
|
|
1396
|
+
hostedWebSearchEnabled: true,
|
|
1397
|
+
remoteCompactionEnabled: true
|
|
1398
|
+
};
|
|
1399
|
+
const CODEX_OPTION_KEYS = Object.keys(DEFAULT_CODEX_PRESET_OPTIONS);
|
|
1400
|
+
/** Parse tags as syntax only; never execute !!js or resolve aliases into objects. */
|
|
1401
|
+
function yaml(content) {
|
|
1402
|
+
const doc = parseDocument(content, {
|
|
1403
|
+
strict: true,
|
|
1404
|
+
uniqueKeys: true
|
|
1405
|
+
});
|
|
1406
|
+
if (doc.errors.length) throw new Error("invalid-preset-yaml");
|
|
1407
|
+
return doc;
|
|
1408
|
+
}
|
|
1409
|
+
function harnessConfig(content) {
|
|
1410
|
+
const doc = yaml(content);
|
|
1411
|
+
if (!isSeq(doc.contents)) throw new Error("unsupported-preset");
|
|
1412
|
+
const rows = doc.contents.items.filter((row) => isMap(row) && row.get("name") === "@shuind/dsh-codex-harness" && row.get("disabled") !== true);
|
|
1413
|
+
if (rows.length !== 1) throw new Error("unsupported-preset");
|
|
1414
|
+
const row = rows[0];
|
|
1415
|
+
let config = row.get("config", true);
|
|
1416
|
+
if (config === void 0) {
|
|
1417
|
+
config = new YAMLMap();
|
|
1418
|
+
row.set("config", config);
|
|
1419
|
+
}
|
|
1420
|
+
if (!isMap(config) || config.get("codexCore") === false) throw new Error("unsupported-preset");
|
|
1421
|
+
return {
|
|
1422
|
+
doc,
|
|
1423
|
+
config
|
|
1424
|
+
};
|
|
1425
|
+
}
|
|
1426
|
+
function explicitPrompt(content) {
|
|
1427
|
+
const { config } = harnessConfig(content);
|
|
1428
|
+
const node = config.get("presetPrompt", true) ?? config.get("systemPrompt", true);
|
|
1429
|
+
if (node === void 0) return void 0;
|
|
1430
|
+
if (!isScalar(node) || typeof node.value !== "string" || node.tag) throw new Error("unsupported-prompt-expression");
|
|
1431
|
+
return node.value;
|
|
1432
|
+
}
|
|
1433
|
+
function readCodexPresetOptions(content) {
|
|
1434
|
+
try {
|
|
1435
|
+
const { config } = harnessConfig(content);
|
|
1436
|
+
const options = { ...DEFAULT_CODEX_PRESET_OPTIONS };
|
|
1437
|
+
for (const key of CODEX_OPTION_KEYS) {
|
|
1438
|
+
const value = config.get(key);
|
|
1439
|
+
if (typeof value === "boolean") options[key] = value;
|
|
1440
|
+
}
|
|
1441
|
+
return options;
|
|
1442
|
+
} catch {
|
|
1443
|
+
return { ...DEFAULT_CODEX_PRESET_OPTIONS };
|
|
1444
|
+
}
|
|
1445
|
+
}
|
|
1446
|
+
function supportsCodex(content) {
|
|
1447
|
+
try {
|
|
1448
|
+
harnessConfig(content);
|
|
1449
|
+
return true;
|
|
1450
|
+
} catch {
|
|
1451
|
+
return false;
|
|
1452
|
+
}
|
|
1453
|
+
}
|
|
1454
|
+
/** Structural validation only: executable tags stay inert until DSH mounts a selected preset. */
|
|
1455
|
+
function validateComposition(content) {
|
|
1456
|
+
if (content.length > 1e6) throw new Error("invalid-preset-yaml");
|
|
1457
|
+
const doc = yaml(content);
|
|
1458
|
+
if (!isSeq(doc.contents) || !doc.contents.items.length) throw new Error("invalid-preset-yaml");
|
|
1459
|
+
const ids = /* @__PURE__ */ new Set();
|
|
1460
|
+
for (const entry of doc.contents.items) {
|
|
1461
|
+
if (!isMap(entry)) throw new Error("invalid-preset-yaml");
|
|
1462
|
+
const row = entry;
|
|
1463
|
+
if (typeof row.get("name") !== "string") throw new Error("invalid-preset-yaml");
|
|
1464
|
+
const id = row.get("id");
|
|
1465
|
+
if (typeof id !== "string" || ids.has(id)) throw new Error("invalid-preset-yaml");
|
|
1466
|
+
ids.add(id);
|
|
1467
|
+
}
|
|
1468
|
+
}
|
|
1469
|
+
function enhanceComposition(content) {
|
|
1470
|
+
validateComposition(content);
|
|
1471
|
+
if (supportsCodex(content)) return content;
|
|
1472
|
+
const doc = yaml(content);
|
|
1473
|
+
if (!isSeq(doc.contents)) throw new Error("invalid-preset-yaml");
|
|
1474
|
+
if (doc.contents.items.some((row) => isMap(row) && row.get("name") === "@shuind/dsh-codex-harness")) throw new Error("ambiguous-harness-row");
|
|
1475
|
+
for (const row of doc.contents.items) {
|
|
1476
|
+
if (!isMap(row) || row.get("name") !== "@deepseek-ai/dsh-persona") continue;
|
|
1477
|
+
const persona = row.get("config", true);
|
|
1478
|
+
if (isMap(persona) && persona.get("complete") === true) persona.set("complete", false);
|
|
1479
|
+
}
|
|
1480
|
+
doc.add(doc.createNode({
|
|
1481
|
+
id: `codex-harness-${randomUUID().slice(0, 8)}`,
|
|
1482
|
+
name: "@shuind/dsh-codex-harness",
|
|
1483
|
+
config: {
|
|
1484
|
+
globalEnhancements: false,
|
|
1485
|
+
codexCore: true
|
|
1486
|
+
}
|
|
1487
|
+
}));
|
|
1488
|
+
return doc.toString({ lineWidth: 0 });
|
|
1489
|
+
}
|
|
1490
|
+
function patchPresetComposition(content, prompt, inherit = false) {
|
|
1491
|
+
const { doc, config } = harnessConfig(content);
|
|
1492
|
+
config.delete("systemPrompt");
|
|
1493
|
+
if (inherit) config.delete("presetPrompt");
|
|
1494
|
+
else {
|
|
1495
|
+
const node = new Scalar(prompt);
|
|
1496
|
+
node.type = prompt.includes("\n") ? Scalar.BLOCK_LITERAL : Scalar.QUOTE_DOUBLE;
|
|
1497
|
+
config.set("presetPrompt", node);
|
|
1498
|
+
}
|
|
1499
|
+
return doc.toString({ lineWidth: 0 });
|
|
1500
|
+
}
|
|
1501
|
+
/** Store user-facing Codex capability switches in the Harness row. */
|
|
1502
|
+
function patchCodexPresetOptions(content, options) {
|
|
1503
|
+
const { doc, config } = harnessConfig(content);
|
|
1504
|
+
for (const key of CODEX_OPTION_KEYS) {
|
|
1505
|
+
const value = options[key];
|
|
1506
|
+
if (value !== void 0) config.set(key, value);
|
|
1507
|
+
}
|
|
1508
|
+
return doc.toString({ lineWidth: 0 });
|
|
1509
|
+
}
|
|
1510
|
+
function patchPresetMetadata(content, name, description) {
|
|
1511
|
+
const doc = yaml(content);
|
|
1512
|
+
if (doc.contents !== null && !isMap(doc.contents)) throw new Error("invalid-preset-metadata");
|
|
1513
|
+
for (const [key, value] of Object.entries({
|
|
1514
|
+
name,
|
|
1515
|
+
description
|
|
1516
|
+
})) {
|
|
1517
|
+
const node = new Scalar(value);
|
|
1518
|
+
node.type = Scalar.QUOTE_DOUBLE;
|
|
1519
|
+
doc.set(key, node);
|
|
1520
|
+
}
|
|
1521
|
+
return doc.toString({ lineWidth: 0 });
|
|
1522
|
+
}
|
|
1523
|
+
function validate(input) {
|
|
1524
|
+
if (typeof input.name !== "string" || !input.name.trim() || /[\r\n]/.test(input.name) || input.name.length > 200) throw new Error("invalid-preset-name");
|
|
1525
|
+
if (typeof input.description !== "string" || input.description.length > 4e3) throw new Error("invalid-preset-description");
|
|
1526
|
+
if (typeof input.systemPrompt !== "string" || input.systemPrompt.length > 1e6) throw new Error("invalid-preset-prompt");
|
|
1527
|
+
return {
|
|
1528
|
+
...input,
|
|
1529
|
+
name: input.name.trim()
|
|
1530
|
+
};
|
|
1531
|
+
}
|
|
1532
|
+
function revision(composition, metadata) {
|
|
1533
|
+
return createHash("sha256").update(composition).update("\0").update(metadata ?? "").digest("hex");
|
|
1534
|
+
}
|
|
1535
|
+
async function optionalFile(path) {
|
|
1536
|
+
try {
|
|
1537
|
+
return await readFile(path, "utf8");
|
|
1538
|
+
} catch (error) {
|
|
1539
|
+
if (error.code === "ENOENT") return void 0;
|
|
1540
|
+
throw error;
|
|
1541
|
+
}
|
|
1542
|
+
}
|
|
1543
|
+
async function mode(path) {
|
|
1544
|
+
try {
|
|
1545
|
+
return (await stat(path)).mode & 511;
|
|
1546
|
+
} catch {
|
|
1547
|
+
return 384;
|
|
1548
|
+
}
|
|
1549
|
+
}
|
|
1550
|
+
async function assertWithinRoot(path, roots) {
|
|
1551
|
+
if (!roots?.length) throw new Error("preset-root-unavailable");
|
|
1552
|
+
const target = await realpath(path);
|
|
1553
|
+
for (const root of roots) {
|
|
1554
|
+
if (root.trust !== "user") continue;
|
|
1555
|
+
const home = process.env.DSH_HOME ?? process.env.USERPROFILE ?? process.env.HOME ?? "";
|
|
1556
|
+
const expanded = root.path.replace(/^~(?=[\\/]|$)/, home);
|
|
1557
|
+
try {
|
|
1558
|
+
const rel = relative(await realpath(resolve(expanded)), target);
|
|
1559
|
+
if (!isAbsolute(rel) && rel !== ".." && !rel.startsWith("../") && !rel.startsWith("..\\")) return;
|
|
1560
|
+
} catch {}
|
|
1561
|
+
}
|
|
1562
|
+
throw new Error("preset-outside-user-root");
|
|
1563
|
+
}
|
|
1564
|
+
var CodexPresetEditor = class extends TypertRemoteService {
|
|
1565
|
+
static inject = ["agentPresets"];
|
|
1566
|
+
agentPresets;
|
|
1567
|
+
constructor(ctx, _config) {
|
|
1568
|
+
super(ctx, "codexPresetEditor");
|
|
1569
|
+
this.agentPresets = ctx.get("agentPresets");
|
|
1570
|
+
}
|
|
1571
|
+
async catalog() {
|
|
1572
|
+
const roster = await this.agentPresets.remoteExportList();
|
|
1573
|
+
const presets = roster.presets.filter((row) => row.broken === void 0).map((row) => ({
|
|
1574
|
+
id: row.id,
|
|
1575
|
+
name: row.name || row.id,
|
|
1576
|
+
description: row.description ?? "",
|
|
1577
|
+
editable: row.trust === "user",
|
|
1578
|
+
isDefault: row.isDefault
|
|
1579
|
+
}));
|
|
1580
|
+
return {
|
|
1581
|
+
presets,
|
|
1582
|
+
authorable: roster.authorable,
|
|
1583
|
+
excludedCount: roster.presets.length - presets.length
|
|
1584
|
+
};
|
|
1585
|
+
}
|
|
1586
|
+
async read(id) {
|
|
1587
|
+
const preset = await this.preset(id);
|
|
1588
|
+
const composition = await readFile(preset.path, "utf8");
|
|
1589
|
+
const metadata = await optionalFile(resolve(dirname(preset.path), "preset.yml"));
|
|
1590
|
+
const meta = metadata ? yaml(metadata) : void 0;
|
|
1591
|
+
validateComposition(composition);
|
|
1592
|
+
const codex = supportsCodex(composition);
|
|
1593
|
+
const prompt = codex ? explicitPrompt(composition) : void 0;
|
|
1594
|
+
return {
|
|
1595
|
+
id,
|
|
1596
|
+
name: String(meta?.get("name") ?? id),
|
|
1597
|
+
description: String(meta?.get("description") ?? ""),
|
|
1598
|
+
systemPrompt: prompt ?? DEFAULT_CODEX_SYSTEM_PROMPT,
|
|
1599
|
+
inheritPrompt: prompt === void 0,
|
|
1600
|
+
revision: revision(composition, metadata),
|
|
1601
|
+
editable: preset.trust === "user",
|
|
1602
|
+
codex,
|
|
1603
|
+
codexOptions: readCodexPresetOptions(composition),
|
|
1604
|
+
composition
|
|
1605
|
+
};
|
|
1606
|
+
}
|
|
1607
|
+
async create(rawInput) {
|
|
1608
|
+
const input = validate(rawInput);
|
|
1609
|
+
await this.preset(input.sourceId);
|
|
1610
|
+
const id = `codex-${randomUUID().slice(0, 12)}`;
|
|
1611
|
+
await this.agentPresets.copy(input.sourceId, id, input.name);
|
|
1612
|
+
try {
|
|
1613
|
+
const copy = await this.read(id);
|
|
1614
|
+
const base = input.composition ?? copy.composition;
|
|
1615
|
+
let next = input.enableCodex ? enhanceComposition(base) : base;
|
|
1616
|
+
if (supportsCodex(next)) {
|
|
1617
|
+
next = patchPresetComposition(next, input.systemPrompt, input.inheritPrompt);
|
|
1618
|
+
next = patchCodexPresetOptions(next, input.codexOptions ?? {});
|
|
1619
|
+
}
|
|
1620
|
+
return await this.update({
|
|
1621
|
+
...input,
|
|
1622
|
+
id,
|
|
1623
|
+
revision: copy.revision,
|
|
1624
|
+
composition: next
|
|
1625
|
+
});
|
|
1626
|
+
} catch (error) {
|
|
1627
|
+
await this.agentPresets.remove(id);
|
|
1628
|
+
throw error;
|
|
1629
|
+
}
|
|
1630
|
+
}
|
|
1631
|
+
async update(rawInput) {
|
|
1632
|
+
const input = validate(rawInput);
|
|
1633
|
+
const preset = await this.preset(input.id);
|
|
1634
|
+
if (preset.trust !== "user") throw new Error("built-in presets cannot be edited here");
|
|
1635
|
+
const composition = resolve(preset.path);
|
|
1636
|
+
if (composition.split(/[\\/]/).at(-1) !== "agent.cordis.yml") throw new Error("invalid-preset-path");
|
|
1637
|
+
await assertWithinRoot(composition, this.agentPresets.roots);
|
|
1638
|
+
const metadata = resolve(dirname(composition), "preset.yml");
|
|
1639
|
+
if (await optionalFile(metadata) !== void 0) await assertWithinRoot(metadata, this.agentPresets.roots);
|
|
1640
|
+
const { withFileLock, writeFileAtomic } = await loadAtomicWrite();
|
|
1641
|
+
return withFileLock(composition, async () => {
|
|
1642
|
+
const oldComposition = await readFile(composition, "utf8");
|
|
1643
|
+
const oldMetadata = await optionalFile(metadata);
|
|
1644
|
+
if (input.revision !== void 0 && input.revision !== revision(oldComposition, oldMetadata)) throw new Error("preset-conflict");
|
|
1645
|
+
const editedComposition = input.composition !== void 0 ? input.composition : oldComposition;
|
|
1646
|
+
let nextComposition = input.enableCodex && !supportsCodex(editedComposition) ? enhanceComposition(editedComposition) : editedComposition;
|
|
1647
|
+
if (supportsCodex(nextComposition)) {
|
|
1648
|
+
nextComposition = patchPresetComposition(nextComposition, input.systemPrompt, input.inheritPrompt);
|
|
1649
|
+
if (input.codexOptions !== void 0) nextComposition = patchCodexPresetOptions(nextComposition, input.codexOptions);
|
|
1650
|
+
}
|
|
1651
|
+
validateComposition(nextComposition);
|
|
1652
|
+
const nextMetadata = patchPresetMetadata(oldMetadata ?? "", input.name, input.description);
|
|
1653
|
+
const compositionMode = await mode(composition);
|
|
1654
|
+
const metadataMode = await mode(metadata);
|
|
1655
|
+
await writeFileAtomic(resolve(dirname(composition), ".codex-editor-backup.json"), JSON.stringify({
|
|
1656
|
+
composition: oldComposition,
|
|
1657
|
+
metadata: oldMetadata ?? null
|
|
1658
|
+
}), {
|
|
1659
|
+
mode: 384,
|
|
1660
|
+
dirMode: 448
|
|
1661
|
+
});
|
|
1662
|
+
try {
|
|
1663
|
+
await writeFileAtomic(composition, nextComposition, {
|
|
1664
|
+
mode: compositionMode,
|
|
1665
|
+
dirMode: 448
|
|
1666
|
+
});
|
|
1667
|
+
await writeFileAtomic(metadata, nextMetadata, {
|
|
1668
|
+
mode: metadataMode,
|
|
1669
|
+
dirMode: 448
|
|
1670
|
+
});
|
|
1671
|
+
if ((await this.agentPresets.resolve(input.id)).broken !== void 0) throw new Error("invalid-preset-after-save");
|
|
1672
|
+
return await this.read(input.id);
|
|
1673
|
+
} catch (error) {
|
|
1674
|
+
await writeFileAtomic(composition, oldComposition, {
|
|
1675
|
+
mode: compositionMode,
|
|
1676
|
+
dirMode: 448
|
|
1677
|
+
});
|
|
1678
|
+
if (oldMetadata !== void 0) await writeFileAtomic(metadata, oldMetadata, {
|
|
1679
|
+
mode: metadataMode,
|
|
1680
|
+
dirMode: 448
|
|
1681
|
+
});
|
|
1682
|
+
else await unlink(metadata).catch((cause) => {
|
|
1683
|
+
if (cause.code !== "ENOENT") throw cause;
|
|
1684
|
+
});
|
|
1685
|
+
throw error;
|
|
1686
|
+
}
|
|
1687
|
+
}, { waitMs: 1e4 });
|
|
1688
|
+
}
|
|
1689
|
+
async preset(id) {
|
|
1690
|
+
if (!PRESET_ID.test(id)) throw new Error("invalid-preset-id");
|
|
1691
|
+
const preset = await this.agentPresets.resolve(id);
|
|
1692
|
+
if (preset.broken !== void 0) throw new Error("invalid-preset");
|
|
1693
|
+
return preset;
|
|
1694
|
+
}
|
|
1695
|
+
};
|
|
1696
|
+
function markRemoteMethod(methodName) {
|
|
1697
|
+
const descriptor = Object.getOwnPropertyDescriptor(CodexPresetEditor.prototype, methodName);
|
|
1698
|
+
const initializers = [];
|
|
1699
|
+
Remote(methodName)(descriptor.value, {
|
|
1700
|
+
kind: "method",
|
|
1701
|
+
name: methodName,
|
|
1702
|
+
static: false,
|
|
1703
|
+
private: false,
|
|
1704
|
+
addInitializer: (initializer) => {
|
|
1705
|
+
initializers.push(initializer);
|
|
1706
|
+
}
|
|
1707
|
+
});
|
|
1708
|
+
const receiver = Object.create(CodexPresetEditor.prototype);
|
|
1709
|
+
for (const initializer of initializers) initializer.call(receiver);
|
|
1710
|
+
}
|
|
1711
|
+
for (const method of [
|
|
1712
|
+
"read",
|
|
1713
|
+
"update",
|
|
1714
|
+
"catalog",
|
|
1715
|
+
"create"
|
|
1716
|
+
]) markRemoteMethod(method);
|
|
1717
|
+
//#endregion
|
|
1382
1718
|
//#region lib/types/index.js
|
|
1383
1719
|
/** Codex-compatible prompt overlay and core tools for a dsh agent preset. */
|
|
1384
1720
|
const name = "codex";
|
|
@@ -1392,6 +1728,19 @@ const inject = [
|
|
|
1392
1728
|
"settings"
|
|
1393
1729
|
];
|
|
1394
1730
|
const DEFAULT_MAX_OUTPUT_BYTES = 1048576;
|
|
1731
|
+
/** Add the preset editor when DSH's optional user-preset service is available. */
|
|
1732
|
+
function installPresetEditor(ctx) {
|
|
1733
|
+
ctx.inject(["agentPresets"], (presetCtx) => {
|
|
1734
|
+
(async () => {
|
|
1735
|
+
try {
|
|
1736
|
+
await presetCtx.plugin(CodexPresetEditor);
|
|
1737
|
+
} catch (error) {
|
|
1738
|
+
ctx.logger.warn("codex: preset editor is unavailable on this host");
|
|
1739
|
+
ctx.logger.warn(error);
|
|
1740
|
+
}
|
|
1741
|
+
})();
|
|
1742
|
+
});
|
|
1743
|
+
}
|
|
1395
1744
|
/** Runtime configuration schema for the Codex tool bridge. */
|
|
1396
1745
|
const Config = z.object({
|
|
1397
1746
|
globalEnhancements: z.boolean().default(true),
|
|
@@ -1403,6 +1752,13 @@ const Config = z.object({
|
|
|
1403
1752
|
hostedWebSearch: z.boolean().default(true),
|
|
1404
1753
|
remoteCompact: z.boolean().default(true),
|
|
1405
1754
|
systemPrompt: z.string().default(DEFAULT_CODEX_SYSTEM_PROMPT),
|
|
1755
|
+
presetPrompt: z.string(),
|
|
1756
|
+
promptEnabled: z.boolean(),
|
|
1757
|
+
terminalToolsEnabled: z.boolean(),
|
|
1758
|
+
patchToolEnabled: z.boolean(),
|
|
1759
|
+
planToolEnabled: z.boolean(),
|
|
1760
|
+
hostedWebSearchEnabled: z.boolean(),
|
|
1761
|
+
remoteCompactionEnabled: z.boolean(),
|
|
1406
1762
|
persona: z.string().default(DEFAULT_CODEX_PERSONA),
|
|
1407
1763
|
harnessSourcePrompt: z.string().default(DEFAULT_DSH_CORE_SOURCE_PROMPT),
|
|
1408
1764
|
webSurfacePrompt: z.string().default(DEFAULT_DSH_CORE_WEB_PROMPT)
|
|
@@ -2069,8 +2425,16 @@ function registerPlanTool(ctx, currentSettings) {
|
|
|
2069
2425
|
}
|
|
2070
2426
|
}));
|
|
2071
2427
|
}
|
|
2428
|
+
/** Explicit preset instructions win without changing shared tools or permissions. */
|
|
2429
|
+
function withPresetPrompt(settings, presetPrompt) {
|
|
2430
|
+
return presetPrompt === void 0 ? settings : {
|
|
2431
|
+
...settings,
|
|
2432
|
+
systemPrompt: presetPrompt
|
|
2433
|
+
};
|
|
2434
|
+
}
|
|
2072
2435
|
/** Mount the Codex prompt/tool layer inside one fixed agent preset. */
|
|
2073
2436
|
function apply(ctx, config = {}) {
|
|
2437
|
+
installPresetEditor(ctx);
|
|
2074
2438
|
const resolved = {
|
|
2075
2439
|
globalEnhancements: config.globalEnhancements ?? true,
|
|
2076
2440
|
codexCore: config.codexCore ?? true,
|
|
@@ -2086,7 +2450,18 @@ function apply(ctx, config = {}) {
|
|
|
2086
2450
|
webSurfacePrompt: config.webSurfacePrompt ?? DEFAULT_DSH_CORE_WEB_PROMPT
|
|
2087
2451
|
};
|
|
2088
2452
|
if (resolved.codexCore && ctx.fs.sandboxMode !== void 0 && ctx.get("sandboxPolicy") === void 0) throw new Error("codex: a sandboxing filesystem requires ctx.sandboxPolicy");
|
|
2089
|
-
const
|
|
2453
|
+
const sharedSettings = installCodexSettings(ctx, resolved.systemPrompt, resolved.persona, resolved.harnessSourcePrompt, resolved.webSurfacePrompt);
|
|
2454
|
+
const codexSettings = { current: () => {
|
|
2455
|
+
return {
|
|
2456
|
+
...withPresetPrompt(sharedSettings.current(), config.presetPrompt),
|
|
2457
|
+
...config.promptEnabled === void 0 ? {} : { promptEnabled: config.promptEnabled },
|
|
2458
|
+
...config.terminalToolsEnabled === void 0 ? {} : { terminalToolsEnabled: config.terminalToolsEnabled },
|
|
2459
|
+
...config.patchToolEnabled === void 0 ? {} : { patchToolEnabled: config.patchToolEnabled },
|
|
2460
|
+
...config.planToolEnabled === void 0 ? {} : { planToolEnabled: config.planToolEnabled },
|
|
2461
|
+
...config.hostedWebSearchEnabled === void 0 ? {} : { hostedWebSearchEnabled: config.hostedWebSearchEnabled },
|
|
2462
|
+
...config.remoteCompactionEnabled === void 0 ? {} : { remoteCompactionEnabled: config.remoteCompactionEnabled }
|
|
2463
|
+
};
|
|
2464
|
+
} };
|
|
2090
2465
|
const execConfig = {
|
|
2091
2466
|
...resolved,
|
|
2092
2467
|
currentSettings: codexSettings.current
|
|
@@ -2141,4 +2516,4 @@ var types_default = {
|
|
|
2141
2516
|
apply
|
|
2142
2517
|
};
|
|
2143
2518
|
//#endregion
|
|
2144
|
-
export { CODEX_SETTINGS_NAMESPACE, CODEX_SETTINGS_SCHEMA, Config, DEFAULT_CODEX_PERSONA, DEFAULT_CODEX_SYSTEM_PROMPT, DEFAULT_DSH_CORE_SOURCE_PROMPT, DEFAULT_DSH_CORE_WEB_PROMPT, apply, applyCodexCapabilitySettings, applyCodexRequestSettings, buildCodexSystemPrompt, types_default as default, enrichCodexModel, inject, name, normalizeCodexPromptAssembly, syncCodexContextWindow };
|
|
2519
|
+
export { CODEX_SETTINGS_NAMESPACE, CODEX_SETTINGS_SCHEMA, Config, DEFAULT_CODEX_PERSONA, DEFAULT_CODEX_SYSTEM_PROMPT, DEFAULT_DSH_CORE_SOURCE_PROMPT, DEFAULT_DSH_CORE_WEB_PROMPT, apply, applyCodexCapabilitySettings, applyCodexRequestSettings, buildCodexSystemPrompt, types_default as default, enrichCodexModel, inject, name, normalizeCodexPromptAssembly, syncCodexContextWindow, withPresetPrompt };
|
|
@@ -4,6 +4,7 @@ import type { Context } from '@deepseek-ai/cordis';
|
|
|
4
4
|
import type { SettingsScope } from '@deepseek-ai/dsh-client-runtime/client';
|
|
5
5
|
import type { CodexActivity } from '../activity-types.ts';
|
|
6
6
|
import { modelActivity } from './activity.ts';
|
|
7
|
+
import type { PresetManagerActions } from './preset-manager.tsx';
|
|
7
8
|
declare const LEGACY_OVERLAY_SLOT: "conversation.input.overlay";
|
|
8
9
|
interface CodexSettings {
|
|
9
10
|
fast: boolean;
|
|
@@ -32,13 +33,10 @@ declare const en: {
|
|
|
32
33
|
readonly contextSizeDescription: "Next request capacity in K tokens.";
|
|
33
34
|
readonly contextRestore: "Restore model default";
|
|
34
35
|
readonly promptCardTitle: "Codex Harness";
|
|
35
|
-
readonly promptCardDescription: "
|
|
36
|
-
readonly
|
|
37
|
-
readonly otherCapabilitiesLabel: "Additional capabilities";
|
|
36
|
+
readonly promptCardDescription: "Edit presets and their Codex capabilities. Activity status is global.";
|
|
37
|
+
readonly otherCapabilitiesLabel: "Global capabilities";
|
|
38
38
|
readonly capabilityPrompt: "Codex operating prompt";
|
|
39
39
|
readonly capabilityPromptHint: "Inject the editable instructions and persona-first prompt layout.";
|
|
40
|
-
readonly capabilityFast: "Fast mode control";
|
|
41
|
-
readonly capabilityFastHint: "Show the Fast mode switch beside the conversation composer.";
|
|
42
40
|
readonly compactRemote: "Remote compaction";
|
|
43
41
|
readonly compactRemoteHint: "Use the provider remote compaction endpoint first.";
|
|
44
42
|
readonly compactLocal: "Local compaction";
|
|
@@ -55,27 +53,39 @@ declare const en: {
|
|
|
55
53
|
readonly capabilityCompactionHint: "Prefer the provider Responses compact endpoint before local compaction.";
|
|
56
54
|
readonly capabilityActivity: "Activity indicator";
|
|
57
55
|
readonly capabilityActivityHint: "Show request, reply, and compaction status beside the conversation.";
|
|
58
|
-
readonly promptCustomizationLabel: "Prompt customization";
|
|
59
|
-
readonly personaLabel: "Persona";
|
|
60
|
-
readonly personaHint: "Deployment identity and role. Supports {{model}} and {{cwd}}.";
|
|
61
|
-
readonly sourcePromptLabel: "DSH Core source instructions";
|
|
62
|
-
readonly sourcePromptHint: "Guidance about the DSH checkout and working directory. Supports {{sourceRoot}}.";
|
|
63
|
-
readonly webPromptLabel: "DSH Core Web instructions";
|
|
64
|
-
readonly webPromptHint: "Guidance about this Web GUI, HMR, builds, and verification. Supports {{webUrl}}.";
|
|
65
|
-
readonly promptRestoreAll: "Restore all prompt defaults";
|
|
66
56
|
readonly promptLabel: "Codex operating prompt";
|
|
67
|
-
readonly promptHint: "This is the Codex operating prompt. Persona and DSH Core instructions are edited separately above.";
|
|
68
|
-
readonly promptUnsaved: "Unsaved";
|
|
69
|
-
readonly promptDiscard: "Discard";
|
|
70
|
-
readonly promptSave: "Save";
|
|
71
|
-
readonly promptSaving: "Saving...";
|
|
72
|
-
readonly promptSaveFailed: "Could not save the prompt.";
|
|
73
57
|
readonly promptExpand: "Expand settings";
|
|
74
58
|
readonly promptCollapse: "Collapse settings";
|
|
75
59
|
readonly promptReadOnly: "This settings document is read-only.";
|
|
76
60
|
readonly activityCompacting: "Compacting context...";
|
|
77
61
|
readonly activityRequestingModel: "Requesting model...";
|
|
78
62
|
readonly activityModelReply: "Model replying...";
|
|
63
|
+
readonly peTitle: "Preset editor";
|
|
64
|
+
readonly peHierarchy: "Codex mode and other presets are peers. Choose one to edit, or make an editable copy of a built-in preset first.";
|
|
65
|
+
readonly peSelect: "Preset";
|
|
66
|
+
readonly peSelectPlaceholder: "Choose a preset…";
|
|
67
|
+
readonly peEditable: "This is an editable user preset.";
|
|
68
|
+
readonly peBuiltinEdit: "Built-in presets are read-only. Create a copy to edit it.";
|
|
69
|
+
readonly peCreateCopy: "Create editable copy";
|
|
70
|
+
readonly peCodexSection: "Codex mode capabilities";
|
|
71
|
+
readonly peAddCodex: "Add Codex capabilities to this preset";
|
|
72
|
+
readonly peAddCodexHint: "Adds the Codex prompt, tools, hosted search, and remote compaction to this preset.";
|
|
73
|
+
readonly peActivityGlobal: "Activity status is a global display setting and is shared by all presets.";
|
|
74
|
+
readonly peSaveCopy: "Save new preset";
|
|
75
|
+
readonly peSaved: "Saved. Select this preset in a new conversation.";
|
|
76
|
+
readonly pmGlobalSettings: "Global settings";
|
|
77
|
+
readonly pmRefresh: "Refresh";
|
|
78
|
+
readonly pmBuiltIn: "Built-in";
|
|
79
|
+
readonly pmCustom: "Custom";
|
|
80
|
+
readonly pmDiscard: "Discard your unsaved changes?";
|
|
81
|
+
readonly pmConflict: "This preset changed in another page or on disk. Reopen the latest version before saving.";
|
|
82
|
+
readonly pmYamlError: "The configuration must be valid YAML. Your draft has not been saved.";
|
|
83
|
+
readonly pmErrorDetails: "Technical details";
|
|
84
|
+
readonly pmSaveError: "Could not complete this action. Your draft is still here.";
|
|
85
|
+
readonly pmName: "Name";
|
|
86
|
+
readonly pmDescription: "Description";
|
|
87
|
+
readonly pmCancel: "Cancel";
|
|
88
|
+
readonly pmSave: "Save changes";
|
|
79
89
|
};
|
|
80
90
|
type CodexKey = keyof typeof en;
|
|
81
91
|
declare module '@deepseek-ai/dsh-client-ui-slots' {
|
|
@@ -102,8 +112,9 @@ interface InputSettingsControlInjected {
|
|
|
102
112
|
};
|
|
103
113
|
setSetting: (field: string, value: unknown) => Promise<void>;
|
|
104
114
|
unsetSetting: (field: string) => Promise<void>;
|
|
115
|
+
presetManager: PresetManagerActions;
|
|
105
116
|
}
|
|
106
|
-
/**
|
|
117
|
+
/** Preset editor and global activity control contributed to Settings > Plugins. */
|
|
107
118
|
export declare function PromptSettingsCard(props: PropsRuntime<'settings.plugin.item'> & InjectFace<InputSettingsControlInjected> & PropsLocale<'codex'>): import("react").JSX.Element | null;
|
|
108
119
|
type LegacyOverlayProps = PropsRuntime<typeof LEGACY_OVERLAY_SLOT> & InjectFace<InputSettingsControlInjected> & PropsLocale<'codex'>;
|
|
109
120
|
type ActivityProps = Pick<LegacyOverlayProps, 'sessionId' | 'useSession' | 'useSessions' | 'useProjection' | 'useSettings' | 't'>;
|