dsh-bash-terminal-ts 0.8.8 → 0.9.1

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.
Files changed (52) hide show
  1. package/CHANGELOG.md +205 -190
  2. package/CHANGELOG.pt.md +151 -0
  3. package/README.de.md +1 -1
  4. package/README.en.md +3 -2
  5. package/README.es.md +1 -1
  6. package/README.fr.md +1 -1
  7. package/README.it.md +1 -1
  8. package/README.md +4 -3
  9. package/README.pt.md +212 -0
  10. package/README.ru.md +1 -1
  11. package/agent-presets/README.md +171 -170
  12. package/agent-presets/install-presets.mjs +180 -179
  13. package/agent-presets/standard-win-niu/agent.cordis.yml +271 -0
  14. package/agent-presets/standard-win-niu/preset.yml +2 -0
  15. package/cordis.patch.yml +84 -83
  16. package/dist/client.core.js +59 -2
  17. package/dist/client.js +59 -2
  18. package/docs/dsh-plugin-development.md +169 -0
  19. package/docs/niu-backend.md +197 -0
  20. package/dsh.plugin.json +4 -3
  21. package/lib/client.js +59 -2
  22. package/lib/dsh-types.d.ts +14 -2
  23. package/lib/index.d.ts +15 -2
  24. package/lib/index.js +43 -5
  25. package/lib/locales.js +59 -2
  26. package/lib/shell-id.d.ts +1 -1
  27. package/lib/shells.d.ts +1 -0
  28. package/lib/shells.js +8 -2
  29. package/lib/terminal.js +4 -0
  30. package/lib/webterminals/host.js +2 -2
  31. package/lib/webterminals/mount.js +1 -0
  32. package/locale/de.json +6 -6
  33. package/locale/en.json +6 -6
  34. package/locale/es.json +6 -6
  35. package/locale/fr.json +6 -6
  36. package/locale/it.json +6 -6
  37. package/locale/ja.json +6 -6
  38. package/locale/ko.json +6 -6
  39. package/locale/pt.json +6 -0
  40. package/locale/ru.json +6 -6
  41. package/locale/zh.json +6 -6
  42. package/package.json +153 -149
  43. package/scripts/check-artifacts.mjs +96 -96
  44. package/src/client.tsx +685 -685
  45. package/src/dsh-types.ts +332 -320
  46. package/src/index.ts +1316 -1275
  47. package/src/locales.ts +509 -452
  48. package/src/shell-id.ts +11 -11
  49. package/src/shells.ts +279 -272
  50. package/src/terminal.ts +616 -612
  51. package/src/webterminals/host.ts +361 -361
  52. package/src/webterminals/mount.ts +237 -236
@@ -1,179 +1,180 @@
1
- #!/usr/bin/env node
2
- // agent-presets/install-presets.mjs - copy a terminal-semantics preset template
3
- // into the DSH deployment (%USERPROFILE%\.dsh\.agent-presets by default).
4
- //
5
- // What it does:
6
- // 1. resolves the %%placeholder%% tokens from --set key=value pairs;
7
- // 2. DROPS any line whose placeholder was not provided (the line is optional
8
- // machine guidance by design - an unfilled `%%pythonPath%%` sentence is
9
- // worse than no sentence);
10
- // 3. backs up an existing same-name preset OUTSIDE .agent-presets (a backup
11
- // inside the preset dir would be mounted as a preset), then writes.
12
- // It never deletes anything: overwrite happens only after the backup copy.
13
- import { parseArgs } from "node:util";
14
- import { cpSync, existsSync, mkdirSync, readFileSync, readdirSync, statSync, writeFileSync } from "node:fs";
15
- import { homedir } from "node:os";
16
- import { dirname, join, resolve } from "node:path";
17
- import { fileURLToPath } from "node:url";
18
-
19
- const HERE = dirname(fileURLToPath(import.meta.url));
20
- const TEMPLATES = readdirSync(HERE, { withFileTypes: true }).filter((d) => d.isDirectory()).map((d) => d.name);
21
-
22
- const { values: opt, positionals } = parseArgs({
23
- allowPositionals: true,
24
- options: {
25
- name: { type: "string", multiple: true },
26
- all: { type: "boolean", default: false },
27
- dest: { type: "string" },
28
- set: { type: "string", multiple: true },
29
- "dry-run": { type: "boolean", default: false },
30
- list: { type: "boolean", default: false },
31
- help: { type: "boolean", default: false }
32
- }
33
- });
34
-
35
- if (opt.help || opt.list) {
36
- console.log(`templates here: ${TEMPLATES.join(", ")}`);
37
- if (opt.help) {
38
- console.log([
39
- "usage:",
40
- " node install-presets.mjs --list # what is available",
41
- " node install-presets.mjs --name <preset> [--name ...] # install selected templates",
42
- " node install-presets.mjs --all [--dry-run] # everything, or preview first",
43
- " from an installed plugin (profile dir):",
44
- " node node_modules/dsh-bash-terminal-ts/agent-presets/install-presets.mjs --name <preset>",
45
- " from the source repo: npm run presets:install -- --name <preset>",
46
- "",
47
- "what each template anchors (default terminal + its failure-mode guidance):",
48
- " standard-win PowerShell (pwsh) - the Windows default, six-item pitfall list",
49
- " standard-win-gitbash Git Bash - POSIX bash, /c/... paths, MSYS path-conversion traps",
50
- " standard-win-msys2 MSYS2 bash - + msys-vs-mingw64 dual-runtime guidance",
51
- " standard-win-wsl2 WSL2 Linux bash - /mnt/c paths, case-sensitivity/CRLF/wslpath traps",
52
- " standard-win-payload pinned POSIX payload - digest-verified backup runtime; opt-in twice, see below",
53
- "",
54
- "placeholders (%%token%% lines in the persona):",
55
- " --set pythonPath=<path> Windows interpreter; bash templates want /c/... form",
56
- " --set winPythonWslPath=<path> the same interpreter as WSL sees it (/mnt/c/... form)",
57
- "A line whose token was not --set is DROPPED whole - installing with no --set flags",
58
- "is always safe and machine-neutral (no %% residue can ever be written).",
59
- "",
60
- "after installing - keep the three layers in agreement:",
61
- " 1. restart / hot-reload DSH (the host mounts %USERPROFILE%\\.dsh\\.agent-presets at boot);",
62
- " 2. pick the preset for the session (subagents inherit it through agentPreset);",
63
- " 3. set this plugin's default terminal to the SAME shell: Settings -> General ->",
64
- " Default terminal (or defaultShell in cordis.patch.yml). For the payload",
65
- " template ALSO: enablePosixPayload: true in cordis.patch.yml (operator gate,",
66
- " takes effect on restart) AND the 'POSIX payload' row switch shellPayload: true",
67
- " on the settings page - the payload is deliberately opt-in twice.",
68
- "",
69
- "safety: an existing same-name preset is copied OUTSIDE the mount root",
70
- "(%USERPROFILE%\\.dsh\\_agent-presets-backup\\<timestamp>\\) before overwriting; nothing is deleted.",
71
- "",
72
- "companion: install the dsh-preset-doctor plugin (npm) - it scans these mounted",
73
- "presets across host-version migrations, auto-realigns what it can and gives",
74
- "per-row switches inside each preset card, so the templates stay governable",
75
- "without hand-editing YAML."
76
- ].join("\n"));
77
- }
78
- process.exit(0);
79
- }
80
-
81
- const chosen = opt.all ? TEMPLATES : (opt.name ?? positionals);
82
- if (chosen.length === 0) {
83
- console.error("install-presets: nothing selected - use --name <preset> or --all");
84
- process.exit(2);
85
- }
86
- for (const name of chosen) {
87
- if (!TEMPLATES.includes(name)) {
88
- console.error(`install-presets: unknown template ${JSON.stringify(name)}; available: ${TEMPLATES.join(", ")}`);
89
- process.exit(2);
90
- }
91
- }
92
-
93
- const sets = {};
94
- for (const kv of opt.set ?? []) {
95
- const i = kv.indexOf("=");
96
- if (i <= 0) {
97
- console.error(`install-presets: bad --set ${JSON.stringify(kv)} (expected key=value)`);
98
- process.exit(2);
99
- }
100
- sets[kv.slice(0, i).trim()] = kv.slice(i + 1);
101
- }
102
-
103
- const dest = resolve(opt.dest ?? join(process.env.USERPROFILE ?? homedir(), ".dsh", "agent-presets"));
104
- // Backup lives OUTSIDE the preset directory: .agent-presets is a mount root and
105
- // every subdirectory of it is treated as a preset by the host.
106
- const backupRoot = resolve(dest, "..", "_agent-presets-backup");
107
-
108
- function render(text) {
109
- const out = [];
110
- for (const line of text.split(/\r?\n/)) {
111
- const tokens = [...line.matchAll(/%%([A-Za-z][\w]*)%%/g)].map((m) => m[1]);
112
- if (tokens.length === 0) {
113
- out.push(line);
114
- continue;
115
- }
116
- const missing = tokens.filter((t) => !(t in sets));
117
- if (missing.length > 0) {
118
- // An optional machine-guidance line without its value: drop the whole
119
- // line rather than ship a sentence with a hole in it.
120
- console.log(` note: dropped line (missing --set ${missing.join(", ")}): ${line.trim().slice(0, 80)}...`);
121
- continue;
122
- }
123
- out.push(line.replace(/%%([A-Za-z][\w]*)%%/g, (_m, t) => sets[t]));
124
- }
125
- return out.join(/\r\n/.test(text) ? "\r\n" : "\n");
126
- }
127
-
128
- let wrote = 0;
129
- for (const name of chosen) {
130
- const srcDir = join(HERE, name);
131
- const target = join(dest, name);
132
- console.log(`\n[${name}] -> ${target}`);
133
- const files = readdirSync(srcDir).filter((f) => statSync(join(srcDir, f)).isFile());
134
- const rendered = new Map();
135
- for (const f of files) {
136
- const raw = readFileSync(join(srcDir, f), "utf8");
137
- // preset.yml has no placeholders but goes through the same pipe for the
138
- // BOM/encoding check; render() is a no-op there.
139
- rendered.set(f, f.endsWith(".yml") ? render(raw) : raw);
140
- }
141
- // Refuse to write a file that still contains an unresolved token.
142
- for (const [f, text] of rendered) {
143
- const leftover = text.match(/%%[A-Za-z][\w]*%%/g);
144
- if (leftover !== null) {
145
- console.error(`install-presets: ${f} still holds ${leftover.join(", ")} - pass --set for each or fix the template`);
146
- process.exit(1);
147
- }
148
- }
149
- if (opt["dry-run"]) {
150
- console.log(" dry-run: nothing written");
151
- continue;
152
- }
153
- if (existsSync(target)) {
154
- const stamp = new Date().toISOString().replace(/[:.]/g, "-");
155
- const bak = join(backupRoot, stamp, name);
156
- mkdirSync(dirname(bak), { recursive: true });
157
- cpSync(target, bak, { recursive: true });
158
- console.log(` existing preset backed up to ${bak}`);
159
- }
160
- mkdirSync(target, { recursive: true });
161
- for (const [f, text] of rendered) {
162
- writeFileSync(join(target, f), text, "utf8");
163
- console.log(` wrote ${f}`);
164
- wrote++;
165
- }
166
- }
167
- console.log(`\ndone (${wrote} files).`);
168
- console.log("next: 1) restart / hot-reload DSH to mount the presets; 2) pick the preset per session;");
169
- console.log("3) set this plugin's defaultShell (Settings -> General) to the SAME terminal the preset anchors.");
170
- if (chosen.includes("standard-win-payload")) {
171
- console.log("and for standard-win-payload: enablePosixPayload: true in cordis.patch.yml (restart),");
172
- console.log("then flip the 'POSIX payload' row switch (shellPayload) on the settings page - opt-in twice.");
173
- }
174
- if (Object.keys(sets).length === 0) {
175
- console.log("note: no --set was passed, so machine-specific sentences (python path) were dropped;");
176
- console.log("re-run with --set pythonPath=<path> later if you want them in the prompt.");
177
- }
178
- console.log("tip: the dsh-preset-doctor plugin keeps these presets mountable across host");
179
- console.log("versions (auto-realign + per-row switches in each preset card) - worth installing.");
1
+ #!/usr/bin/env node
2
+ // agent-presets/install-presets.mjs - copy a terminal-semantics preset template
3
+ // into the DSH deployment (%USERPROFILE%\.dsh\.agent-presets by default).
4
+ //
5
+ // What it does:
6
+ // 1. resolves the %%placeholder%% tokens from --set key=value pairs;
7
+ // 2. DROPS any line whose placeholder was not provided (the line is optional
8
+ // machine guidance by design - an unfilled `%%pythonPath%%` sentence is
9
+ // worse than no sentence);
10
+ // 3. backs up an existing same-name preset OUTSIDE .agent-presets (a backup
11
+ // inside the preset dir would be mounted as a preset), then writes.
12
+ // It never deletes anything: overwrite happens only after the backup copy.
13
+ import { parseArgs } from "node:util";
14
+ import { cpSync, existsSync, mkdirSync, readFileSync, readdirSync, statSync, writeFileSync } from "node:fs";
15
+ import { homedir } from "node:os";
16
+ import { dirname, join, resolve } from "node:path";
17
+ import { fileURLToPath } from "node:url";
18
+
19
+ const HERE = dirname(fileURLToPath(import.meta.url));
20
+ const TEMPLATES = readdirSync(HERE, { withFileTypes: true }).filter((d) => d.isDirectory()).map((d) => d.name);
21
+
22
+ const { values: opt, positionals } = parseArgs({
23
+ allowPositionals: true,
24
+ options: {
25
+ name: { type: "string", multiple: true },
26
+ all: { type: "boolean", default: false },
27
+ dest: { type: "string" },
28
+ set: { type: "string", multiple: true },
29
+ "dry-run": { type: "boolean", default: false },
30
+ list: { type: "boolean", default: false },
31
+ help: { type: "boolean", default: false }
32
+ }
33
+ });
34
+
35
+ if (opt.help || opt.list) {
36
+ console.log(`templates here: ${TEMPLATES.join(", ")}`);
37
+ if (opt.help) {
38
+ console.log([
39
+ "usage:",
40
+ " node install-presets.mjs --list # what is available",
41
+ " node install-presets.mjs --name <preset> [--name ...] # install selected templates",
42
+ " node install-presets.mjs --all [--dry-run] # everything, or preview first",
43
+ " from an installed plugin (profile dir):",
44
+ " node node_modules/dsh-bash-terminal-ts/agent-presets/install-presets.mjs --name <preset>",
45
+ " from the source repo: npm run presets:install -- --name <preset>",
46
+ "",
47
+ "what each template anchors (default terminal + its failure-mode guidance):",
48
+ " standard-win PowerShell (pwsh) - the Windows default, six-item pitfall list",
49
+ " standard-win-gitbash Git Bash - POSIX bash, /c/... paths, MSYS path-conversion traps",
50
+ " standard-win-msys2 MSYS2 bash - + msys-vs-mingw64 dual-runtime guidance",
51
+ " standard-win-wsl2 WSL2 Linux bash - /mnt/c paths, case-sensitivity/CRLF/wslpath traps",
52
+ " standard-win-payload pinned POSIX payload - digest-verified backup runtime; opt-in twice, see below",
53
+ " standard-win-niu Niubash (niu) - Rust-native bash 5.3 semantics, no MSYS layer, Windows-native paths",
54
+ "",
55
+ "placeholders (%%token%% lines in the persona):",
56
+ " --set pythonPath=<path> Windows interpreter; bash templates want /c/... form",
57
+ " --set winPythonWslPath=<path> the same interpreter as WSL sees it (/mnt/c/... form)",
58
+ "A line whose token was not --set is DROPPED whole - installing with no --set flags",
59
+ "is always safe and machine-neutral (no %% residue can ever be written).",
60
+ "",
61
+ "after installing - keep the three layers in agreement:",
62
+ " 1. restart / hot-reload DSH (the host mounts %USERPROFILE%\\.dsh\\.agent-presets at boot);",
63
+ " 2. pick the preset for the session (subagents inherit it through agentPreset);",
64
+ " 3. set this plugin's default terminal to the SAME shell: Settings -> General ->",
65
+ " Default terminal (or defaultShell in cordis.patch.yml). For the payload",
66
+ " template ALSO: enablePosixPayload: true in cordis.patch.yml (operator gate,",
67
+ " takes effect on restart) AND the 'POSIX payload' row switch shellPayload: true",
68
+ " on the settings page - the payload is deliberately opt-in twice.",
69
+ "",
70
+ "safety: an existing same-name preset is copied OUTSIDE the mount root",
71
+ "(%USERPROFILE%\\.dsh\\_agent-presets-backup\\<timestamp>\\) before overwriting; nothing is deleted.",
72
+ "",
73
+ "companion: install the dsh-preset-doctor plugin (npm) - it scans these mounted",
74
+ "presets across host-version migrations, auto-realigns what it can and gives",
75
+ "per-row switches inside each preset card, so the templates stay governable",
76
+ "without hand-editing YAML."
77
+ ].join("\n"));
78
+ }
79
+ process.exit(0);
80
+ }
81
+
82
+ const chosen = opt.all ? TEMPLATES : (opt.name ?? positionals);
83
+ if (chosen.length === 0) {
84
+ console.error("install-presets: nothing selected - use --name <preset> or --all");
85
+ process.exit(2);
86
+ }
87
+ for (const name of chosen) {
88
+ if (!TEMPLATES.includes(name)) {
89
+ console.error(`install-presets: unknown template ${JSON.stringify(name)}; available: ${TEMPLATES.join(", ")}`);
90
+ process.exit(2);
91
+ }
92
+ }
93
+
94
+ const sets = {};
95
+ for (const kv of opt.set ?? []) {
96
+ const i = kv.indexOf("=");
97
+ if (i <= 0) {
98
+ console.error(`install-presets: bad --set ${JSON.stringify(kv)} (expected key=value)`);
99
+ process.exit(2);
100
+ }
101
+ sets[kv.slice(0, i).trim()] = kv.slice(i + 1);
102
+ }
103
+
104
+ const dest = resolve(opt.dest ?? join(process.env.USERPROFILE ?? homedir(), ".dsh", "agent-presets"));
105
+ // Backup lives OUTSIDE the preset directory: .agent-presets is a mount root and
106
+ // every subdirectory of it is treated as a preset by the host.
107
+ const backupRoot = resolve(dest, "..", "_agent-presets-backup");
108
+
109
+ function render(text) {
110
+ const out = [];
111
+ for (const line of text.split(/\r?\n/)) {
112
+ const tokens = [...line.matchAll(/%%([A-Za-z][\w]*)%%/g)].map((m) => m[1]);
113
+ if (tokens.length === 0) {
114
+ out.push(line);
115
+ continue;
116
+ }
117
+ const missing = tokens.filter((t) => !(t in sets));
118
+ if (missing.length > 0) {
119
+ // An optional machine-guidance line without its value: drop the whole
120
+ // line rather than ship a sentence with a hole in it.
121
+ console.log(` note: dropped line (missing --set ${missing.join(", ")}): ${line.trim().slice(0, 80)}...`);
122
+ continue;
123
+ }
124
+ out.push(line.replace(/%%([A-Za-z][\w]*)%%/g, (_m, t) => sets[t]));
125
+ }
126
+ return out.join(/\r\n/.test(text) ? "\r\n" : "\n");
127
+ }
128
+
129
+ let wrote = 0;
130
+ for (const name of chosen) {
131
+ const srcDir = join(HERE, name);
132
+ const target = join(dest, name);
133
+ console.log(`\n[${name}] -> ${target}`);
134
+ const files = readdirSync(srcDir).filter((f) => statSync(join(srcDir, f)).isFile());
135
+ const rendered = new Map();
136
+ for (const f of files) {
137
+ const raw = readFileSync(join(srcDir, f), "utf8");
138
+ // preset.yml has no placeholders but goes through the same pipe for the
139
+ // BOM/encoding check; render() is a no-op there.
140
+ rendered.set(f, f.endsWith(".yml") ? render(raw) : raw);
141
+ }
142
+ // Refuse to write a file that still contains an unresolved token.
143
+ for (const [f, text] of rendered) {
144
+ const leftover = text.match(/%%[A-Za-z][\w]*%%/g);
145
+ if (leftover !== null) {
146
+ console.error(`install-presets: ${f} still holds ${leftover.join(", ")} - pass --set for each or fix the template`);
147
+ process.exit(1);
148
+ }
149
+ }
150
+ if (opt["dry-run"]) {
151
+ console.log(" dry-run: nothing written");
152
+ continue;
153
+ }
154
+ if (existsSync(target)) {
155
+ const stamp = new Date().toISOString().replace(/[:.]/g, "-");
156
+ const bak = join(backupRoot, stamp, name);
157
+ mkdirSync(dirname(bak), { recursive: true });
158
+ cpSync(target, bak, { recursive: true });
159
+ console.log(` existing preset backed up to ${bak}`);
160
+ }
161
+ mkdirSync(target, { recursive: true });
162
+ for (const [f, text] of rendered) {
163
+ writeFileSync(join(target, f), text, "utf8");
164
+ console.log(` wrote ${f}`);
165
+ wrote++;
166
+ }
167
+ }
168
+ console.log(`\ndone (${wrote} files).`);
169
+ console.log("next: 1) restart / hot-reload DSH to mount the presets; 2) pick the preset per session;");
170
+ console.log("3) set this plugin's defaultShell (Settings -> General) to the SAME terminal the preset anchors.");
171
+ if (chosen.includes("standard-win-payload")) {
172
+ console.log("and for standard-win-payload: enablePosixPayload: true in cordis.patch.yml (restart),");
173
+ console.log("then flip the 'POSIX payload' row switch (shellPayload) on the settings page - opt-in twice.");
174
+ }
175
+ if (Object.keys(sets).length === 0) {
176
+ console.log("note: no --set was passed, so machine-specific sentences (python path) were dropped;");
177
+ console.log("re-run with --set pythonPath=<path> later if you want them in the prompt.");
178
+ }
179
+ console.log("tip: the dsh-preset-doctor plugin keeps these presets mountable across host");
180
+ console.log("versions (auto-realign + per-row switches in each preset card) - worth installing.");