dsh-tg-bridge 1.24.0 → 1.25.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +68 -10
- package/aset-profile.mjs +37 -8
- package/commands-registry.mjs +1 -1
- package/control/cd-path.mjs +69 -0
- package/control/cmd-agents.mjs +48 -19
- package/control/cmd-bridge.mjs +45 -2
- package/control/cmd-session.mjs +55 -15
- package/control/cmd-views.mjs +13 -1
- package/docs/SUPPORT.md +93 -0
- package/handle-message.mjs +42 -5
- package/help-explain.mjs +1 -1
- package/i18n/en/core.mjs +6 -1
- package/i18n/en/ctrl.mjs +12 -0
- package/i18n/ru/core.mjs +6 -1
- package/i18n/ru/ctrl.mjs +12 -0
- package/i18n/zh/core.mjs +6 -1
- package/i18n/zh/ctrl.mjs +12 -0
- package/menu-card.mjs +1 -1
- package/package.json +6 -2
- package/patch-rows.mjs +5 -9
- package/permission-rows.mjs +155 -0
- package/profile-edit.mjs +32 -0
- package/profile-view.mjs +113 -29
- package/report.mjs +140 -0
- package/settings-card.mjs +9 -0
package/README.md
CHANGED
|
@@ -16,7 +16,9 @@ a bot that answers, one step at a time.
|
|
|
16
16
|
- **Voice**: local faster-whisper, the transcript is shown before the answer.
|
|
17
17
|
- **Photos**: the turn's own model reads them through `read_image`, text and UI
|
|
18
18
|
included; no second model is needed (a vision overlay stays opt-in).
|
|
19
|
-
- **Project per topic**: `/cd my-app`, and all turns run from that directory
|
|
19
|
+
- **Project per topic**: `/cd my-app`, and all turns run from that directory — on
|
|
20
|
+
a permission-enabled profile the sandbox is narrowed to it too, so the agent
|
|
21
|
+
cannot write outside the project.
|
|
20
22
|
- **Goal and checklist per topic**: `/goal`, `/tasks`; both survive restarts and are prepended to every turn.
|
|
21
23
|
- **Live progress**: one edited message per turn — steps, a timer and the cache hit rate, plus
|
|
22
24
|
the model's reasoning in a collapsed block you can tap open. A long turn adds a second
|
|
@@ -29,6 +31,9 @@ a bot that answers, one step at a time.
|
|
|
29
31
|
- **`dsh-tg check`**: diagnostics in one command, no changes to the system.
|
|
30
32
|
- **Languages**: menus and service messages in `en`, `ru`, `zh`; `/lang` pins the topic language, and without it a new topic takes the language of the message itself (Cyrillic → `ru`, Han characters → `zh`), then the Telegram `language_code`, then `en`.
|
|
31
33
|
- **"Stop"/"Retry" buttons, tool confirmations**: right in the message, no commands to type.
|
|
34
|
+
- **`/report`**: one command turns "it broke" into a redacted document — version,
|
|
35
|
+
profile, preset, model, directory, the last failure and the log tail, with
|
|
36
|
+
tokens, keys and home paths removed before the file is written.
|
|
32
37
|
|
|
33
38
|
## Requirements
|
|
34
39
|
|
|
@@ -210,7 +215,8 @@ Send the bot:
|
|
|
210
215
|
| `/update` | which bridge runs, what npm has, and whether a newer release exists (`/update confirm` installs it) |
|
|
211
216
|
| `/thoughts [file\|all\|off]` | the last turn's reasoning as a message; `file`/`all` send the full log as a Markdown document, `off` hides the block |
|
|
212
217
|
| `/help` | commands grouped by category |
|
|
213
|
-
| `/cd my-app` | topic bound to the project |
|
|
218
|
+
| `/cd my-app` | topic bound to the project, and the sandbox narrowed to it |
|
|
219
|
+
| `/report` | a redacted bundle (version, profile, preset, model, cwd, last failure, log tail) sent to the owner as a document; in a group, the path only |
|
|
214
220
|
| `/prices` | what the current model costs, and whose price that is: your provider's, the same model on another gateway, or "no public price" when nobody publishes one |
|
|
215
221
|
|
|
216
222
|
## Commands
|
|
@@ -226,7 +232,7 @@ Profiles: /profile · /profile <name> · /profile new <name> from <template>
|
|
|
226
232
|
Sets: /crew · /crew use|off|new|copy|rm · /crew model <v>
|
|
227
233
|
Extensions: /skills · /plugins · /plugins search <word> · /plugins disable|enable <id> · /soul
|
|
228
234
|
Updates: /update · /update confirm · /update on|off|check|auto · /subscribe on|off
|
|
229
|
-
Diagnostics: /doctor · /logs [errors|N|text]
|
|
235
|
+
Diagnostics: /doctor · /logs [errors|N|text] · /report
|
|
230
236
|
Service: /app · /restart · /help
|
|
231
237
|
Settings: /settings — the same switches as buttons, grouped in four tabs
|
|
232
238
|
Display: /lang · /reasoning on|off · /thoughts
|
|
@@ -309,13 +315,18 @@ local path and that path is steered, exactly as an idle turn would hand it over.
|
|
|
309
315
|
|
|
310
316
|
What each kind of attachment becomes inside a running turn:
|
|
311
317
|
|
|
312
|
-
| Sent | Inside the turn |
|
|
313
|
-
|
|
314
|
-
| voice note, audio file, audio sent as a document | transcript, echoed as `🎤 …` before the steer |
|
|
315
|
-
| small text file (`.md`, `.json`, `.csv`, `.py`, `.log`, … up to 60 KB) | the content itself between `<file>` markers — no tool call needed |
|
|
316
|
-
| PDF, archive, binary, anything bigger | its local path under `~/.dsh/tg-bridge/inbox/` |
|
|
317
|
-
| video, video note, animation | its path; the agent can pull frames or sound out with ffmpeg |
|
|
318
|
-
| photo | its path plus one honest line; the turn reads it with `read_image`, and says so in one line if it cannot |
|
|
318
|
+
| Sent | Inside the turn | Needs |
|
|
319
|
+
|---|---|---|
|
|
320
|
+
| voice note, audio file, audio sent as a document | transcript, echoed as `🎤 …` before the steer | `faster-whisper` on `PATH`, enabled with `init --voice`; **off by default** |
|
|
321
|
+
| small text file (`.md`, `.json`, `.csv`, `.py`, `.log`, … up to 60 KB) | the content itself between `<file>` markers — no tool call needed | nothing |
|
|
322
|
+
| PDF, archive, binary, anything bigger | its local path under `~/.dsh/tg-bridge/inbox/` | nothing; the agent opens it with its own tools |
|
|
323
|
+
| video, video note, animation | its path; the agent can pull frames or sound out with ffmpeg | ffmpeg, only if frames or audio are needed |
|
|
324
|
+
| photo | its path plus one honest line; the turn reads it with `read_image`, and says so in one line if it cannot | a model that accepts images |
|
|
325
|
+
|
|
326
|
+
Voice is the one row with a hidden prerequisite. Without `faster-whisper`
|
|
327
|
+
installed, a voice note still arrives — as a path the agent cannot read — so the
|
|
328
|
+
bridge says transcription is off instead of pretending it heard something. Run
|
|
329
|
+
`dsh-tg init --voice` after installing the transcriber; nothing else changes.
|
|
319
330
|
|
|
320
331
|
A caption does not turn the attachment into a text-only message: it is folded into the same
|
|
321
332
|
hand-over, so "why did this fail" plus a `.log` file arrives as one steer.
|
|
@@ -431,6 +442,52 @@ profile's first turn. The binding is per topic: `/model` then edits that profile
|
|
|
431
442
|
has with the `dsh-plugin` keyword — the desktop app's plugin browser, from the chat. Each result
|
|
432
443
|
carries a plus button that runs `/plugins add <name>`.
|
|
433
444
|
|
|
445
|
+
### The directory a topic writes in
|
|
446
|
+
|
|
447
|
+
`/cd my-app` does two things, and they are worth separating because they used to
|
|
448
|
+
be one: the turn runs *in* that directory, and the sandbox *stops* at it. The
|
|
449
|
+
second half only works on a profile that has a permission table — the bridge
|
|
450
|
+
writes the row only when one exists, and never invents one for a profile that
|
|
451
|
+
opted out.
|
|
452
|
+
|
|
453
|
+
```
|
|
454
|
+
/cd my-app bind the topic: run here, and write only here
|
|
455
|
+
/cd ~/Projects/api wide run here, but do not narrow the sandbox
|
|
456
|
+
/cd reset unbind; the topic goes back to config.cwd
|
|
457
|
+
/cd what this topic is bound to, and how
|
|
458
|
+
```
|
|
459
|
+
|
|
460
|
+
| Sandbox mode | Writes inside the root | Writes outside the root |
|
|
461
|
+
|---|---|---|
|
|
462
|
+
| `read-only` | denied | denied |
|
|
463
|
+
| `workspace-write` | allowed | denied |
|
|
464
|
+
| `danger-full-access` | allowed | allowed |
|
|
465
|
+
|
|
466
|
+
`workspaceRoot` is the boundary, and it holds even when the turn switches its own
|
|
467
|
+
working directory: the refusal follows the configured root, not the directory the
|
|
468
|
+
agent moved to. That is the point — a model that wanders into another project
|
|
469
|
+
gets a refusal instead of a write.
|
|
470
|
+
|
|
471
|
+
Three things this table does **not** say, because measurement disagreed with the
|
|
472
|
+
obvious reading:
|
|
473
|
+
|
|
474
|
+
- the sandbox row alone changes nothing. `mode: read-only` in the
|
|
475
|
+
`sandbox-policy` row plus `defaultPreset: danger-full-access` in the permission
|
|
476
|
+
table still wrote outside the root. The permission table wins; the sandbox row
|
|
477
|
+
is a default for a profile that has no table.
|
|
478
|
+
- `danger-full-access` therefore has to be chosen on purpose, per topic
|
|
479
|
+
(`/permissions danger-full-access`), and it is the only mode that reaches
|
|
480
|
+
outside the root.
|
|
481
|
+
- a preset with `approval: ask` cannot be used from a chat at all: a headless
|
|
482
|
+
turn has no approval channel, so the escalation fails closed and the turn
|
|
483
|
+
errors. `/permissions` lists such a preset with the reason instead of letting
|
|
484
|
+
someone pick a trap.
|
|
485
|
+
|
|
486
|
+
Stock installs are not permission-enabled: `cordis.patch.yml` ships with the
|
|
487
|
+
`tg-bridge` plugin row only, so `/cd` binds the directory and `/permissions`
|
|
488
|
+
edits the profile-wide preset, exactly as before. The per-topic behaviour starts
|
|
489
|
+
the first time a profile gains a permission table.
|
|
490
|
+
|
|
434
491
|
### Goals and tasks
|
|
435
492
|
|
|
436
493
|
A topic carries its own goal and checklist, so the aim survives `/new`, a
|
|
@@ -464,6 +521,7 @@ no lock race and no lost update.
|
|
|
464
521
|
## Documentation
|
|
465
522
|
|
|
466
523
|
- [docs/TELEGRAM-SETUP.md](https://github.com/aleksvega/dsh-tg-bridge/blob/master/docs/TELEGRAM-SETUP.md): BotFather settings, group and bot permissions
|
|
524
|
+
- [docs/SUPPORT.md](https://github.com/aleksvega/dsh-tg-bridge/blob/master/docs/SUPPORT.md): what to send with a bug report, what never to send, and the one-line answer for "the bot went silent"
|
|
467
525
|
- [docs/ROADMAP.md](https://github.com/aleksvega/dsh-tg-bridge/blob/master/docs/ROADMAP.md): what comes next
|
|
468
526
|
- [docs/UX-ANALYSIS.md](https://github.com/aleksvega/dsh-tg-bridge/blob/master/docs/UX-ANALYSIS.md): interactive UX review
|
|
469
527
|
- [docs/COST.md](https://github.com/aleksvega/dsh-tg-bridge/blob/master/docs/COST.md): what one turn costs and how to reduce it
|
package/aset-profile.mjs
CHANGED
|
@@ -16,7 +16,8 @@ import { createHash } from 'node:crypto';
|
|
|
16
16
|
import { copyFileSync, existsSync, mkdirSync, readFileSync, readdirSync, rmSync, symlinkSync, writeFileSync } from 'node:fs';
|
|
17
17
|
import { homedir } from 'node:os';
|
|
18
18
|
import { join } from 'node:path';
|
|
19
|
-
import { setAgentPreset, setModel,
|
|
19
|
+
import { setAgentPreset, setModel, setSubagents } from './patch-rows.mjs';
|
|
20
|
+
import { sandboxModeOf, setPermission } from './permission-rows.mjs';
|
|
20
21
|
|
|
21
22
|
const DSH_HOME = process.env.DSH_HOME || join(homedir(), '.dsh');
|
|
22
23
|
const PROFILES = join(DSH_HOME, 'profiles');
|
|
@@ -25,7 +26,7 @@ const PROFILES = join(DSH_HOME, 'profiles');
|
|
|
25
26
|
export const DERIVED_PREFIX = 'aset-';
|
|
26
27
|
|
|
27
28
|
/** `aset-` + 10 hex: short enough for a DSH profile name, long enough to collide never. */
|
|
28
|
-
export function derivedName(base, set) {
|
|
29
|
+
export function derivedName(base, set, workspace = '') {
|
|
29
30
|
const material = JSON.stringify([
|
|
30
31
|
base,
|
|
31
32
|
set?.name || '',
|
|
@@ -33,6 +34,11 @@ export function derivedName(base, set) {
|
|
|
33
34
|
set?.effort || '',
|
|
34
35
|
set?.permissions || '',
|
|
35
36
|
set?.dshPreset || '',
|
|
37
|
+
// The bound directory belongs in the name: a topic moved with `/cd` must not
|
|
38
|
+
// keep a profile whose workspaceRoot points at the project it left. It is a
|
|
39
|
+
// separate argument, not a set field, because a set is shared between topics
|
|
40
|
+
// and the workspace is not.
|
|
41
|
+
String(workspace || ''),
|
|
36
42
|
set?.agents || null,
|
|
37
43
|
set?.toolFilter || null,
|
|
38
44
|
]);
|
|
@@ -44,14 +50,30 @@ export function derivedName(base, set) {
|
|
|
44
50
|
* A field that already matches the base is skipped, so the copy differs from
|
|
45
51
|
* the base only where the set differs — otherwise every generated profile
|
|
46
52
|
* would pin today's model forever.
|
|
53
|
+
*
|
|
54
|
+
* The workspace is the exception: a bound topic states its own boundary even
|
|
55
|
+
* when the base happens to name the same directory, because inheriting one is
|
|
56
|
+
* how a later edit to the base quietly widens a topic that never asked.
|
|
47
57
|
*/
|
|
48
|
-
export function overlayPatch(basePatch, set, base = {}) {
|
|
58
|
+
export function overlayPatch(basePatch, set, base = {}, workspace = '') {
|
|
49
59
|
const source = String(basePatch ?? '');
|
|
50
60
|
let next = source;
|
|
51
61
|
const model = String(set?.model || '').trim();
|
|
52
62
|
if (model && model !== base.model) next = setModel(next, model, String(set?.provider || '').trim());
|
|
53
63
|
const permissions = String(set?.permissions || '').trim();
|
|
54
|
-
|
|
64
|
+
const bound = String(workspace || '').trim();
|
|
65
|
+
// Both permission rows are written together (see `permission-rows.mjs`): the
|
|
66
|
+
// preset that is chosen and the sandbox mode it stands for. A profile that
|
|
67
|
+
// moves one and not the other describes a policy it does not run.
|
|
68
|
+
const presetId = (permissions && permissions !== base.permissions) ? permissions : '';
|
|
69
|
+
if (presetId || bound) {
|
|
70
|
+
const wanted = presetId || base.permissions || '';
|
|
71
|
+
next = setPermission(next, {
|
|
72
|
+
preset: wanted,
|
|
73
|
+
sandbox: sandboxModeOf(next, wanted),
|
|
74
|
+
workspaceRoot: bound,
|
|
75
|
+
});
|
|
76
|
+
}
|
|
55
77
|
const preset = String(set?.dshPreset || '').trim();
|
|
56
78
|
if (preset && preset !== base.preset) next = setAgentPreset(next, preset);
|
|
57
79
|
if (set?.agents && typeof set.agents === 'object') next = setSubagents(next, set.agents);
|
|
@@ -62,16 +84,23 @@ export function overlayPatch(basePatch, set, base = {}) {
|
|
|
62
84
|
* Build `<base>`'s copy for `set` and return the profile name to run under.
|
|
63
85
|
* Returns '' when there is nothing to materialise (the set changes nothing a
|
|
64
86
|
* profile owns) or when the base profile is missing.
|
|
87
|
+
*
|
|
88
|
+
* `workspace` is the topic's bound directory, if any: it becomes this profile's
|
|
89
|
+
* `workspaceRoot`, which is what makes the host sandbox — not a prompt — the
|
|
90
|
+
* thing that stops a turn at the project's edge.
|
|
65
91
|
*/
|
|
66
|
-
export function materialiseProfile(set, base, { profiles = PROFILES } = {}) {
|
|
67
|
-
|
|
92
|
+
export function materialiseProfile(set, base, { profiles = PROFILES, workspace = '' } = {}) {
|
|
93
|
+
// A topic may be bound to a directory without being bound to a set: `/cd` is
|
|
94
|
+
// the common case and it still needs a profile of its own, or the boundary is
|
|
95
|
+
// whatever the base says.
|
|
96
|
+
if (!base || (!set && !workspace)) return '';
|
|
68
97
|
const baseDir = join(profiles, base);
|
|
69
98
|
const basePatchPath = join(baseDir, 'cordis.patch.yml');
|
|
70
99
|
if (!existsSync(basePatchPath)) return '';
|
|
71
100
|
const basePatch = readFileSync(basePatchPath, 'utf8');
|
|
72
|
-
const { patch, changed } = overlayPatch(basePatch, set, baseRowOf(basePatch));
|
|
101
|
+
const { patch, changed } = overlayPatch(basePatch, set, baseRowOf(basePatch), workspace);
|
|
73
102
|
if (!changed) return '';
|
|
74
|
-
const name = derivedName(base, set);
|
|
103
|
+
const name = derivedName(base, set, workspace);
|
|
75
104
|
const dir = join(profiles, name);
|
|
76
105
|
if (existsSync(join(dir, 'cordis.patch.yml'))) return name;
|
|
77
106
|
mkdirSync(dir, { recursive: true });
|
package/commands-registry.mjs
CHANGED
|
@@ -10,7 +10,7 @@ export const CONTROL_COMMANDS = [
|
|
|
10
10
|
'status', 'models', 'model', 'effort', 'profile', 'agents', 'preset', 'permissions', 'plan',
|
|
11
11
|
'jobs', 'remind', 'sessions', 'resume', 'plugins', 'plugin',
|
|
12
12
|
'skills', 'soul', 'restart', 'app', 'stop', 'new', 'seed', 'send', 'cd',
|
|
13
|
-
'prices', 'help', 'doctor', 'logs', 'lang', 'reasoning', 'goal', 'task', 'tasks',
|
|
13
|
+
'prices', 'help', 'doctor', 'logs', 'report', 'lang', 'reasoning', 'goal', 'task', 'tasks',
|
|
14
14
|
'thoughts', 'version', 'update', 'crew', 'agentset', 'subscribe', 'settings',
|
|
15
15
|
'rewind', 'fork', 'branches', 'menu',
|
|
16
16
|
];
|
|
@@ -0,0 +1,69 @@
|
|
|
1
|
+
// Where `/cd` points, decided without touching a real filesystem.
|
|
2
|
+
//
|
|
3
|
+
// The old resolver tested `existsSync` and stopped there: a path to a FILE was
|
|
4
|
+
// "bound" and every later turn spawned with a file as its working directory,
|
|
5
|
+
// which fails inside the CLI with an error nobody can read. A missing path was
|
|
6
|
+
// reported as "no such directory" using the raw input rather than the path it
|
|
7
|
+
// actually tried.
|
|
8
|
+
//
|
|
9
|
+
// Pure on purpose: `probe` is the only filesystem question, so the table of
|
|
10
|
+
// cases below is a test, not a story about a machine.
|
|
11
|
+
import { isAbsolute, join, normalize, resolve } from 'node:path';
|
|
12
|
+
|
|
13
|
+
/** How a topic path was understood — the reply says which, so nobody guesses. */
|
|
14
|
+
export const CD_KIND = {
|
|
15
|
+
ABSOLUTE: 'absolute',
|
|
16
|
+
HOME: 'home',
|
|
17
|
+
PROJECT: 'project',
|
|
18
|
+
RELATIVE: 'relative',
|
|
19
|
+
};
|
|
20
|
+
|
|
21
|
+
/** `C:\x`, `C:/x`, `\\server\share`, `/x` — anything the platform calls absolute. */
|
|
22
|
+
function looksAbsolute(input) {
|
|
23
|
+
return /^[A-Za-z]:[\\/]/.test(input) || /^\\\\/.test(input) || input.startsWith('/') || isAbsolute(input);
|
|
24
|
+
}
|
|
25
|
+
|
|
26
|
+
/**
|
|
27
|
+
* Turn what a person typed into the directory a turn should run in.
|
|
28
|
+
*
|
|
29
|
+
* Order matters and is the whole point: an absolute path is never re-interpreted
|
|
30
|
+
* as a project name, and a bare word is never treated as a relative path from
|
|
31
|
+
* the bridge's own directory — `my-app` means `<projectsDir>/my-app`, because
|
|
32
|
+
* that is what a person means when they type it.
|
|
33
|
+
*
|
|
34
|
+
* @param {string} input what followed `/cd`
|
|
35
|
+
* @param {object} ctx
|
|
36
|
+
* @param {string} ctx.home the user's home directory
|
|
37
|
+
* @param {string} ctx.projectsDir where bare names are looked up
|
|
38
|
+
* @param {string} ctx.configCwd directory a relative path resolves against
|
|
39
|
+
* @param {(path: string) => 'dir'|'file'|'none'} ctx.probe
|
|
40
|
+
* @returns {{path: string, kind: string} | {error: 'empty'|'none'|'notdir', path: string, kind: string}}
|
|
41
|
+
*/
|
|
42
|
+
export function resolveCd(input, { home, projectsDir, configCwd, probe }) {
|
|
43
|
+
const raw = String(input ?? '').trim().replace(/^["']|["']$/g, '').trim();
|
|
44
|
+
if (!raw) return { error: 'empty', path: '', kind: '' };
|
|
45
|
+
|
|
46
|
+
let candidate = raw;
|
|
47
|
+
let kind = CD_KIND.ABSOLUTE;
|
|
48
|
+
if (raw === '~' || raw.startsWith('~/') || raw.startsWith('~\\')) {
|
|
49
|
+
kind = CD_KIND.HOME;
|
|
50
|
+
candidate = join(home, raw.slice(1));
|
|
51
|
+
} else if (looksAbsolute(raw)) {
|
|
52
|
+
kind = CD_KIND.ABSOLUTE;
|
|
53
|
+
} else if (raw.includes('/') || raw.includes('\\')) {
|
|
54
|
+
// A relative path with a separator is a path, not a project name.
|
|
55
|
+
kind = CD_KIND.RELATIVE;
|
|
56
|
+
candidate = resolve(configCwd || home, raw);
|
|
57
|
+
} else {
|
|
58
|
+
kind = CD_KIND.PROJECT;
|
|
59
|
+
candidate = join(projectsDir, raw);
|
|
60
|
+
}
|
|
61
|
+
|
|
62
|
+
const path = normalize(candidate);
|
|
63
|
+
const found = probe(path);
|
|
64
|
+
// A file is not a working directory. Saying "no such directory" about a file
|
|
65
|
+
// that is plainly there is the reply that turned this into a bug report.
|
|
66
|
+
if (found === 'file') return { error: 'notdir', path, kind };
|
|
67
|
+
if (found !== 'dir') return { error: 'none', path, kind };
|
|
68
|
+
return { path, kind };
|
|
69
|
+
}
|
package/control/cmd-agents.mjs
CHANGED
|
@@ -11,6 +11,7 @@ import { t, LANGS, normalizeLang } from '../i18n.mjs';
|
|
|
11
11
|
import { addTask, clearGoal, doneTask, editTask, finishGoal, goalOf, progressOf, reopenGoal, removeTask, setGoal } from '../goals.mjs';
|
|
12
12
|
import { lastTurnReasoning, lastTurnReasoningSteps, lastTurnText, reasoningMarkdown, sessionFile, sessionReasoningSteps, sessionStats } from '../thoughts.mjs';
|
|
13
13
|
import { parseAgentPresets, parseModelSelection, parsePermissionPresets, parseReasoningEfforts, parseSubagentFleet, parseSubagentRows } from '../agents.mjs';
|
|
14
|
+
import { effectivePreset, setPermission } from '../permission-rows.mjs';
|
|
14
15
|
import { setRowConfig, unsetRowConfig } from '../profile-edit.mjs';
|
|
15
16
|
import { parseReminder, stampAt, upcoming } from '../reminders.mjs';
|
|
16
17
|
import { AgentsetStore, emptySet, slugId } from '../agentsets.mjs';
|
|
@@ -254,46 +255,74 @@ export async function handleAgentCommands(ctx) {
|
|
|
254
255
|
}
|
|
255
256
|
case '/permissions': {
|
|
256
257
|
// Sandbox and approval policy decide what a turn may touch. The desktop
|
|
257
|
-
// shows them as a preset picker; here they are
|
|
258
|
-
//
|
|
259
|
-
//
|
|
260
|
-
|
|
258
|
+
// shows them as a preset picker; here they are two profile rows, and the
|
|
259
|
+
// *effective* preset is what `defaultPreset` names — not the first row of
|
|
260
|
+
// the table, which happens to agree only because nobody edits by hand.
|
|
261
|
+
//
|
|
262
|
+
// A topic bound to an agent set already runs under a profile of its own
|
|
263
|
+
// (`aset-profile.mjs`), so there the choice belongs to the set: it moves
|
|
264
|
+
// this topic and leaves every other topic where it was. An unbound topic
|
|
265
|
+
// has no such profile, so the write is profile-wide — and says so.
|
|
266
|
+
const boundId = state.agentsets?.[key] || '';
|
|
267
|
+
const boundSet = boundId ? agentset().get(boundId) : null;
|
|
268
|
+
const text = read(patchPath(activeProfile));
|
|
269
|
+
const table = parsePermissionPresets(text);
|
|
261
270
|
if (!table) {
|
|
262
271
|
say(t(lang, 'ctrl.perm.none', { name: activeProfile }));
|
|
263
272
|
return true;
|
|
264
273
|
}
|
|
274
|
+
const current = effectivePreset(text);
|
|
275
|
+
const currentId = boundSet
|
|
276
|
+
? String(boundSet.permissions || current?.id || '')
|
|
277
|
+
: current?.from === 'unknown' ? '' : current?.id || '';
|
|
265
278
|
const wanted = String(arg || '').trim();
|
|
266
279
|
if (!wanted) {
|
|
267
|
-
const lines = [
|
|
268
|
-
|
|
269
|
-
|
|
270
|
-
|
|
271
|
-
|
|
272
|
-
];
|
|
280
|
+
const lines = [t(lang, 'ctrl.perm.title', { name: activeProfile })];
|
|
281
|
+
if (boundSet) lines.push(t(lang, 'ctrl.perm.topicTitle', { name: boundSet.name || boundSet.id }));
|
|
282
|
+
if (currentId) lines.push(t(lang, 'ctrl.perm.current', { name: currentId }));
|
|
283
|
+
else if (current?.from === 'unknown') lines.push(t(lang, 'ctrl.perm.broken', { name: current.id }));
|
|
284
|
+
else lines.push(t(lang, 'ctrl.perm.noCurrent'));
|
|
273
285
|
for (const preset of table.presets) {
|
|
274
|
-
const mark = preset.id ===
|
|
275
|
-
|
|
286
|
+
const mark = preset.id === currentId ? '*' : ' ';
|
|
287
|
+
// A chat has no approval channel: `ask` fails closed at spawn, so the
|
|
288
|
+
// preset is listed with the reason instead of looking selectable.
|
|
289
|
+
const note = preset.approval === 'ask' ? t(lang, 'ctrl.perm.needsApproval') : '';
|
|
290
|
+
lines.push(` ${mark} ${preset.id}${preset.sandbox ? ` — ${preset.sandbox}, ${preset.approval || '?'}` : ''}${note}`);
|
|
276
291
|
}
|
|
277
292
|
if (table.presets.length === 0) lines.push(t(lang, 'ctrl.perm.noPresets'));
|
|
278
|
-
lines.push(t(lang, 'ctrl.perm.hint'));
|
|
293
|
+
lines.push(t(lang, boundSet ? 'ctrl.perm.hintTopic' : 'ctrl.perm.hint'));
|
|
279
294
|
say(lines.join('\n'));
|
|
280
295
|
return true;
|
|
281
296
|
}
|
|
282
|
-
|
|
297
|
+
const chosen = table.presets.find((preset) => preset.id === wanted);
|
|
298
|
+
if (!chosen) {
|
|
283
299
|
say(t(lang, 'ctrl.perm.unknown', {
|
|
284
300
|
name: wanted,
|
|
285
301
|
list: table.presets.map((preset) => preset.id).join(', '),
|
|
286
302
|
}));
|
|
287
303
|
return true;
|
|
288
304
|
}
|
|
289
|
-
if (
|
|
305
|
+
if (chosen.approval === 'ask') {
|
|
306
|
+
say(t(lang, 'ctrl.perm.cannotAsk', { name: wanted }));
|
|
307
|
+
return true;
|
|
308
|
+
}
|
|
309
|
+
if (wanted === currentId) {
|
|
290
310
|
say(t(lang, 'ctrl.perm.already', { name: wanted }));
|
|
291
311
|
return true;
|
|
292
312
|
}
|
|
293
|
-
|
|
294
|
-
|
|
295
|
-
|
|
296
|
-
|
|
313
|
+
if (boundSet) {
|
|
314
|
+
const result = agentset().put({ ...boundSet, permissions: wanted });
|
|
315
|
+
if (!result.ok) {
|
|
316
|
+
say(t(lang, 'ctrl.set.failed', { error: result.error || '?' }));
|
|
317
|
+
return true;
|
|
318
|
+
}
|
|
319
|
+
ctx.saveState();
|
|
320
|
+
say(t(lang, 'ctrl.perm.setTopic', { name: wanted, set: boundSet.name || boundSet.id }));
|
|
321
|
+
return true;
|
|
322
|
+
}
|
|
323
|
+
// One writer for both rows: the preset and the sandbox mode it stands for.
|
|
324
|
+
const next = setPermission(text, { preset: wanted });
|
|
325
|
+
if (!next || next === text) { say(t(lang, 'ctrl.perm.already', { name: wanted })); return true; }
|
|
297
326
|
writePatch(activeProfile, next);
|
|
298
327
|
say(t(lang, 'ctrl.perm.set', { name: wanted, profile: activeProfile }));
|
|
299
328
|
return true;
|
package/control/cmd-bridge.mjs
CHANGED
|
@@ -24,7 +24,7 @@ import { profileValues, resolveSettings } from '../settings.mjs';
|
|
|
24
24
|
import { UPDATE_DEFAULTS, describeUpdate, modeChange, updateState } from '../update-policy.mjs';
|
|
25
25
|
import { isNewer, pluginInfo, rowLine, searchPlugins } from '../plugin-search.mjs';
|
|
26
26
|
import { COMMAND_ALIASES, CONTROL_COMMANDS, DOCUMENTED_COMMANDS } from '../commands-registry.mjs';
|
|
27
|
-
import { APP, CLI_JS, DSH_CMD, DSH_HOME, EXE, HOME, PROFILES, THOUGHT_DIR } from '../paths.mjs';
|
|
27
|
+
import { APP, CLI_JS, DSH_CMD, DSH_HOME, DIR, EXE, HOME, LOG, PROFILES, THOUGHT_DIR } from '../paths.mjs';
|
|
28
28
|
import { read, readJson, patchPath, pkgPath, OVERLAY_MARK, modelsOf, modelOf, windowOf, modelIndent, depthOf, modelsReport, setModel, disabledIds, setDisabled, writePatch } from './models.mjs';
|
|
29
29
|
import { listPids, waitForExit, waitForStart, pluginsOf, bundleRowIds, addBundle, removeBundle, createProfile, dshPlugin } from './plugins.mjs';
|
|
30
30
|
import { cwdSlug, bareId, stamp, recentSessions, sessionTitle } from './sessions.mjs';
|
|
@@ -32,6 +32,8 @@ import { agentsOf, fleetOf, patchRows, skillsOf, AGENTS, PERSONA_HEADING, soulOf
|
|
|
32
32
|
import { fmt, AGENTSETS, agentset, agentsetOf, profileRowOf, bindAgentset, agentsetCard, agentsetKeyboard } from './agentsets.mjs';
|
|
33
33
|
import { taskKeyboard, goalView, taskView, reasoningOf, filterLogLines } from './tasks.mjs';
|
|
34
34
|
import { updatePolicy, bridgeRoot, copyRelease, installRelease, bridgeVersion, newestModuleMtime, npmLatest, npmLatestAsync } from './release.mjs';
|
|
35
|
+
import { buildReport, tailOf, writeReport } from '../report.mjs';
|
|
36
|
+
import { effectivePreset } from '../permission-rows.mjs';
|
|
35
37
|
|
|
36
38
|
/**
|
|
37
39
|
* Which bridge is running, which one npm has, and whether this install can
|
|
@@ -63,7 +65,7 @@ function versionCard(lang) {
|
|
|
63
65
|
}
|
|
64
66
|
|
|
65
67
|
export async function handleBridgeCommands(ctx) {
|
|
66
|
-
const { command, arg, send, reply, log, profile, state, key, config, lang: rawLang, saveState } = ctx;
|
|
68
|
+
const { command, arg, send, reply, log, profile, state, key, config, chatId, threadId, lang: rawLang, saveState } = ctx;
|
|
67
69
|
// The topic's language, then the config default, then English. Never Russian:
|
|
68
70
|
// a group that has no opinion still must not guess a language.
|
|
69
71
|
const lang = normalizeLang(rawLang) || normalizeLang(config?.lang) || 'en';
|
|
@@ -330,6 +332,47 @@ export async function handleBridgeCommands(ctx) {
|
|
|
330
332
|
say(versionCard(lang) + '\n\n' + describeUpdate(updateState({ installed, latest, mode: policy.mode, notified: policy.notified })));
|
|
331
333
|
return true;
|
|
332
334
|
}
|
|
335
|
+
case '/report': {
|
|
336
|
+
// A bug report assembled from what the bridge already knows, so "it broke"
|
|
337
|
+
// does not need five follow-up questions. It is redacted before it leaves
|
|
338
|
+
// (`report.mjs`), and it goes to the owner's own id: in a group the answer
|
|
339
|
+
// is the path on this machine, because the log tail is not group material.
|
|
340
|
+
const owner = Number(config.allowedUserIds?.[0]) || 0;
|
|
341
|
+
const toOwner = Boolean(owner) && Number(chatId) === owner && !Number(threadId);
|
|
342
|
+
const patchText = read(patchPath(activeProfile));
|
|
343
|
+
const preset = effectivePreset(patchText)?.id || '';
|
|
344
|
+
const chain = (config.fallbackModels || []).map((entry) => (entry.provider ? `${entry.provider}/${entry.model}` : entry.model)).join(' → ');
|
|
345
|
+
const failure = state.lastFailure?.[key]?.error || '';
|
|
346
|
+
const text = buildReport({
|
|
347
|
+
version: bridgeVersion(),
|
|
348
|
+
profile: activeProfile,
|
|
349
|
+
preset,
|
|
350
|
+
model: modelOf(activeProfile).model,
|
|
351
|
+
chain,
|
|
352
|
+
cwd: state.cwd?.[key] || config.cwd || '',
|
|
353
|
+
failure,
|
|
354
|
+
log: tailOf(LOG, 120),
|
|
355
|
+
home: HOME,
|
|
356
|
+
ids: [chatId, threadId, ...(config.allowedUserIds || [])],
|
|
357
|
+
note: String(arg || '').trim(),
|
|
358
|
+
});
|
|
359
|
+
const path = writeReport(text, join(DIR, 'reports'));
|
|
360
|
+
if (!path) {
|
|
361
|
+
say(t(lang, 'ctrl.report.failed'));
|
|
362
|
+
return true;
|
|
363
|
+
}
|
|
364
|
+
if (toOwner && ctx.sendFile) {
|
|
365
|
+
try {
|
|
366
|
+
await ctx.sendFile(path, t(lang, 'ctrl.report.caption', { v: bridgeVersion() || '?' }));
|
|
367
|
+
return true;
|
|
368
|
+
} catch (error) {
|
|
369
|
+
say(t(lang, 'ctrl.report.sendFailed', { err: error.message, path }));
|
|
370
|
+
return true;
|
|
371
|
+
}
|
|
372
|
+
}
|
|
373
|
+
say(t(lang, 'ctrl.report.pathOnly', { path }));
|
|
374
|
+
return true;
|
|
375
|
+
}
|
|
333
376
|
default:
|
|
334
377
|
return false;
|
|
335
378
|
}
|
package/control/cmd-session.mjs
CHANGED
|
@@ -32,6 +32,8 @@ import { agentsOf, fleetOf, patchRows, skillsOf, AGENTS, PERSONA_HEADING, soulOf
|
|
|
32
32
|
import { fmt, AGENTSETS, agentset, agentsetOf, profileRowOf, bindAgentset, agentsetCard, agentsetKeyboard } from './agentsets.mjs';
|
|
33
33
|
import { taskKeyboard, goalView, taskView, reasoningOf, filterLogLines } from './tasks.mjs';
|
|
34
34
|
import { updatePolicy, bridgeRoot, copyRelease, installRelease, bridgeVersion, newestModuleMtime, npmLatest, npmLatestAsync } from './release.mjs';
|
|
35
|
+
import { resolveCd } from './cd-path.mjs';
|
|
36
|
+
import { permissionEnabled } from '../permission-rows.mjs';
|
|
35
37
|
|
|
36
38
|
export async function handleSessionCommands(ctx) {
|
|
37
39
|
const { command, arg, send, reply, log, profile, state, key, config, lang: rawLang } = ctx;
|
|
@@ -186,9 +188,16 @@ export async function handleSessionCommands(ctx) {
|
|
|
186
188
|
}
|
|
187
189
|
case '/cd': {
|
|
188
190
|
// Bind THIS topic to a project directory. Every later turn in the topic
|
|
189
|
-
// spawns the CLI with that cwd, so "work in my-app" stops
|
|
190
|
-
//
|
|
191
|
-
|
|
191
|
+
// spawns the CLI with that cwd, so "work in my-app" stops meaning
|
|
192
|
+
// "cd ... in every single command".
|
|
193
|
+
//
|
|
194
|
+
// The same binding also narrows the host sandbox: the topic's derived
|
|
195
|
+
// profile gets `workspaceRoot` = this directory, so a write outside it is
|
|
196
|
+
// refused by the host, not discouraged by a prompt. `/cd <dir> wide` keeps
|
|
197
|
+
// the old, profile-wide boundary for a topic that genuinely needs it.
|
|
198
|
+
const parts = String(arg || '').trim().split(/\s+/).filter(Boolean);
|
|
199
|
+
const wide = parts.length > 1 && parts[parts.length - 1].toLowerCase() === 'wide';
|
|
200
|
+
const wanted = (wide ? parts.slice(0, -1).join(' ') : parts.join(' ')).replace(/^"|"$/g, '');
|
|
192
201
|
state.cwd = state.cwd || {};
|
|
193
202
|
if (!wanted) {
|
|
194
203
|
// A topic without its own directory still has one: the bridge default.
|
|
@@ -199,10 +208,13 @@ export async function handleSessionCommands(ctx) {
|
|
|
199
208
|
current
|
|
200
209
|
? `${current}${state.cwd[key] ? '' : t(lang, 'ctrl.cd.defaultSuffix')}`
|
|
201
210
|
: t(lang, 'ctrl.cd.unset'),
|
|
202
|
-
'',
|
|
203
|
-
t(lang, 'ctrl.cd.bind'),
|
|
204
|
-
t(lang, 'ctrl.cd.resetHint'),
|
|
205
211
|
];
|
|
212
|
+
if (state.cwd[key]) {
|
|
213
|
+
lines.push(state.wide?.[key]
|
|
214
|
+
? t(lang, 'ctrl.cd.boundWide')
|
|
215
|
+
: t(lang, 'ctrl.cd.boundNarrow'));
|
|
216
|
+
}
|
|
217
|
+
lines.push('', t(lang, 'ctrl.cd.bind'), t(lang, 'ctrl.cd.resetHint'));
|
|
206
218
|
try {
|
|
207
219
|
const dirs = readdirSync(config.projectsDir || join(HOME, 'Projects'), { withFileTypes: true })
|
|
208
220
|
.filter((entry) => entry.isDirectory())
|
|
@@ -214,23 +226,51 @@ export async function handleSessionCommands(ctx) {
|
|
|
214
226
|
}
|
|
215
227
|
if (wanted === 'reset') {
|
|
216
228
|
delete state.cwd[key];
|
|
229
|
+
if (state.wide) delete state.wide[key];
|
|
217
230
|
ctx.saveState();
|
|
218
231
|
say(t(lang, 'cmd.cd.reset'));
|
|
219
232
|
return true;
|
|
220
233
|
}
|
|
221
|
-
|
|
222
|
-
//
|
|
223
|
-
|
|
224
|
-
|
|
225
|
-
|
|
234
|
+
// Resolution lives in `cd-path.mjs`: a pure table of the ways a person
|
|
235
|
+
// spells a directory, so "is it a file?" and "did it try Projects?" are
|
|
236
|
+
// tested instead of discovered in a turn that spawns in the wrong place.
|
|
237
|
+
const resolved = resolveCd(wanted, {
|
|
238
|
+
home: HOME,
|
|
239
|
+
projectsDir: config.projectsDir || join(HOME, 'Projects'),
|
|
240
|
+
configCwd: config.cwd || HOME,
|
|
241
|
+
probe: (path) => {
|
|
242
|
+
try {
|
|
243
|
+
return statSync(path).isDirectory() ? 'dir' : 'file';
|
|
244
|
+
} catch {
|
|
245
|
+
return 'none';
|
|
246
|
+
}
|
|
247
|
+
},
|
|
248
|
+
});
|
|
249
|
+
if (resolved.error === 'notdir') {
|
|
250
|
+
say(t(lang, 'cmd.cd.file', { path: resolved.path }));
|
|
251
|
+
return true;
|
|
226
252
|
}
|
|
227
|
-
if (
|
|
228
|
-
say(t(lang, 'cmd.cd.none', { path:
|
|
253
|
+
if (resolved.error) {
|
|
254
|
+
say(t(lang, 'cmd.cd.none', { path: resolved.path }));
|
|
229
255
|
return true;
|
|
230
256
|
}
|
|
231
|
-
state.cwd[key] =
|
|
257
|
+
state.cwd[key] = resolved.path;
|
|
258
|
+
state.wide = state.wide || {};
|
|
259
|
+
if (wide) state.wide[key] = true;
|
|
260
|
+
else delete state.wide[key];
|
|
232
261
|
ctx.saveState();
|
|
233
|
-
|
|
262
|
+
// Say which boundary the topic now has. "Bound" alone reads as "the agent
|
|
263
|
+
// may write here", and with `wide` that would be the opposite of the truth.
|
|
264
|
+
// The boundary only exists when the profile can express one; reading the
|
|
265
|
+
// patch here keeps this file out of the profile module's import cycle.
|
|
266
|
+
let narrow = false;
|
|
267
|
+
try {
|
|
268
|
+
const patch = readFileSync(join(DSH_HOME, 'profiles', activeProfile, 'cordis.patch.yml'), 'utf8');
|
|
269
|
+
narrow = permissionEnabled(patch);
|
|
270
|
+
} catch {
|
|
271
|
+
narrow = false;
|
|
272
|
+
}
|
|
273
|
+
say(t(lang, narrow ? 'cmd.cd.boundNarrow' : 'cmd.cd.bound', { path: resolved.path }));
|
|
234
274
|
return true;
|
|
235
275
|
}
|
|
236
276
|
case '/menu': {
|
package/control/cmd-views.mjs
CHANGED
|
@@ -32,6 +32,7 @@ import { agentsOf, fleetOf, patchRows, skillsOf, AGENTS, PERSONA_HEADING, soulOf
|
|
|
32
32
|
import { fmt, AGENTSETS, agentset, agentsetOf, profileRowOf, bindAgentset, agentsetCard, agentsetKeyboard } from './agentsets.mjs';
|
|
33
33
|
import { taskKeyboard, goalView, taskView, reasoningOf, filterLogLines } from './tasks.mjs';
|
|
34
34
|
import { updatePolicy, bridgeRoot, copyRelease, installRelease, bridgeVersion, newestModuleMtime, npmLatest, npmLatestAsync } from './release.mjs';
|
|
35
|
+
import { presetOf } from '../profile-view.mjs';
|
|
35
36
|
|
|
36
37
|
export async function handleViewCommands(ctx) {
|
|
37
38
|
const { command, arg, send, reply, log, profile, state, key, config, lang: rawLang } = ctx;
|
|
@@ -229,7 +230,18 @@ export async function handleViewCommands(ctx) {
|
|
|
229
230
|
say(t(lang, 'ctrl.settings.usage'));
|
|
230
231
|
return true;
|
|
231
232
|
}
|
|
232
|
-
|
|
233
|
+
// The preset the topic actually starts in comes from the profile it boots,
|
|
234
|
+
// which for a bound topic is a derived copy — not the install's profile.
|
|
235
|
+
let permission = null;
|
|
236
|
+
try {
|
|
237
|
+
permission = presetOf(key);
|
|
238
|
+
} catch {
|
|
239
|
+
permission = null;
|
|
240
|
+
}
|
|
241
|
+
const current = {
|
|
242
|
+
...settingsCurrent({ config, state, key, reasoningOf }),
|
|
243
|
+
permissions: permission ? { profile: permission.profile, preset: permission.preset?.id || '' } : null,
|
|
244
|
+
};
|
|
233
245
|
const bound = agentsetOf(state, key);
|
|
234
246
|
const card = renderSettingsCard({
|
|
235
247
|
page: SETTINGS_PAGES.includes(page) ? page : 'reply',
|