@rarog/server 1.1.2-beta.1 → 1.1.2-beta.2
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/node_modules/@rarog/shared/package.json +1 -1
- package/node_modules/@rarog/shared/src/decode.js +43 -1
- package/node_modules/@rarog/shared/src/notify-copy.js +1 -0
- package/node_modules/@rarog/shared/src/protocol/context.js +57 -0
- package/node_modules/@rarog/shared/src/protocol/coordination.js +42 -0
- package/node_modules/@rarog/shared/src/protocol/dialog-live.js +117 -0
- package/node_modules/@rarog/shared/src/protocol/files.js +1 -1
- package/node_modules/@rarog/shared/src/protocol/inbox.js +6 -0
- package/node_modules/@rarog/shared/src/protocol/presence.js +47 -0
- package/node_modules/@rarog/shared/src/protocol.js +14 -146
- package/node_modules/@rarog/shared/src/rest.js +16 -1
- package/node_modules/@rarog/shared/src/sentences/push.js +6 -0
- package/node_modules/@rarog/shared/src/sentences/rest.js +9 -0
- package/node_modules/@rarog/shared/src/sentences/restart.js +1 -0
- package/node_modules/@rarog/shared/src/sentences/session.js +24 -0
- package/package.json +2 -2
- package/plugin/rarog/.claude-plugin/plugin.json +4 -0
- package/plugin/rarog/bin/rarog-coordinator +7 -0
- package/plugin/rarog/hooks/hooks.json +18 -0
- package/plugin/rarog/hooks/recipient.mjs +95 -0
- package/plugin/rarog/lib/coordinator.mjs +1340 -0
- package/plugin/rarog/lib/threads.mjs +350 -0
- package/plugin/rarog/skills/coordinator/SKILL.md +111 -0
- package/plugin/rarog/skills/coordinator/check-and-merge.md +46 -0
- package/plugin/rarog/skills/coordinator/close-thread.md +15 -0
- package/plugin/rarog/skills/coordinator/role.md +61 -0
- package/plugin/rarog/skills/coordinator/send-back.md +39 -0
- package/plugin/rarog/skills/coordinator/start-thread.md +43 -0
- package/server/src/bootstrap/coordination.js +49 -0
- package/server/src/bootstrap/coordinator-start.js +27 -0
- package/server/src/bootstrap/inbox.js +4 -0
- package/server/src/bootstrap/push.js +24 -1
- package/server/src/companion/catalog.js +1 -1
- package/server/src/companion/index.js +2 -4
- package/server/src/config/flags.js +4 -0
- package/server/src/config-env.js +15 -0
- package/server/src/config.js +17 -3
- package/server/src/coordination/merge-events.js +86 -0
- package/server/src/coordination/merge-prompt.js +244 -0
- package/server/src/coordination/registry.js +289 -0
- package/server/src/coordination/state.js +94 -0
- package/server/src/coordination/summary.js +422 -0
- package/server/src/coordination/thread-file.js +245 -0
- package/server/src/coordination/thread-git.js +110 -0
- package/server/src/coordination/watch.js +237 -0
- package/server/src/demo/content/coordinator.js +89 -0
- package/server/src/demo/content/en.js +57 -1
- package/server/src/demo/content/pl.js +57 -1
- package/server/src/demo/inbox.js +12 -0
- package/server/src/demo/mock-herdr.js +3 -2
- package/server/src/demo/review-routes.js +2 -2
- package/server/src/demo/seeds.js +20 -2
- package/server/src/drivers/herdr/live-dialog.js +412 -0
- package/server/src/drivers/herdr/live-step.js +261 -0
- package/server/src/drivers/herdr/pause-gate.js +60 -0
- package/server/src/drivers/herdr/returned-prompt.js +4 -1
- package/server/src/drivers/herdr/screen-fallback.js +50 -0
- package/server/src/drivers/herdr/start-dialog-gate.js +4 -0
- package/server/src/drivers/herdr-driver.js +88 -66
- package/server/src/files/refusals.js +9 -2
- package/server/src/files/session-gate.js +5 -4
- package/server/src/git-branch-diff.js +194 -0
- package/server/src/herdr/argv.js +34 -3
- package/server/src/herdr/audit.js +32 -1
- package/server/src/herdr/background/cli-shapes.js +19 -0
- package/server/src/herdr/background/queued-prompt.js +46 -0
- package/server/src/herdr/background/work.js +12 -0
- package/server/src/herdr/client.js +22 -46
- package/server/src/herdr/commands/catalog.js +11 -7
- package/server/src/herdr/commands/discover.js +33 -1
- package/server/src/herdr/commands/index.js +3 -2
- package/server/src/herdr/dialogs/index.js +9 -0
- package/server/src/herdr/dialogs/layer1/hook-list/hook-list.js +4 -56
- package/server/src/herdr/dialogs/live/model.js +220 -0
- package/server/src/herdr/dialogs/live/policy.js +108 -0
- package/server/src/herdr/dialogs/live/view.js +261 -0
- package/server/src/herdr/dialogs/screen/form.js +4 -3
- package/server/src/herdr/dialogs/screen/signatures.js +23 -0
- package/server/src/herdr/engines.js +96 -0
- package/server/src/herdr/history-steps.js +9 -4
- package/server/src/herdr/identity.js +20 -5
- package/server/src/herdr/jsonl-follow.js +20 -1
- package/server/src/herdr/plugin-copy.js +281 -0
- package/server/src/herdr/session-index.js +19 -0
- package/server/src/herdr/supervisor.js +16 -13
- package/server/src/herdr/types.js +1 -0
- package/server/src/inbox/card.js +31 -8
- package/server/src/inbox/heads.js +1 -0
- package/server/src/inbox/inbox.js +21 -4
- package/server/src/inbox/removals.js +10 -1
- package/server/src/index.js +37 -5
- package/server/src/notify/content.js +27 -0
- package/server/src/notify/index.js +7 -3
- package/server/src/notify/live-activity-state.js +14 -5
- package/server/src/notify/policy.js +49 -11
- package/server/src/notify/ready-to-merge.js +148 -0
- package/server/src/project-root.js +233 -0
- package/server/src/routes/sessions.js +68 -2
- package/server/src/sessions/branch-diff.js +57 -0
- package/server/src/sessions/cli-registry.js +17 -3
- package/server/src/sessions/companion-scope.js +2 -1
- package/server/src/sessions/consent-cards.js +49 -2
- package/server/src/sessions/conversation-lists.js +4 -1
- package/server/src/sessions/coordinator-start.js +172 -0
- package/server/src/sessions/demo-modules.js +1 -0
- package/server/src/sessions/demo-seeds.js +100 -0
- package/server/src/sessions/driver-events.js +61 -11
- package/server/src/sessions/herdr-lifecycle.js +11 -4
- package/server/src/sessions/launch-gate.js +36 -11
- package/server/src/sessions/live-dialog.js +69 -0
- package/server/src/sessions/manager.js +124 -282
- package/server/src/sessions/owner-turn.js +36 -0
- package/server/src/sessions/seen-marks.js +31 -12
- package/server/src/sessions/session-dialog.js +82 -0
- package/server/src/sessions/session-git.js +1 -0
- package/server/src/sessions/session-scope.js +6 -5
- package/server/src/sessions/session-take-back.js +5 -0
- package/server/src/sessions/session.js +72 -7
- package/server/src/sessions/state-machine.js +2 -0
- package/server/src/sessions/state-sentences.js +87 -30
- package/server/src/sessions/waiting-line.js +49 -0
- package/server/src/transcript-import.js +20 -2
- package/server/src/version.js +4 -0
- /package/server/src/{companion/asks-owner.js → asks-owner.js} +0 -0
|
@@ -18,7 +18,9 @@
|
|
|
18
18
|
* korzeniowi repo `cwd`, włączone wg `enabledPlugins` (`settings.local.json` > `settings.json`
|
|
19
19
|
* projektu > `~/.claude/settings.json`; brak wpisu → `defaultEnabled` manifestu, domyślnie `true`),
|
|
20
20
|
* wyłącznie z domyślnych katalogów `skills/<katalog>/SKILL.md` i `commands/<plik>.md`; komenda
|
|
21
|
-
* `/<plugin>:<name|katalog>` albo `/<plugin>:<plik
|
|
21
|
+
* `/<plugin>:<name|katalog>` albo `/<plugin>:<plik>`;
|
|
22
|
+
* - plugin directories of the session (`pluginDirs`, `--plugin-dir` of a coordinator): the same default directories
|
|
23
|
+
* and names, the plugin name from the manifest, without an install entry or `enabledPlugins`.
|
|
22
24
|
*
|
|
23
25
|
* Filtry: `user-invocable: false` i `skillOverrides[nazwa] === "off"` (tego drugiego pluginy nie mają)
|
|
24
26
|
* chowają skill; nazwa spoza kształtu nazw Raroga (`isCommandName`) i nazwa komendy wbudowanej też (przy tej drugiej
|
|
@@ -499,6 +501,34 @@ function scanPlugin(scan, pluginsDir, settings, key, entry) {
|
|
|
499
501
|
scan.skipped.push({ plugin: key, reason: 'name' });
|
|
500
502
|
return;
|
|
501
503
|
}
|
|
504
|
+
scanPluginCommands(scan, installPath, plugin);
|
|
505
|
+
}
|
|
506
|
+
/**
|
|
507
|
+
* Plugin directories the session loads with `--plugin-dir` (the coordinator's plugin copy): no install entry and no
|
|
508
|
+
* `enabledPlugins`, the plugin name only from its manifest (the directory of a copy is named after a version), and the
|
|
509
|
+
* same default directories and name rules as an installed plugin. A manifest without a valid name, or with its own
|
|
510
|
+
* command or skill paths, skips the directory.
|
|
511
|
+
*/
|
|
512
|
+
function scanSessionPlugins(scan, dirs) {
|
|
513
|
+
const layout = DISK_LAYOUT.plugins;
|
|
514
|
+
const keys = DISK_LAYOUT.manifestKeys;
|
|
515
|
+
for (const dir of dirs) {
|
|
516
|
+
const manifest = scan.json(join(dir, layout.manifestDir, layout.manifest)) ?? {};
|
|
517
|
+
if (keys.commands in manifest || keys.skills in manifest) {
|
|
518
|
+
scan.skipped.push({ plugin: dir, reason: 'manifest-paths' });
|
|
519
|
+
scan.note(`command catalog: plugin ${dir} has its own command or skill paths in the manifest — skipping`);
|
|
520
|
+
continue;
|
|
521
|
+
}
|
|
522
|
+
const plugin = manifest[keys.name];
|
|
523
|
+
if (typeof plugin !== 'string' || !isCommandSegment(plugin)) {
|
|
524
|
+
scan.skipped.push({ plugin: dir, reason: 'name' });
|
|
525
|
+
continue;
|
|
526
|
+
}
|
|
527
|
+
scanPluginCommands(scan, dir, plugin);
|
|
528
|
+
}
|
|
529
|
+
}
|
|
530
|
+
/** Skills `skills/<dir>/SKILL.md` and commands `commands/<file>.md` of one plugin, named `<plugin>:<…>`. */
|
|
531
|
+
function scanPluginCommands(scan, installPath, plugin) {
|
|
502
532
|
const skillsDir = join(installPath, DISK_LAYOUT.skillsDir);
|
|
503
533
|
for (const dir of scan.entries(skillsDir, 'dir')) {
|
|
504
534
|
if (!isCommandSegment(dir))
|
|
@@ -604,6 +634,8 @@ export function discoverCommands(opts) {
|
|
|
604
634
|
scanCommandFiles(scan, join(projectDir, DISK_LAYOUT.commandsDir), 'project-command', settings);
|
|
605
635
|
}
|
|
606
636
|
scanSynced(scan, opts.home);
|
|
637
|
+
// The session's own plugin first: on a name it shares with an installed plugin, its description goes to the list.
|
|
638
|
+
scanSessionPlugins(scan, opts.pluginDirs ?? []);
|
|
607
639
|
scanPlugins(scan, opts.home, settings, repoRoot ?? resolve(opts.cwd));
|
|
608
640
|
const { commands, hidden } = resolveNames(scan, opts.reserved);
|
|
609
641
|
return {
|
|
@@ -16,8 +16,9 @@
|
|
|
16
16
|
* (`createSendThrottle`).
|
|
17
17
|
* - `shape.ts` — reguła rozpoznania komendy w tekście (`classifySlashText`) i kształt Raroga dla
|
|
18
18
|
* nazwy komendy, jedna definicja dla strażnika managera i drivera.
|
|
19
|
-
* - `catalog.ts` — migawka katalogu sesji per `(cwd, wersja CLI)` z `revision`
|
|
20
|
-
* `registryCatalog`) i lista dla apki z migawki (`commandListOf`,
|
|
19
|
+
* - `catalog.ts` — migawka katalogu sesji per `(cwd, wersja CLI)` and `--plugin-dir` z `revision`
|
|
20
|
+
* (`createCommandCatalogs`, `registryCatalog`) i lista dla apki z migawki (`commandListOf`,
|
|
21
|
+
* `GET /api/sessions/:id/commands`).
|
|
21
22
|
* - `discover.ts` — skille i komendy z dysku w wąskim, jawnym podzbiorze źródeł CLI.
|
|
22
23
|
* - `transcript.ts` — wpis komendy w pliku rozmowy → wiadomość transkryptu (notka `system` komendy lokalnej
|
|
23
24
|
* i jej wyniku, wiadomość `user` komendy typu prompt), bezstanowo; tu też rozpoznanie promptu
|
|
@@ -167,6 +167,15 @@
|
|
|
167
167
|
* the audit (`episodeVerdictOf`, `LAYER2_EPISODE_VERDICTS`).
|
|
168
168
|
* - `layer2/verdict.ts` — layer 2 rule (`layer2Verdict`): buttons with whole literal labels from the block's raw
|
|
169
169
|
* rows, or the reason for none (pure function; the server calls it through `layer2Gate`).
|
|
170
|
+
* - `live/view.ts` — the live dialog card, screen half (`liveRegion`): the dialog region of a raw screen from
|
|
171
|
+
* the top rule to the last footer line, its options, the cursor, the cut and scroll marks,
|
|
172
|
+
* the text under the presentation ceiling and the fingerprint.
|
|
173
|
+
* - `live/policy.ts` — the Enter rule of the live card (`liveEnterWhy`, the closed list `LIVE_ENTER_WHYS`) and
|
|
174
|
+
* the keys the server takes (`liveKeys`); Esc is always among them.
|
|
175
|
+
* - `live/model.ts` — the live card of a screen (`liveDialogView`): the label under the cursor, its lasting
|
|
176
|
+
* effect, the whole option set of a dialog without a key footer, and the wire field
|
|
177
|
+
* `herdrDialogLive` (`liveDialogWire`). Pure functions; `drivers/herdr/live-dialog.ts`
|
|
178
|
+
* calls them.
|
|
170
179
|
*
|
|
171
180
|
* ── Jak importować
|
|
172
181
|
*
|
|
@@ -84,6 +84,7 @@ import { DISK_LAYOUT } from '../../../commands/registry.js';
|
|
|
84
84
|
import { parseElapsed } from '../../shadow/liveness.js';
|
|
85
85
|
import { HOOK_PERMISSION_EVENT } from '../../../hook-commands.js';
|
|
86
86
|
import { DIRECT_DISK } from '../../../../folder-gate/disk.js';
|
|
87
|
+
import { mainCheckoutOf, upwards } from '../../../../project-root.js';
|
|
87
88
|
/** Zapas na rozdzielczość `etime` (pełne sekundy) i czas samego `ps`. */
|
|
88
89
|
export const HOOK_LIST_START_SLACK_MS = 2_000;
|
|
89
90
|
/** Rejestr CLI pisze `startedAt` 1–7 s po starcie procesu (`cli-version.ts`); zapas do 10 s. */
|
|
@@ -184,9 +185,6 @@ const MARKETPLACE_SOURCES = {
|
|
|
184
185
|
directory: 'directory',
|
|
185
186
|
file: 'file',
|
|
186
187
|
};
|
|
187
|
-
/** Linked worktree gita: plik `.git` z jedną linią `gitdir: <katalog>`, a w tym katalogu `commondir`. */
|
|
188
|
-
const GIT_FILE_PREFIX = 'gitdir: ';
|
|
189
|
-
const GIT_COMMONDIR = 'commondir';
|
|
190
188
|
class HookListNoProof extends Error {
|
|
191
189
|
}
|
|
192
190
|
/**
|
|
@@ -532,18 +530,6 @@ class Reader {
|
|
|
532
530
|
}
|
|
533
531
|
}
|
|
534
532
|
}
|
|
535
|
-
/** Katalog i wszystkie wyżej, od niego do korzenia. */
|
|
536
|
-
function upwards(dir) {
|
|
537
|
-
const out = [];
|
|
538
|
-
let current = path.resolve(dir);
|
|
539
|
-
for (;;) {
|
|
540
|
-
out.push(current);
|
|
541
|
-
const parent = path.dirname(current);
|
|
542
|
-
if (parent === current)
|
|
543
|
-
return out;
|
|
544
|
-
current = parent;
|
|
545
|
-
}
|
|
546
|
-
}
|
|
547
533
|
/** The negative verdict of a read that threw. */
|
|
548
534
|
function verdictOf(err) {
|
|
549
535
|
if (err instanceof HookListNoProof)
|
|
@@ -681,7 +667,9 @@ async function readLayers(input, io, current) {
|
|
|
681
667
|
const localDirs = new Set();
|
|
682
668
|
for (const cwd of cwds) {
|
|
683
669
|
const main = await mainCheckoutOf(reader, cwd);
|
|
684
|
-
|
|
670
|
+
if (!main.ok)
|
|
671
|
+
throw new HookListNoProof(`worktree:${main.dotGit}`);
|
|
672
|
+
for (const root of main.root === null ? [cwd] : [cwd, main.root]) {
|
|
685
673
|
projectDirs.add(path.resolve(root));
|
|
686
674
|
for (const dir of upwards(root))
|
|
687
675
|
localDirs.add(dir);
|
|
@@ -786,46 +774,6 @@ async function syncedTrees(io, reader, root) {
|
|
|
786
774
|
}
|
|
787
775
|
}
|
|
788
776
|
}
|
|
789
|
-
/**
|
|
790
|
-
* Główny checkout dla `cwd` w linked worktree gita albo `null` (opis modułu; dokumentacja Claude Code: settings,
|
|
791
|
-
* „Where Claude Code keeps the local file in a git repository”; worktrees, „What worktrees share with the main
|
|
792
|
-
* checkout”). Najbliższy `.git` od `cwd` w górę: katalog = zwykły checkout (`null`); plik = jedna linia
|
|
793
|
-
* `gitdir: <katalog>` (ścieżka bezwzględna albo względna wobec katalogu pliku), a w tym katalogu `commondir` ze
|
|
794
|
-
* wspólnym katalogiem repozytorium; bez `commondir` to nie worktree (submoduł, `--separate-git-dir`), korzeniem jest
|
|
795
|
-
* katalog z plikiem `.git`. Wspólny katalog musi się nazywać `.git`, główny checkout to katalog nad nim; repozytorium
|
|
796
|
-
* bare, `gitdir` bez katalogu i każdy inny układ = brak dowodu. Odczyt bez uruchamiania `git`; pliki `.git` i
|
|
797
|
-
* `commondir` przechodzą przez sprawdzenie startu, katalogi gita nie (zmieniają się przy każdej operacji gita),
|
|
798
|
-
* dowiązania tak.
|
|
799
|
-
*/
|
|
800
|
-
async function mainCheckoutOf(reader, cwd) {
|
|
801
|
-
for (const dir of upwards(cwd)) {
|
|
802
|
-
const dotGit = path.join(dir, DISK_LAYOUT.gitDir);
|
|
803
|
-
const found = await reader.linked(dotGit);
|
|
804
|
-
if (found.info === null)
|
|
805
|
-
continue;
|
|
806
|
-
if (found.info.kind === 'dir')
|
|
807
|
-
return null;
|
|
808
|
-
const lines = (await reader.text(dotGit) ?? '').split('\n').filter((line) => line.trim() !== '');
|
|
809
|
-
const line = lines.length === 1 ? lines[0] ?? '' : '';
|
|
810
|
-
const target = line.startsWith(GIT_FILE_PREFIX) ? line.slice(GIT_FILE_PREFIX.length).trim() : '';
|
|
811
|
-
if (target === '')
|
|
812
|
-
throw new HookListNoProof(`worktree:${dotGit}`);
|
|
813
|
-
const gitDir = await reader.linked(path.isAbsolute(target) ? target : `${path.dirname(found.real)}/${target}`);
|
|
814
|
-
if (gitDir.info?.kind !== 'dir')
|
|
815
|
-
throw new HookListNoProof(`worktree:${dotGit}`);
|
|
816
|
-
const common = (await reader.text(path.join(gitDir.real, GIT_COMMONDIR)))?.trim();
|
|
817
|
-
if (common === undefined)
|
|
818
|
-
return null;
|
|
819
|
-
if (common === '' || common.includes('\n'))
|
|
820
|
-
throw new HookListNoProof(`worktree:${dotGit}`);
|
|
821
|
-
const commonDir = await reader.linked(path.isAbsolute(common) ? common : `${gitDir.real}/${common}`);
|
|
822
|
-
if (commonDir.info?.kind !== 'dir' || path.basename(commonDir.real) !== DISK_LAYOUT.gitDir) {
|
|
823
|
-
throw new HookListNoProof(`worktree:${dotGit}`);
|
|
824
|
-
}
|
|
825
|
-
return path.dirname(commonDir.real);
|
|
826
|
-
}
|
|
827
|
-
return null;
|
|
828
|
-
}
|
|
829
777
|
/** Ścieżka względna bez wyjścia w górę (`..`), bez ukośnika wstecznego. */
|
|
830
778
|
const relativeInside = (rel) => !path.isAbsolute(rel) && !rel.includes('\\') && rel.split('/').every((part) => part !== '..');
|
|
831
779
|
/**
|
|
@@ -0,0 +1,220 @@
|
|
|
1
|
+
import { standingConsentDialog } from '../policy/consent.js';
|
|
2
|
+
import { contentEscalates } from '../policy/escalation.js';
|
|
3
|
+
import { optionPolicy } from '../policy/option-policy.js';
|
|
4
|
+
import { matchTerminalDialog } from '../policy/terminal.js';
|
|
5
|
+
import { NOTES_EDITING_MARKER, formFooter, formSubmitMode } from '../screen/form.js';
|
|
6
|
+
import { dialogKind } from '../screen/kinds.js';
|
|
7
|
+
import { OPTION_BOX_GLYPH_PATTERN } from '../screen/options.js';
|
|
8
|
+
import { HORIZONTAL_RULE_PATTERN } from '../screen/region.js';
|
|
9
|
+
import { SCREEN_SIGNATURES } from '../screen/signatures.js';
|
|
10
|
+
import { LIVE_REFUSE, liveEnterWhy, liveKeys } from './policy.js';
|
|
11
|
+
import { LIVE_CURSOR, liveRegion } from './view.js';
|
|
12
|
+
export { LIVE_ENTER_KEY, LIVE_ESCAPE_KEY, LIVE_NAVIGATION_KEYS } from './policy.js';
|
|
13
|
+
const OPTION_ROW = SCREEN_SIGNATURES.dialogOptionRow.pattern;
|
|
14
|
+
const KEY_HINT = SCREEN_SIGNATURES.keyHintLine.pattern;
|
|
15
|
+
const SETS_DEFAULT = SCREEN_SIGNATURES.footerSetsDefault.pattern;
|
|
16
|
+
const CHECKBOX = SCREEN_SIGNATURES.optionCheckbox.pattern;
|
|
17
|
+
const SUBMIT_ROW = SCREEN_SIGNATURES.formSubmitRow.pattern;
|
|
18
|
+
const NEGATIVE = SCREEN_SIGNATURES.negativeOption.pattern;
|
|
19
|
+
const CUSTOM_ANSWER = SCREEN_SIGNATURES.customAnswerOption.pattern;
|
|
20
|
+
/** The checkbox glyphs of the form tab bar (☐ ☒ ☑), all of them: checking a box of the form turns ☐ into ☒. */
|
|
21
|
+
export const LIVE_TAB_GLYPHS = new RegExp(SCREEN_SIGNATURES.tabGlyph.pattern.source, 'gu');
|
|
22
|
+
/**
|
|
23
|
+
* What stands on the phone next to a live card: the three shapes of today's card without buttons (a degraded consent
|
|
24
|
+
* card or one without the approve button, a screen card of a dialog Rarog does not know, a card of a dialog answered in
|
|
25
|
+
* the terminal), or no card for the dialog at all. A closed list: the audit log counts it.
|
|
26
|
+
*/
|
|
27
|
+
export const LIVE_CARD_SHAPES = ['degraded', 'screen-dialog', 'terminal', 'no-card'];
|
|
28
|
+
/**
|
|
29
|
+
* What the verify read after a key of the live card saw: the cursor moved to another option (`cursor`), the dialog is
|
|
30
|
+
* gone (`gone`), the same view unchanged (`same`), the same dialog with another print (`changed`), a dialog of another
|
|
31
|
+
* class (`other-dialog`), or a failed read (`unknown`). A closed list: the audit log counts it.
|
|
32
|
+
*/
|
|
33
|
+
export const LIVE_VERIFY_OUTCOMES = ['cursor', 'gone', 'same', 'changed', 'other-dialog', 'unknown'];
|
|
34
|
+
const indent = (line) => line.length - line.trimStart().length;
|
|
35
|
+
/**
|
|
36
|
+
* The registry class of the place, which the Enter rule reads and the audit lines carry: in a session the registry's,
|
|
37
|
+
* before the session starts `dialog` for a known start dialog and `permission` for an unknown one (the consent guards).
|
|
38
|
+
*/
|
|
39
|
+
export function liveClass(place) {
|
|
40
|
+
if (place.kind === 'session')
|
|
41
|
+
return place.cliDialog;
|
|
42
|
+
return place.startDialog === null ? 'permission' : 'dialog';
|
|
43
|
+
}
|
|
44
|
+
/**
|
|
45
|
+
* Whether row `i` of the option zone continues the label of the option above it: indented to the label column at
|
|
46
|
+
* least, not empty, not an option, a key hint or a rule.
|
|
47
|
+
*/
|
|
48
|
+
function continues(region, i) {
|
|
49
|
+
const line = region.rows[i] ?? '';
|
|
50
|
+
const trimmed = line.trim();
|
|
51
|
+
return trimmed !== '' && indent(line) >= region.labelColumn && !region.options.some((option) => option.row === i)
|
|
52
|
+
&& !OPTION_ROW.test(line) && !KEY_HINT.test(trimmed) && !HORIZONTAL_RULE_PATTERN.test(trimmed);
|
|
53
|
+
}
|
|
54
|
+
/**
|
|
55
|
+
* The rows of the label under the cursor, from the raw rows (gaps kept), each trimmed. A question form: the cursor row
|
|
56
|
+
* alone, up to the frame of a preview box, because option descriptions stand in the label column under it. Other
|
|
57
|
+
* dialogs: the cursor row and its continuation rows. The card joins them by one space.
|
|
58
|
+
*/
|
|
59
|
+
function cursorLabelRows(region, question) {
|
|
60
|
+
const at = region.cursorRow;
|
|
61
|
+
const row = region.rows[at] ?? '';
|
|
62
|
+
const own = region.options.find((option) => option.row === at)?.label
|
|
63
|
+
?? row.slice(row.indexOf(LIVE_CURSOR) + LIVE_CURSOR.length).trim();
|
|
64
|
+
if (question) {
|
|
65
|
+
const box = own.search(OPTION_BOX_GLYPH_PATTERN);
|
|
66
|
+
return [(box === -1 ? own : own.slice(0, box)).trim()];
|
|
67
|
+
}
|
|
68
|
+
const parts = [own.trim()];
|
|
69
|
+
for (let i = at + 1; i < region.zoneEnd && continues(region, i); i += 1)
|
|
70
|
+
parts.push((region.rows[i] ?? '').trim());
|
|
71
|
+
return parts;
|
|
72
|
+
}
|
|
73
|
+
/**
|
|
74
|
+
* Whether the option under the cursor has a lasting effect: an escalating label, a footer that says Enter saves the
|
|
75
|
+
* default, a standing consent dialog (`standingConsentDialog`), or escalation markers in the dialog content above the
|
|
76
|
+
* options (the operation frame stays out) with the cursor not on a declining option.
|
|
77
|
+
*/
|
|
78
|
+
function lasting(region, label) {
|
|
79
|
+
const facts = { label, terminalDialog: null, multiSelect: false, notesEditing: false };
|
|
80
|
+
if (optionPolicy(facts, 'hook').why === 'escalation')
|
|
81
|
+
return true;
|
|
82
|
+
if (region.footer !== null && SETS_DEFAULT.test(region.rows.slice(region.footer).join(' ')))
|
|
83
|
+
return true;
|
|
84
|
+
if (standingConsentDialog(region.rows.join('\n')) !== null)
|
|
85
|
+
return true;
|
|
86
|
+
const firstOption = region.options[0]?.row ?? 0;
|
|
87
|
+
const body = region.rows.slice(region.bodyStart, firstOption).map((line) => line.trim());
|
|
88
|
+
return !NEGATIVE.test(label) && contentEscalates(body);
|
|
89
|
+
}
|
|
90
|
+
/**
|
|
91
|
+
* Numbered options 1..N whose last option declines and, with its continuation rows, ends the screen. These captures
|
|
92
|
+
* have no key footer and end on a declining option: the WebFetch permission (`measured/zgoda-webfetch-2.1.322.txt`),
|
|
93
|
+
* the sandbox network permission (`measured/zgoda-siec-2.1.328.txt`), exit plan mode without a plan
|
|
94
|
+
* (`measured/exitplanmode-bez-planu-2.1.328.txt`), the model switch (`dialog-model-switch.txt`).
|
|
95
|
+
*/
|
|
96
|
+
function endsOnDecline(region) {
|
|
97
|
+
const last = region.options.at(-1);
|
|
98
|
+
if (!region.numbered || last === undefined || last.digit === null || !NEGATIVE.test(last.label))
|
|
99
|
+
return false;
|
|
100
|
+
for (let i = last.row + 1; i < region.rows.length; i += 1)
|
|
101
|
+
if (!continues(region, i))
|
|
102
|
+
return false;
|
|
103
|
+
return true;
|
|
104
|
+
}
|
|
105
|
+
/**
|
|
106
|
+
* The option set without a key footer is closed: a dialog of the terminal list matched with its whole option set, or
|
|
107
|
+
* options that end on a declining one at the bottom of the screen.
|
|
108
|
+
*/
|
|
109
|
+
function closedSet(region) {
|
|
110
|
+
const title = region.rows.find((row) => row.trim() !== '') ?? '';
|
|
111
|
+
const options = region.options.flatMap((option) => (option.digit === null
|
|
112
|
+
? []
|
|
113
|
+
: [{ digit: option.digit, label: option.label }]));
|
|
114
|
+
return matchTerminalDialog(title, options) !== null || endsOnDecline(region);
|
|
115
|
+
}
|
|
116
|
+
/**
|
|
117
|
+
* Whether the region is a question form: its key footer names the select and navigation keys of the form. Only the
|
|
118
|
+
* footer counts, because the question and the option descriptions may carry the words of another dialog's footer
|
|
119
|
+
* ("Do you want to proceed?"). The plan dialog's footer ("ctrl+g to edit in …") names neither.
|
|
120
|
+
*/
|
|
121
|
+
function questionForm(region) {
|
|
122
|
+
if (region.footer === null)
|
|
123
|
+
return false;
|
|
124
|
+
return dialogKind(region.rows.slice(region.footer).join('\n').toLowerCase()) === 'question';
|
|
125
|
+
}
|
|
126
|
+
/**
|
|
127
|
+
* Whether the cursor stands on the free-text row of a question form: the last numbered option of its block (no
|
|
128
|
+
* numbered option under it above the next rule) whose label, without its checkbox, reads "Type something"
|
|
129
|
+
* (`live/multi-form-free-text-2.1.332.txt`). The row takes typed text, so Enter on it does not answer the form. The
|
|
130
|
+
* preview variant adds no such row, so its last option is the author's even when it reads so.
|
|
131
|
+
*/
|
|
132
|
+
function freeTextRow(region, question, cursorRow) {
|
|
133
|
+
if (!question || cursorRow === undefined || previewForm(region))
|
|
134
|
+
return false;
|
|
135
|
+
const option = region.options.find((candidate) => candidate.row === region.cursorRow);
|
|
136
|
+
if (option === undefined || option.digit === null)
|
|
137
|
+
return false;
|
|
138
|
+
const box = CHECKBOX.exec(cursorRow);
|
|
139
|
+
if (!CUSTOM_ANSWER.test((box === null ? cursorRow : box[3] ?? '').trim()))
|
|
140
|
+
return false;
|
|
141
|
+
for (let i = option.row + 1; i < region.zoneEnd; i += 1) {
|
|
142
|
+
if (HORIZONTAL_RULE_PATTERN.test((region.rows[i] ?? '').trim()))
|
|
143
|
+
return true;
|
|
144
|
+
if (region.options.some((candidate) => candidate.row === i && candidate.digit !== null))
|
|
145
|
+
return false;
|
|
146
|
+
}
|
|
147
|
+
return true;
|
|
148
|
+
}
|
|
149
|
+
/**
|
|
150
|
+
* Whether a question form is in notes editing: `ctrl+g` in its footer next to a notes field. The notes field exists
|
|
151
|
+
* only in the preview variant of the form (the notes marker in the footer or a preview frame on an option line,
|
|
152
|
+
* `formSubmitMode`). Without it the phrase is no notes editing: Claude Code 2.1.332 adds "ctrl+g to edit in Vim" to
|
|
153
|
+
* the footer of a multi-select form while the cursor stands on "Type something".
|
|
154
|
+
*/
|
|
155
|
+
function notesEditing(region) {
|
|
156
|
+
return formFooter(region.rows).includes(NOTES_EDITING_MARKER) && previewForm(region);
|
|
157
|
+
}
|
|
158
|
+
/** Whether the form is the preview variant: the notes marker in its footer or a preview frame on an option line. */
|
|
159
|
+
function previewForm(region) {
|
|
160
|
+
// `formSubmitMode` reads the rows as the parser keeps them: trimmed, the option line without the cursor.
|
|
161
|
+
const rows = region.rows.map((row) => {
|
|
162
|
+
const trimmed = row.trim();
|
|
163
|
+
return trimmed.startsWith(LIVE_CURSOR) ? trimmed.slice(LIVE_CURSOR.length).trimStart() : trimmed;
|
|
164
|
+
});
|
|
165
|
+
return formSubmitMode(rows) === 'digit-enter';
|
|
166
|
+
}
|
|
167
|
+
/**
|
|
168
|
+
* The live card of a screen, or `null`: level `0`, a dialog with its own card, no dialog with options on the screen,
|
|
169
|
+
* or a question form in notes editing (a key would type into the note).
|
|
170
|
+
*/
|
|
171
|
+
export function liveDialogView(screen, input) {
|
|
172
|
+
if (input.level === 0 || input.ownCard)
|
|
173
|
+
return null;
|
|
174
|
+
const region = liveRegion(screen);
|
|
175
|
+
if (region === null)
|
|
176
|
+
return null;
|
|
177
|
+
const question = questionForm(region);
|
|
178
|
+
if (question && notesEditing(region))
|
|
179
|
+
return null;
|
|
180
|
+
const cls = liveClass(input.place);
|
|
181
|
+
const labelRows = region.cursorRow === -1 ? [] : cursorLabelRows(region, question);
|
|
182
|
+
const label = labelRows.join(' ');
|
|
183
|
+
const why = liveEnterWhy({
|
|
184
|
+
level: input.level,
|
|
185
|
+
light: (cls === 'input' || cls === 'dialog') && input.consent.mode !== null,
|
|
186
|
+
consent: input.consent,
|
|
187
|
+
region,
|
|
188
|
+
labelRows,
|
|
189
|
+
closedSet: region.footer === null && closedSet(region),
|
|
190
|
+
freeText: freeTextRow(region, question, labelRows[0]),
|
|
191
|
+
});
|
|
192
|
+
const multiSelect = region.options.some((option) => CHECKBOX.test(option.label));
|
|
193
|
+
const enter = CHECKBOX.test(label)
|
|
194
|
+
? 'toggle'
|
|
195
|
+
: multiSelect && SUBMIT_ROW.test(label) ? 'submit' : 'choose';
|
|
196
|
+
return {
|
|
197
|
+
text: region.text,
|
|
198
|
+
print: region.print,
|
|
199
|
+
cursorLabel: why === null ? label : null,
|
|
200
|
+
keys: liveKeys(why),
|
|
201
|
+
...(why === null ? {} : { why, refuse: LIVE_REFUSE[why] }),
|
|
202
|
+
...(why === null && lasting(region, label) ? { lasting: true } : {}),
|
|
203
|
+
...(region.hiddenAbove === undefined ? {} : { hiddenAbove: region.hiddenAbove }),
|
|
204
|
+
...(why === null ? { enter } : {}),
|
|
205
|
+
bind: input.place.kind === 'start' ? 'pane' : 'session',
|
|
206
|
+
};
|
|
207
|
+
}
|
|
208
|
+
/** The wire field `herdrDialogLive` of a view, in the occurrence `id` at revision `rev`. */
|
|
209
|
+
export function liveDialogWire(view, id, rev) {
|
|
210
|
+
return {
|
|
211
|
+
id,
|
|
212
|
+
rev,
|
|
213
|
+
text: view.text,
|
|
214
|
+
cursorLabel: view.cursorLabel,
|
|
215
|
+
keys: [...view.keys],
|
|
216
|
+
...(view.refuse === undefined ? {} : { refuse: view.refuse }),
|
|
217
|
+
...(view.lasting === undefined ? {} : { lasting: view.lasting }),
|
|
218
|
+
...(view.hiddenAbove === undefined ? {} : { hiddenAbove: view.hiddenAbove }),
|
|
219
|
+
};
|
|
220
|
+
}
|
|
@@ -0,0 +1,108 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* The live dialog card, key half: one function decides whether the server takes Enter for a dialog region
|
|
3
|
+
* ({@link liveEnterWhy}), and the keys of the card follow from its answer ({@link liveKeys}). Esc is always there.
|
|
4
|
+
*
|
|
5
|
+
* Every doubt refuses Enter. The consent guards of the emergency approve button (`screenFallbackGuard`) apply to a
|
|
6
|
+
* consent dialog in channel modes `main` and `all`; the guards of the card itself (`card`, `class`, a subagent's
|
|
7
|
+
* dialog in `main`) do not, because the live card shows the dialog as the terminal does. No I/O.
|
|
8
|
+
*/
|
|
9
|
+
import { DIALOG_LIVE_KEYS } from '@rarog/shared';
|
|
10
|
+
import { hasCardHiddenChar } from '../../../hidden-chars.js';
|
|
11
|
+
import { screenFallbackGuard } from '../screen-fallback.js';
|
|
12
|
+
import { SCREEN_SIGNATURES } from '../screen/signatures.js';
|
|
13
|
+
/** The keys of the contract, named by their position in `DIALOG_LIVE_KEYS`. */
|
|
14
|
+
const [ESCAPE, UP, DOWN, ENTER] = DIALOG_LIVE_KEYS;
|
|
15
|
+
const LABEL_CUT = SCREEN_SIGNATURES.optionLabelCut.pattern;
|
|
16
|
+
export const LIVE_ESCAPE_KEY = ESCAPE;
|
|
17
|
+
export const LIVE_NAVIGATION_KEYS = [UP, DOWN];
|
|
18
|
+
export const LIVE_ENTER_KEY = ENTER;
|
|
19
|
+
/**
|
|
20
|
+
* Why the server does not take Enter, in the order the rule checks. A closed list: the audit log and the app read
|
|
21
|
+
* the reason, so a new one needs an entry here and in {@link LIVE_REFUSE}.
|
|
22
|
+
*/
|
|
23
|
+
export const LIVE_ENTER_WHYS = [
|
|
24
|
+
'level', 'no-cursor', 'cursors', 'cursor-off-options', 'options-scrolled', 'options-cut', 'hidden-char',
|
|
25
|
+
'free-text', 'channel-mode', 'unjudged', 'hook-trace', 'hook-waits', 'hook-process', 'foreign-hook',
|
|
26
|
+
'restart-grace', 'no-tool-use',
|
|
27
|
+
];
|
|
28
|
+
/** The refusal word of the contract for each reason: the app builds its sentence from it. */
|
|
29
|
+
export const LIVE_REFUSE = {
|
|
30
|
+
level: 'terminal-only',
|
|
31
|
+
'no-cursor': 'unreadable',
|
|
32
|
+
cursors: 'unreadable',
|
|
33
|
+
'cursor-off-options': 'unreadable',
|
|
34
|
+
'options-scrolled': 'unreadable',
|
|
35
|
+
'options-cut': 'unreadable',
|
|
36
|
+
'hidden-char': 'unreadable',
|
|
37
|
+
'free-text': 'terminal-only',
|
|
38
|
+
'channel-mode': 'consent-dialog',
|
|
39
|
+
unjudged: 'consent-dialog',
|
|
40
|
+
'hook-trace': 'consent-dialog',
|
|
41
|
+
'hook-waits': 'consent-dialog',
|
|
42
|
+
'hook-process': 'consent-dialog',
|
|
43
|
+
'foreign-hook': 'consent-dialog',
|
|
44
|
+
'restart-grace': 'consent-dialog',
|
|
45
|
+
'no-tool-use': 'no-jsonl',
|
|
46
|
+
};
|
|
47
|
+
/** The reason for a consent guard the emergency button refuses on. */
|
|
48
|
+
function consentWhy(guard) {
|
|
49
|
+
switch (guard) {
|
|
50
|
+
case 'judgement': return 'unjudged';
|
|
51
|
+
case 'trace': return 'hook-trace';
|
|
52
|
+
case 'hook': return 'hook-waits';
|
|
53
|
+
case 'hook-running':
|
|
54
|
+
case 'ps': return 'hook-process';
|
|
55
|
+
case 'hook-list': return 'foreign-hook';
|
|
56
|
+
case 'restart': return 'restart-grace';
|
|
57
|
+
// `mode`, and the guards the fixed facts of `liveEnterWhy` rule out: a doubt about the channel refuses.
|
|
58
|
+
default: return 'channel-mode';
|
|
59
|
+
}
|
|
60
|
+
}
|
|
61
|
+
/** The first reason Enter is not taken, or `null` when it is. Esc is taken in every case. */
|
|
62
|
+
export function liveEnterWhy(facts) {
|
|
63
|
+
if (!facts.light && facts.level < 2)
|
|
64
|
+
return 'level';
|
|
65
|
+
const { region } = facts;
|
|
66
|
+
if (region.cursors === 0)
|
|
67
|
+
return 'no-cursor';
|
|
68
|
+
if (region.cursors > 1)
|
|
69
|
+
return 'cursors';
|
|
70
|
+
if (region.cursorRow === -1)
|
|
71
|
+
return 'cursor-off-options';
|
|
72
|
+
if (region.scrolled)
|
|
73
|
+
return 'options-scrolled';
|
|
74
|
+
if (!region.numbered || (region.footer === null && !facts.closedSet))
|
|
75
|
+
return 'options-cut';
|
|
76
|
+
// A label row that ends in the cut mark does not show the option whole; a cut operation above the options does
|
|
77
|
+
// not refuse (the region marks it with `hiddenAbove`).
|
|
78
|
+
if (facts.labelRows.some((row) => LABEL_CUT.test(row)))
|
|
79
|
+
return 'options-cut';
|
|
80
|
+
if (hasCardHiddenChar(region.rows.join('\n')) || facts.labelRows.some((row) => hasCardHiddenChar(row))) {
|
|
81
|
+
return 'hidden-char';
|
|
82
|
+
}
|
|
83
|
+
if (facts.freeText)
|
|
84
|
+
return 'free-text';
|
|
85
|
+
if (facts.light)
|
|
86
|
+
return null;
|
|
87
|
+
const { consent } = facts;
|
|
88
|
+
if (consent.mode === 'off' || consent.mode === 'shadow')
|
|
89
|
+
return null;
|
|
90
|
+
// The facts the live card does not have are fixed so that only the channel guards remain.
|
|
91
|
+
const guard = screenFallbackGuard({ ...consent, cliDialog: 'permission', card: true, thread: 'main' });
|
|
92
|
+
if (guard !== null)
|
|
93
|
+
return consentWhy(guard);
|
|
94
|
+
// The emergency button needs `ps` to answer only for a subagent's dialog; Enter on a consent dialog always does.
|
|
95
|
+
if (consent.hookRunning === null)
|
|
96
|
+
return 'hook-process';
|
|
97
|
+
if (!consent.toolUse)
|
|
98
|
+
return 'no-tool-use';
|
|
99
|
+
return null;
|
|
100
|
+
}
|
|
101
|
+
/** The keys the server takes: all four with Enter, Esc alone on a consent dialog below level 2, else Esc and arrows. */
|
|
102
|
+
export function liveKeys(why) {
|
|
103
|
+
if (why === null)
|
|
104
|
+
return [LIVE_ESCAPE_KEY, ...LIVE_NAVIGATION_KEYS, LIVE_ENTER_KEY];
|
|
105
|
+
if (why === 'level')
|
|
106
|
+
return [LIVE_ESCAPE_KEY];
|
|
107
|
+
return [LIVE_ESCAPE_KEY, ...LIVE_NAVIGATION_KEYS];
|
|
108
|
+
}
|