@aiwayds/dsh-opentui 0.17.1 → 0.17.2

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 CHANGED
@@ -5,6 +5,12 @@ All notable changes to this project will be documented in this file.
5
5
  The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.1.0/),
6
6
  and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html).
7
7
 
8
+ ## [0.17.2] - 2026-11-15
9
+
10
+ ### Added
11
+
12
+ - **append-system, ported from dsh-tui-pi.** `~/.dsh/APPEND_SYSTEM.md` is appended to the system prompt of every new main session. The additions ride an `agentPreset` persona row the client provisions into the opentui profile — zero host changes, and no other profile is affected. The file is seeded once when missing and never rewritten; edits apply after the next host restart; emptying or deleting the file disables the additions (the seed only ever runs on first provision). The persona read is capped at 64 KiB with a truncation marker. `/preset` lists the composition as "Standard + Append"; resuming an existing session carries the additions only when explicitly selected.
13
+
8
14
  ## [0.17.1] - 2026-11-15
9
15
 
10
16
  ### Fixed
@@ -989,10 +989,283 @@ var init_host_probe = __esm(() => {
989
989
  init_mux_frame();
990
990
  });
991
991
 
992
+ // src/client/append-system.ts
993
+ import { chmodSync as chmodSync2, mkdirSync as mkdirSync2, readFileSync as readFileSync2, renameSync as renameSync2, unlinkSync as unlinkSync2, writeFileSync as writeFileSync2 } from "fs";
994
+ import { homedir } from "os";
995
+ import { join as join3 } from "path";
996
+ function defaultDshHome() {
997
+ return process.env.DSH_HOME || join3(homedir(), ".dsh");
998
+ }
999
+ function appendSystemPath(home = defaultDshHome()) {
1000
+ return join3(home, "APPEND_SYSTEM.md");
1001
+ }
1002
+ function appendSystemPresetBlock() {
1003
+ return `${APPEND_SYSTEM_MARKER} \u2014 managed block (client-owned; the client appends it once and never rewrites other lines).
1004
+ ${APPEND_SYSTEM_MARKER} persona suffix = $DSH_HOME/APPEND_SYSTEM.md, evaluated by the host at boot (!!js guarded read; empty file => empty section => dropped).
1005
+ - insert:
1006
+ - id: ${APPEND_SYSTEM_ROW_ID}
1007
+ name: '@deepseek-ai/dsh-agent-preset'
1008
+ config:
1009
+ id: ${APPEND_SYSTEM_PRESET_ID}
1010
+ name: Standard + Append
1011
+ description: The shipped standard preset plus the user's APPEND_SYSTEM.md appended to the system prompt.
1012
+ order: 5
1013
+ plugins:
1014
+ - id: persona
1015
+ name: '@deepseek-ai/dsh-persona'
1016
+ config:
1017
+ prefix: You are a coding agent powered by the {{model}} model.
1018
+ suffix: !!js "${APPEND_SYSTEM_SUFFIX_EXPR}"
1019
+ - id: agent-instructions
1020
+ name: '@deepseek-ai/dsh-agent-instructions'
1021
+ config:
1022
+ maxBytes: 65536
1023
+ - id: time-context
1024
+ name: '@deepseek-ai/dsh-time-context'
1025
+ - id: tool-bash
1026
+ name: '@deepseek-ai/dsh-tool-bash'
1027
+ disabled: !!js process.platform === 'win32'
1028
+ - id: tool-pwsh
1029
+ name: '@deepseek-ai/dsh-tool-pwsh'
1030
+ disabled: !!js process.platform !== 'win32'
1031
+ - id: tool-fs
1032
+ name: '@deepseek-ai/dsh-tool-fs'
1033
+ config:
1034
+ # Set false to drop the apply_patch tool beside edit.
1035
+ applyPatch: false
1036
+ - id: tool-fs-search
1037
+ name: '@deepseek-ai/dsh-tool-fs-search'
1038
+ config:
1039
+ sampleOverCapGlobResults: false
1040
+ - id: tool-jobs
1041
+ name: '@deepseek-ai/dsh-tool-jobs'
1042
+ - id: tool-schedule
1043
+ name: '@deepseek-ai/dsh-tool-schedule'
1044
+ - id: skill-filesystem
1045
+ name: '@deepseek-ai/dsh-skill-filesystem'
1046
+ config:
1047
+ customSkillDirs:
1048
+ - !!js process.getBuiltinModule('node:path').join(process.getBuiltinModule('node:path').dirname(process.getBuiltinModule('node:module').createRequire(baseUrl).resolve('@deepseek-ai/dsh-agent-preset/package.json')), 'skills')
1049
+ - id: tool-skill
1050
+ name: '@deepseek-ai/dsh-tool-skill'
1051
+ - id: command-goal
1052
+ name: '@deepseek-ai/dsh-command-goal'
1053
+ - id: tool-goal
1054
+ name: '@deepseek-ai/dsh-tool-goal'
1055
+ - id: planning
1056
+ name: cordis:group
1057
+ group: true
1058
+ isolate:
1059
+ planMode: true
1060
+ config:
1061
+ - id: plan-mode
1062
+ name: '@deepseek-ai/dsh-plan-mode'
1063
+ config:
1064
+ section: |
1065
+ You are in plan mode. Stay in plan mode until the user approves your plan through exit_plan_mode or switches the session mode. Imperative language to implement changes means plan the implementation, not execute it. A user's conversational agreement \u2014 including an answer confirming something you asked \u2014 approves nothing and does not end plan mode; fold the confirmed decision into the plan and submit it through exit_plan_mode.
1066
+
1067
+ Explore first. Use non-mutating reads, searches, static analysis, and checks to ground the plan in the actual repository. Do not edit or write files, change configuration, run formatters or code generation that rewrites tracked files, commit, or otherwise carry out the plan. Prefer existing functions and patterns over new machinery.
1068
+
1069
+ The tool catalog stays the same across modes for request-cache stability. These plan-mode rules override any later tool description or guidance that suggests using mutation tools; those tools remain listed to keep the tool catalog unchanged. Do not use todo_write to track this planning phase: it tracks implementation after an approved plan, while the plan itself belongs in exit_plan_mode.
1070
+
1071
+ Resolve discoverable facts by inspection. Use ask_user_question only for user-owned choices or material ambiguity that inspection cannot answer. Do not ask the user where code lives or how current behavior works when you can find out.
1072
+
1073
+ Make the plan decision-complete: state the goal and success criteria; group implementation changes by subsystem; identify public API, schema, and data-flow changes; cover edge cases, failure modes, tests, acceptance criteria, and explicit assumptions. Keep it concise enough to review but detailed enough that another engineer can implement it without making design decisions.
1074
+
1075
+ When ready, call exit_plan_mode with the complete plan markdown, starting with a # title. Make exit_plan_mode the only and final tool call in that assistant response: it presents the plan for approval, and implementation begins only in a later step after approval. Do not paste the final plan as a plain reply or ask "should I proceed?" through prose or ask_user_question. If review rejects it, incorporate the feedback and present again. If the review channel is unavailable or aborted, stay in plan mode and ask the user to switch modes manually; do not proceed with implementation.
1076
+ - id: compaction
1077
+ name: cordis:group
1078
+ group: true
1079
+ isolate:
1080
+ compaction: true
1081
+ toolResultPruner: true
1082
+ config:
1083
+ - id: compaction-basic
1084
+ name: '@deepseek-ai/dsh-compaction-basic'
1085
+ - id: command-compact
1086
+ name: '@deepseek-ai/dsh-command-compact'
1087
+ - id: tool-result-pruner
1088
+ name: '@deepseek-ai/dsh-compaction-tool-result-pruner'
1089
+ config:
1090
+ thresholdChars: 8192
1091
+ headChars: 4096
1092
+ tailChars: 1024
1093
+ - id: delegation
1094
+ name: cordis:group
1095
+ group: true
1096
+ isolate:
1097
+ workflowEngine: true
1098
+ config:
1099
+ - id: tool-subagent-control
1100
+ name: '@deepseek-ai/dsh-tool-subagent-control'
1101
+ config:
1102
+ interrupt: false
1103
+ - id: tool-subagent
1104
+ name: '@deepseek-ai/dsh-tool-subagent'
1105
+ config:
1106
+ provider: spawn
1107
+ toolName: subagent
1108
+ modelSelection: true
1109
+ modelDiscovery: true
1110
+ - id: tool-subagent-fork
1111
+ name: '@deepseek-ai/dsh-tool-subagent'
1112
+ config:
1113
+ provider: fork
1114
+ toolName: subagent_fork
1115
+ - id: workflow-ptc
1116
+ name: '@deepseek-ai/dsh-workflow-ptc'
1117
+ config:
1118
+ provider: spawn
1119
+ - id: tool-workflow
1120
+ name: '@deepseek-ai/dsh-tool-workflow'
1121
+ - id: tool-ask-user
1122
+ name: '@deepseek-ai/dsh-tool-ask-user'
1123
+ - id: tool-todo
1124
+ name: '@deepseek-ai/dsh-tool-todo'
1125
+ config:
1126
+ allowParallelInProgress: true
1127
+ - id: tool-web
1128
+ name: '@deepseek-ai/dsh-tool-web'
1129
+ config:
1130
+ fetch: true
1131
+ searchTimeoutMs: 60000
1132
+ - id: present
1133
+ name: '@deepseek-ai/dsh-tool-present'
1134
+ - id: tool-office
1135
+ name: '@deepseek-ai/dsh-tool-office'
1136
+ - id: tool-plugin-manager
1137
+ name: '@deepseek-ai/dsh-plugin-manager/tools'
1138
+ disabled: !!js "!ctx.get('profileContext')"
1139
+ - id: tool-plugin-market
1140
+ name: '@deepseek-ai/dsh-plugin-market/tools'
1141
+ disabled: true
1142
+ `;
1143
+ }
1144
+ function writeAtomically(path, content, mode) {
1145
+ mkdirSync2(join3(path, ".."), { recursive: true });
1146
+ const tmp = `${path}.${process.pid}.tmp`;
1147
+ try {
1148
+ writeFileSync2(tmp, content, { mode });
1149
+ renameSync2(tmp, path);
1150
+ } catch (error) {
1151
+ try {
1152
+ unlinkSync2(tmp);
1153
+ } catch {}
1154
+ throw error;
1155
+ }
1156
+ }
1157
+ function ensureAppendSystemFile(path = appendSystemPath()) {
1158
+ try {
1159
+ readFileSync2(path, "utf8");
1160
+ return "kept";
1161
+ } catch {
1162
+ writeAtomically(path, APPEND_SYSTEM_TEMPLATE, 420);
1163
+ try {
1164
+ chmodSync2(path, 420);
1165
+ } catch {}
1166
+ return "seeded";
1167
+ }
1168
+ }
1169
+ function profilePatchPath(home, profile) {
1170
+ return join3(home, "profiles", profile, "cordis.patch.yml");
1171
+ }
1172
+ function managedSpan(lines) {
1173
+ const start = lines.findIndex((line) => line.startsWith(APPEND_SYSTEM_MARKER));
1174
+ if (start < 0)
1175
+ return;
1176
+ let end = lines.length;
1177
+ let seenOwnInsert = false;
1178
+ for (let i = start + 1;i < lines.length; i++) {
1179
+ if (/^- /.test(lines[i])) {
1180
+ if (!seenOwnInsert) {
1181
+ seenOwnInsert = true;
1182
+ continue;
1183
+ }
1184
+ end = i;
1185
+ break;
1186
+ }
1187
+ }
1188
+ return [start, end];
1189
+ }
1190
+ function provisionAppendSystem(home, profile) {
1191
+ let preText;
1192
+ try {
1193
+ preText = readFileSync2(profilePatchPath(home, profile), "utf8");
1194
+ } catch {
1195
+ preText = undefined;
1196
+ }
1197
+ const patch = syncAppendSystemPreset(home, profile);
1198
+ if (preText !== undefined && managedSpan(preText.split(`
1199
+ `)) !== undefined) {
1200
+ return { patch, file: "kept" };
1201
+ }
1202
+ return { patch, file: ensureAppendSystemFile(appendSystemPath(home)) };
1203
+ }
1204
+ function syncAppendSystemPreset(home, profile) {
1205
+ const path = profilePatchPath(home, profile);
1206
+ let before;
1207
+ try {
1208
+ before = readFileSync2(path, "utf8");
1209
+ } catch {
1210
+ return { status: "skipped", detail: `no profile patch at ${path}` };
1211
+ }
1212
+ const lines = before.split(`
1213
+ `);
1214
+ const span = managedSpan(lines);
1215
+ const outside = (needle) => {
1216
+ for (let i = 0;i < lines.length; i++) {
1217
+ if (span !== undefined && i >= span[0] && i < span[1])
1218
+ continue;
1219
+ if (lines[i].includes(needle))
1220
+ return `line ${i + 1}: ${lines[i].trim()}`;
1221
+ }
1222
+ return;
1223
+ };
1224
+ for (const needle of [APPEND_SYSTEM_PRESET_ID, APPEND_SYSTEM_ROW_ID]) {
1225
+ const hit = outside(needle);
1226
+ if (hit !== undefined) {
1227
+ return { status: "collision", detail: `${needle} already declared (${hit})` };
1228
+ }
1229
+ }
1230
+ if (span !== undefined)
1231
+ return { status: "present" };
1232
+ const separator = before.length === 0 || before.endsWith(`
1233
+
1234
+ `) ? "" : before.endsWith(`
1235
+ `) ? `
1236
+ ` : `
1237
+
1238
+ `;
1239
+ const next = `${before}${separator}${appendSystemPresetBlock()}`;
1240
+ writeAtomically(path, next, 384);
1241
+ return { status: "added" };
1242
+ }
1243
+ var APPEND_SYSTEM_PRESET_ID = "opentui-append-system", APPEND_SYSTEM_ROW_ID, APPEND_SYSTEM_MARKER = "# dsh-opentui:append-system", APPEND_SYSTEM_TEMPLATE = `# APPEND_SYSTEM.md \u2014 standing system-prompt additions
1244
+
1245
+ The content of this file is appended to the system prompt of every main
1246
+ session the dsh-opentui client creates (ported from dsh-tui-pi).
1247
+
1248
+ The file is user-owned: the client seeds it once and never rewrites it.
1249
+ Edits apply to sessions created after the next client start; clearing or
1250
+ deleting this file switches the append off (it is not re-seeded).
1251
+
1252
+ ## Vocabulary
1253
+
1254
+ - "subagent" means the registered subagents only; never invent or use
1255
+ unregistered subagents.
1256
+
1257
+ ## Additions
1258
+
1259
+ Write your persistent instructions below this line.
1260
+ `, APPEND_SYSTEM_SUFFIX_EXPR = `((req, path) => { try { const text = req('node:fs').readFileSync(path.join(process.env.DSH_HOME || ((process.env.HOME || '') + '/.dsh'), 'APPEND_SYSTEM.md'), 'utf8'); return text.length > 65536 ? text.slice(0, 65536) + String.fromCharCode(10) + '[append-system: truncated at 64KiB]' : text } catch { return '' } })(process.getBuiltinModule('node:module').createRequire(baseUrl), process.getBuiltinModule('node:path'))`;
1261
+ var init_append_system = __esm(() => {
1262
+ APPEND_SYSTEM_ROW_ID = `preset-${APPEND_SYSTEM_PRESET_ID}`;
1263
+ });
1264
+
992
1265
  // src/client/cookie-mint.ts
993
1266
  import { createHash, createHmac } from "crypto";
994
- import { readFileSync as readFileSync2, statSync as statSync2 } from "fs";
995
- import { join as join3 } from "path";
1267
+ import { readFileSync as readFileSync3, statSync as statSync2 } from "fs";
1268
+ import { join as join4 } from "path";
996
1269
  function ownerCookieName(authority) {
997
1270
  return "dsh-auth-" + base64url(createHash("sha256").update(authority).digest());
998
1271
  }
@@ -1010,14 +1283,14 @@ function mintOwnerCookie(options) {
1010
1283
  return `${ownerCookieName(authority)}=v1.${body}.${signature}`;
1011
1284
  }
1012
1285
  function readGrantSecret(home) {
1013
- const path = join3(home, ".credentials.yaml");
1286
+ const path = join4(home, ".credentials.yaml");
1014
1287
  const deadline = Date.now() + RETRY_WINDOW_MS;
1015
1288
  let sawFile = false;
1016
1289
  while (true) {
1017
1290
  let file = "";
1018
1291
  try {
1019
1292
  assertOwnerOnly(path);
1020
- file = readFileSync2(path, "utf8");
1293
+ file = readFileSync3(path, "utf8");
1021
1294
  sawFile = true;
1022
1295
  } catch (error) {
1023
1296
  if (error instanceof CredentialsFileInsecureError)
@@ -1245,7 +1518,7 @@ __export(exports_lifecycle, {
1245
1518
  MintUnavailableError: () => MintUnavailableError,
1246
1519
  ProfileMissingError: () => ProfileMissingError,
1247
1520
  __internals: () => __internals,
1248
- defaultDshHome: () => defaultDshHome,
1521
+ defaultDshHome: () => defaultDshHome2,
1249
1522
  ensureHost: () => ensureHost,
1250
1523
  isListening: () => isListening,
1251
1524
  pidAlive: () => pidAlive,
@@ -1253,10 +1526,10 @@ __export(exports_lifecycle, {
1253
1526
  resolveIdleExitSec: () => resolveIdleExitSec
1254
1527
  });
1255
1528
  import { spawn as spawn2 } from "child_process";
1256
- import { existsSync as existsSync3, linkSync, mkdirSync as mkdirSync2, readFileSync as readFileSync3, renameSync as renameSync2, rmSync, writeFileSync as writeFileSync2 } from "fs";
1257
- import { homedir } from "os";
1529
+ import { existsSync as existsSync3, linkSync, mkdirSync as mkdirSync3, readFileSync as readFileSync4, renameSync as renameSync3, rmSync, writeFileSync as writeFileSync3 } from "fs";
1530
+ import { homedir as homedir2 } from "os";
1258
1531
  import { connect as netConnect, Server } from "net";
1259
- import { join as join4 } from "path";
1532
+ import { join as join5 } from "path";
1260
1533
  function resolveIdleExitMs(explicitSec) {
1261
1534
  if (explicitSec !== undefined && Number.isFinite(explicitSec)) {
1262
1535
  return Math.max(0, Math.round(explicitSec * 1000));
@@ -1284,11 +1557,11 @@ ${lines.slice(-ERROR_TAIL_LINES).join(`
1284
1557
  function registryKey(dshHome, profile) {
1285
1558
  return `${dshHome}\x00${profile}`;
1286
1559
  }
1287
- function defaultDshHome() {
1288
- return process.env.DSH_HOME || join4(homedir(), ".dsh");
1560
+ function defaultDshHome2() {
1561
+ return process.env.DSH_HOME || join5(homedir2(), ".dsh");
1289
1562
  }
1290
1563
  function lockPathFor(dshHome, profile) {
1291
- return join4(dshHome, `opentui-host.${profile}.json`);
1564
+ return join5(dshHome, `opentui-host.${profile}.json`);
1292
1565
  }
1293
1566
  function pidAlive(pid) {
1294
1567
  try {
@@ -1341,7 +1614,7 @@ function getFreePort() {
1341
1614
  }
1342
1615
  function readLock(dshHome, profile) {
1343
1616
  try {
1344
- const raw = JSON.parse(readFileSync3(lockPathFor(dshHome, profile), "utf8"));
1617
+ const raw = JSON.parse(readFileSync4(lockPathFor(dshHome, profile), "utf8"));
1345
1618
  if (typeof raw.pid !== "number" || typeof raw.port !== "number")
1346
1619
  return null;
1347
1620
  return {
@@ -1357,7 +1630,7 @@ function readLock(dshHome, profile) {
1357
1630
  }
1358
1631
  }
1359
1632
  function writeLock(dshHome, profile, host) {
1360
- mkdirSync2(dshHome, { recursive: true });
1633
+ mkdirSync3(dshHome, { recursive: true });
1361
1634
  const path = lockPathFor(dshHome, profile);
1362
1635
  const payload = {
1363
1636
  pid: host.pid,
@@ -1367,9 +1640,9 @@ function writeLock(dshHome, profile, host) {
1367
1640
  profile
1368
1641
  };
1369
1642
  const tmp = `${path}.tmp`;
1370
- writeFileSync2(tmp, JSON.stringify(payload, null, 2) + `
1643
+ writeFileSync3(tmp, JSON.stringify(payload, null, 2) + `
1371
1644
  `);
1372
- renameSync2(tmp, path);
1645
+ renameSync3(tmp, path);
1373
1646
  }
1374
1647
  function clearOurLock(host) {
1375
1648
  if (!host.lockOwned)
@@ -1380,7 +1653,7 @@ function clearOurLock(host) {
1380
1653
  }
1381
1654
  }
1382
1655
  function claimBootLock(dshHome, profile) {
1383
- mkdirSync2(dshHome, { recursive: true });
1656
+ mkdirSync3(dshHome, { recursive: true });
1384
1657
  const path = lockPathFor(dshHome, profile);
1385
1658
  const payload = {
1386
1659
  pid: process.pid,
@@ -1391,7 +1664,7 @@ function claimBootLock(dshHome, profile) {
1391
1664
  booting: true
1392
1665
  };
1393
1666
  const tmp = `${path}.claim-${process.pid}-${Date.now()}`;
1394
- writeFileSync2(tmp, JSON.stringify(payload, null, 2) + `
1667
+ writeFileSync3(tmp, JSON.stringify(payload, null, 2) + `
1395
1668
  `);
1396
1669
  try {
1397
1670
  linkSync(tmp, path);
@@ -1407,7 +1680,7 @@ function claimBootLock(dshHome, profile) {
1407
1680
  function removeBootClaim(dshHome, profile, claim) {
1408
1681
  const path = lockPathFor(dshHome, profile);
1409
1682
  try {
1410
- const raw = JSON.parse(readFileSync3(path, "utf8"));
1683
+ const raw = JSON.parse(readFileSync4(path, "utf8"));
1411
1684
  if (raw.booting !== true || raw.pid !== claim.pid)
1412
1685
  return false;
1413
1686
  if (claim.startedAt !== undefined && raw.startedAt !== claim.startedAt)
@@ -1421,7 +1694,7 @@ function removeBootClaim(dshHome, profile, claim) {
1421
1694
  function removeStaleLock(dshHome, profile, stale) {
1422
1695
  const path = lockPathFor(dshHome, profile);
1423
1696
  try {
1424
- const raw = JSON.parse(readFileSync3(path, "utf8"));
1697
+ const raw = JSON.parse(readFileSync4(path, "utf8"));
1425
1698
  if (raw.booting === true || raw.pid !== stale.pid || raw.port !== stale.port)
1426
1699
  return false;
1427
1700
  } catch {
@@ -1432,7 +1705,7 @@ function removeStaleLock(dshHome, profile, stale) {
1432
1705
  }
1433
1706
  function bootClaimIntact(dshHome, profile, startedAt) {
1434
1707
  try {
1435
- const raw = JSON.parse(readFileSync3(lockPathFor(dshHome, profile), "utf8"));
1708
+ const raw = JSON.parse(readFileSync4(lockPathFor(dshHome, profile), "utf8"));
1436
1709
  return raw.booting === true && raw.pid === process.pid && raw.startedAt === startedAt;
1437
1710
  } catch {
1438
1711
  return false;
@@ -1674,7 +1947,7 @@ function adoptHost(lock, o) {
1674
1947
  }
1675
1948
  function resolveOptions(opts) {
1676
1949
  const profile = opts.profile ?? DEFAULT_PROFILE;
1677
- const dshHome = opts.dshHome ?? defaultDshHome();
1950
+ const dshHome = opts.dshHome ?? defaultDshHome2();
1678
1951
  const idleExitSec = resolveIdleExitSec(opts.idleExitSec);
1679
1952
  return {
1680
1953
  profile,
@@ -1722,7 +1995,7 @@ async function bootHost(o) {
1722
1995
  removeStaleLock(o.dshHome, o.profile, lock);
1723
1996
  const lockPath = lockPathFor(o.dshHome, o.profile);
1724
1997
  if (!existsSync3(lockPath)) {
1725
- const profileDir = join4(o.dshHome, "profiles", o.profile);
1998
+ const profileDir = join5(o.dshHome, "profiles", o.profile);
1726
1999
  if (!existsSync3(profileDir))
1727
2000
  throw new ProfileMissingError(o.profile, profileDir);
1728
2001
  const claimed = claimBootLock(o.dshHome, o.profile);
@@ -1735,7 +2008,15 @@ async function bootHost(o) {
1735
2008
  }
1736
2009
  await sleep(BOOT_JOIN_POLL_MS);
1737
2010
  }
1738
- const profileDir = join4(o.dshHome, "profiles", o.profile);
2011
+ const profileDir = join5(o.dshHome, "profiles", o.profile);
2012
+ try {
2013
+ const provision = provisionAppendSystem(o.dshHome, o.profile);
2014
+ if (provision.patch.status === "collision" || provision.patch.status === "skipped") {
2015
+ console.error(`[lifecycle] append-system preset not provisioned (${provision.patch.status}): ${provision.patch.detail}`);
2016
+ }
2017
+ } catch (error) {
2018
+ console.error("[lifecycle] append-system sync failed (booting without the preset):", error);
2019
+ }
1739
2020
  const port = await getFreePort();
1740
2021
  const child = o.spawnDsh(["--profile", o.profile, "--no-open", "--port", String(port)], {
1741
2022
  cwd: profileDir,
@@ -1918,6 +2199,7 @@ async function ensureHost(opts = {}) {
1918
2199
  var DEFAULT_PROFILE = "opentui", DEFAULT_IDLE_EXIT_MS = 5000, DEFAULT_IDLE_EXIT_SEC, ENV_IDLE_EXIT_MS = "DSH_OPENTUI_HOST_IDLE_MS", DEFAULT_READINESS_TIMEOUT_MS = 30000, DEFAULT_STALE_PROBE_MS = 8000, BOOT_JOIN_MARGIN_MS = 20000, BOOT_JOIN_POLL_MS = 200, RESPAWN_WINDOW_MS = 15000, MAX_RAPID_RESPAWNS = 3, LISTEN_PROBE_TIMEOUT_MS = 750, LISTEN_POLL_MS = 200, ADOPT_PROBE_TIMEOUT_MS = 2000, SERVE_PROBE_POLL_MS = 250, SERVE_PROBE_BUDGET_MS = 20000, ERROR_TAIL_LINES = 12, KILL_GRACE_MS = 5000, KILL_ESCALATE_MS = 2000, OUTPUT_TAIL_CAP = 8000, URL_LINE, HostLifecycleError, HostBootTimeoutError, HostDiedError, HostNotServingError, HostSpawnError, HostRespawnLoopError, HostBootSupersededError, ProfileMissingError, MintUnavailableError, registry, pendingBoots, respawnHistory, sleep = (ms) => new Promise((resolve) => setTimeout(resolve, ms)), realMintPromise = null, RETRYABLE_MINT_ERRORS, MINT_RETRY_BUDGET_MS = 15000, MINT_RETRY_INTERVAL_MS = 250, FFI_FLAG = "--experimental-ffi", __internals;
1919
2200
  var init_lifecycle = __esm(() => {
1920
2201
  init_host_probe();
2202
+ init_append_system();
1921
2203
  DEFAULT_IDLE_EXIT_SEC = DEFAULT_IDLE_EXIT_MS / 1000;
1922
2204
  URL_LINE = /dsh web: (https?:\/\/\S+)/;
1923
2205
  HostLifecycleError = class HostLifecycleError extends Error {
@@ -5648,23 +5930,23 @@ class WaterfallAnswerer {
5648
5930
 
5649
5931
  // src/client/remote-local-fs.ts
5650
5932
  import {
5651
- chmodSync as chmodSync2,
5933
+ chmodSync as chmodSync3,
5652
5934
  closeSync,
5653
5935
  existsSync as existsSync4,
5654
5936
  openSync,
5655
- readFileSync as readFileSync4,
5937
+ readFileSync as readFileSync5,
5656
5938
  readdirSync,
5657
5939
  readSync,
5658
- renameSync as renameSync3,
5940
+ renameSync as renameSync4,
5659
5941
  statSync as statSync3,
5660
- unlinkSync as unlinkSync2,
5661
- writeFileSync as writeFileSync3
5942
+ unlinkSync as unlinkSync3,
5943
+ writeFileSync as writeFileSync4
5662
5944
  } from "fs";
5663
- import { homedir as homedir2 } from "os";
5664
- import { basename, dirname, join as join5 } from "path";
5945
+ import { homedir as homedir3 } from "os";
5946
+ import { basename, dirname, join as join6 } from "path";
5665
5947
  import * as nodeZlib from "zlib";
5666
5948
  function resolveDshHome(explicit) {
5667
- return explicit ?? (process.env.DSH_HOME || join5(homedir2(), ".dsh"));
5949
+ return explicit ?? (process.env.DSH_HOME || join6(homedir3(), ".dsh"));
5668
5950
  }
5669
5951
  function stripQuotes(value) {
5670
5952
  if (value.length >= 2) {
@@ -5755,15 +6037,15 @@ function listAgentFiles(explicitHome) {
5755
6037
  const broken = [];
5756
6038
  try {
5757
6039
  const home = resolveDshHome(explicitHome);
5758
- const dir = join5(home, "agents");
6040
+ const dir = join6(home, "agents");
5759
6041
  if (!existsSync4(dir))
5760
6042
  return [];
5761
6043
  for (const entry of readdirSync(dir, { withFileTypes: true })) {
5762
6044
  if (!entry.isFile() || !entry.name.endsWith(".md"))
5763
6045
  continue;
5764
- const full = join5(dir, entry.name);
6046
+ const full = join6(dir, entry.name);
5765
6047
  try {
5766
- const result = parseAgentMarkdown(readFileSync4(full, "utf8"), full);
6048
+ const result = parseAgentMarkdown(readFileSync5(full, "utf8"), full);
5767
6049
  if (result.ok)
5768
6050
  agents.push(result.agent);
5769
6051
  else
@@ -5786,7 +6068,7 @@ function listAgentFiles(explicitHome) {
5786
6068
  function updateAgentFrontmatter(path, updates) {
5787
6069
  let text;
5788
6070
  try {
5789
- text = readFileSync4(path, "utf8");
6071
+ text = readFileSync5(path, "utf8");
5790
6072
  } catch (e) {
5791
6073
  return `cannot read ${path}: ${String(e instanceof Error ? e.message : e)}`;
5792
6074
  }
@@ -5839,7 +6121,7 @@ function updateAgentFrontmatter(path, updates) {
5839
6121
  if (!changed)
5840
6122
  return;
5841
6123
  try {
5842
- writeFileSync3(path, lines.join(eol));
6124
+ writeFileSync4(path, lines.join(eol));
5843
6125
  return;
5844
6126
  } catch (e) {
5845
6127
  return String(e instanceof Error ? e.message : e);
@@ -5847,7 +6129,7 @@ function updateAgentFrontmatter(path, updates) {
5847
6129
  }
5848
6130
  function setAgentField(name, field, value, explicitHome) {
5849
6131
  const home = resolveDshHome(explicitHome);
5850
- const file = join5(home, "agents", `${name}.md`);
6132
+ const file = join6(home, "agents", `${name}.md`);
5851
6133
  if (field === "deep") {
5852
6134
  if (value !== null && !/^\d+$/.test(value)) {
5853
6135
  return `expected a non-negative integer, got "${value}"`;
@@ -5875,7 +6157,7 @@ function repairScanSessions(explicitHome) {
5875
6157
  const out = [];
5876
6158
  try {
5877
6159
  const home = resolveDshHome(explicitHome);
5878
- const root = join5(home, "sessions");
6160
+ const root = join6(home, "sessions");
5879
6161
  if (!existsSync4(root))
5880
6162
  return ["no sessions directory"];
5881
6163
  let total = 0;
@@ -5908,7 +6190,7 @@ function scanBrokenSessionLogs(explicitHome) {
5908
6190
  const broken = [];
5909
6191
  try {
5910
6192
  const home = resolveDshHome(explicitHome);
5911
- const root = join5(home, "sessions");
6193
+ const root = join6(home, "sessions");
5912
6194
  if (!existsSync4(root))
5913
6195
  return broken;
5914
6196
  visitSessionLogs(root, 0, (full, name) => {
@@ -5936,7 +6218,7 @@ function visitSessionLogs(dir, depth, onLog) {
5936
6218
  return;
5937
6219
  }
5938
6220
  for (const entry of entries) {
5939
- const full = join5(dir, entry.name);
6221
+ const full = join6(dir, entry.name);
5940
6222
  if (entry.isDirectory()) {
5941
6223
  visitSessionLogs(full, depth + 1, onLog);
5942
6224
  continue;
@@ -6002,7 +6284,7 @@ function probeZstdFrame(path) {
6002
6284
  if (verify === undefined)
6003
6285
  return { broken: false };
6004
6286
  try {
6005
- verify(readFileSync4(path));
6287
+ verify(readFileSync5(path));
6006
6288
  return { broken: false };
6007
6289
  } catch {
6008
6290
  return { broken: true, reason: `truncated or corrupt zstd frame${notRepairable}` };
@@ -6048,14 +6330,14 @@ function sleepSync2(ms) {
6048
6330
  }
6049
6331
  function repairSessionLogTail(path, options = {}) {
6050
6332
  const delayFn = options.delayFn ?? sleepSync2;
6051
- const writeFn = options.writeFn ?? writeFileSync3;
6052
- const renameFn = options.renameFn ?? renameSync3;
6333
+ const writeFn = options.writeFn ?? writeFileSync4;
6334
+ const renameFn = options.renameFn ?? renameSync4;
6053
6335
  if (!path.endsWith(".jsonl")) {
6054
6336
  return { kind: "failed", detail: "not a plain jsonl log \u2014 client-side repair only truncates invalid jsonl tails" };
6055
6337
  }
6056
6338
  let text;
6057
6339
  try {
6058
- text = readFileSync4(path, "utf8");
6340
+ text = readFileSync5(path, "utf8");
6059
6341
  } catch (e) {
6060
6342
  return { kind: "failed", detail: `cannot read ${basename(path)}: ${String(e instanceof Error ? e.message : e)}` };
6061
6343
  }
@@ -6098,11 +6380,11 @@ function repairSessionLogTail(path, options = {}) {
6098
6380
  return { kind: "failed", detail: `cannot write the repaired copy: ${String(e instanceof Error ? e.message : e)}` };
6099
6381
  }
6100
6382
  try {
6101
- if (readFileSync4(tmpPath, "utf8") !== repaired)
6383
+ if (readFileSync5(tmpPath, "utf8") !== repaired)
6102
6384
  throw new Error("repaired copy content mismatch");
6103
6385
  } catch (e) {
6104
6386
  try {
6105
- unlinkSync2(tmpPath);
6387
+ unlinkSync3(tmpPath);
6106
6388
  } catch {}
6107
6389
  return {
6108
6390
  kind: "failed",
@@ -6118,7 +6400,7 @@ function repairSessionLogTail(path, options = {}) {
6118
6400
  renameFn(path, backupPath);
6119
6401
  } catch (e) {
6120
6402
  try {
6121
- unlinkSync2(tmpPath);
6403
+ unlinkSync3(tmpPath);
6122
6404
  } catch {}
6123
6405
  return { kind: "failed", detail: `cannot back up the original: ${String(e instanceof Error ? e.message : e)}` };
6124
6406
  }
@@ -6126,7 +6408,7 @@ function repairSessionLogTail(path, options = {}) {
6126
6408
  renameFn(tmpPath, path);
6127
6409
  } catch (e) {
6128
6410
  try {
6129
- unlinkSync2(tmpPath);
6411
+ unlinkSync3(tmpPath);
6130
6412
  } catch {}
6131
6413
  let restored = false;
6132
6414
  try {
@@ -6139,7 +6421,7 @@ function repairSessionLogTail(path, options = {}) {
6139
6421
  };
6140
6422
  }
6141
6423
  try {
6142
- chmodSync2(path, 384);
6424
+ chmodSync3(path, 384);
6143
6425
  } catch {}
6144
6426
  return { kind: "repaired", backupPath };
6145
6427
  }
@@ -6150,10 +6432,10 @@ var init_remote_local_fs = __esm(() => {
6150
6432
  });
6151
6433
 
6152
6434
  // src/client/remote-agent-profiles.ts
6153
- import { existsSync as existsSync5, mkdirSync as mkdirSync3, readFileSync as readFileSync5, renameSync as renameSync4, rmSync as rmSync2, writeFileSync as writeFileSync4 } from "fs";
6154
- import { dirname as dirname2, join as join6, resolve } from "path";
6435
+ import { existsSync as existsSync5, mkdirSync as mkdirSync4, readFileSync as readFileSync6, renameSync as renameSync5, rmSync as rmSync2, writeFileSync as writeFileSync5 } from "fs";
6436
+ import { dirname as dirname2, join as join7, resolve } from "path";
6155
6437
  function modelProfilesPath(home) {
6156
- return join6(home, "model-profiles.json");
6438
+ return join7(home, "model-profiles.json");
6157
6439
  }
6158
6440
  function narrowEntry(value) {
6159
6441
  if (value === null || typeof value !== "object" || Array.isArray(value))
@@ -6194,7 +6476,7 @@ function seedModelProfilesDoc() {
6194
6476
  function readModelProfilesDoc(home) {
6195
6477
  let raw;
6196
6478
  try {
6197
- raw = JSON.parse(readFileSync5(modelProfilesPath(home), "utf8"));
6479
+ raw = JSON.parse(readFileSync6(modelProfilesPath(home), "utf8"));
6198
6480
  } catch {
6199
6481
  return seedModelProfilesDoc();
6200
6482
  }
@@ -6237,10 +6519,10 @@ function parsePinText(text) {
6237
6519
  function readNearestProfilePin(startDir) {
6238
6520
  let current = resolve(startDir);
6239
6521
  while (true) {
6240
- const candidate = join6(current, PROFILE_PIN_FILE);
6522
+ const candidate = join7(current, PROFILE_PIN_FILE);
6241
6523
  try {
6242
6524
  if (existsSync5(candidate)) {
6243
- const name = parsePinText(readFileSync5(candidate, "utf8"));
6525
+ const name = parsePinText(readFileSync6(candidate, "utf8"));
6244
6526
  if (name !== undefined)
6245
6527
  return name;
6246
6528
  }
@@ -6305,7 +6587,7 @@ function saveProfileAgentOverrides(home, profileName, agentName, edit) {
6305
6587
  profiles: DEFAULT_PROFILE_NAMES.map((name) => ({ name, agents: {} }))
6306
6588
  };
6307
6589
  try {
6308
- const parsed = JSON.parse(readFileSync5(path, "utf8"));
6590
+ const parsed = JSON.parse(readFileSync6(path, "utf8"));
6309
6591
  if (parsed !== null && typeof parsed === "object" && !Array.isArray(parsed)) {
6310
6592
  const candidate = parsed;
6311
6593
  if (candidate.version === MODEL_PROFILES_VERSION && Array.isArray(candidate.profiles))
@@ -6343,11 +6625,11 @@ function saveProfileAgentOverrides(home, profileName, agentName, edit) {
6343
6625
  profiles[index] = profile;
6344
6626
  const body = JSON.stringify(raw);
6345
6627
  const dir = dirname2(path);
6346
- const tmp = join6(dir, `.model-profiles.json.tmp-${process.pid}`);
6628
+ const tmp = join7(dir, `.model-profiles.json.tmp-${process.pid}`);
6347
6629
  try {
6348
- mkdirSync3(dir, { recursive: true });
6349
- writeFileSync4(tmp, body);
6350
- renameSync4(tmp, path);
6630
+ mkdirSync4(dir, { recursive: true });
6631
+ writeFileSync5(tmp, body);
6632
+ renameSync5(tmp, path);
6351
6633
  return;
6352
6634
  } catch (e) {
6353
6635
  try {
@@ -6549,7 +6831,13 @@ async function askBtw(options) {
6549
6831
  let sessionId = options.previousSessionId ?? "";
6550
6832
  if (!sessionId) {
6551
6833
  const requested = randomUUID2();
6552
- const value = await options.rpc("session/create", { request: { cwd: options.cwd, sessionId: requested } });
6834
+ const value = await options.rpc("session/create", {
6835
+ request: {
6836
+ cwd: options.cwd,
6837
+ sessionId: requested,
6838
+ ...options.agentPreset !== undefined ? { agentPreset: options.agentPreset } : {}
6839
+ }
6840
+ });
6553
6841
  sessionId = typeof value.sessionId === "string" ? value.sessionId : requested;
6554
6842
  if (options.stagedModel) {
6555
6843
  try {
@@ -7508,8 +7796,8 @@ var init_remote_subagents = __esm(() => {
7508
7796
 
7509
7797
  // src/client/remote-restart.ts
7510
7798
  import { spawn as spawn3 } from "child_process";
7511
- import { existsSync as existsSync6, readFileSync as readFileSync6, renameSync as renameSync5, rmSync as rmSync3, unlinkSync as unlinkSync3, writeFileSync as writeFileSync5 } from "fs";
7512
- import { join as join7 } from "path";
7799
+ import { existsSync as existsSync6, readFileSync as readFileSync7, renameSync as renameSync6, rmSync as rmSync3, unlinkSync as unlinkSync4, writeFileSync as writeFileSync6 } from "fs";
7800
+ import { join as join8 } from "path";
7513
7801
  function defaultSpawnDsh2(argv, options) {
7514
7802
  const child = spawn3("dsh", argv, {
7515
7803
  cwd: options.cwd,
@@ -7524,7 +7812,7 @@ function defaultSpawnDsh2(argv, options) {
7524
7812
  return child;
7525
7813
  }
7526
7814
  function writeRestartedLock(home, profile, host) {
7527
- const path = join7(home, `opentui-host.${profile}.json`);
7815
+ const path = join8(home, `opentui-host.${profile}.json`);
7528
7816
  const payload = {
7529
7817
  pid: host.pid,
7530
7818
  port: host.port,
@@ -7533,17 +7821,17 @@ function writeRestartedLock(home, profile, host) {
7533
7821
  profile
7534
7822
  };
7535
7823
  const tmp = `${path}.tmp`;
7536
- writeFileSync5(tmp, JSON.stringify(payload, null, 2) + `
7824
+ writeFileSync6(tmp, JSON.stringify(payload, null, 2) + `
7537
7825
  `);
7538
- renameSync5(tmp, path);
7826
+ renameSync6(tmp, path);
7539
7827
  }
7540
7828
  async function restartSamePortHost(options = {}) {
7541
7829
  const profile = options.profile ?? "opentui";
7542
7830
  const home = resolveDshHome(options.dshHome);
7543
- const lockPath = join7(home, `opentui-host.${profile}.json`);
7831
+ const lockPath = join8(home, `opentui-host.${profile}.json`);
7544
7832
  let lock;
7545
7833
  try {
7546
- const raw = JSON.parse(readFileSync6(lockPath, "utf8"));
7834
+ const raw = JSON.parse(readFileSync7(lockPath, "utf8"));
7547
7835
  if (typeof raw.pid === "number" && typeof raw.port === "number") {
7548
7836
  lock = { pid: raw.pid, port: raw.port, ...raw.booting === true ? { booting: true } : {} };
7549
7837
  }
@@ -7579,12 +7867,12 @@ async function restartSamePortHost(options = {}) {
7579
7867
  await sleep2(POLL_MS);
7580
7868
  }
7581
7869
  try {
7582
- const current = JSON.parse(readFileSync6(lockPath, "utf8"));
7870
+ const current = JSON.parse(readFileSync7(lockPath, "utf8"));
7583
7871
  if (current.booting !== true && current.pid === pid && current.port === port)
7584
7872
  rmSync3(lockPath, { force: true });
7585
7873
  } catch {
7586
7874
  try {
7587
- unlinkSync3(lockPath);
7875
+ unlinkSync4(lockPath);
7588
7876
  } catch {}
7589
7877
  }
7590
7878
  const quietDeadline = deadline(KILL_GRACE_MS2 + KILL_ESCALATE_MS2 + LISTEN_RELEASE_GRACE_MS);
@@ -7593,7 +7881,7 @@ async function restartSamePortHost(options = {}) {
7593
7881
  if (await isListening(port)) {
7594
7882
  throw new HostRestartError("port-held", `port ${port} is still held after the old host died \u2014 refusing to spawn into EADDRINUSE`);
7595
7883
  }
7596
- const profileDir = join7(home, "profiles", profile);
7884
+ const profileDir = join8(home, "profiles", profile);
7597
7885
  if (!existsSync6(profileDir)) {
7598
7886
  throw new HostRestartError("profile-missing", `profile '${profile}' is not provisioned (${profileDir} missing)`);
7599
7887
  }
@@ -7663,7 +7951,7 @@ __export(exports_remote_host_session, {
7663
7951
  openRemoteStream: () => openRemoteStream
7664
7952
  });
7665
7953
  import { randomUUID as randomUUID4 } from "crypto";
7666
- import { existsSync as existsSync7, mkdirSync as mkdirSync4, readFileSync as readFileSync7, renameSync as renameSync6, rmSync as rmSync4, writeFileSync as writeFileSync6 } from "fs";
7954
+ import { existsSync as existsSync7, mkdirSync as mkdirSync5, readFileSync as readFileSync8, renameSync as renameSync7, rmSync as rmSync4, writeFileSync as writeFileSync7 } from "fs";
7667
7955
  import { join as joinPath } from "path";
7668
7956
  import WS3 from "ws";
7669
7957
  function trace(message) {
@@ -7709,6 +7997,8 @@ class RemoteHostSession {
7709
7997
  #sessionId;
7710
7998
  #resumeId;
7711
7999
  #presetId;
8000
+ #appendPresetChecked = false;
8001
+ #appendPresetAvailable = false;
7712
8002
  #cb;
7713
8003
  #askProvider;
7714
8004
  #resolveTurn;
@@ -8122,6 +8412,23 @@ class RemoteHostSession {
8122
8412
  return [];
8123
8413
  }
8124
8414
  }
8415
+ async#appendPresetRosterCheck() {
8416
+ if (this.#appendPresetChecked)
8417
+ return this.#appendPresetAvailable;
8418
+ let roster;
8419
+ try {
8420
+ roster = await this.#rpc("agentPresets/list");
8421
+ } catch {
8422
+ return false;
8423
+ }
8424
+ this.#appendPresetChecked = true;
8425
+ const presets = Array.isArray(roster.presets) ? roster.presets : [];
8426
+ this.#appendPresetAvailable = presets.some((p) => {
8427
+ const row = typeof p === "object" && p !== null ? p : {};
8428
+ return String(row.id ?? "") === APPEND_SYSTEM_PRESET_ID && !(typeof row.broken === "string" && row.broken);
8429
+ });
8430
+ return this.#appendPresetAvailable;
8431
+ }
8125
8432
  async readPreset(presetId) {
8126
8433
  try {
8127
8434
  const doc = await this.#rpc("agentPresets/read", { agentPreset: presetId });
@@ -8162,8 +8469,10 @@ class RemoteHostSession {
8162
8469
  if (this.#presetId !== undefined)
8163
8470
  return this.#presetId;
8164
8471
  if (proj.agentPreset !== undefined && proj.agentPreset !== this.#presetId) {
8165
- this.#presetId = proj.agentPreset;
8166
- this.#probeExecutionMode();
8472
+ if (!(this.#presetId === undefined && proj.agentPreset === APPEND_SYSTEM_PRESET_ID)) {
8473
+ this.#presetId = proj.agentPreset;
8474
+ this.#probeExecutionMode();
8475
+ }
8167
8476
  }
8168
8477
  return proj.agentPreset;
8169
8478
  } catch {
@@ -8272,7 +8581,7 @@ class RemoteHostSession {
8272
8581
  }
8273
8582
  keybindingsLoad() {
8274
8583
  try {
8275
- return JSON.parse(readFileSync7(this.configPath("keybindings.json"), "utf8"));
8584
+ return JSON.parse(readFileSync8(this.configPath("keybindings.json"), "utf8"));
8276
8585
  } catch {
8277
8586
  return {};
8278
8587
  }
@@ -8285,14 +8594,14 @@ class RemoteHostSession {
8285
8594
  configLoad() {
8286
8595
  let base = {};
8287
8596
  try {
8288
- base = JSON.parse(readFileSync7(this.configPath(), "utf8"));
8597
+ base = JSON.parse(readFileSync8(this.configPath(), "utf8"));
8289
8598
  } catch {}
8290
8599
  const merged = mergeConfig(base, this.#overlayCache ?? {}, process.env);
8291
8600
  return { ...base, ...merged };
8292
8601
  }
8293
8602
  configRaw() {
8294
8603
  try {
8295
- return JSON.parse(readFileSync7(this.configPath(), "utf8"));
8604
+ return JSON.parse(readFileSync8(this.configPath(), "utf8"));
8296
8605
  } catch {
8297
8606
  return {};
8298
8607
  }
@@ -8326,13 +8635,13 @@ class RemoteHostSession {
8326
8635
  const merged = { ...this.#readProfileConfig(), ...rest };
8327
8636
  const profileDir = joinPath(this.#dshHome, "profiles", this.#profile);
8328
8637
  if (!existsSync7(profileDir))
8329
- mkdirSync4(profileDir, { recursive: true });
8638
+ mkdirSync5(profileDir, { recursive: true });
8330
8639
  const path = this.configPath();
8331
8640
  const tmp = `${path}.${process.pid}.tmp`;
8332
8641
  try {
8333
- writeFileSync6(tmp, JSON.stringify(merged, null, 2) + `
8642
+ writeFileSync7(tmp, JSON.stringify(merged, null, 2) + `
8334
8643
  `);
8335
- renameSync6(tmp, path);
8644
+ renameSync7(tmp, path);
8336
8645
  } catch (error) {
8337
8646
  try {
8338
8647
  rmSync4(tmp, { force: true });
@@ -8347,7 +8656,7 @@ class RemoteHostSession {
8347
8656
  }
8348
8657
  #readProfileConfig() {
8349
8658
  try {
8350
- return JSON.parse(readFileSync7(this.configPath(), "utf8"));
8659
+ return JSON.parse(readFileSync8(this.configPath(), "utf8"));
8351
8660
  } catch {
8352
8661
  return {};
8353
8662
  }
@@ -8612,6 +8921,7 @@ class RemoteHostSession {
8612
8921
  try {
8613
8922
  await this.start();
8614
8923
  const staged = this.#pendingModel ?? await this.currentModelSelection();
8924
+ const btwPreset = this.#presetId ?? (await this.#appendPresetRosterCheck() ? APPEND_SYSTEM_PRESET_ID : undefined);
8615
8925
  const result = await askBtw({
8616
8926
  rpc: (method, args) => this.#rpc(method, args),
8617
8927
  socketFactory: this.#socketFactory,
@@ -8620,7 +8930,8 @@ class RemoteHostSession {
8620
8930
  snapshot,
8621
8931
  ...onDelta ? { onDelta } : {},
8622
8932
  ...this.#btwSessionId !== undefined ? { previousSessionId: this.#btwSessionId } : {},
8623
- ...staged !== undefined ? { stagedModel: staged } : {}
8933
+ ...staged !== undefined ? { stagedModel: staged } : {},
8934
+ ...btwPreset !== undefined ? { agentPreset: btwPreset } : {}
8624
8935
  });
8625
8936
  this.#btwSessionId = result.sessionId;
8626
8937
  return result.answer;
@@ -8815,11 +9126,14 @@ class RemoteHostSession {
8815
9126
  await this.#attachFollow(false);
8816
9127
  return this.#sessionId;
8817
9128
  }
9129
+ const resumed = this.#resumeId !== undefined;
8818
9130
  const requestedId = this.#resumeId ?? randomUUID4();
8819
9131
  this.#resumeId = undefined;
8820
9132
  const request = { cwd: this.#cwd, sessionId: requestedId };
8821
9133
  if (this.#presetId !== undefined)
8822
9134
  request.agentPreset = this.#presetId;
9135
+ else if (!resumed && await this.#appendPresetRosterCheck())
9136
+ request.agentPreset = APPEND_SYSTEM_PRESET_ID;
8823
9137
  let value;
8824
9138
  try {
8825
9139
  value = await this.#rpc("session/create", { request });
@@ -8830,8 +9144,9 @@ class RemoteHostSession {
8830
9144
  throw error;
8831
9145
  }
8832
9146
  this.#sessionId = typeof value.sessionId === "string" ? value.sessionId : requestedId;
8833
- if (typeof value.agentPreset === "string" && value.agentPreset)
9147
+ if (typeof value.agentPreset === "string" && value.agentPreset && !(this.#presetId === undefined && value.agentPreset === APPEND_SYSTEM_PRESET_ID)) {
8834
9148
  this.#presetId = value.agentPreset;
9149
+ }
8835
9150
  if (this.#pendingModel !== undefined && this.#sessionId !== undefined) {
8836
9151
  const staged = this.#pendingModel;
8837
9152
  this.#pendingModel = undefined;
@@ -8845,7 +9160,9 @@ class RemoteHostSession {
8845
9160
  }
8846
9161
  const opening = await this.#attachFollow(false);
8847
9162
  if (opening.header.agentPreset && opening.header.agentPreset !== this.#presetId) {
8848
- this.#presetId = opening.header.agentPreset;
9163
+ if (!(this.#presetId === undefined && opening.header.agentPreset === APPEND_SYSTEM_PRESET_ID)) {
9164
+ this.#presetId = opening.header.agentPreset;
9165
+ }
8849
9166
  this.#probeExecutionMode();
8850
9167
  }
8851
9168
  return this.#sessionId;
@@ -9179,6 +9496,7 @@ class RemoteHostSession {
9179
9496
  return;
9180
9497
  if (this.#follow?.attached)
9181
9498
  return;
9499
+ this.#appendPresetChecked = false;
9182
9500
  this.#reattachInFlight = true;
9183
9501
  if (this.#awaiting)
9184
9502
  this.#setReconnecting(true);
@@ -9329,6 +9647,7 @@ var init_remote_host_session = __esm(() => {
9329
9647
  init_remote_follow();
9330
9648
  init_remote_session_ops();
9331
9649
  init_token_estimate();
9650
+ init_append_system();
9332
9651
  init_remote_stream();
9333
9652
  init_transport();
9334
9653
  init_remote_local_fs();
@@ -33252,9 +33571,9 @@ var init_theme3 = __esm(() => {
33252
33571
  });
33253
33572
 
33254
33573
  // ../i18n/src/registry.ts
33255
- import { existsSync as existsSync8, readdirSync as readdirSync2, readFileSync as readFileSync8 } from "fs";
33256
- import { homedir as homedir3 } from "os";
33257
- import { dirname as dirname3, join as join8 } from "path";
33574
+ import { existsSync as existsSync8, readdirSync as readdirSync2, readFileSync as readFileSync9 } from "fs";
33575
+ import { homedir as homedir4 } from "os";
33576
+ import { dirname as dirname3, join as join9 } from "path";
33258
33577
  function validateLocaleFile(raw) {
33259
33578
  if (typeof raw !== "object" || raw === null || Array.isArray(raw)) {
33260
33579
  return { ok: false, errors: [{ key: "(file)", reason: "not a flat JSON object" }] };
@@ -33298,21 +33617,21 @@ function mergeTables(bundled, override) {
33298
33617
  return { ...bundled, ...override };
33299
33618
  }
33300
33619
  function userLocalesDir(dshHome) {
33301
- const home = dshHome ?? process.env.DSH_HOME ?? join8(homedir3(), ".dsh");
33302
- return join8(home, "locales");
33620
+ const home = dshHome ?? process.env.DSH_HOME ?? join9(homedir4(), ".dsh");
33621
+ return join9(home, "locales");
33303
33622
  }
33304
33623
  function bundledLocalesDir() {
33305
33624
  let dir = dirname3(new URL(import.meta.url).pathname);
33306
33625
  for (let up = 0;up < 6; up++) {
33307
- const candidate = join8(dir, "locales");
33308
- if (existsSync8(join8(candidate, `${DEFAULT_LANGUAGE}.json`)))
33626
+ const candidate = join9(dir, "locales");
33627
+ if (existsSync8(join9(candidate, `${DEFAULT_LANGUAGE}.json`)))
33309
33628
  return candidate;
33310
33629
  const parent = dirname3(dir);
33311
33630
  if (parent === dir)
33312
33631
  break;
33313
33632
  dir = parent;
33314
33633
  }
33315
- return join8(dirname3(new URL(import.meta.url).pathname), "..", "locales");
33634
+ return join9(dirname3(new URL(import.meta.url).pathname), "..", "locales");
33316
33635
  }
33317
33636
  function loadLocales(options) {
33318
33637
  const bundledDir = options?.bundledDir ?? bundledLocalesDir();
@@ -33323,7 +33642,7 @@ function loadLocales(options) {
33323
33642
  if (!entry.endsWith(".json"))
33324
33643
  continue;
33325
33644
  const id = entry.slice(0, -".json".length);
33326
- const result = parseLocaleFile(readFileSync8(join8(bundledDir, entry), "utf8"));
33645
+ const result = parseLocaleFile(readFileSync9(join9(bundledDir, entry), "utf8"));
33327
33646
  if (!result.ok) {
33328
33647
  warnings.push(`[i18n] bundled locale file rejected, skipping '${entry}': ${formatErrors(result.errors)}`);
33329
33648
  continue;
@@ -33339,7 +33658,7 @@ function loadLocales(options) {
33339
33658
  if (!entry.endsWith(".json"))
33340
33659
  continue;
33341
33660
  const id = entry.slice(0, -".json".length);
33342
- const result = parseLocaleFile(readFileSync8(join8(userDir, entry), "utf8"));
33661
+ const result = parseLocaleFile(readFileSync9(join9(userDir, entry), "utf8"));
33343
33662
  if (!result.ok) {
33344
33663
  warnings.push(`[i18n] user locale file rejected, skipping '${entry}': ${formatErrors(result.errors)}`);
33345
33664
  continue;
@@ -40756,7 +41075,7 @@ var init_string_width = __esm(() => {
40756
41075
  });
40757
41076
 
40758
41077
  // ../tui-base/src/routes/session/composer-context.tsx
40759
- import { homedir as homedir4 } from "os";
41078
+ import { homedir as homedir5 } from "os";
40760
41079
  function truncateLeft(text, limit) {
40761
41080
  if (limit <= 0)
40762
41081
  return "";
@@ -40849,7 +41168,7 @@ function ComposerContext(props) {
40849
41168
  }
40850
41169
  function safeHome() {
40851
41170
  try {
40852
- return homedir4();
41171
+ return homedir5();
40853
41172
  } catch {
40854
41173
  return;
40855
41174
  }
@@ -50226,14 +50545,14 @@ var init_login = __esm(() => {
50226
50545
  });
50227
50546
 
50228
50547
  // ../tui-base/src/routes/session/export.ts
50229
- import { homedir as homedir5 } from "os";
50548
+ import { homedir as homedir6 } from "os";
50230
50549
  import { resolve as resolve5 } from "path";
50231
50550
  function exportTargetPath(sessionId, arg) {
50232
50551
  const trimmed = arg?.trim();
50233
50552
  if (trimmed)
50234
50553
  return resolve5(trimmed);
50235
50554
  const id8 = sessionId.slice(0, 8).replace(/[^A-Za-z0-9._-]/g, "-");
50236
- return resolve5(homedir5(), "Downloads", `dsh-session-${id8}.jsonl`);
50555
+ return resolve5(homedir6(), "Downloads", `dsh-session-${id8}.jsonl`);
50237
50556
  }
50238
50557
  function journalToJSONL(entries) {
50239
50558
  if (entries.length === 0)
@@ -51359,14 +51678,14 @@ var init_slash_usage = __esm(() => {
51359
51678
  });
51360
51679
 
51361
51680
  // ../tui-base/src/routes/session/skills-source.ts
51362
- import { existsSync as existsSync9, readdirSync as readdirSync3, readFileSync as readFileSync9, statSync as statSync4 } from "fs";
51363
- import { homedir as homedir6 } from "os";
51364
- import { dirname as dirname5, join as join9, resolve as resolve6 } from "path";
51681
+ import { existsSync as existsSync9, readdirSync as readdirSync3, readFileSync as readFileSync10, statSync as statSync4 } from "fs";
51682
+ import { homedir as homedir7 } from "os";
51683
+ import { dirname as dirname5, join as join10, resolve as resolve6 } from "path";
51365
51684
  import { TextAttributes as TextAttributes8 } from "@opentui/core";
51366
51685
  function findProjectRoot(cwd) {
51367
51686
  let dir = resolve6(cwd);
51368
51687
  for (let depth = 0;depth < 64; depth++) {
51369
- if (existsSync9(join9(dir, ".git")))
51688
+ if (existsSync9(join10(dir, ".git")))
51370
51689
  return dir;
51371
51690
  const parent = dirname5(dir);
51372
51691
  if (parent === dir)
@@ -51381,7 +51700,7 @@ function resolveAgentsHome(explicit) {
51381
51700
  const env = process.env.DSH_AGENTS_HOME;
51382
51701
  if (typeof env === "string" && env.trim() !== "")
51383
51702
  return resolve6(env);
51384
- return resolve6(join9(homedir6(), ".agents"));
51703
+ return resolve6(join10(homedir7(), ".agents"));
51385
51704
  }
51386
51705
  function agentsHomeEnvWarning(env, configValue) {
51387
51706
  const value = typeof env === "string" ? env : process.env.DSH_AGENTS_HOME;
@@ -51400,18 +51719,18 @@ function agentsHomeEnvWarning(env, configValue) {
51400
51719
  function skillRoots(options) {
51401
51720
  const roots = [];
51402
51721
  const projectRoot = findProjectRoot(options.cwd);
51403
- roots.push({ path: join9(projectRoot, ".dsh", "skills"), rank: 100, skipSystem: false });
51404
- roots.push({ path: join9(projectRoot, ".agents", "skills"), rank: 200, skipSystem: false });
51722
+ roots.push({ path: join10(projectRoot, ".dsh", "skills"), rank: 100, skipSystem: false });
51723
+ roots.push({ path: join10(projectRoot, ".agents", "skills"), rank: 200, skipSystem: false });
51405
51724
  for (const dir of options.customSkillDirs ?? []) {
51406
51725
  if (typeof dir === "string" && dir.trim() !== "") {
51407
51726
  roots.push({ path: resolve6(dir), rank: 300, skipSystem: false });
51408
51727
  }
51409
51728
  }
51410
51729
  if (options.dshHome !== undefined) {
51411
- roots.push({ path: join9(options.dshHome, "skills"), rank: 400, skipSystem: true });
51730
+ roots.push({ path: join10(options.dshHome, "skills"), rank: 400, skipSystem: true });
51412
51731
  }
51413
51732
  const agentsHome = resolveAgentsHome(options.agentsHome);
51414
- roots.push({ path: join9(agentsHome, "skills"), rank: 500, skipSystem: false });
51733
+ roots.push({ path: join10(agentsHome, "skills"), rank: 500, skipSystem: false });
51415
51734
  const seen = new Set;
51416
51735
  const deduped = [];
51417
51736
  for (const root of roots.sort((a, b) => a.rank - b.rank)) {
@@ -51475,7 +51794,7 @@ function oneLine(value) {
51475
51794
  function readSkillFile(path) {
51476
51795
  let raw;
51477
51796
  try {
51478
- raw = readFileSync9(path, "utf8");
51797
+ raw = readFileSync10(path, "utf8");
51479
51798
  } catch {
51480
51799
  return;
51481
51800
  }
@@ -51512,7 +51831,7 @@ function discoverSkills(options) {
51512
51831
  let isFile = entry.isFile();
51513
51832
  if (entry.isSymbolicLink()) {
51514
51833
  try {
51515
- const target = statSync4(join9(root.path, entry.name));
51834
+ const target = statSync4(join10(root.path, entry.name));
51516
51835
  isDirectory = target.isDirectory();
51517
51836
  isFile = target.isFile();
51518
51837
  } catch {
@@ -51521,9 +51840,9 @@ function discoverSkills(options) {
51521
51840
  }
51522
51841
  let file;
51523
51842
  if (isDirectory)
51524
- file = join9(root.path, entry.name, "SKILL.md");
51843
+ file = join10(root.path, entry.name, "SKILL.md");
51525
51844
  else if (isFile && entry.name.endsWith(".md"))
51526
- file = join9(root.path, entry.name);
51845
+ file = join10(root.path, entry.name);
51527
51846
  if (file === undefined)
51528
51847
  continue;
51529
51848
  const row = readSkillFile(file);
@@ -51902,14 +52221,14 @@ var init_slash_palette = __esm(() => {
51902
52221
  // ../tui-base/src/routes/session/skills-manage.ts
51903
52222
  import { existsSync as existsSync10 } from "fs";
51904
52223
  import { lstat, mkdir as mkdir3, readFile as readFile3, readdir, realpath, symlink, unlink } from "fs/promises";
51905
- import { join as join10, sep } from "path";
52224
+ import { join as join11, sep } from "path";
51906
52225
  function skillSymlinkPaths(publicDir, curatedDir, name) {
51907
- const srcMd = join10(publicDir, `${name}.md`);
52226
+ const srcMd = join11(publicDir, `${name}.md`);
51908
52227
  if (existsSync10(srcMd))
51909
- return { src: srcMd, dest: join10(curatedDir, `${name}.md`) };
51910
- const srcBundle = join10(publicDir, name);
52228
+ return { src: srcMd, dest: join11(curatedDir, `${name}.md`) };
52229
+ const srcBundle = join11(publicDir, name);
51911
52230
  if (existsSync10(srcBundle))
51912
- return { src: srcBundle, dest: join10(curatedDir, name) };
52231
+ return { src: srcBundle, dest: join11(curatedDir, name) };
51913
52232
  return;
51914
52233
  }
51915
52234
  async function installSkillSymlink(src, dest) {
@@ -51973,8 +52292,8 @@ async function applyOneSkillChange(name, targetState, publicDir, curatedDir) {
51973
52292
  }
51974
52293
  }
51975
52294
  try {
51976
- const destMd = join10(curatedDir, `${name}.md`);
51977
- const destBundle = join10(curatedDir, name);
52295
+ const destMd = join11(curatedDir, `${name}.md`);
52296
+ const destBundle = join11(curatedDir, name);
51978
52297
  const mdStat = await lstat(destMd).catch(() => {
51979
52298
  return;
51980
52299
  });
@@ -52065,14 +52384,14 @@ async function scanAvailableSkills(publicDir, curatedDir) {
52065
52384
  if (name.endsWith(".md")) {
52066
52385
  skillNames.add(name.slice(0, -3));
52067
52386
  } else if (!name.startsWith(".")) {
52068
- if (existsSync10(join10(publicDir, name, "SKILL.md")))
52387
+ if (existsSync10(join11(publicDir, name, "SKILL.md")))
52069
52388
  skillNames.add(name);
52070
52389
  }
52071
52390
  }
52072
52391
  const rows = [];
52073
52392
  for (const name of skillNames) {
52074
- const installed = existsSync10(join10(curatedDir, `${name}.md`)) || existsSync10(join10(curatedDir, name));
52075
- const description = await readSkillDescription(existsSync10(join10(publicDir, name, "SKILL.md")) ? join10(publicDir, name, "SKILL.md") : join10(publicDir, `${name}.md`));
52393
+ const installed = existsSync10(join11(curatedDir, `${name}.md`)) || existsSync10(join11(curatedDir, name));
52394
+ const description = await readSkillDescription(existsSync10(join11(publicDir, name, "SKILL.md")) ? join11(publicDir, name, "SKILL.md") : join11(publicDir, `${name}.md`));
52076
52395
  rows.push({ name, description, installed });
52077
52396
  }
52078
52397
  rows.sort((a, b) => a.name.localeCompare(b.name));
@@ -59311,7 +59630,7 @@ var init_subagents_viewer = __esm(() => {
59311
59630
  import { TextAttributes as TextAttributes12 } from "@opentui/core";
59312
59631
  function resolveVersion() {
59313
59632
  try {
59314
- return "0.17.1";
59633
+ return "0.17.2";
59315
59634
  } catch {
59316
59635
  return "dev";
59317
59636
  }
@@ -61777,7 +62096,7 @@ var init_session_seam_adapter = __esm(() => {
61777
62096
  });
61778
62097
 
61779
62098
  // ../tui-base/examples/v2-entry.tsx
61780
- import { join as join11 } from "path";
62099
+ import { join as join12 } from "path";
61781
62100
  async function loadShell() {
61782
62101
  const [shared, lifecycle, transport, rhs, adapter, git] = await Promise.all([
61783
62102
  Promise.resolve().then(() => (init_boot_shared(), exports_boot_shared)),
@@ -62448,8 +62767,8 @@ async function bootClientV2(options = {}) {
62448
62767
  agentsHome: agentsHomeForSkills
62449
62768
  });
62450
62769
  const skillsManagerRoots = {
62451
- source: join11(agentsHomeForSkills, "skills"),
62452
- curated: join11(host.dshHome, "skills")
62770
+ source: join12(agentsHomeForSkills, "skills"),
62771
+ curated: join12(host.dshHome, "skills")
62453
62772
  };
62454
62773
  const envTheme = process.env[shared.ENV_THEME];
62455
62774
  const workspaceConfig = seam.workspaceConfig();
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@aiwayds/dsh-opentui",
3
- "version": "0.17.1",
3
+ "version": "0.17.2",
4
4
  "license": "Apache-2.0",
5
5
  "type": "module",
6
6
  "bin": {