@awebai/oats 0.51.0 → 0.53.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 +3 -1
- package/bin/oats.mjs +407 -123
- package/docs/capabilities.md +75 -6
- package/docs/configuration.md +200 -91
- package/docs/desktop-cli-api.md +1563 -113
- package/docs/desktop-instance-start.md +69 -0
- package/docs/desktop.md +10 -7
- package/docs/execution-targets.md +145 -58
- package/docs/first-team.md +3 -1
- package/docs/harness-trust.md +50 -2
- package/docs/implementation.md +238 -17
- package/docs/integrations.md +13 -9
- package/docs/knowledge-reference/acceptance.md +1 -0
- package/docs/knowledge-reference/harvester.md +5 -3
- package/docs/knowledge-reference/model.md +5 -3
- package/docs/knowledge-theory.md +1 -1
- package/docs/knowledge.md +25 -2
- package/docs/launch-prompt-completion.md +50 -48
- package/docs/macos-test-runs.md +246 -0
- package/docs/oats-local.schema.json +4 -3
- package/docs/official-catalog.md +5 -5
- package/docs/packages.md +14 -14
- package/docs/release-lane.md +225 -11
- package/docs/release-notes/v0.44.0.md +1 -1
- package/docs/release-notes/v0.52.0.md +933 -0
- package/docs/release-notes/v0.53.0.md +1274 -0
- package/docs/schedules.md +97 -4
- package/docs/souls-and-instances.md +332 -40
- package/docs/tui.md +584 -0
- package/docs/upgrading.md +298 -0
- package/docs/workspaces.md +3 -3
- package/lib/automations.mjs +22 -22
- package/lib/claim.mjs +278 -49
- package/lib/config-data.mjs +4 -1
- package/lib/core.mjs +1282 -289
- package/lib/errors.mjs +170 -0
- package/lib/harness-trust-write.mjs +68 -27
- package/lib/harness-trust.mjs +34 -16
- package/lib/instance-events.mjs +19 -1
- package/lib/instance-git.mjs +39 -3
- package/lib/instance-inspect.mjs +45 -17
- package/lib/instance-lifecycle.mjs +306 -57
- package/lib/instance-resolution.mjs +59 -6
- package/lib/launch-preference.mjs +236 -9
- package/lib/launch-prompt-completion.mjs +7 -43
- package/lib/launch-prompt-evidence.mjs +14 -7
- package/lib/launch-prompt-fixtures/README.md +86 -152
- package/lib/launch-prompt-fixtures/dev-channel-confirmation.json +50 -0
- package/lib/launch-prompt-fixtures.mjs +122 -109
- package/lib/launch-prompt-transport.mjs +2 -56
- package/lib/launch-prompts.mjs +102 -100
- package/lib/local-edit.mjs +118 -0
- package/lib/packages.mjs +13 -4
- package/lib/pi-bridge.mjs +308 -0
- package/lib/refused-text.mjs +11 -0
- package/lib/remote.mjs +190 -25
- package/lib/resolve.mjs +2 -1
- package/lib/retained-after-retire.mjs +2 -2
- package/lib/retire-output.mjs +12 -1
- package/lib/schedule-host.mjs +125 -22
- package/lib/schedule.mjs +73 -24
- package/lib/shell-word.mjs +13 -0
- package/lib/soul-launch-verbs.mjs +153 -0
- package/lib/stable-node.mjs +62 -0
- package/lib/system-tools.mjs +39 -0
- package/lib/teams-verbs.mjs +18 -46
- package/lib/tmux-server-scope.mjs +62 -0
- package/lib/triggers.mjs +4 -4
- package/lib/workspace.mjs +54 -30
- package/lib/worktree-hooks.mjs +98 -20
- package/lib/worktree.mjs +83 -24
- package/package-catalog.json +4 -4
- package/package.json +8 -2
- package/packages/client/attach-exit.mjs +25 -0
- package/packages/client/capability-show-contract.mjs +230 -0
- package/packages/client/capability-warnings-contract.mjs +57 -0
- package/packages/client/cli-adapter.mjs +561 -0
- package/packages/client/cli-environment.mjs +53 -0
- package/packages/client/cli-locator.mjs +253 -0
- package/packages/client/cli-probe-contract.mjs +47 -0
- package/packages/client/client-terms.mjs +60 -0
- package/packages/client/deployment-contract.mjs +72 -0
- package/packages/client/deployment-data.mjs +483 -0
- package/packages/client/deployment-facts.mjs +95 -0
- package/packages/client/deployment-label.mjs +76 -0
- package/packages/client/deployment-observer.mjs +89 -0
- package/packages/client/deployment-panel.mjs +180 -0
- package/packages/client/deployment-read-cli.mjs +57 -0
- package/packages/client/display-text.mjs +50 -0
- package/packages/client/harness-names.mjs +30 -0
- package/packages/client/inspect-contract.mjs +62 -0
- package/packages/client/instance-acts.mjs +90 -0
- package/packages/client/instance-admission.mjs +45 -0
- package/packages/client/instance-events-contract.mjs +76 -0
- package/packages/client/instance-git-contract.mjs +80 -0
- package/packages/client/instance-presentation.mjs +86 -0
- package/packages/client/instance-tree.mjs +462 -0
- package/packages/client/kernel-environment.mjs +11 -0
- package/packages/client/kernel-lines.mjs +31 -0
- package/packages/client/kernel-made.mjs +23 -0
- package/packages/client/launch-contract.mjs +51 -0
- package/packages/client/launch-prompt-outcome.mjs +200 -0
- package/packages/client/lifecycle-cli.mjs +61 -0
- package/packages/client/lifecycle-contract.mjs +413 -0
- package/packages/client/liveness-main.mjs +10 -0
- package/packages/client/liveness.mjs +48 -0
- package/packages/client/machine-contract.mjs +123 -0
- package/packages/client/own-codes.mjs +31 -0
- package/packages/client/own-environment.mjs +22 -0
- package/packages/client/panel-views.mjs +293 -0
- package/packages/client/readiness-contract.mjs +174 -0
- package/packages/client/refresh-loop.mjs +52 -0
- package/packages/client/remote-address.mjs +151 -0
- package/packages/client/remote-identity-memory.mjs +94 -0
- package/packages/client/remote-roster.mjs +153 -0
- package/packages/client/roster-sections.mjs +80 -0
- package/packages/client/session-attach.mjs +175 -0
- package/packages/client/spawn-apply-cli.mjs +104 -0
- package/packages/client/spawn-apply-contract.mjs +195 -0
- package/packages/client/spawn-decision.mjs +46 -0
- package/packages/client/spawn-messages.mjs +142 -0
- package/packages/client/spawn-preview-cli.mjs +38 -0
- package/packages/client/spawn-preview-contract.mjs +318 -0
- package/packages/client/team-members.mjs +41 -0
- package/packages/client/team-rows.mjs +45 -0
- package/packages/client/terminal-contract.mjs +57 -0
- package/packages/client/terminal-exec.mjs +21 -0
- package/packages/client/tmux-status.mjs +66 -0
- package/packages/client/waiting-on-you.mjs +88 -0
- package/packages/client/workspace-admission.mjs +45 -0
- package/packages/client/workspace-choices.mjs +95 -0
- package/packages/client/workspace-cli.mjs +142 -0
- package/packages/client/workspace-views.mjs +183 -0
- package/packages/record/README.md +21 -0
- package/packages/record/bin/setup.mjs +108 -15
- package/packages/tui/README.md +64 -0
- package/packages/tui/bin/tui.mjs +7 -0
- package/packages/tui/lib/actions.mjs +44 -0
- package/packages/tui/lib/client.mjs +35 -0
- package/packages/tui/lib/config.mjs +151 -0
- package/packages/tui/lib/main.mjs +176 -0
- package/packages/tui/lib/model.mjs +392 -0
- package/packages/tui/lib/read.mjs +473 -0
- package/packages/tui/lib/store.mjs +364 -0
- package/packages/tui/lib/term/keys.mjs +367 -0
- package/packages/tui/lib/term/screen.mjs +134 -0
- package/packages/tui/lib/term/style.mjs +43 -0
- package/packages/tui/lib/term/text.mjs +109 -0
- package/packages/tui/lib/term/tty.mjs +178 -0
- package/packages/tui/lib/term/width.mjs +124 -0
- package/packages/tui/lib/views/detail.mjs +46 -0
- package/packages/tui/lib/views/frame.mjs +256 -0
- package/packages/tui/lib/views/help.mjs +140 -0
- package/packages/tui/lib/views/instances.mjs +137 -0
- package/packages/tui/lib/views/scroll.mjs +19 -0
- package/packages/tui/lib/views/switcher.mjs +97 -0
- package/packages/tui/package.json +8 -0
- package/skills/oats-getting-started/SKILL.md +30 -23
- package/lib/launch-prompt-fixtures/claude-2.1.289-darwin-arm64/frame-05-channel-seeded.txt +0 -35
- package/lib/launch-prompt-fixtures/claude-2.1.289-darwin-arm64/frame-06-first-after-channel.txt +0 -35
- package/lib/launch-prompt-fixtures/claude-2.1.289-darwin-arm64/frame-07-after-channel-200ms.txt +0 -35
- package/lib/launch-prompt-fixtures/claude-2.1.289-darwin-arm64/frame-08-installed-after-channel-200ms.txt +0 -35
- package/lib/launch-prompt-fixtures/claude-2.1.289-darwin-arm64/manifest.json +0 -77
- package/lib/launch-prompt-fixtures/claude-2.1.289-darwin-arm64/max-bypass-source.json +0 -88
- package/lib/launch-prompt-fixtures/structural-completion.json +0 -205
- package/lib/launch-prompt-policy.mjs +0 -87
|
@@ -0,0 +1,230 @@
|
|
|
1
|
+
/** `oats capabilities show <name> (--member <repoKey> | --package <id>) [--file <path>] --json`
|
|
2
|
+
* (feature `capability-show`, `capabilityShowApi: 1`): what a capability ships — its injected
|
|
3
|
+
* instructions and its skills' files — read at the commit the catalog reports. Shared by the
|
|
4
|
+
* zero-dependency server (it validates before caching) and the capability page's Contents reader.
|
|
5
|
+
*
|
|
6
|
+
* The decoder is strict and bounded: an unknown API version, a field of the wrong type, an
|
|
7
|
+
* oversize string or list, or a path that is not a plain relative POSIX path inside the
|
|
8
|
+
* capability refuses the WHOLE answer (null), never a partial render. Presentation-only: nothing
|
|
9
|
+
* here infers a file the kernel did not list. The tolerant fields: `warnings` (OATS 0.49.0), projected by
|
|
10
|
+
* capability-warnings-contract.mjs, and `triggerSources` / `triggerSourceProblems` (feature `trigger-sources`),
|
|
11
|
+
* projected below: never a reason to refuse the answer (an older kernel sends none). */
|
|
12
|
+
import { warningsOf } from './capability-warnings-contract.mjs';
|
|
13
|
+
import { requireTerms } from './client-terms.mjs';
|
|
14
|
+
|
|
15
|
+
export const CAPABILITY_SHOW_API = 1;
|
|
16
|
+
export const CAPABILITY_SHOW_FEATURE = 'capability-show';
|
|
17
|
+
/** What a kernel answer the client cannot read says (the failed state's message), in the client's terms
|
|
18
|
+
* (client-terms.mjs): here the client is the old one, so the sentence names what to update. */
|
|
19
|
+
export function capabilityShowUnreadable(terms) {
|
|
20
|
+
requireTerms(terms, 'capabilityShowUnreadable');
|
|
21
|
+
return `${terms.selfInitial} can't read what this OATS version reports about the capability. Update ${terms.update}.`;
|
|
22
|
+
}
|
|
23
|
+
|
|
24
|
+
/** Bounds. A file's text is at most 256 KiB (the kernel truncates there, `truncated: true`). */
|
|
25
|
+
export const FILE_TEXT_MAX_BYTES = 256 * 1024;
|
|
26
|
+
export const LIMITS = Object.freeze({ path: 1024, skills: 256, files: 200, description: 1024, problems: 64, message: 4096, code: 128, name: 128,
|
|
27
|
+
sources: 16, events: 16, event: 64 });
|
|
28
|
+
|
|
29
|
+
const record = v => !!v && typeof v === 'object' && !Array.isArray(v);
|
|
30
|
+
const CONTROL = /[\u0000-\u001f\u007f]/;
|
|
31
|
+
const CAPABILITY_NAME = /^[A-Za-z0-9][A-Za-z0-9._-]{0,127}$/;
|
|
32
|
+
const PACKAGE_ID = /^[a-z0-9][a-z0-9._-]{0,127}$/; // the kernel's package-id grammar, bounded
|
|
33
|
+
const CODE = /^[A-Za-z][A-Za-z0-9_.-]{0,127}$/;
|
|
34
|
+
const COMMIT = /^[0-9a-f]{40}$/;
|
|
35
|
+
|
|
36
|
+
export const validCapabilityName = v => typeof v === 'string' && CAPABILITY_NAME.test(v);
|
|
37
|
+
export const validPackageId = v => typeof v === 'string' && PACKAGE_ID.test(v);
|
|
38
|
+
/** A repository key is the kernel's to parse; the Desktop refuses only what could not be one argv value. */
|
|
39
|
+
export const validRepoKey = v => typeof v === 'string' && v.length > 0 && v.length <= LIMITS.path && v.trim() === v && !CONTROL.test(v) && !v.startsWith('-');
|
|
40
|
+
/** A plain relative POSIX path inside the capability: no leading `/`, no `.`/`..`/empty segment,
|
|
41
|
+
* no backslash, no control character, not option-looking, bounded. */
|
|
42
|
+
export function validRelativePath(v) {
|
|
43
|
+
if (typeof v !== 'string' || !v || v.length > LIMITS.path || CONTROL.test(v) || v.includes('\\') || v.startsWith('-') || v.startsWith('/')) return false;
|
|
44
|
+
return v.split('/').every(part => part !== '' && part !== '.' && part !== '..');
|
|
45
|
+
}
|
|
46
|
+
|
|
47
|
+
/** The connected CLI can answer `capabilities show` (the feature AND the API integer; never a version number). */
|
|
48
|
+
export const capabilityShowSupported = cli => cli?.ok === true && Array.isArray(cli.features) && cli.features.includes(CAPABILITY_SHOW_FEATURE)
|
|
49
|
+
&& cli.capabilityShowApi === CAPABILITY_SHOW_API;
|
|
50
|
+
|
|
51
|
+
/** The verb's selector for a catalog row: { name, kind: 'member', repoKey } | { name, kind: 'package', package };
|
|
52
|
+
* null for a row the verb cannot address (an external capability, a malformed row). */
|
|
53
|
+
export function capabilitySelector(row) {
|
|
54
|
+
if (!record(row) || !validCapabilityName(row.name)) return null;
|
|
55
|
+
if (row.kind === 'member' && validRepoKey(row.repoKey)) return { name: row.name, kind: 'member', repoKey: row.repoKey };
|
|
56
|
+
if (row.kind === 'package' && validPackageId(row.package)) return { name: row.name, kind: 'package', package: row.package };
|
|
57
|
+
return null;
|
|
58
|
+
}
|
|
59
|
+
/** The same selector, validated as a request body field (the server's half: exact keys only). */
|
|
60
|
+
export function selectorOf(v) {
|
|
61
|
+
if (!record(v)) return null;
|
|
62
|
+
const keys = Object.keys(v).sort().join(',');
|
|
63
|
+
if (v.kind === 'member' && keys === 'kind,name,repoKey') return capabilitySelector(v);
|
|
64
|
+
if (v.kind === 'package' && keys === 'kind,name,package') return capabilitySelector(v);
|
|
65
|
+
return null;
|
|
66
|
+
}
|
|
67
|
+
export const sameSelector = (a, b) => !!a && !!b && a.name === b.name && a.kind === b.kind && (a.kind === 'member' ? a.repoKey === b.repoKey : a.package === b.package);
|
|
68
|
+
|
|
69
|
+
/* ── the decoder ─────────────────────────────────────────────────────────── */
|
|
70
|
+
class Unreadable extends Error {}
|
|
71
|
+
const refuse = () => { throw new Unreadable(); };
|
|
72
|
+
const byteLength = s => new TextEncoder().encode(s).byteLength;
|
|
73
|
+
function str(v, max) { if (typeof v !== 'string' || v.length > max) refuse(); return v; }
|
|
74
|
+
function nullableStr(v, max) { return v === null ? null : str(v, max); }
|
|
75
|
+
function path(v) { if (!validRelativePath(v)) refuse(); return v; }
|
|
76
|
+
function bytes(v) { if (v === null) return null; if (!Number.isSafeInteger(v) || v < 0) refuse(); return v; }
|
|
77
|
+
function bool(v) { if (typeof v !== 'boolean') refuse(); return v; }
|
|
78
|
+
|
|
79
|
+
/** File = { path, bytes: number|null, text: string|null, binary, truncated }, the kernel's invariants: text is at
|
|
80
|
+
* most 256 KiB of UTF-8 (truncated or not); a binary file has no text and is never truncated; a truncated one has
|
|
81
|
+
* text. `text: null` on a text file (and `bytes: null`) happens only for an unreadable declared inject, which a
|
|
82
|
+
* problem names: never in a `--file` answer (`fileAnswer`). An inject's `path` is null when the manifest's value
|
|
83
|
+
* is not a safe relative path (a problem with `path: null` carries the raw value); then it has no content. */
|
|
84
|
+
function file(v, { fileAnswer = false, inject = false } = {}) {
|
|
85
|
+
if (!record(v)) refuse();
|
|
86
|
+
const out = { path: inject && v.path === null ? null : path(v.path), bytes: bytes(v.bytes), text: nullableStr(v.text, FILE_TEXT_MAX_BYTES), binary: bool(v.binary), truncated: bool(v.truncated) };
|
|
87
|
+
if (out.text !== null && byteLength(out.text) > FILE_TEXT_MAX_BYTES) refuse();
|
|
88
|
+
if (out.binary && (out.text !== null || out.truncated)) refuse();
|
|
89
|
+
if (out.truncated && out.text === null) refuse();
|
|
90
|
+
if (fileAnswer && (out.bytes === null || (!out.binary && out.text === null))) refuse();
|
|
91
|
+
if (out.path === null && (out.text !== null || out.binary || out.bytes !== null)) refuse();
|
|
92
|
+
return out;
|
|
93
|
+
}
|
|
94
|
+
/** A skill's `files` is null when its directory could not be listed (a problem names the skill's path; never
|
|
95
|
+
* truncated then); a listed skill always has at least its SKILL.md. */
|
|
96
|
+
function skill(v) {
|
|
97
|
+
if (!record(v)) refuse();
|
|
98
|
+
const files = v.files === null ? null : Array.isArray(v.files) && v.files.length > 0 && v.files.length <= LIMITS.files ? v.files : refuse();
|
|
99
|
+
const description = nullableStr(v.description ?? null, 4 * LIMITS.description);
|
|
100
|
+
if (description !== null && byteLength(description) > LIMITS.description) refuse();
|
|
101
|
+
const out = { name: str(v.name, LIMITS.name), path: path(v.path), description,
|
|
102
|
+
files: files && files.map(f => { if (!record(f)) refuse(); return { path: path(f.path), bytes: bytes(f.bytes) }; }), filesTruncated: bool(v.filesTruncated) };
|
|
103
|
+
if (!out.name || CONTROL.test(out.name)) refuse();
|
|
104
|
+
if (out.files === null) { if (out.filesTruncated) refuse(); return out; }
|
|
105
|
+
// Every path is relative to the capability directory: a skill's files sit under its own directory.
|
|
106
|
+
if (out.files.some(f => !f.path.startsWith(`${out.path}/`))) refuse();
|
|
107
|
+
if (new Set(out.files.map(f => f.path)).size !== out.files.length) refuse();
|
|
108
|
+
return out;
|
|
109
|
+
}
|
|
110
|
+
function problem(v) {
|
|
111
|
+
if (!record(v)) refuse();
|
|
112
|
+
const code = str(v.code, LIMITS.code);
|
|
113
|
+
if (!CODE.test(code)) refuse();
|
|
114
|
+
return { code, message: str(v.message, LIMITS.message), path: v.path === null || v.path === undefined ? null : path(v.path) };
|
|
115
|
+
}
|
|
116
|
+
function head(v, name) {
|
|
117
|
+
if (!record(v) || v.capabilityShowApi !== CAPABILITY_SHOW_API) refuse();
|
|
118
|
+
if (!validCapabilityName(v.name) || (name !== undefined && v.name !== name)) refuse();
|
|
119
|
+
if (!['member', 'package'].includes(v.kind)) refuse();
|
|
120
|
+
if (typeof v.commit !== 'string' || !COMMIT.test(v.commit)) refuse();
|
|
121
|
+
}
|
|
122
|
+
|
|
123
|
+
/* ── trigger sources (feature `trigger-sources`) ─────────────────────────── */
|
|
124
|
+
/** A string held to `max` UTF-16 units, cut there (never inside a surrogate pair): cutting twice equals cutting once. */
|
|
125
|
+
function cut(s, max) {
|
|
126
|
+
if (s.length <= max) return s;
|
|
127
|
+
const last = s.charCodeAt(max - 1);
|
|
128
|
+
return s.slice(0, last >= 0xD800 && last <= 0xDBFF ? max - 1 : max);
|
|
129
|
+
}
|
|
130
|
+
/** One declared source as far as the page shows it: { events, description? }, or null when the value is not that
|
|
131
|
+
* shape. `command`, `parameters`, `fields` and `urlHosts` are not shown, so they are not relayed. */
|
|
132
|
+
function triggerSourceOf(v) {
|
|
133
|
+
if (!record(v) || !Array.isArray(v.events)) return null;
|
|
134
|
+
const events = v.events.filter(e => typeof e === 'string').slice(0, LIMITS.events).map(e => cut(e, LIMITS.event));
|
|
135
|
+
return { events, ...(typeof v.description === 'string' ? { description: cut(v.description, LIMITS.description) } : {}) };
|
|
136
|
+
}
|
|
137
|
+
/** The manifest's `triggerSources`, which the kernel answers exactly as written, whatever its shape: null when it
|
|
138
|
+
* is not an object (declared, not readable; the raw value is not relayed), else its first LIMITS.sources entries in
|
|
139
|
+
* the kernel's order, each name bounded and each value a `triggerSourceOf`. Every string is the manifest's:
|
|
140
|
+
* untrusted, shown only as quoted text (packages/desktop/renderer/source-quote.mjs). Built from entries, never by assignment: a manifest key
|
|
141
|
+
* may be `__proto__`. Tolerant, bounded and idempotent, like `warningsOf`. */
|
|
142
|
+
export function triggerSourcesOf(v) {
|
|
143
|
+
if (!record(v)) return null;
|
|
144
|
+
return Object.fromEntries(Object.entries(v).slice(0, LIMITS.sources).map(([name, value]) => [cut(name, LIMITS.name), triggerSourceOf(value)]));
|
|
145
|
+
}
|
|
146
|
+
/** `triggerSourceProblems`: [{ source, pointer, message }], the kernel's text (what a trigger naming the source
|
|
147
|
+
* gets as E_TRIGGER_SOURCE). `source: null` is a top-level problem; `pointer` a JSON pointer into the manifest.
|
|
148
|
+
* An entry that is not an object or has no message is skipped; at most LIMITS.problems are kept. They are never
|
|
149
|
+
* `problems`: a malformed declaration does not fail the capability. */
|
|
150
|
+
export function triggerSourceProblemsOf(v) {
|
|
151
|
+
const out = [];
|
|
152
|
+
for (const entry of Array.isArray(v) ? v : []) {
|
|
153
|
+
if (!record(entry) || typeof entry.message !== 'string') continue;
|
|
154
|
+
out.push({ source: typeof entry.source === 'string' ? cut(entry.source, LIMITS.name) : null,
|
|
155
|
+
pointer: typeof entry.pointer === 'string' ? cut(entry.pointer, LIMITS.path) : null, message: cut(entry.message, LIMITS.message) });
|
|
156
|
+
if (out.length === LIMITS.problems) break;
|
|
157
|
+
}
|
|
158
|
+
return out;
|
|
159
|
+
}
|
|
160
|
+
/** What the capability page says about the declaration, from a projected answer (presentation-free):
|
|
161
|
+
* null — the manifest declares none (or an older kernel answered);
|
|
162
|
+
* { unreadable: [the kernel's messages] } — it is not an object, or a top-level problem (`source: null`) disables
|
|
163
|
+
* every source; the messages may be none;
|
|
164
|
+
* { sources: [{ name, events: [..] | null, description: string | null, problems: [the kernel's messages] }] } —
|
|
165
|
+
* the listed sources in the kernel's order, then every source a problem names that the listing does not hold,
|
|
166
|
+
* at most LIMITS.sources. A source with a problem, or with `events: null` (its value is not a source's shape),
|
|
167
|
+
* is declared but not usable. */
|
|
168
|
+
export function triggerSourcesView(show) {
|
|
169
|
+
if (!record(show) || !Object.hasOwn(show, 'triggerSources')) return null;
|
|
170
|
+
const declared = show.triggerSources, problems = Array.isArray(show.triggerSourceProblems) ? show.triggerSourceProblems.filter(record) : [];
|
|
171
|
+
const top = problems.filter(p => p.source === null);
|
|
172
|
+
if (!record(declared) || top.length) return { unreadable: (record(declared) ? top : problems).map(p => p.message) };
|
|
173
|
+
const sources = Object.entries(declared).map(([name, value]) => ({ name, events: Array.isArray(value?.events) ? value.events : null,
|
|
174
|
+
description: typeof value?.description === 'string' ? value.description : null, problems: [] }));
|
|
175
|
+
const named = new Map(sources.map(source => [source.name, source]));
|
|
176
|
+
for (const p of problems) {
|
|
177
|
+
if (!named.has(p.source)) { const source = { name: p.source, events: null, description: null, problems: [] }; named.set(p.source, source); sources.push(source); }
|
|
178
|
+
named.get(p.source).problems.push(p.message);
|
|
179
|
+
}
|
|
180
|
+
return { sources: sources.slice(0, LIMITS.sources) };
|
|
181
|
+
}
|
|
182
|
+
|
|
183
|
+
/** The show answer, normalized, or null when this Desktop cannot read it. `name` / `selector`: the capability
|
|
184
|
+
* asked for (an answer about another capability, or the same name from another member or package, is refused). Every path — the inject's, a skill's, a skill file's — is
|
|
185
|
+
* relative to the capability directory: what `--file` takes, verbatim. */
|
|
186
|
+
export function capabilityShowData(v, { selector, name = selector?.name } = {}) {
|
|
187
|
+
try {
|
|
188
|
+
head(v, name);
|
|
189
|
+
if (v.kind === 'member' ? !validRepoKey(v.repoKey) : !(validPackageId(v.package) && (v.repoKey === null || v.repoKey === undefined || validRepoKey(v.repoKey)))) refuse();
|
|
190
|
+
if (selector && (v.kind !== selector.kind || (v.kind === 'member' ? v.repoKey !== selector.repoKey : v.package !== selector.package))) refuse();
|
|
191
|
+
const skills = v.skills === null ? null : Array.isArray(v.skills) && v.skills.length <= LIMITS.skills ? v.skills.map(skill) : refuse();
|
|
192
|
+
if (skills && new Set(skills.map(s => s.path)).size !== skills.length) refuse();
|
|
193
|
+
const problems = Array.isArray(v.problems) && v.problems.length <= LIMITS.problems ? v.problems.map(problem) : refuse();
|
|
194
|
+
return {
|
|
195
|
+
capabilityShowApi: CAPABILITY_SHOW_API, name: v.name, kind: v.kind, repoKey: v.repoKey ?? null,
|
|
196
|
+
package: v.kind === 'package' ? v.package : null, version: v.version === null || v.version === undefined ? null : str(v.version, 64),
|
|
197
|
+
commit: v.commit, path: v.path === null || v.path === undefined ? null : str(v.path, LIMITS.path),
|
|
198
|
+
inject: v.inject === null ? null : file(v.inject, { inject: true }), skills, problems,
|
|
199
|
+
// Tolerant and idempotent: the server's projection, relayed, projects to itself in the renderer.
|
|
200
|
+
warnings: warningsOf(v.warnings),
|
|
201
|
+
// Only when the kernel answers them (feature `trigger-sources`: the manifest declares the key; the problems
|
|
202
|
+
// follow only when it has some), so an older kernel's answer projects as before. Never `problems`.
|
|
203
|
+
...(Object.hasOwn(v, 'triggerSources') ? { triggerSources: triggerSourcesOf(v.triggerSources) } : {}),
|
|
204
|
+
...(Array.isArray(v.triggerSourceProblems) ? { triggerSourceProblems: triggerSourceProblemsOf(v.triggerSourceProblems) } : {}),
|
|
205
|
+
};
|
|
206
|
+
} catch (error) { if (error instanceof Unreadable) return null; throw error; }
|
|
207
|
+
}
|
|
208
|
+
/** The `--file` answer, normalized, or null when unreadable or not about `name` / `path`. */
|
|
209
|
+
export function capabilityFileData(v, { selector, name = selector?.name, path: asked } = {}) {
|
|
210
|
+
try {
|
|
211
|
+
head(v, name);
|
|
212
|
+
if (selector && v.kind !== selector.kind) refuse();
|
|
213
|
+
const out = { capabilityShowApi: CAPABILITY_SHOW_API, name: v.name, kind: v.kind, commit: v.commit, file: file(v.file, { fileAnswer: true }) };
|
|
214
|
+
if (asked !== undefined && out.file.path !== asked) refuse();
|
|
215
|
+
return out;
|
|
216
|
+
} catch (error) { if (error instanceof Unreadable) return null; throw error; }
|
|
217
|
+
}
|
|
218
|
+
|
|
219
|
+
/** A skill file's path relative to the capability root (what `--file` takes): the kernel's, verbatim. */
|
|
220
|
+
export const skillFilePath = (skill, file) => file.path;
|
|
221
|
+
/** The same path relative to its skill's directory (what the navigation shows). */
|
|
222
|
+
export const skillRelativePath = (skill, file) => file.path.slice(skill.path.length + 1);
|
|
223
|
+
/** Every file the answer lists, by its path relative to the capability root (what `--file` may be asked for):
|
|
224
|
+
* the inject (when its path is safe), then each listed skill's files. */
|
|
225
|
+
export function listedFiles(show) {
|
|
226
|
+
const out = new Map();
|
|
227
|
+
if (show?.inject?.path) out.set(show.inject.path, { kind: 'inject', file: show.inject });
|
|
228
|
+
for (const skill of show?.skills || []) for (const f of skill.files || []) out.set(skillFilePath(skill, f), { kind: 'skill', skill, file: f });
|
|
229
|
+
return out;
|
|
230
|
+
}
|
|
@@ -0,0 +1,57 @@
|
|
|
1
|
+
/** Capability warnings (OATS 0.49.0, `hook-event-unsupported`; docs/desktop-cli-api.md § "Capability
|
|
2
|
+
* warnings"): `{code, capability, path, message}` in `capabilities show`, `inspect` and `readiness`, and
|
|
3
|
+
* the message strings of `spawn --preview`. A warning means "this capability composes, and one declared
|
|
4
|
+
* hook never runs here": it is not an error, it blocks nothing and it never changes a ready state.
|
|
5
|
+
*
|
|
6
|
+
* The projections are tolerant: a missing or malformed `warnings` reads as none and a malformed entry is
|
|
7
|
+
* skipped, never refusing the document around it (an older kernel answers no `warnings` key). Every
|
|
8
|
+
* string is already a display line (display-text.mjs), so projecting twice equals projecting once: the
|
|
9
|
+
* server projects before it relays and the renderer projects the relayed answer again. Pure, no DOM: the
|
|
10
|
+
* server imports it. The list's presentation is packages/desktop/renderer/capability-warnings.mjs. */
|
|
11
|
+
import { displayLine } from './display-text.mjs';
|
|
12
|
+
|
|
13
|
+
/** Warnings shown per surface; the rest are counted ("and N more"). */
|
|
14
|
+
export const WARNINGS_SHOWN = 32;
|
|
15
|
+
/** Entries a projection keeps (a bound on what is relayed, far above what is shown). */
|
|
16
|
+
export const WARNINGS_KEPT = 1000;
|
|
17
|
+
/** Lines one preview warning may hold (the kernel's own bound). */
|
|
18
|
+
export const WARNING_LINES = 32;
|
|
19
|
+
|
|
20
|
+
const record = v => !!v && typeof v === 'object' && !Array.isArray(v);
|
|
21
|
+
/** The kernel's capability-name grammar: only such a name is ever looked up (Open capability). */
|
|
22
|
+
const CAPABILITY_NAME = /^[A-Za-z0-9][A-Za-z0-9._-]{0,127}$/;
|
|
23
|
+
|
|
24
|
+
/** One warning, or null when it cannot be shown (not an object, no message). `capability` is kept only when it
|
|
25
|
+
* is a capability name (the kernel always sends one): it is both shown and looked up (Open capability). */
|
|
26
|
+
export function warningOf(v) {
|
|
27
|
+
if (!record(v)) return null;
|
|
28
|
+
const message = displayLine(v.message);
|
|
29
|
+
if (!message) return null;
|
|
30
|
+
const capability = typeof v.capability === 'string' && CAPABILITY_NAME.test(v.capability) ? v.capability : null;
|
|
31
|
+
return { code: displayLine(v.code), capability, path: displayLine(v.path), message };
|
|
32
|
+
}
|
|
33
|
+
/** A document's `warnings`: the showable entries, in the kernel's order ([] when absent or not a list). */
|
|
34
|
+
export function warningsOf(v) {
|
|
35
|
+
if (!Array.isArray(v)) return [];
|
|
36
|
+
const out = [];
|
|
37
|
+
for (const entry of v) { const w = warningOf(entry); if (w) out.push(w); if (out.length === WARNINGS_KEPT) break; }
|
|
38
|
+
return out;
|
|
39
|
+
}
|
|
40
|
+
/** The preview's warning strings, each its lines as display lines joined by "\n" (a warning may hold several
|
|
41
|
+
* lines, at most WARNING_LINES); a string with nothing to show is dropped. */
|
|
42
|
+
export function previewWarningsOf(v) {
|
|
43
|
+
if (!Array.isArray(v)) return [];
|
|
44
|
+
const out = [];
|
|
45
|
+
for (const entry of v) {
|
|
46
|
+
if (typeof entry !== 'string') continue;
|
|
47
|
+
const lines = entry.split(/\r\n|\r|\n/).map(displayLine).filter(Boolean).slice(0, WARNING_LINES);
|
|
48
|
+
if (lines.length) out.push(lines.join('\n'));
|
|
49
|
+
if (out.length === WARNINGS_KEPT) break;
|
|
50
|
+
}
|
|
51
|
+
return out;
|
|
52
|
+
}
|
|
53
|
+
/** What a surface shows: the first WARNINGS_SHOWN and how many more. */
|
|
54
|
+
export function warningsShown(list) {
|
|
55
|
+
const all = Array.isArray(list) ? list : [];
|
|
56
|
+
return { shown: all.slice(0, WARNINGS_SHOWN), more: Math.max(0, all.length - WARNINGS_SHOWN) };
|
|
57
|
+
}
|