dsh-tg-bridge 1.23.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 +94 -11
- package/aset-profile.mjs +37 -8
- package/commands-registry.mjs +1 -1
- package/control/agentsets.mjs +13 -12
- 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/fallback.mjs +141 -0
- package/handle-message.mjs +66 -93
- 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/model-probe.mjs +97 -30
- package/package.json +7 -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
|
|
|
@@ -112,10 +117,35 @@ Optional provider settings live in `config.json`:
|
|
|
112
117
|
| `pricesUrl` | retired: `/prices` always reads OpenRouter's public list and labels the number as a reference for the model |
|
|
113
118
|
| `vision.patch` | opt-in overlay profile for photo turns; default `""` — the turn's own model reads images |
|
|
114
119
|
| `vision.enabled` | set `true` to run photo turns on `vision.patch` instead of the topic profile |
|
|
115
|
-
| `fallbackModels` |
|
|
120
|
+
| `fallbackModels` | ordered failover chain; default `[]` — see below |
|
|
116
121
|
| `maxParallel` | how many topics run at once, 1–8, default `3`; also `/jobs 5` in the chat |
|
|
117
122
|
| `replayWindowMs` | how old a journaled update may be and still be replayed after a restart; default `600000` (10 min) |
|
|
118
123
|
|
|
124
|
+
Each `fallbackModels` entry is one attempt, tried in order after the turn's own
|
|
125
|
+
model refuses:
|
|
126
|
+
|
|
127
|
+
```json
|
|
128
|
+
{
|
|
129
|
+
"provider": "router-a",
|
|
130
|
+
"model": "some-model",
|
|
131
|
+
"patch": "~/.dsh/tg-bridge/model-a.yml",
|
|
132
|
+
"free": false
|
|
133
|
+
}
|
|
134
|
+
```
|
|
135
|
+
|
|
136
|
+
`patch` is an overlay file with a single `agent-default-model` row
|
|
137
|
+
(`provider` + `model`); it is materialised once as its own profile, so the turn
|
|
138
|
+
keeps every other setting and only the model changes. `provider` is the id the
|
|
139
|
+
provider is written under in the profile — it decides whose key and host the
|
|
140
|
+
pre-flight probe asks, so the same model id on two routers stays two attempts.
|
|
141
|
+
`free` only adds `(free)` to the switch notice.
|
|
142
|
+
|
|
143
|
+
The chain may mix companies: a 503 from one provider says nothing about another,
|
|
144
|
+
so a busy channel skips its own models and the next company is still tried. Put
|
|
145
|
+
models from different companies next to each other — two arms of one router are
|
|
146
|
+
one outage, not two chances — and keep the `:free` models at the end, as the
|
|
147
|
+
last resort.
|
|
148
|
+
|
|
119
149
|
Get your id from [@userinfobot](https://t.me/userinfobot), the token from
|
|
120
150
|
[@BotFather](https://t.me/BotFather).
|
|
121
151
|
|
|
@@ -185,7 +215,8 @@ Send the bot:
|
|
|
185
215
|
| `/update` | which bridge runs, what npm has, and whether a newer release exists (`/update confirm` installs it) |
|
|
186
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 |
|
|
187
217
|
| `/help` | commands grouped by category |
|
|
188
|
-
| `/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 |
|
|
189
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 |
|
|
190
221
|
|
|
191
222
|
## Commands
|
|
@@ -201,7 +232,7 @@ Profiles: /profile · /profile <name> · /profile new <name> from <template>
|
|
|
201
232
|
Sets: /crew · /crew use|off|new|copy|rm · /crew model <v>
|
|
202
233
|
Extensions: /skills · /plugins · /plugins search <word> · /plugins disable|enable <id> · /soul
|
|
203
234
|
Updates: /update · /update confirm · /update on|off|check|auto · /subscribe on|off
|
|
204
|
-
Diagnostics: /doctor · /logs [errors|N|text]
|
|
235
|
+
Diagnostics: /doctor · /logs [errors|N|text] · /report
|
|
205
236
|
Service: /app · /restart · /help
|
|
206
237
|
Settings: /settings — the same switches as buttons, grouped in four tabs
|
|
207
238
|
Display: /lang · /reasoning on|off · /thoughts
|
|
@@ -284,13 +315,18 @@ local path and that path is steered, exactly as an idle turn would hand it over.
|
|
|
284
315
|
|
|
285
316
|
What each kind of attachment becomes inside a running turn:
|
|
286
317
|
|
|
287
|
-
| Sent | Inside the turn |
|
|
288
|
-
|
|
289
|
-
| voice note, audio file, audio sent as a document | transcript, echoed as `🎤 …` before the steer |
|
|
290
|
-
| small text file (`.md`, `.json`, `.csv`, `.py`, `.log`, … up to 60 KB) | the content itself between `<file>` markers — no tool call needed |
|
|
291
|
-
| PDF, archive, binary, anything bigger | its local path under `~/.dsh/tg-bridge/inbox/` |
|
|
292
|
-
| video, video note, animation | its path; the agent can pull frames or sound out with ffmpeg |
|
|
293
|
-
| 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.
|
|
294
330
|
|
|
295
331
|
A caption does not turn the attachment into a text-only message: it is folded into the same
|
|
296
332
|
hand-over, so "why did this fail" plus a `.log` file arrives as one steer.
|
|
@@ -406,6 +442,52 @@ profile's first turn. The binding is per topic: `/model` then edits that profile
|
|
|
406
442
|
has with the `dsh-plugin` keyword — the desktop app's plugin browser, from the chat. Each result
|
|
407
443
|
carries a plus button that runs `/plugins add <name>`.
|
|
408
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
|
+
|
|
409
491
|
### Goals and tasks
|
|
410
492
|
|
|
411
493
|
A topic carries its own goal and checklist, so the aim survives `/new`, a
|
|
@@ -439,6 +521,7 @@ no lock race and no lost update.
|
|
|
439
521
|
## Documentation
|
|
440
522
|
|
|
441
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"
|
|
442
525
|
- [docs/ROADMAP.md](https://github.com/aleksvega/dsh-tg-bridge/blob/master/docs/ROADMAP.md): what comes next
|
|
443
526
|
- [docs/UX-ANALYSIS.md](https://github.com/aleksvega/dsh-tg-bridge/blob/master/docs/UX-ANALYSIS.md): interactive UX review
|
|
444
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
|
];
|
package/control/agentsets.mjs
CHANGED
|
@@ -1,15 +1,16 @@
|
|
|
1
|
-
// Agent sets: a named bundle of subagents a topic can be bound to, with the card and the keyboard that edit it.
|
|
2
|
-
//
|
|
3
|
-
// Split out of `control.mjs` by the 500-line plan: the command handlers that
|
|
4
|
-
// follow call these, and none of them needs the dispatcher to do it.
|
|
5
|
-
import { join } from 'node:path';
|
|
6
|
-
import { t } from '../i18n.mjs';
|
|
7
|
-
import { parseAgentPresets, parsePermissionPresets, parseReasoningEfforts } from '../agents.mjs';
|
|
8
|
-
import { AgentsetStore } from '../agentsets.mjs';
|
|
9
|
-
import { profileValues, resolveSettings } from '../settings.mjs';
|
|
10
|
-
import { DSH_HOME } from '../paths.mjs';
|
|
11
|
-
|
|
12
|
-
|
|
1
|
+
// Agent sets: a named bundle of subagents a topic can be bound to, with the card and the keyboard that edit it.
|
|
2
|
+
//
|
|
3
|
+
// Split out of `control.mjs` by the 500-line plan: the command handlers that
|
|
4
|
+
// follow call these, and none of them needs the dispatcher to do it.
|
|
5
|
+
import { join } from 'node:path';
|
|
6
|
+
import { t } from '../i18n.mjs';
|
|
7
|
+
import { parseAgentPresets, parsePermissionPresets, parseReasoningEfforts } from '../agents.mjs';
|
|
8
|
+
import { AgentsetStore } from '../agentsets.mjs';
|
|
9
|
+
import { profileValues, resolveSettings } from '../settings.mjs';
|
|
10
|
+
import { DSH_HOME } from '../paths.mjs';
|
|
11
|
+
import { cardKeyboard } from '../aset-schema.mjs';
|
|
12
|
+
|
|
13
|
+
import { read, patchPath, modelsOf, modelOf } from './models.mjs';
|
|
13
14
|
export const fmt = (rows) => rows.map((row) => ` ${row}`).join('\n');
|
|
14
15
|
|
|
15
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
|
}
|