@shuind/dsh-codex-harness 0.2.16 → 0.2.18
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/docs/preset-library.md +20 -18
- package/lib/client.js +300 -177
- package/lib/index.js +266 -13
- package/lib/typert.js +117 -0
- package/lib/types/client/index.d.ts +28 -2
- package/lib/types/client/index.js +32 -62
- package/lib/types/client/preset-copy.d.ts +12 -0
- package/lib/types/client/preset-copy.js +24 -0
- package/lib/types/client/preset-manager.js +70 -9
- package/lib/types/client/preset-requests.d.ts +4 -0
- package/lib/types/client/preset-requests.js +19 -0
- package/lib/types/index.d.ts +1 -0
- package/lib/types/index.js +3 -1
- package/lib/types/preset-contract.d.ts +11 -0
- package/lib/types/preset-editor-remote.js +4 -3
- package/lib/types/preset-editor.d.ts +12 -1
- package/lib/types/preset-editor.js +234 -9
- package/lib/types/prompt-sections.d.ts +15 -0
- package/lib/types/prompt-sections.js +23 -0
- package/lib/types/typert.host.d.ts +47 -0
- package/lib/types/typert.host.js +99 -0
- package/package.json +296 -285
package/lib/index.js
CHANGED
|
@@ -1430,6 +1430,180 @@ function explicitPrompt(content) {
|
|
|
1430
1430
|
if (!isScalar(node) || typeof node.value !== "string" || node.tag) throw new Error("unsupported-prompt-expression");
|
|
1431
1431
|
return node.value;
|
|
1432
1432
|
}
|
|
1433
|
+
const SECTION_PLUGIN = "@shuind/dsh-codex-harness/prompt-sections";
|
|
1434
|
+
function promptFile(node) {
|
|
1435
|
+
if (!node.tag || typeof node.value !== "string") return void 0;
|
|
1436
|
+
return node.value.match(/^process\.getBuiltinModule\(['"]node:fs['"]\)\.readFileSync\(new URL\(['"]([^'"]+)['"],\s*baseUrl\),\s*['"]utf8['"]\)$/)?.[1];
|
|
1437
|
+
}
|
|
1438
|
+
/** Read the actual literal prompt fields, including nested groups, without evaluating YAML tags. */
|
|
1439
|
+
function promptFields(doc) {
|
|
1440
|
+
const fields = [];
|
|
1441
|
+
function visit(sequence, parents = []) {
|
|
1442
|
+
if (!isSeq(sequence)) return;
|
|
1443
|
+
for (const row of sequence.items) {
|
|
1444
|
+
if (!isMap(row) || row.get("disabled") === true) continue;
|
|
1445
|
+
const path = [...parents, String(row.get("id"))];
|
|
1446
|
+
const config = row.get("config", true);
|
|
1447
|
+
if (isSeq(config)) {
|
|
1448
|
+
visit(config, path);
|
|
1449
|
+
continue;
|
|
1450
|
+
}
|
|
1451
|
+
if (!isMap(config)) continue;
|
|
1452
|
+
const plugin = String(row.get("name"));
|
|
1453
|
+
if (plugin === "@deepseek-ai/dsh-plan-mode") continue;
|
|
1454
|
+
const keys = plugin === "@deepseek-ai/dsh-persona" ? [
|
|
1455
|
+
"prefix",
|
|
1456
|
+
"text",
|
|
1457
|
+
"suffix"
|
|
1458
|
+
] : plugin === "@shuind/dsh-codex-harness" || plugin === SECTION_PLUGIN ? [] : [
|
|
1459
|
+
"prefix",
|
|
1460
|
+
"suffix",
|
|
1461
|
+
"text",
|
|
1462
|
+
"section",
|
|
1463
|
+
"prompt",
|
|
1464
|
+
"systemPrompt",
|
|
1465
|
+
"instructions"
|
|
1466
|
+
];
|
|
1467
|
+
for (const key of keys) {
|
|
1468
|
+
const node = config.get(key, true);
|
|
1469
|
+
if (!isScalar(node)) continue;
|
|
1470
|
+
fields.push({
|
|
1471
|
+
id: JSON.stringify([...path, key]),
|
|
1472
|
+
label: plugin === "@deepseek-ai/dsh-persona" ? key === "suffix" ? "Persona · suffix" : "Persona" : `${path.join(" / ")} · ${key}`,
|
|
1473
|
+
node,
|
|
1474
|
+
row: config,
|
|
1475
|
+
key
|
|
1476
|
+
});
|
|
1477
|
+
}
|
|
1478
|
+
}
|
|
1479
|
+
}
|
|
1480
|
+
visit(doc.contents);
|
|
1481
|
+
return fields;
|
|
1482
|
+
}
|
|
1483
|
+
function sectionConfig(content) {
|
|
1484
|
+
if (supportsCodex(content)) {
|
|
1485
|
+
const value = harnessConfig(content).config.get("presetSections", true);
|
|
1486
|
+
return isMap(value) ? value : void 0;
|
|
1487
|
+
}
|
|
1488
|
+
const doc = yaml(content);
|
|
1489
|
+
if (!isSeq(doc.contents)) return void 0;
|
|
1490
|
+
const row = doc.contents.items.find((row) => isMap(row) && row.get("name") === SECTION_PLUGIN);
|
|
1491
|
+
const config = isMap(row) ? row.get("config", true) : void 0;
|
|
1492
|
+
return isMap(config) ? config : void 0;
|
|
1493
|
+
}
|
|
1494
|
+
/** Some presets intentionally shadow host prompt sections with empty entries. */
|
|
1495
|
+
function suppressesHostSections(content) {
|
|
1496
|
+
const doc = yaml(content);
|
|
1497
|
+
let suppressed = false;
|
|
1498
|
+
function visit(sequence) {
|
|
1499
|
+
if (!isSeq(sequence)) return;
|
|
1500
|
+
for (const row of sequence.items) {
|
|
1501
|
+
if (!isMap(row)) continue;
|
|
1502
|
+
const id = String(row.get("id") ?? "");
|
|
1503
|
+
const plugin = String(row.get("name") ?? "");
|
|
1504
|
+
if (id === "story-prompt-clean-slate" || plugin === "./tools/prompt/clean-slate.mjs" || /(?:^|[\\/])clean-slate\.mjs$/u.test(plugin)) {
|
|
1505
|
+
suppressed = true;
|
|
1506
|
+
return;
|
|
1507
|
+
}
|
|
1508
|
+
const config = row.get("config", true);
|
|
1509
|
+
if (isSeq(config)) visit(config);
|
|
1510
|
+
if (suppressed) return;
|
|
1511
|
+
}
|
|
1512
|
+
}
|
|
1513
|
+
visit(doc.contents);
|
|
1514
|
+
return suppressed;
|
|
1515
|
+
}
|
|
1516
|
+
function readPromptSections(content, shared = {}) {
|
|
1517
|
+
const codex = supportsCodex(content);
|
|
1518
|
+
const overrides = sectionConfig(content);
|
|
1519
|
+
const fields = promptFields(yaml(content));
|
|
1520
|
+
const sections = fields.map(({ id, label, node }) => ({
|
|
1521
|
+
id,
|
|
1522
|
+
label,
|
|
1523
|
+
text: String(node.value ?? ""),
|
|
1524
|
+
editable: !node.tag && typeof node.value === "string"
|
|
1525
|
+
}));
|
|
1526
|
+
const persona = sections.find((section) => section.label === "Persona");
|
|
1527
|
+
const personaOverride = !overrides?.has("persona") && codex ? shared.persona : void 0;
|
|
1528
|
+
if (persona && typeof personaOverride === "string" && personaOverride !== DEFAULT_CODEX_PERSONA) persona.text = personaOverride;
|
|
1529
|
+
const hostSections = !fields.some((field) => field.label.startsWith("Persona") && field.row.get("complete") === true) && !suppressesHostSections(content) ? [...overrides?.get("harnessSourcePrompt") === "" ? [] : [{
|
|
1530
|
+
id: "harness:source",
|
|
1531
|
+
label: "DSH Core 源码说明",
|
|
1532
|
+
text: String(overrides?.get("harnessSourcePrompt") ?? (codex ? shared.harnessSourcePrompt : void 0) ?? DEFAULT_DSH_CORE_SOURCE_PROMPT),
|
|
1533
|
+
editable: true
|
|
1534
|
+
}], ...overrides?.get("webSurfacePrompt") === "" ? [] : [{
|
|
1535
|
+
id: "app:web-surface",
|
|
1536
|
+
label: "DSH Core Web 说明",
|
|
1537
|
+
text: String(overrides?.get("webSurfacePrompt") ?? (codex ? shared.webSurfacePrompt : void 0) ?? DEFAULT_DSH_CORE_WEB_PROMPT),
|
|
1538
|
+
editable: true
|
|
1539
|
+
}]] : [];
|
|
1540
|
+
if (hostSections.length) sections.splice(persona ? 1 : 0, 0, ...hostSections);
|
|
1541
|
+
if (codex) {
|
|
1542
|
+
const index = persona ? hostSections.length + 1 : hostSections.length;
|
|
1543
|
+
sections.splice(index, 0, {
|
|
1544
|
+
id: "codex:base",
|
|
1545
|
+
label: "Codex 操作提示词",
|
|
1546
|
+
text: explicitPrompt(content) ?? shared.systemPrompt ?? DEFAULT_CODEX_SYSTEM_PROMPT,
|
|
1547
|
+
editable: true
|
|
1548
|
+
});
|
|
1549
|
+
}
|
|
1550
|
+
return sections;
|
|
1551
|
+
}
|
|
1552
|
+
/** Patch the contributing fields, not a disconnected secondary prompt. */
|
|
1553
|
+
function patchPromptSections(content, sections) {
|
|
1554
|
+
const doc = yaml(content);
|
|
1555
|
+
const fields = promptFields(doc);
|
|
1556
|
+
const known = new Map(readPromptSections(content).map((section) => [section.id, section]));
|
|
1557
|
+
const overrides = {};
|
|
1558
|
+
const seen = /* @__PURE__ */ new Set();
|
|
1559
|
+
for (const section of sections) {
|
|
1560
|
+
const field = fields.find((field) => field.id === section.id);
|
|
1561
|
+
if (seen.has(section.id) || !known.get(section.id)?.editable && !(field && promptFile(field.node)) || typeof section.text !== "string" || section.text.length > 1e6) throw new Error("invalid-prompt-section");
|
|
1562
|
+
seen.add(section.id);
|
|
1563
|
+
if (field) {
|
|
1564
|
+
const node = new Scalar(section.text);
|
|
1565
|
+
node.type = Scalar.BLOCK_LITERAL;
|
|
1566
|
+
field.row.set(field.key, node);
|
|
1567
|
+
continue;
|
|
1568
|
+
}
|
|
1569
|
+
if (!supportsCodex(content) && known.get(section.id)?.text === section.text) continue;
|
|
1570
|
+
if (section.id === "harness:source") overrides.harnessSourcePrompt = section.text;
|
|
1571
|
+
if (section.id === "app:web-surface") overrides.webSurfacePrompt = section.text;
|
|
1572
|
+
}
|
|
1573
|
+
const personaFields = fields.filter((field) => known.get(field.id)?.label.startsWith("Persona"));
|
|
1574
|
+
if (supportsCodex(content) && personaFields.length) overrides.persona = personaFields.map((field) => sections.find((section) => section.id === field.id)?.text ?? String(field.node.value)).join("\n\n");
|
|
1575
|
+
let result = doc.toString({ lineWidth: 0 });
|
|
1576
|
+
if (supportsCodex(result)) {
|
|
1577
|
+
const { doc: next, config } = harnessConfig(result);
|
|
1578
|
+
const previous = config.get("presetSections", true);
|
|
1579
|
+
const merged = isMap(previous) ? previous : new YAMLMap();
|
|
1580
|
+
for (const [key, value] of Object.entries(overrides)) merged.set(key, value);
|
|
1581
|
+
config.set("presetSections", merged);
|
|
1582
|
+
result = next.toString({ lineWidth: 0 });
|
|
1583
|
+
const operating = sections.find((section) => section.id === "codex:base");
|
|
1584
|
+
if (operating) result = patchPresetComposition(result, operating.text);
|
|
1585
|
+
} else if (Object.keys(overrides).length) {
|
|
1586
|
+
const next = yaml(result);
|
|
1587
|
+
if (!isSeq(next.contents)) throw new Error("invalid-preset-yaml");
|
|
1588
|
+
let row = next.contents.items.find((row) => isMap(row) && row.get("name") === SECTION_PLUGIN);
|
|
1589
|
+
if (!isMap(row)) {
|
|
1590
|
+
const created = new YAMLMap();
|
|
1591
|
+
created.set("id", `prompt-sections-${randomUUID().slice(0, 8)}`);
|
|
1592
|
+
created.set("name", SECTION_PLUGIN);
|
|
1593
|
+
next.add(created);
|
|
1594
|
+
row = created;
|
|
1595
|
+
}
|
|
1596
|
+
const map = row;
|
|
1597
|
+
let config = map.get("config", true);
|
|
1598
|
+
if (!isMap(config)) {
|
|
1599
|
+
config = new YAMLMap();
|
|
1600
|
+
map.set("config", config);
|
|
1601
|
+
}
|
|
1602
|
+
for (const [key, value] of Object.entries(overrides)) config.set(key, value);
|
|
1603
|
+
result = next.toString({ lineWidth: 0 });
|
|
1604
|
+
}
|
|
1605
|
+
return result;
|
|
1606
|
+
}
|
|
1433
1607
|
function readCodexPresetOptions(content) {
|
|
1434
1608
|
try {
|
|
1435
1609
|
const { config } = harnessConfig(content);
|
|
@@ -1472,18 +1646,27 @@ function enhanceComposition(content) {
|
|
|
1472
1646
|
const doc = yaml(content);
|
|
1473
1647
|
if (!isSeq(doc.contents)) throw new Error("invalid-preset-yaml");
|
|
1474
1648
|
if (doc.contents.items.some((row) => isMap(row) && row.get("name") === "@shuind/dsh-codex-harness")) throw new Error("ambiguous-harness-row");
|
|
1649
|
+
let wasCompletePersona = false;
|
|
1475
1650
|
for (const row of doc.contents.items) {
|
|
1476
1651
|
if (!isMap(row) || row.get("name") !== "@deepseek-ai/dsh-persona") continue;
|
|
1477
1652
|
const persona = row.get("config", true);
|
|
1478
|
-
if (isMap(persona) && persona.get("complete") === true)
|
|
1653
|
+
if (isMap(persona) && persona.get("complete") === true) {
|
|
1654
|
+
wasCompletePersona = true;
|
|
1655
|
+
persona.set("complete", false);
|
|
1656
|
+
}
|
|
1479
1657
|
}
|
|
1658
|
+
const config = {
|
|
1659
|
+
globalEnhancements: false,
|
|
1660
|
+
codexCore: true
|
|
1661
|
+
};
|
|
1662
|
+
if (wasCompletePersona) config.presetSections = {
|
|
1663
|
+
harnessSourcePrompt: "",
|
|
1664
|
+
webSurfacePrompt: ""
|
|
1665
|
+
};
|
|
1480
1666
|
doc.add(doc.createNode({
|
|
1481
1667
|
id: `codex-harness-${randomUUID().slice(0, 8)}`,
|
|
1482
1668
|
name: "@shuind/dsh-codex-harness",
|
|
1483
|
-
config
|
|
1484
|
-
globalEnhancements: false,
|
|
1485
|
-
codexCore: true
|
|
1486
|
-
}
|
|
1669
|
+
config
|
|
1487
1670
|
}));
|
|
1488
1671
|
return doc.toString({ lineWidth: 0 });
|
|
1489
1672
|
}
|
|
@@ -1562,13 +1745,32 @@ async function assertWithinRoot(path, roots) {
|
|
|
1562
1745
|
throw new Error("preset-outside-user-root");
|
|
1563
1746
|
}
|
|
1564
1747
|
var CodexPresetEditor = class extends TypertRemoteService {
|
|
1565
|
-
static inject = ["agentPresets"];
|
|
1748
|
+
static inject = ["agentPresets", "settings"];
|
|
1566
1749
|
agentPresets;
|
|
1750
|
+
sharedSettings;
|
|
1751
|
+
indexed;
|
|
1567
1752
|
constructor(ctx, _config) {
|
|
1568
1753
|
super(ctx, "codexPresetEditor");
|
|
1569
1754
|
this.agentPresets = ctx.get("agentPresets");
|
|
1755
|
+
const settings = ctx.get("settings");
|
|
1756
|
+
this.sharedSettings = () => settings?.get("codex") ?? {};
|
|
1570
1757
|
}
|
|
1571
1758
|
async catalog() {
|
|
1759
|
+
if (this.agentPresets.list) {
|
|
1760
|
+
const rows = await this.agentPresets.list();
|
|
1761
|
+
this.indexed = new Map(rows.map((row) => [row.id, row]));
|
|
1762
|
+
return {
|
|
1763
|
+
presets: rows.filter((row) => row.broken === void 0).map((row) => ({
|
|
1764
|
+
id: row.id,
|
|
1765
|
+
name: row.name || row.id,
|
|
1766
|
+
description: row.description ?? "",
|
|
1767
|
+
editable: row.trust === "user",
|
|
1768
|
+
isDefault: row.id === this.agentPresets.defaultId
|
|
1769
|
+
})),
|
|
1770
|
+
authorable: this.agentPresets.authorable ?? false,
|
|
1771
|
+
excludedCount: rows.filter((row) => row.broken !== void 0).length
|
|
1772
|
+
};
|
|
1773
|
+
}
|
|
1572
1774
|
const roster = await this.agentPresets.remoteExportList();
|
|
1573
1775
|
const presets = roster.presets.filter((row) => row.broken === void 0).map((row) => ({
|
|
1574
1776
|
id: row.id,
|
|
@@ -1584,24 +1786,41 @@ var CodexPresetEditor = class extends TypertRemoteService {
|
|
|
1584
1786
|
};
|
|
1585
1787
|
}
|
|
1586
1788
|
async read(id) {
|
|
1587
|
-
const preset = await this.preset(id);
|
|
1588
|
-
|
|
1589
|
-
const metadata = await optionalFile(resolve(dirname(preset.path), "preset.yml"));
|
|
1789
|
+
const preset = this.indexed?.get(id) ?? await this.preset(id);
|
|
1790
|
+
if (preset.broken !== void 0) throw new Error("invalid-preset");
|
|
1791
|
+
const [composition, metadata] = await Promise.all([readFile(preset.path, "utf8"), optionalFile(resolve(dirname(preset.path), "preset.yml"))]);
|
|
1590
1792
|
const meta = metadata ? yaml(metadata) : void 0;
|
|
1591
1793
|
validateComposition(composition);
|
|
1592
1794
|
const codex = supportsCodex(composition);
|
|
1593
1795
|
const prompt = codex ? explicitPrompt(composition) : void 0;
|
|
1796
|
+
const shared = this.sharedSettings?.() ?? {};
|
|
1797
|
+
const promptSections = readPromptSections(composition, shared);
|
|
1798
|
+
for (const field of promptFields(yaml(composition))) {
|
|
1799
|
+
const reference = promptFile(field.node);
|
|
1800
|
+
if (!reference) continue;
|
|
1801
|
+
const section = promptSections.find((section) => section.id === field.id);
|
|
1802
|
+
try {
|
|
1803
|
+
const root = await realpath(dirname(preset.path));
|
|
1804
|
+
const target = await realpath(resolve(root, reference));
|
|
1805
|
+
const rel = relative(root, target);
|
|
1806
|
+
if (isAbsolute(rel) || rel === ".." || rel.startsWith("../") || rel.startsWith("..\\")) continue;
|
|
1807
|
+
if ((await stat(target)).size > 1e6) continue;
|
|
1808
|
+
section.text = await readFile(target, "utf8");
|
|
1809
|
+
section.editable = true;
|
|
1810
|
+
} catch {}
|
|
1811
|
+
}
|
|
1594
1812
|
return {
|
|
1595
1813
|
id,
|
|
1596
1814
|
name: String(meta?.get("name") ?? id),
|
|
1597
1815
|
description: String(meta?.get("description") ?? ""),
|
|
1598
|
-
systemPrompt: prompt ?? DEFAULT_CODEX_SYSTEM_PROMPT,
|
|
1816
|
+
systemPrompt: prompt ?? shared.systemPrompt ?? DEFAULT_CODEX_SYSTEM_PROMPT,
|
|
1599
1817
|
inheritPrompt: prompt === void 0,
|
|
1600
1818
|
revision: revision(composition, metadata),
|
|
1601
1819
|
editable: preset.trust === "user",
|
|
1602
1820
|
codex,
|
|
1603
1821
|
codexOptions: readCodexPresetOptions(composition),
|
|
1604
|
-
composition
|
|
1822
|
+
composition,
|
|
1823
|
+
promptSections
|
|
1605
1824
|
};
|
|
1606
1825
|
}
|
|
1607
1826
|
async create(rawInput) {
|
|
@@ -1648,6 +1867,7 @@ var CodexPresetEditor = class extends TypertRemoteService {
|
|
|
1648
1867
|
nextComposition = patchPresetComposition(nextComposition, input.systemPrompt, input.inheritPrompt);
|
|
1649
1868
|
if (input.codexOptions !== void 0) nextComposition = patchCodexPresetOptions(nextComposition, input.codexOptions);
|
|
1650
1869
|
}
|
|
1870
|
+
if (input.promptSections) nextComposition = patchPromptSections(nextComposition, input.promptSections);
|
|
1651
1871
|
validateComposition(nextComposition);
|
|
1652
1872
|
const nextMetadata = patchPresetMetadata(oldMetadata ?? "", input.name, input.description);
|
|
1653
1873
|
const compositionMode = await mode(composition);
|
|
@@ -1668,7 +1888,9 @@ var CodexPresetEditor = class extends TypertRemoteService {
|
|
|
1668
1888
|
mode: metadataMode,
|
|
1669
1889
|
dirMode: 448
|
|
1670
1890
|
});
|
|
1671
|
-
|
|
1891
|
+
const result = await this.agentPresets.resolve(input.id);
|
|
1892
|
+
if (result.broken !== void 0) throw new Error("invalid-preset-after-save");
|
|
1893
|
+
this.indexed?.set(input.id, result);
|
|
1672
1894
|
return await this.read(input.id);
|
|
1673
1895
|
} catch (error) {
|
|
1674
1896
|
await writeFileAtomic(composition, oldComposition, {
|
|
@@ -1690,6 +1912,8 @@ var CodexPresetEditor = class extends TypertRemoteService {
|
|
|
1690
1912
|
if (!PRESET_ID.test(id)) throw new Error("invalid-preset-id");
|
|
1691
1913
|
const preset = await this.agentPresets.resolve(id);
|
|
1692
1914
|
if (preset.broken !== void 0) throw new Error("invalid-preset");
|
|
1915
|
+
this.indexed ??= /* @__PURE__ */ new Map();
|
|
1916
|
+
this.indexed.set(id, preset);
|
|
1693
1917
|
return preset;
|
|
1694
1918
|
}
|
|
1695
1919
|
};
|
|
@@ -1715,6 +1939,34 @@ for (const method of [
|
|
|
1715
1939
|
"create"
|
|
1716
1940
|
]) markRemoteMethod(method);
|
|
1717
1941
|
//#endregion
|
|
1942
|
+
//#region lib/types/prompt-sections.js
|
|
1943
|
+
const Config$1 = z.object({
|
|
1944
|
+
persona: z.string(),
|
|
1945
|
+
harnessSourcePrompt: z.string(),
|
|
1946
|
+
webSurfacePrompt: z.string()
|
|
1947
|
+
});
|
|
1948
|
+
/** Override only existing sections; dynamic runtime context and tool guidance remain host-owned. */
|
|
1949
|
+
function applyPromptSections(assembly, config) {
|
|
1950
|
+
const variables = { ...assembly.variables };
|
|
1951
|
+
variables.sourceRoot ??= assembly.sections.find((s) => s.name === "harness:source")?.text.match(/^The DeepSeek Harness implementation checkout is at (.+?)\. The checkout location/u)?.[1];
|
|
1952
|
+
variables.webUrl ??= assembly.sections.find((s) => s.name === "app:web-surface")?.text.match(/^You are interacting with the user through the DeepSeek Harness Web GUI at (.+?)\. When/u)?.[1];
|
|
1953
|
+
const values = {
|
|
1954
|
+
"deployment:persona": config.persona,
|
|
1955
|
+
"harness:source": config.harnessSourcePrompt,
|
|
1956
|
+
"app:web-surface": config.webSurfacePrompt
|
|
1957
|
+
};
|
|
1958
|
+
return {
|
|
1959
|
+
...assembly,
|
|
1960
|
+
sections: assembly.sections.map((section) => {
|
|
1961
|
+
const text = values[section.name];
|
|
1962
|
+
return text === void 0 ? section : {
|
|
1963
|
+
...section,
|
|
1964
|
+
text: text.replace(/\{\{([\w.-]+)\}\}/g, (whole, key) => variables[key] ?? whole)
|
|
1965
|
+
};
|
|
1966
|
+
})
|
|
1967
|
+
};
|
|
1968
|
+
}
|
|
1969
|
+
//#endregion
|
|
1718
1970
|
//#region lib/types/index.js
|
|
1719
1971
|
/** Codex-compatible prompt overlay and core tools for a dsh agent preset. */
|
|
1720
1972
|
const name = "codex";
|
|
@@ -1753,6 +2005,7 @@ const Config = z.object({
|
|
|
1753
2005
|
remoteCompact: z.boolean().default(true),
|
|
1754
2006
|
systemPrompt: z.string().default(DEFAULT_CODEX_SYSTEM_PROMPT),
|
|
1755
2007
|
presetPrompt: z.string(),
|
|
2008
|
+
presetSections: Config$1,
|
|
1756
2009
|
promptEnabled: z.boolean(),
|
|
1757
2010
|
terminalToolsEnabled: z.boolean(),
|
|
1758
2011
|
patchToolEnabled: z.boolean(),
|
|
@@ -2498,7 +2751,7 @@ function apply(ctx, config = {}) {
|
|
|
2498
2751
|
}));
|
|
2499
2752
|
}
|
|
2500
2753
|
if (resolved.codexCore) {
|
|
2501
|
-
ctx.on("system-prompt/assemble", async (_assembly, _context, next) => applyCodexCapabilitySettings(await next(), codexSettings.current()));
|
|
2754
|
+
ctx.on("system-prompt/assemble", async (_assembly, _context, next) => applyPromptSections(applyCodexCapabilitySettings(await next(), codexSettings.current()), config.presetSections ?? {}));
|
|
2502
2755
|
ctx.systemPrompt.section({
|
|
2503
2756
|
name: "codex:base",
|
|
2504
2757
|
order: 10,
|
package/lib/typert.js
ADDED
|
@@ -0,0 +1,117 @@
|
|
|
1
|
+
import { z } from "zod";
|
|
2
|
+
//#region lib/types/typert.host.js
|
|
3
|
+
const PACKAGE = "@shuind/dsh-codex-harness";
|
|
4
|
+
const SERVICE = "codexPresetEditor";
|
|
5
|
+
const promptSections = z.array(z.object({
|
|
6
|
+
id: z.string(),
|
|
7
|
+
label: z.string(),
|
|
8
|
+
text: z.string().max(1e6),
|
|
9
|
+
editable: z.boolean(),
|
|
10
|
+
suppressed: z.boolean().optional()
|
|
11
|
+
})).max(200);
|
|
12
|
+
const fields = {
|
|
13
|
+
name: z.string().max(200),
|
|
14
|
+
description: z.string().max(4e3),
|
|
15
|
+
systemPrompt: z.string().max(1e6),
|
|
16
|
+
inheritPrompt: z.boolean()
|
|
17
|
+
};
|
|
18
|
+
const codexOptions = z.object({
|
|
19
|
+
promptEnabled: z.boolean(),
|
|
20
|
+
terminalToolsEnabled: z.boolean(),
|
|
21
|
+
patchToolEnabled: z.boolean(),
|
|
22
|
+
planToolEnabled: z.boolean(),
|
|
23
|
+
hostedWebSearchEnabled: z.boolean(),
|
|
24
|
+
remoteCompactionEnabled: z.boolean()
|
|
25
|
+
});
|
|
26
|
+
const document = z.object({
|
|
27
|
+
...fields,
|
|
28
|
+
id: z.string(),
|
|
29
|
+
revision: z.string(),
|
|
30
|
+
editable: z.boolean(),
|
|
31
|
+
codex: z.boolean(),
|
|
32
|
+
codexOptions,
|
|
33
|
+
promptSections,
|
|
34
|
+
composition: z.string()
|
|
35
|
+
});
|
|
36
|
+
const catalog = z.object({
|
|
37
|
+
presets: z.array(z.object({
|
|
38
|
+
id: z.string(),
|
|
39
|
+
name: z.string(),
|
|
40
|
+
description: z.string(),
|
|
41
|
+
editable: z.boolean(),
|
|
42
|
+
isDefault: z.boolean()
|
|
43
|
+
})),
|
|
44
|
+
authorable: z.boolean(),
|
|
45
|
+
excludedCount: z.number()
|
|
46
|
+
});
|
|
47
|
+
const codexOptionsPatch = codexOptions.partial();
|
|
48
|
+
function descriptor(method, parameter, input, output) {
|
|
49
|
+
const id = `${PACKAGE}#${SERVICE}/${method}`;
|
|
50
|
+
return {
|
|
51
|
+
id,
|
|
52
|
+
service: SERVICE,
|
|
53
|
+
namespace: SERVICE,
|
|
54
|
+
method,
|
|
55
|
+
invocation: { kind: "direct" },
|
|
56
|
+
parameters: parameter === void 0 ? [] : [{
|
|
57
|
+
name: parameter,
|
|
58
|
+
wire: parameter,
|
|
59
|
+
source: "json",
|
|
60
|
+
codec: {
|
|
61
|
+
mode: "strict",
|
|
62
|
+
typeSymbol: `${id}:${parameter}`,
|
|
63
|
+
schema: input
|
|
64
|
+
}
|
|
65
|
+
}],
|
|
66
|
+
result: {
|
|
67
|
+
mode: "strict",
|
|
68
|
+
typeSymbol: `${id}:result`,
|
|
69
|
+
schema: output
|
|
70
|
+
}
|
|
71
|
+
};
|
|
72
|
+
}
|
|
73
|
+
const updateInput = z.object({
|
|
74
|
+
...fields,
|
|
75
|
+
id: z.string(),
|
|
76
|
+
revision: z.string().optional(),
|
|
77
|
+
composition: z.string().max(1e6).optional(),
|
|
78
|
+
enableCodex: z.boolean().optional(),
|
|
79
|
+
promptSections: promptSections.optional(),
|
|
80
|
+
codexOptions: codexOptionsPatch.optional()
|
|
81
|
+
});
|
|
82
|
+
const createInput = z.object({
|
|
83
|
+
...fields,
|
|
84
|
+
sourceId: z.string(),
|
|
85
|
+
enableCodex: z.boolean().optional(),
|
|
86
|
+
composition: z.string().max(1e6).optional(),
|
|
87
|
+
promptSections: promptSections.optional(),
|
|
88
|
+
codexOptions: codexOptionsPatch.optional()
|
|
89
|
+
});
|
|
90
|
+
/** Host-side Remote contract consumed by the browser's preset editor. */
|
|
91
|
+
const TYPERT = {
|
|
92
|
+
package: PACKAGE,
|
|
93
|
+
face: "host",
|
|
94
|
+
schemas: [],
|
|
95
|
+
invocations: [
|
|
96
|
+
descriptor("catalog", void 0, z.unknown(), catalog),
|
|
97
|
+
descriptor("read", "id", z.string(), document),
|
|
98
|
+
descriptor("update", "rawInput", updateInput, document),
|
|
99
|
+
descriptor("create", "rawInput", createInput, document)
|
|
100
|
+
],
|
|
101
|
+
model: {
|
|
102
|
+
services: [{
|
|
103
|
+
description: "Author and inspect DSH agent presets with Codex capabilities.",
|
|
104
|
+
summary: "Codex preset editor.",
|
|
105
|
+
tags: [],
|
|
106
|
+
jsDoc: "",
|
|
107
|
+
key: SERVICE,
|
|
108
|
+
exportName: "CodexPresetEditor",
|
|
109
|
+
members: [],
|
|
110
|
+
types: []
|
|
111
|
+
}],
|
|
112
|
+
events: [],
|
|
113
|
+
objects: []
|
|
114
|
+
}
|
|
115
|
+
};
|
|
116
|
+
//#endregion
|
|
117
|
+
export { TYPERT, TYPERT as default };
|
|
@@ -33,7 +33,7 @@ declare const en: {
|
|
|
33
33
|
readonly contextSizeDescription: "Next request capacity in K tokens.";
|
|
34
34
|
readonly contextRestore: "Restore model default";
|
|
35
35
|
readonly promptCardTitle: "Codex Harness";
|
|
36
|
-
readonly promptCardDescription: "Edit presets and
|
|
36
|
+
readonly promptCardDescription: "Edit presets, Codex capabilities, and the operating prompt. Activity status is global.";
|
|
37
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.";
|
|
@@ -53,13 +53,39 @@ declare const en: {
|
|
|
53
53
|
readonly capabilityCompactionHint: "Prefer the provider Responses compact endpoint before local compaction.";
|
|
54
54
|
readonly capabilityActivity: "Activity indicator";
|
|
55
55
|
readonly capabilityActivityHint: "Show request, reply, and compaction status beside the conversation.";
|
|
56
|
+
readonly promptCustomizationLabel: "Prompt customization";
|
|
57
|
+
readonly personaLabel: "Persona";
|
|
58
|
+
readonly personaHint: "Deployment identity and role. Supports {{model}} and {{cwd}}.";
|
|
59
|
+
readonly sourcePromptLabel: "DSH Core source instructions";
|
|
60
|
+
readonly sourcePromptHint: "Guidance about the DSH checkout and working directory. Supports {{sourceRoot}}.";
|
|
61
|
+
readonly webPromptLabel: "DSH Core Web instructions";
|
|
62
|
+
readonly webPromptHint: "Guidance about this Web GUI, HMR, builds, and verification. Supports {{webUrl}}.";
|
|
63
|
+
readonly promptRestoreAll: "Restore all prompt defaults";
|
|
56
64
|
readonly promptLabel: "Codex operating prompt";
|
|
65
|
+
readonly promptHint: "This is the Codex operating prompt. Persona and DSH Core instructions are edited separately above.";
|
|
66
|
+
readonly promptUnsaved: "Unsaved";
|
|
67
|
+
readonly promptDiscard: "Discard";
|
|
68
|
+
readonly promptSave: "Save";
|
|
69
|
+
readonly promptSaving: "Saving...";
|
|
70
|
+
readonly promptSaveFailed: "Could not save the prompt.";
|
|
57
71
|
readonly promptExpand: "Expand settings";
|
|
58
72
|
readonly promptCollapse: "Collapse settings";
|
|
59
73
|
readonly promptReadOnly: "This settings document is read-only.";
|
|
60
74
|
readonly activityCompacting: "Compacting context...";
|
|
61
75
|
readonly activityRequestingModel: "Requesting model...";
|
|
62
76
|
readonly activityModelReply: "Model replying...";
|
|
77
|
+
readonly peConnectionError: "Could not connect to the local service. Retry loading; if the connection still fails, reconnect the page.";
|
|
78
|
+
readonly peReadError: "Could not read this preset. Retry loading or refresh the preset list.";
|
|
79
|
+
readonly peRetryRead: "Retry loading";
|
|
80
|
+
readonly peReconnect: "Reconnect page";
|
|
81
|
+
readonly peSystemPrompt: "System prompt sections";
|
|
82
|
+
readonly peSectionsHint: "These templates contribute to this preset’s system prompt before the tools. Runtime variables, workspace instructions and plugin-provided guidance are assembled when the conversation runs.";
|
|
83
|
+
readonly peDynamicPrompt: "This field is an expression; it is preserved without executing it in the editor.";
|
|
84
|
+
readonly peDshSourcePrompt: "Tells the agent where the DSH source checkout is and keeps it separate from the current workspace. It is used when inspecting or extending DSH itself.";
|
|
85
|
+
readonly peDshWebPrompt: "Tells the agent which Web page it is talking through, what “this page” means, and when Web changes need a rebuild or refresh.";
|
|
86
|
+
readonly peSuppressed: "Not used";
|
|
87
|
+
readonly peCompletePersona: "This preset uses Persona as its entire system prompt, so this section is excluded.";
|
|
88
|
+
readonly peLoading: "Reading preset…";
|
|
63
89
|
readonly peTitle: "Preset editor";
|
|
64
90
|
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
91
|
readonly peSelect: "Preset";
|
|
@@ -114,7 +140,7 @@ interface InputSettingsControlInjected {
|
|
|
114
140
|
unsetSetting: (field: string) => Promise<void>;
|
|
115
141
|
presetManager: PresetManagerActions;
|
|
116
142
|
}
|
|
117
|
-
/**
|
|
143
|
+
/** One editor per preset; only display preferences are global. */
|
|
118
144
|
export declare function PromptSettingsCard(props: PropsRuntime<'settings.plugin.item'> & InjectFace<InputSettingsControlInjected> & PropsLocale<'codex'>): import("react").JSX.Element | null;
|
|
119
145
|
type LegacyOverlayProps = PropsRuntime<typeof LEGACY_OVERLAY_SLOT> & InjectFace<InputSettingsControlInjected> & PropsLocale<'codex'>;
|
|
120
146
|
type ActivityProps = Pick<LegacyOverlayProps, 'sessionId' | 'useSession' | 'useSessions' | 'useProjection' | 'useSettings' | 't'>;
|