@inventarch/cli 0.0.0-stage → 1.0.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/LICENSE +202 -0
- package/NOTICE +4 -0
- package/README.md +19 -2
- package/SPEC.md +30 -0
- package/assets/base/71f0665cb1ffc3f3964fc7710528451f635d664bdf4b8c95005ee97c21db5928.ia.tgz +0 -0
- package/assets/base.json +6 -0
- package/assets/host/43a1f8c471141b1f2f46cef4411a9a61c00da1c1aa19d277189ae2423282bfd6.tgz +0 -0
- package/assets/host.json +6 -0
- package/assets/vocabulary.json +3268 -0
- package/dist/args.d.ts +62 -0
- package/dist/args.d.ts.map +1 -0
- package/dist/args.js +117 -0
- package/dist/args.js.map +1 -0
- package/dist/briefing.d.ts +76 -0
- package/dist/briefing.d.ts.map +1 -0
- package/dist/briefing.js +105 -0
- package/dist/briefing.js.map +1 -0
- package/dist/channel.d.ts +22 -0
- package/dist/channel.d.ts.map +1 -0
- package/dist/channel.js +74 -0
- package/dist/channel.js.map +1 -0
- package/dist/claude-cli.d.ts +35 -0
- package/dist/claude-cli.d.ts.map +1 -0
- package/dist/claude-cli.js +101 -0
- package/dist/claude-cli.js.map +1 -0
- package/dist/commands.d.ts +39 -0
- package/dist/commands.d.ts.map +1 -0
- package/dist/commands.js +436 -0
- package/dist/commands.js.map +1 -0
- package/dist/compile.d.ts +39 -0
- package/dist/compile.d.ts.map +1 -0
- package/dist/compile.js +136 -0
- package/dist/compile.js.map +1 -0
- package/dist/consumer.d.ts +137 -0
- package/dist/consumer.d.ts.map +1 -0
- package/dist/consumer.js +366 -0
- package/dist/consumer.js.map +1 -0
- package/dist/decline.d.ts +7 -0
- package/dist/decline.d.ts.map +1 -0
- package/dist/decline.js +78 -0
- package/dist/decline.js.map +1 -0
- package/dist/distribute.d.ts +163 -0
- package/dist/distribute.d.ts.map +1 -0
- package/dist/distribute.js +664 -0
- package/dist/distribute.js.map +1 -0
- package/dist/doctor-user.d.ts +45 -0
- package/dist/doctor-user.d.ts.map +1 -0
- package/dist/doctor-user.js +193 -0
- package/dist/doctor-user.js.map +1 -0
- package/dist/doctor.d.ts +57 -0
- package/dist/doctor.d.ts.map +1 -0
- package/dist/doctor.js +754 -0
- package/dist/doctor.js.map +1 -0
- package/dist/format.d.ts +25 -0
- package/dist/format.d.ts.map +1 -0
- package/dist/format.js +168 -0
- package/dist/format.js.map +1 -0
- package/dist/home-remedy.d.ts +10 -0
- package/dist/home-remedy.d.ts.map +1 -0
- package/dist/home-remedy.js +26 -0
- package/dist/home-remedy.js.map +1 -0
- package/dist/host-projection.d.ts +11 -0
- package/dist/host-projection.d.ts.map +1 -0
- package/dist/host-projection.js +73 -0
- package/dist/host-projection.js.map +1 -0
- package/dist/host.d.ts +162 -0
- package/dist/host.d.ts.map +1 -0
- package/dist/host.js +599 -0
- package/dist/host.js.map +1 -0
- package/dist/init.d.ts +217 -0
- package/dist/init.d.ts.map +1 -0
- package/dist/init.js +840 -0
- package/dist/init.js.map +1 -0
- package/dist/inspect.d.ts +32 -0
- package/dist/inspect.d.ts.map +1 -0
- package/dist/inspect.js +226 -0
- package/dist/inspect.js.map +1 -0
- package/dist/main.d.ts +24 -0
- package/dist/main.d.ts.map +1 -0
- package/dist/main.js +215 -0
- package/dist/main.js.map +1 -0
- package/dist/operation-help.d.ts +14 -0
- package/dist/operation-help.d.ts.map +1 -0
- package/dist/operation-help.js +75 -0
- package/dist/operation-help.js.map +1 -0
- package/dist/pack.d.ts +17 -0
- package/dist/pack.d.ts.map +1 -0
- package/dist/pack.js +121 -0
- package/dist/pack.js.map +1 -0
- package/dist/render.d.ts +165 -0
- package/dist/render.d.ts.map +1 -0
- package/dist/render.js +277 -0
- package/dist/render.js.map +1 -0
- package/dist/session.d.ts +13 -0
- package/dist/session.d.ts.map +1 -0
- package/dist/session.js +25 -0
- package/dist/session.js.map +1 -0
- package/dist/user-host.d.ts +59 -0
- package/dist/user-host.d.ts.map +1 -0
- package/dist/user-host.js +228 -0
- package/dist/user-host.js.map +1 -0
- package/dist/validate.d.ts +53 -0
- package/dist/validate.d.ts.map +1 -0
- package/dist/validate.js +220 -0
- package/dist/validate.js.map +1 -0
- package/dist/vocabulary.d.ts +55 -0
- package/dist/vocabulary.d.ts.map +1 -0
- package/dist/vocabulary.js +179 -0
- package/dist/vocabulary.js.map +1 -0
- package/package.json +153 -3
package/dist/consumer.js
ADDED
|
@@ -0,0 +1,366 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* The consumer shell: docs/specs/consumer-cli-contract/README.md §§1.2, 3, 4, 5 and 6.
|
|
3
|
+
*
|
|
4
|
+
* Everything here is pure with respect to the process. The host — argv, environment, cwd, both stream
|
|
5
|
+
* descriptions and the package version — arrives as a parameter and the result is returned as text, so a test
|
|
6
|
+
* observes exactly the bytes the entry point writes and §5's `--json` invariant is checkable without a
|
|
7
|
+
* subprocess. Progress is not produced by any verb in this release; §6.6 permits its absence and requires the
|
|
8
|
+
* terminal state line, which every verb prints as text.
|
|
9
|
+
*/
|
|
10
|
+
import { existsSync, realpathSync, statSync } from 'node:fs';
|
|
11
|
+
import { homedir } from 'node:os';
|
|
12
|
+
import { dirname, isAbsolute, resolve } from 'node:path';
|
|
13
|
+
import { sameFile } from '@inventarch/db';
|
|
14
|
+
import { resolveIaHome } from '@inventarch/distribution/ia-home';
|
|
15
|
+
import { parseArguments, UsageError } from './args.js';
|
|
16
|
+
import { COMMANDS, COMMON_OPTIONS, CORE_TOKENS, findCommand, LEGACY_OPERATIONS, nearestTokens, RESERVED_TOKEN, } from './commands.js';
|
|
17
|
+
import { runCompile } from './compile.js';
|
|
18
|
+
import { runDistribute } from './distribute.js';
|
|
19
|
+
import { runDoctor } from './doctor.js';
|
|
20
|
+
import { runFormat } from './format.js';
|
|
21
|
+
import { runHost } from './host.js';
|
|
22
|
+
import { runInit } from './init.js';
|
|
23
|
+
import { runInspect } from './inspect.js';
|
|
24
|
+
import { runPack } from './pack.js';
|
|
25
|
+
import { runValidate } from './validate.js';
|
|
26
|
+
import { runVocabulary } from './vocabulary.js';
|
|
27
|
+
import { atom, document, entry, errorBlock, fieldRows, resolveCapabilities, sectionLabel, words } from './render.js';
|
|
28
|
+
/** §2.8 rule 3: `y` or `yes`, in any case and ignoring surrounding space. Everything else, EOF included, declines. */
|
|
29
|
+
export const consents = (answer) => answer !== null && ['y', 'yes'].includes(answer.trim().toLowerCase());
|
|
30
|
+
/**
|
|
31
|
+
* Shows the change summary, asks once, and reports the answer. What a declined answer means belongs to the caller:
|
|
32
|
+
* §2.8 rule 3 makes declining an answer to the question, not a failure of the command.
|
|
33
|
+
*/
|
|
34
|
+
export async function confirm(interaction, summary, question) {
|
|
35
|
+
interaction.write(summary);
|
|
36
|
+
interaction.write(question);
|
|
37
|
+
return consents(await interaction.read());
|
|
38
|
+
}
|
|
39
|
+
/** §4: a refusal carries the service's own code unchanged, its exit class, and where it happened. */
|
|
40
|
+
export class Refusal extends Error {
|
|
41
|
+
code;
|
|
42
|
+
exit;
|
|
43
|
+
where;
|
|
44
|
+
next;
|
|
45
|
+
at;
|
|
46
|
+
constructor(code, message, exit, where = null, next = null,
|
|
47
|
+
/** §6.5 element 1 when there is no `where`: the invocation that was refused, rendered but never serialized. */
|
|
48
|
+
at = null) {
|
|
49
|
+
super(message);
|
|
50
|
+
this.code = code;
|
|
51
|
+
this.exit = exit;
|
|
52
|
+
this.where = where;
|
|
53
|
+
this.next = next;
|
|
54
|
+
this.at = at;
|
|
55
|
+
this.name = 'Refusal';
|
|
56
|
+
}
|
|
57
|
+
}
|
|
58
|
+
/**
|
|
59
|
+
* §5's first signal, raised by a verb that had already written when it observed the signal. The JSON result stays
|
|
60
|
+
* §5's fixed object; the one stderr line gains the rerun that finishes the work, which M5.2 §5 requires `ia init`
|
|
61
|
+
* to name once it has written anything.
|
|
62
|
+
*/
|
|
63
|
+
export class Interrupted extends Error {
|
|
64
|
+
next;
|
|
65
|
+
constructor(next) {
|
|
66
|
+
super('Interrupted.');
|
|
67
|
+
this.next = next;
|
|
68
|
+
this.name = 'Interrupted';
|
|
69
|
+
}
|
|
70
|
+
}
|
|
71
|
+
const IA_CODE = /^IA-[A-Z]+-[A-Z-]+$/;
|
|
72
|
+
const codeOf = (error) => {
|
|
73
|
+
if (error === null || typeof error !== 'object' || !('code' in error))
|
|
74
|
+
return undefined;
|
|
75
|
+
const code = error.code;
|
|
76
|
+
return typeof code === 'string' && IA_CODE.test(code) ? code : undefined;
|
|
77
|
+
};
|
|
78
|
+
/**
|
|
79
|
+
* §4.1: the consumer never rewrites a service's code. Class 4 is unreachable from the three verbs this release
|
|
80
|
+
* implements, because none of them acquires anything over a network, so every unmapped failure is class 3.
|
|
81
|
+
*/
|
|
82
|
+
export function refusalOf(error) {
|
|
83
|
+
if (error instanceof Refusal)
|
|
84
|
+
return error;
|
|
85
|
+
const message = error instanceof Error ? error.message : String(error);
|
|
86
|
+
if (error instanceof UsageError)
|
|
87
|
+
return new Refusal('IA-CLI-USAGE', message, 2);
|
|
88
|
+
const code = codeOf(error);
|
|
89
|
+
return code === undefined ? new Refusal('IA-CLI-FAILED', message, 3) : new Refusal(code, message, 3);
|
|
90
|
+
}
|
|
91
|
+
/** §4.3 and §6.5. Human mode renders the block on stderr; `--json` emits the one object on stdout. */
|
|
92
|
+
export function renderRefusal(refusal, caps, json) {
|
|
93
|
+
const located = refusal.where?.path === undefined || refusal.where.path === ''
|
|
94
|
+
? null
|
|
95
|
+
: refusal.where.line === undefined
|
|
96
|
+
? refusal.where.path
|
|
97
|
+
: `${refusal.where.path}:${refusal.where.line}`;
|
|
98
|
+
const location = located ?? refusal.at;
|
|
99
|
+
if (json) {
|
|
100
|
+
const body = {
|
|
101
|
+
version: 1,
|
|
102
|
+
ok: false,
|
|
103
|
+
code: refusal.code,
|
|
104
|
+
message: stripFor(refusal.message, refusal.code, located, refusal.where?.identity ?? null),
|
|
105
|
+
exit: refusal.exit,
|
|
106
|
+
where: refusal.where === null
|
|
107
|
+
? null
|
|
108
|
+
: {
|
|
109
|
+
path: refusal.where.path ?? null,
|
|
110
|
+
line: refusal.where.line ?? null,
|
|
111
|
+
identity: refusal.where.identity ?? null,
|
|
112
|
+
},
|
|
113
|
+
next: refusal.next,
|
|
114
|
+
};
|
|
115
|
+
return { exitCode: refusal.exit, stdout: JSON.stringify(body) + '\n', stderr: '' };
|
|
116
|
+
}
|
|
117
|
+
const block = errorBlock({
|
|
118
|
+
location,
|
|
119
|
+
...(refusal.where?.identity === undefined ? {} : { identity: refusal.where.identity }),
|
|
120
|
+
code: refusal.code,
|
|
121
|
+
message: refusal.message,
|
|
122
|
+
...(refusal.next === null ? {} : { next: words(refusal.next) }),
|
|
123
|
+
}, { depth: 0 }, caps);
|
|
124
|
+
return { exitCode: refusal.exit, stdout: '', stderr: document([block]) };
|
|
125
|
+
}
|
|
126
|
+
/** §6.5's strip rule applied to the serializer as well as the renderer, so both carry the same message. */
|
|
127
|
+
export const stripFor = (message, code, location, identity) => {
|
|
128
|
+
let text = message;
|
|
129
|
+
for (const prefix of [location, identity, code])
|
|
130
|
+
if (prefix && text.startsWith(prefix + ': '))
|
|
131
|
+
text = text.slice(prefix.length + 2);
|
|
132
|
+
return text;
|
|
133
|
+
};
|
|
134
|
+
const OPTION_ORDER = ['root', 'json', 'no-color', 'ascii', 'yes', 'quiet', 'help'];
|
|
135
|
+
export const optionLabel = (name, short, placeholder) => `${short === undefined ? '' : `-${short}, `}--${name}${placeholder === undefined ? '' : ` ${placeholder}`}`;
|
|
136
|
+
const optionRows = (grammar) => grammar.options
|
|
137
|
+
.filter((row) => row.refuse === undefined)
|
|
138
|
+
.map((row) => ({
|
|
139
|
+
label: optionLabel(row.name, row.short, row.kind === 'value'
|
|
140
|
+
? (row.placeholder ?? (row.values === undefined ? '<value>' : `<${row.values.join('|')}>`))
|
|
141
|
+
: undefined),
|
|
142
|
+
value: words(row.summary),
|
|
143
|
+
}));
|
|
144
|
+
const groupBlock = (group, label, caps) => [
|
|
145
|
+
sectionLabel(label, caps),
|
|
146
|
+
...fieldRows(COMMANDS.filter((command) => command.group === group).map((command) => ({
|
|
147
|
+
label: command.name,
|
|
148
|
+
value: words(command.summary),
|
|
149
|
+
})), { depth: 1 }, caps),
|
|
150
|
+
];
|
|
151
|
+
/**
|
|
152
|
+
* §1.2 step 1 and §7.1. The nine legacy operations are listed verbatim under their own heading, together with
|
|
153
|
+
* their own usage line, because the consumer help is the only place a reader learns that the machine protocol
|
|
154
|
+
* exists and is unchanged. One row points at each operation's own help (spec-0012 CLI-04). Private namespaces are
|
|
155
|
+
* supplied by the caller so that a tree without them prints a help text that does not mention them.
|
|
156
|
+
*/
|
|
157
|
+
export function renderHelp(host, caps, namespaces) {
|
|
158
|
+
const common = OPTION_ORDER.map((name) => COMMON_OPTIONS.find((row) => row.name === name));
|
|
159
|
+
return document([
|
|
160
|
+
entry([[atom('ia', 'bold', 0), atom(`${host.version} — author, compile and distribute .ia records`)]], { depth: 0 }, caps),
|
|
161
|
+
[sectionLabel('Usage', caps), ...entry([words('ia <command> [options]')], { depth: 1 }, caps)],
|
|
162
|
+
groupBlock('workspace', 'Workspace', caps),
|
|
163
|
+
groupBlock('distribution', 'Distribution', caps),
|
|
164
|
+
[
|
|
165
|
+
sectionLabel('Machine protocol — frozen, JSON in, one JSON line out, no color', caps),
|
|
166
|
+
...entry([[atom(LEGACY_OPERATIONS.join(' '))]], { depth: 1 }, caps),
|
|
167
|
+
...entry([[atom('Usage: ia', null, 0), ...words('<operation> [--root <workspace>] [--params <JSON|->]')]], { depth: 1 }, caps),
|
|
168
|
+
...fieldRows([
|
|
169
|
+
{ label: 'ia <operation> --help', value: words('Parameters, refusals and an example for one operation') },
|
|
170
|
+
...namespaces.map((namespace) => ({
|
|
171
|
+
label: `ia ${namespace.token} --help`,
|
|
172
|
+
value: words(namespace.summary),
|
|
173
|
+
})),
|
|
174
|
+
], { depth: 1 }, caps),
|
|
175
|
+
],
|
|
176
|
+
[
|
|
177
|
+
sectionLabel('Common options', caps),
|
|
178
|
+
...fieldRows([
|
|
179
|
+
...common.map((row) => ({
|
|
180
|
+
label: optionLabel(row.name, row.short, row.kind === 'value' ? row.placeholder : undefined),
|
|
181
|
+
value: words(row.summary),
|
|
182
|
+
})),
|
|
183
|
+
{ label: '--version', value: words('Print the version') },
|
|
184
|
+
], { depth: 1 }, caps),
|
|
185
|
+
],
|
|
186
|
+
entry([words('Run "ia <command> --help" for one command\'s full syntax.')], { depth: 0 }, caps),
|
|
187
|
+
]);
|
|
188
|
+
}
|
|
189
|
+
export function renderCommandHelp(command, caps) {
|
|
190
|
+
return document([
|
|
191
|
+
entry([[atom(`ia ${command.name}`, 'bold', 0), ...words(command.summary, null, 2)]], { depth: 0 }, caps),
|
|
192
|
+
[
|
|
193
|
+
sectionLabel('Usage', caps),
|
|
194
|
+
...command.syntax.flatMap((line) => entry([[atom(line, null, 0)]], { depth: 1 }, caps)),
|
|
195
|
+
],
|
|
196
|
+
[sectionLabel('Options', caps), ...fieldRows(optionRows(command.grammar), { depth: 1 }, caps)],
|
|
197
|
+
]);
|
|
198
|
+
}
|
|
199
|
+
/**
|
|
200
|
+
* §2.0: walk from cwd toward the filesystem root and take the first directory containing `.ia/src`. Host plugin
|
|
201
|
+
* distribution spec §3: a directory whose `.ia` is the IA home is never a workspace, even if src/ appeared there.
|
|
202
|
+
*/
|
|
203
|
+
export function discoverRoot(start, iaHome) {
|
|
204
|
+
let current = resolve(start);
|
|
205
|
+
for (;;) {
|
|
206
|
+
// The IA home by device and inode, so a home spelled in another case or normalization is still recognized (#315).
|
|
207
|
+
if (existsSync(resolve(current, '.ia/src')) && (iaHome === undefined || !sameFile(resolve(current, '.ia'), iaHome)))
|
|
208
|
+
return current;
|
|
209
|
+
const parent = dirname(current);
|
|
210
|
+
if (parent === current)
|
|
211
|
+
return undefined;
|
|
212
|
+
current = parent;
|
|
213
|
+
}
|
|
214
|
+
}
|
|
215
|
+
/** The IA home for discovery, or undefined when its variable is malformed; the verb that needs the home refuses then. */
|
|
216
|
+
export function iaHomeOf(env, home = homedir()) {
|
|
217
|
+
try {
|
|
218
|
+
return resolveIaHome(env, home).home;
|
|
219
|
+
}
|
|
220
|
+
catch {
|
|
221
|
+
return undefined;
|
|
222
|
+
}
|
|
223
|
+
}
|
|
224
|
+
/**
|
|
225
|
+
* §2.0: the real path of the resolved absolute root, because `workspace()` refuses a relative root and any link on the
|
|
226
|
+
* way to one (`apps/distribution/src/files.ts:51`). A failed discovery is exit 3 with IA-DB-ROOT-INVALID.
|
|
227
|
+
*/
|
|
228
|
+
export function requireRoot(context) {
|
|
229
|
+
const supplied = context.args.value('root');
|
|
230
|
+
if (supplied !== undefined) {
|
|
231
|
+
const path = isAbsolute(supplied) ? resolve(supplied) : resolve(context.host.cwd, supplied);
|
|
232
|
+
// §2.5 names IA-DB-ROOT-INVALID for an unavailable root. The distribution `workspace()` guard would refuse a
|
|
233
|
+
// missing directory as IA-DIST-INPUT-INVALID first, and §4.1 forbids rewriting a service's code, so the CLI
|
|
234
|
+
// makes the check itself and the service is never reached with a root it would name differently.
|
|
235
|
+
if (!statSync(path, { throwIfNoEntry: false })?.isDirectory())
|
|
236
|
+
throw new Refusal('IA-DB-ROOT-INVALID', `Cannot open workspace ${path}: no such directory`, 3, { path }, 'Pass --root <path> with an existing directory.');
|
|
237
|
+
// The root the user chose opens at its real path, as `ia host` resolves it, so a root reached through links (macOS
|
|
238
|
+
// /tmp, a linked checkout) works; every path below it is still checked link by link. The JS `realpathSync`, not
|
|
239
|
+
// `.native`: it keeps each name's case as typed, which the steward guard now folds (`unaliased`, #315). An 8.3
|
|
240
|
+
// short name or a subst drive that the JS form keeps is still an alias to the guard.
|
|
241
|
+
return realpathSync(path);
|
|
242
|
+
}
|
|
243
|
+
const found = discoverRoot(context.host.cwd, iaHomeOf(context.host.env));
|
|
244
|
+
if (found === undefined)
|
|
245
|
+
throw new Refusal('IA-DB-ROOT-INVALID', `No .ia/src directory at ${context.host.cwd} or in any parent`, 3, { path: context.host.cwd }, 'Run "ia init" to see what a new workspace would contain, or pass --root <path>.');
|
|
246
|
+
// A discovered root opens at its real path too: Windows keeps a junction's spelling in the cwd, where POSIX getcwd resolves it.
|
|
247
|
+
return realpathSync(found);
|
|
248
|
+
}
|
|
249
|
+
export const HELP_TOKENS = new Set(['--help', '-h']);
|
|
250
|
+
/** §2.0: `-h` short-circuits before the rest of the grammar, so a command's own help is never gated on it. */
|
|
251
|
+
const wantsHelp = (argv) => {
|
|
252
|
+
const end = argv.indexOf('--');
|
|
253
|
+
return argv.slice(0, end === -1 ? argv.length : end).some((token) => HELP_TOKENS.has(token));
|
|
254
|
+
};
|
|
255
|
+
/** The thirteen verbs of §1.2 step 5. A verb with no row here is a defect in this table, not a missing feature. */
|
|
256
|
+
const HANDLERS = {
|
|
257
|
+
init: runInit,
|
|
258
|
+
vocabulary: runVocabulary,
|
|
259
|
+
format: runFormat,
|
|
260
|
+
compile: runCompile,
|
|
261
|
+
validate: runValidate,
|
|
262
|
+
inspect: runInspect,
|
|
263
|
+
pack: runPack,
|
|
264
|
+
install: runDistribute('install'),
|
|
265
|
+
update: runDistribute('update'),
|
|
266
|
+
remove: runDistribute('remove'),
|
|
267
|
+
restore: runDistribute('restore'),
|
|
268
|
+
doctor: runDoctor,
|
|
269
|
+
host: runHost,
|
|
270
|
+
};
|
|
271
|
+
/** §1.2 step 5. Parse, then run; every class-2 check has already happened when a handler is entered. */
|
|
272
|
+
export async function runCommand(command, argv, host) {
|
|
273
|
+
const preliminary = resolveCapabilities(host.stdout, {});
|
|
274
|
+
if (wantsHelp(argv))
|
|
275
|
+
return { exitCode: 0, stdout: renderCommandHelp(command, preliminary), stderr: '' };
|
|
276
|
+
let caps = preliminary;
|
|
277
|
+
try {
|
|
278
|
+
const args = parseArguments(argv, command.grammar);
|
|
279
|
+
const json = args.flag('json');
|
|
280
|
+
caps = resolveCapabilities(host.stdout, {
|
|
281
|
+
...(args.flag('color') ? { color: true } : args.flag('no-color') ? { color: false } : {}),
|
|
282
|
+
...(args.flag('ascii') ? { ascii: true } : {}),
|
|
283
|
+
json,
|
|
284
|
+
});
|
|
285
|
+
// §2.8 rule 3 and §2.1: the confirmation check is part of parsing, so it precedes every class-3 refusal and
|
|
286
|
+
// keeps §3's promise that an exit 2 read nothing and wrote nothing. Both branches refuse the same invocation
|
|
287
|
+
// for the same reason — the question rule 3 specifies cannot be put where the answer could come from.
|
|
288
|
+
if (args.flag('apply') && !args.flag('yes')) {
|
|
289
|
+
if (!host.interaction.interactive)
|
|
290
|
+
throw new UsageError('--apply without a terminal requires --yes');
|
|
291
|
+
// §5: `--json` stdout is one parseable value with no prompt in it, so a terminal does not make it askable.
|
|
292
|
+
if (json)
|
|
293
|
+
throw new UsageError('--apply --json requires --yes; a --json run is never asked to confirm');
|
|
294
|
+
}
|
|
295
|
+
const context = { host, command, args, caps, json };
|
|
296
|
+
const handler = HANDLERS[command.name];
|
|
297
|
+
if (handler === undefined)
|
|
298
|
+
throw new Refusal('IA-CLI-FAILED', `No handler is installed for ia ${command.name}`, 3);
|
|
299
|
+
host.signal?.throwIfAborted();
|
|
300
|
+
const result = await handler(context);
|
|
301
|
+
host.signal?.throwIfAborted();
|
|
302
|
+
return result;
|
|
303
|
+
}
|
|
304
|
+
catch (error) {
|
|
305
|
+
if (host.signal?.aborted)
|
|
306
|
+
return {
|
|
307
|
+
exitCode: 130,
|
|
308
|
+
stdout: wantsJson(argv)
|
|
309
|
+
? JSON.stringify({ version: 1, ok: false, code: 'IA-CLI-INTERRUPTED', message: 'Interrupted.', exit: 130 }) +
|
|
310
|
+
'\n'
|
|
311
|
+
: '',
|
|
312
|
+
stderr: error instanceof Interrupted ? `Interrupted. ${error.next}\n` : 'Interrupted.\n',
|
|
313
|
+
};
|
|
314
|
+
const raw = refusalOf(error);
|
|
315
|
+
const refusal = raw.where === null && raw.at === null
|
|
316
|
+
? new Refusal(raw.code, raw.message, raw.exit, null, raw.next, `ia ${command.name}`)
|
|
317
|
+
: raw;
|
|
318
|
+
return renderRefusal(refusal, refusal.exit === 2 ? preliminary : caps, wantsJson(argv));
|
|
319
|
+
}
|
|
320
|
+
}
|
|
321
|
+
/** A refusal raised before or during parsing still has to honor §5, so `--json` is read from argv directly. */
|
|
322
|
+
const wantsJson = (argv) => {
|
|
323
|
+
const end = argv.indexOf('--');
|
|
324
|
+
return argv.slice(0, end === -1 ? argv.length : end).includes('--json');
|
|
325
|
+
};
|
|
326
|
+
/**
|
|
327
|
+
* §1.2's ordered table. The first match wins and the order is normative: step 4 precedes step 5 unconditionally,
|
|
328
|
+
* so a legacy operation can never be shadowed by a consumer verb.
|
|
329
|
+
*/
|
|
330
|
+
export async function dispatch(argv, host, legacy, extensions) {
|
|
331
|
+
const plain = (result) => ({ ...result, stderr: '' });
|
|
332
|
+
const token = argv[0];
|
|
333
|
+
const caps = resolveCapabilities(host.stdout, {});
|
|
334
|
+
// §1.2 step 1, which supersedes main.ts:11's usage-exit: no arguments is a request for help, not a syntax
|
|
335
|
+
// error. decisions.md:60 freezes the nine named routes, and a bare invocation is not one of them.
|
|
336
|
+
if (token === undefined || (argv.length === 1 && HELP_TOKENS.has(token)))
|
|
337
|
+
return { exitCode: 0, stdout: renderHelp(host, caps, extensions), stderr: '' };
|
|
338
|
+
if (argv.length === 1 && token === '--version')
|
|
339
|
+
return { exitCode: 0, stdout: host.version + '\n', stderr: '' };
|
|
340
|
+
// §1.6: an extension never takes a core, legacy or reserved token; such a token falls through to its core route.
|
|
341
|
+
const extension = CORE_TOKENS.has(token) ? undefined : extensions.find((candidate) => candidate.token === token);
|
|
342
|
+
if (extension !== undefined)
|
|
343
|
+
return plain(await extension.run(argv.slice(1)));
|
|
344
|
+
if (LEGACY_OPERATIONS.includes(token))
|
|
345
|
+
return plain(legacy(argv));
|
|
346
|
+
const command = findCommand(token);
|
|
347
|
+
if (command !== undefined) {
|
|
348
|
+
const dispose = host.onConsumerRoute?.();
|
|
349
|
+
try {
|
|
350
|
+
return await runCommand(command, argv.slice(1), host);
|
|
351
|
+
}
|
|
352
|
+
finally {
|
|
353
|
+
dispose?.();
|
|
354
|
+
}
|
|
355
|
+
}
|
|
356
|
+
if (token === RESERVED_TOKEN)
|
|
357
|
+
return renderRefusal(new Refusal('IA-CLI-USAGE', `"${RESERVED_TOKEN}" is reserved. Machine operations are invoked directly: ia scope, ia context, ia get.`, 2, null, 'Run "ia --help" for the machine protocol and the consumer commands.', `ia ${RESERVED_TOKEN}`), caps, wantsJson(argv));
|
|
358
|
+
const admitted = [
|
|
359
|
+
...COMMANDS.map((entry) => entry.name),
|
|
360
|
+
...LEGACY_OPERATIONS,
|
|
361
|
+
...extensions.map((entry) => entry.token).filter((candidate) => !CORE_TOKENS.has(candidate)),
|
|
362
|
+
];
|
|
363
|
+
const near = nearestTokens(token, admitted);
|
|
364
|
+
return renderRefusal(new Refusal('IA-CLI-USAGE', `Unknown command ${token}`, 2, null, near.length === 0 ? 'Run "ia --help" for the commands this binary admits.' : `Did you mean ${near.join(', ')}?`, `ia ${token}`), caps, wantsJson(argv));
|
|
365
|
+
}
|
|
366
|
+
//# sourceMappingURL=consumer.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"consumer.js","sourceRoot":"","sources":["../src/consumer.ts"],"names":[],"mappings":"AAAA;;;;;;;;GAQG;AACH,OAAO,EAAE,UAAU,EAAE,YAAY,EAAE,QAAQ,EAAE,MAAM,SAAS,CAAC;AAC7D,OAAO,EAAE,OAAO,EAAE,MAAM,SAAS,CAAC;AAClC,OAAO,EAAE,OAAO,EAAE,UAAU,EAAE,OAAO,EAAE,MAAM,WAAW,CAAC;AACzD,OAAO,EAAE,QAAQ,EAAE,MAAM,gBAAgB,CAAC;AAC1C,OAAO,EAAE,aAAa,EAAE,MAAM,kCAAkC,CAAC;AAEjE,OAAO,EAAE,cAAc,EAAE,UAAU,EAAE,MAAM,WAAW,CAAC;AAEvD,OAAO,EACL,QAAQ,EACR,cAAc,EACd,WAAW,EACX,WAAW,EACX,iBAAiB,EACjB,aAAa,EACb,cAAc,GACf,MAA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AAC;YACT,OAAO,EAAE,EAAE,CAAC;QACd,CAAC;IACH,CAAC;IACD,IAAI,KAAK,KAAK,cAAc;QAC1B,OAAO,aAAa,CAClB,IAAI,OAAO,CACT,cAAc,EACd,IAAI,cAAc,uFAAuF,EACzG,CAAC,EACD,IAAI,EACJ,qEAAqE,EACrE,MAAM,cAAc,EAAE,CACvB,EACD,IAAI,EACJ,SAAS,CAAC,IAAI,CAAC,CAChB,CAAC;IACJ,MAAM,QAAQ,GAAG;QACf,GAAG,QAAQ,CAAC,GAAG,CAAC,CAAC,KAAK,EAAE,EAAE,CAAC,KAAK,CAAC,IAAI,CAAC;QACtC,GAAG,iBAAiB;QACpB,GAAG,UAAU,CAAC,GAAG,CAAC,CAAC,KAAK,EAAE,EAAE,CAAC,KAAK,CAAC,KAAK,CAAC,CAAC,MAAM,CAAC,CAAC,SAAS,EAAE,EAAE,CAAC,CAAC,WAAW,CAAC,GAAG,CAAC,SAAS,CAAC,CAAC;KAC7F,CAAC;IACF,MAAM,IAAI,GAAG,aAAa,CAAC,KAAK,EAAE,QAAQ,CAAC,CAAC;IAC5C,OAAO,aAAa,CAClB,IAAI,OAAO,CACT,cAAc,EACd,mBAAmB,KAAK,EAAE,EAC1B,CAAC,EACD,IAAI,EACJ,IAAI,CAAC,MAAM,KAAK,CAAC,CAAC,CAAC,CAAC,sDAAsD,CAAC,CAAC,CAAC,gBAAgB,IAAI,CAAC,IAAI,CAAC,IAAI,CAAC,GAAG,EAC/G,MAAM,KAAK,EAAE,CACd,EACD,IAAI,EACJ,SAAS,CAAC,IAAI,CAAC,CAChB,CAAC;AACJ,CAAC"}
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
import type { DeclineKind } from '@inventarch/distribution/decisions';
|
|
2
|
+
import type { Context, Result } from './consumer.js';
|
|
3
|
+
type Env = Readonly<Record<string, string | undefined>>;
|
|
4
|
+
export declare function runDecline(context: Context, target: string, kind: DeclineKind | undefined): Result;
|
|
5
|
+
export declare function clearDecline(env: Env, target: string): void;
|
|
6
|
+
export {};
|
|
7
|
+
//# sourceMappingURL=decline.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"decline.d.ts","sourceRoot":"","sources":["../src/decline.ts"],"names":[],"mappings":"AAOA,OAAO,KAAK,EAAY,WAAW,EAAE,MAAM,oCAAoC,CAAC;AAShF,OAAO,KAAK,EAAE,OAAO,EAAE,MAAM,EAAE,MAAM,eAAe,CAAC;AAKrD,KAAK,GAAG,GAAG,QAAQ,CAAC,MAAM,CAAC,MAAM,EAAE,MAAM,GAAG,SAAS,CAAC,CAAC,CAAC;AAiCxD,wBAAgB,UAAU,CAAC,OAAO,EAAE,OAAO,EAAE,MAAM,EAAE,MAAM,EAAE,IAAI,EAAE,WAAW,GAAG,SAAS,GAAG,MAAM,CAoClG;AACD,wBAAgB,YAAY,CAAC,GAAG,EAAE,GAAG,EAAE,MAAM,EAAE,MAAM,GAAG,IAAI,CAM3D"}
|
package/dist/decline.js
ADDED
|
@@ -0,0 +1,78 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* `ia init --decline` and `--forget-decline`: docs/specs/host-plugin-distribution/README.md §7.2 and §9.
|
|
3
|
+
* They write only the IA home's decisions file, never the repository. `clearDecline` is what a successful
|
|
4
|
+
* `ia init --apply` runs, and it never fails the init: a broken decisions file is reported by `ia doctor`.
|
|
5
|
+
*/
|
|
6
|
+
import { homedir } from 'node:os';
|
|
7
|
+
import { join } from 'node:path';
|
|
8
|
+
import { DECISIONS, forgetDecision, readDecisions, recordDecision, repositoryKey, } from '@inventarch/distribution/decisions';
|
|
9
|
+
import { resolveIaHome } from '@inventarch/distribution/ia-home';
|
|
10
|
+
import { Refusal, refusalOf } from './consumer.js';
|
|
11
|
+
import { homeSrcRemedy } from './home-remedy.js';
|
|
12
|
+
import { document, entry, words } from './render.js';
|
|
13
|
+
const homeOf = (env) => resolveIaHome(env, homedir()).home;
|
|
14
|
+
/**
|
|
15
|
+
* §9.2: the remedy depends on why the write failed, not on a fixed sentence. `home` is undefined only when
|
|
16
|
+
* `resolveIaHome` itself refused (a relative IA_HOME/IA_HOST_HOME), before any file could be named; `ia host`'s own
|
|
17
|
+
* `homeSrcRemedy` is reused rather than duplicated for the home-looks-like-a-workspace cause, and an invalid
|
|
18
|
+
* decisions file is inspected directly with `readDecisions` rather than by pattern-matching the caught message.
|
|
19
|
+
*/
|
|
20
|
+
function declineRefusal(home, error) {
|
|
21
|
+
const refusal = refusalOf(error);
|
|
22
|
+
if (home === undefined)
|
|
23
|
+
return new Refusal(refusal.code, refusal.message, 3, null, 'Set IA_HOME to an absolute directory, or unset it to use ~/.ia.');
|
|
24
|
+
if (refusal.code === 'IA-DIST-PATH-UNSAFE')
|
|
25
|
+
return new Refusal(refusal.code, refusal.message, 3, null, homeSrcRemedy(home));
|
|
26
|
+
if (refusal.code === 'IA-DIST-INPUT-INVALID') {
|
|
27
|
+
const file = join(home, DECISIONS);
|
|
28
|
+
const { reason } = readDecisions(home);
|
|
29
|
+
const next = reason === 'parse' || reason === 'schema'
|
|
30
|
+
? `Fix or delete ${file}, then rerun.`
|
|
31
|
+
: `Check the permissions of ${file}, then rerun.`;
|
|
32
|
+
return new Refusal(refusal.code, refusal.message, 3, { path: file }, next);
|
|
33
|
+
}
|
|
34
|
+
return refusal;
|
|
35
|
+
}
|
|
36
|
+
export function runDecline(context, target, kind) {
|
|
37
|
+
const { args, caps, json, host } = context;
|
|
38
|
+
const path = repositoryKey(target).path;
|
|
39
|
+
let home, decision = null, forgotten = false;
|
|
40
|
+
try {
|
|
41
|
+
home = homeOf(host.env);
|
|
42
|
+
if (kind === undefined)
|
|
43
|
+
forgotten = forgetDecision(home, target);
|
|
44
|
+
else
|
|
45
|
+
decision = recordDecision(home, target, kind, args.value('host') ?? 'none');
|
|
46
|
+
}
|
|
47
|
+
catch (error) {
|
|
48
|
+
throw declineRefusal(home, error);
|
|
49
|
+
}
|
|
50
|
+
if (json)
|
|
51
|
+
return {
|
|
52
|
+
exitCode: 0,
|
|
53
|
+
stdout: JSON.stringify({ version: 1, command: 'init', root: target, path, decision, forgotten }) + '\n',
|
|
54
|
+
stderr: '',
|
|
55
|
+
};
|
|
56
|
+
const line = decision === null
|
|
57
|
+
? forgotten
|
|
58
|
+
? `Forgot the recorded decline for ${target}.`
|
|
59
|
+
: `No decline was recorded for ${target}.`
|
|
60
|
+
: decision.decision === 'declined-forever'
|
|
61
|
+
? `Recorded: never offer to initialize ${decision.path}. "ia init" still works when run explicitly.`
|
|
62
|
+
: `Recorded: do not offer to initialize ${decision.path} again today.`;
|
|
63
|
+
return {
|
|
64
|
+
exitCode: 0,
|
|
65
|
+
// §9.2's "no entry" case is informational, not a completed action; every other line records one, and keeps `success`.
|
|
66
|
+
stdout: document([entry([words(line)], { depth: 0, symbol: decision === null && !forgotten ? 'info' : 'success' }, caps)], { leadingBlank: true }),
|
|
67
|
+
stderr: '',
|
|
68
|
+
};
|
|
69
|
+
}
|
|
70
|
+
export function clearDecline(env, target) {
|
|
71
|
+
try {
|
|
72
|
+
forgetDecision(homeOf(env), target);
|
|
73
|
+
}
|
|
74
|
+
catch {
|
|
75
|
+
// §9.2: a broken decisions file never fails an init; `ia doctor` reports it.
|
|
76
|
+
}
|
|
77
|
+
}
|
|
78
|
+
//# sourceMappingURL=decline.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"decline.js","sourceRoot":"","sources":["../src/decline.ts"],"names":[],"mappings":"AAAA;;;;GAIG;AACH,OAAO,EAAE,OAAO,EAAE,MAAM,SAAS,CAAC;AAClC,OAAO,EAAE,IAAI,EAAE,MAAM,WAAW,CAAC;AAEjC,OAAO,EACL,SAAS,EACT,cAAc,EACd,aAAa,EACb,cAAc,EACd,aAAa,GACd,MAAM,oCAAoC,CAAC;AAC5C,OAAO,EAAE,aAAa,EAAE,MAAM,kCAAkC,CAAC;AAEjE,OAAO,EAAE,OAAO,EAAE,SAAS,EAAE,MAAM,eAAe,CAAC;AACnD,OAAO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