primcli 3.0.0-preview.2 → 3.0.0-preview.21
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 +100 -40
- package/bin/run.js +21 -2
- package/dist/api-command-Bab30eNp.js +61097 -0
- package/dist/cli-command-names-BYbYdipl.js +320 -0
- package/dist/help-inputs-NGARVZL_.js +109 -0
- package/dist/{json-output-BzSBR-KX.js → json-output-xgN0ZLWP.js} +31 -6
- package/dist/{listen-background-C0F9gNDD.js → listen-background-DyBYca28.js} +323 -36
- package/dist/{machine-session-g-xPd3X0.js → machine-session-cfgMKQ_U.js} +8 -8
- package/dist/{notify-session-Bo8WgG3q.js → notify-session-BRK9_xSb.js} +71 -32
- package/dist/oclif/auto-signal-worker.js +3 -3
- package/dist/oclif/auto-signals.js +1 -1
- package/dist/oclif/command-not-found.js +132 -0
- package/dist/oclif/command-stdin.js +9 -0
- package/dist/oclif/help.js +70 -13
- package/dist/oclif/index.js +3236 -104541
- package/dist/oclif/listen-supervisor.js +1 -1
- package/dist/oclif/proxy-auto-detect.js +1 -1
- package/dist/oclif/receiver-heal.js +4 -3
- package/dist/oclif/root-signup-hint.js +15 -15
- package/dist/receiver.d.ts +1 -1
- package/dist/{repeats-Dj_o6c-X-BzXj5ICh.js → repeats-Dj_o6c-X-CraZzs4t.js} +14615 -13905
- package/dist/retry-ids-04ZPJCZY.js +59 -0
- package/dist/{scoped-chat-TJlyUTi7.js → scoped-chat-YucNhX6U.js} +1 -1
- package/dist/{signal-command-BO93dM2Q.js → signal-command-AOnn_Him.js} +12 -6
- package/dist/skills/primitive-connect/references/contact-requests.md +4 -4
- package/dist/skills/primitive-connect/references/contacts.md +1 -1
- package/dist/skills/primitive-connect.json +4 -4
- package/man/primitive.1 +31 -15
- package/package.json +30 -14
- package/dist/api-command-B37DPKFA.js +0 -3634
|
@@ -1,24 +1,36 @@
|
|
|
1
|
-
import {
|
|
2
|
-
import {
|
|
1
|
+
import { _ as isTrustedSender, c as classifySignalContent, g as isEmailReceivedEvent, kt as downloadEmailAttachmentPart, v as parseWebhookEvent } from "./repeats-Dj_o6c-X-CraZzs4t.js";
|
|
2
|
+
import { $ as wakeInteractionSentence, L as skillFirstLine, R as wakeReadCommand } from "./api-command-Bab30eNp.js";
|
|
3
3
|
import { _ as acquireListenLock, g as ListenStateError, y as listenIdentity } from "./shared-mail-files-BAQSGxxz.js";
|
|
4
4
|
import { closeSync, copyFileSync, existsSync, fsyncSync, lstatSync, mkdirSync, openSync, opendirSync, readFileSync, readdirSync, readlinkSync, renameSync, rmSync, statSync, symlinkSync, unlinkSync, writeFileSync } from "node:fs";
|
|
5
5
|
import { createHash, randomUUID, scryptSync } from "node:crypto";
|
|
6
6
|
import { dirname, isAbsolute, join, normalize, resolve } from "node:path";
|
|
7
7
|
import { spawn } from "node:child_process";
|
|
8
|
+
import { isDeepStrictEqual } from "node:util";
|
|
8
9
|
import { homedir } from "node:os";
|
|
9
10
|
import { lstat, realpath } from "node:fs/promises";
|
|
10
|
-
import { isDeepStrictEqual } from "node:util";
|
|
11
11
|
import WebSocket from "ws";
|
|
12
12
|
import { request } from "node:http";
|
|
13
13
|
import { request as request$1 } from "node:https";
|
|
14
14
|
import { performance } from "node:perf_hooks";
|
|
15
15
|
// src/oclif/connect-skill.ts
|
|
16
16
|
const CONNECT_SKILL_NAME = "primitive-connect";
|
|
17
|
-
|
|
17
|
+
/** A bundled skill's name is also a directory name, so it stays this plain. */
|
|
18
|
+
const SKILL_NAME_PATTERN = /^[a-z0-9][a-z0-9-]{0,63}$/;
|
|
19
|
+
function isSkillName(value) {
|
|
20
|
+
return SKILL_NAME_PATTERN.test(value);
|
|
21
|
+
}
|
|
22
|
+
/** Where one skill is installed for a runtime, user-level or in the project. */
|
|
23
|
+
function skillTarget(options) {
|
|
18
24
|
const env = options.env ?? process.env;
|
|
19
25
|
const cwd = resolve(options.cwd ?? process.cwd());
|
|
20
26
|
const root = options.runtime === "claude" ? options.project ? join(cwd, ".claude") : resolve(env.CLAUDE_CONFIG_DIR || join(homedir(), ".claude")) : options.project ? join(cwd, ".agents") : resolve(env.CODEX_HOME || join(homedir(), ".codex"));
|
|
21
|
-
return join(root, "skills",
|
|
27
|
+
return join(root, "skills", options.name);
|
|
28
|
+
}
|
|
29
|
+
function connectSkillTarget(options) {
|
|
30
|
+
return skillTarget({
|
|
31
|
+
...options,
|
|
32
|
+
name: CONNECT_SKILL_NAME
|
|
33
|
+
});
|
|
22
34
|
}
|
|
23
35
|
/** A path printed into agent instructions stays on one line. */
|
|
24
36
|
function printablePath(value) {
|
|
@@ -82,26 +94,49 @@ function hashFiles(root, files = listFiles(root)) {
|
|
|
82
94
|
for (const file of files) hashes[file] = createHash("sha256").update(readFileSync(join(root, file))).digest("hex");
|
|
83
95
|
return hashes;
|
|
84
96
|
}
|
|
85
|
-
function
|
|
97
|
+
function skillVersion(hashes) {
|
|
86
98
|
const digest = createHash("sha256");
|
|
87
99
|
for (const file of Object.keys(hashes).sort()) digest.update(`${file}\0${hashes[file]}\n`);
|
|
88
100
|
return digest.digest("hex").slice(0, 16);
|
|
89
101
|
}
|
|
90
|
-
/**
|
|
91
|
-
function
|
|
102
|
+
/** Names of the skills shipped in this CLI package, sorted. */
|
|
103
|
+
function bundledSkillNames(packageRoot) {
|
|
104
|
+
const skillsDir = join(packageRoot, "dist", "skills");
|
|
105
|
+
let entries;
|
|
106
|
+
try {
|
|
107
|
+
entries = readdirSync(skillsDir);
|
|
108
|
+
} catch {
|
|
109
|
+
return [];
|
|
110
|
+
}
|
|
111
|
+
return entries.filter((entry) => entry.endsWith(".json")).map((entry) => entry.slice(0, -5)).filter((name) => {
|
|
112
|
+
if (!isSkillName(name)) return false;
|
|
113
|
+
try {
|
|
114
|
+
return statSync(join(skillsDir, name)).isDirectory();
|
|
115
|
+
} catch {
|
|
116
|
+
return false;
|
|
117
|
+
}
|
|
118
|
+
}).sort();
|
|
119
|
+
}
|
|
120
|
+
/** Read one skill shipped in this CLI package and refuse one that does not match its manifest. */
|
|
121
|
+
function readBundledSkill(packageRoot, name) {
|
|
122
|
+
if (!isSkillName(name)) throw new Error(`Not a skill name: ${name}`);
|
|
92
123
|
const skillsDir = join(packageRoot, "dist", "skills");
|
|
93
|
-
const directory = join(skillsDir,
|
|
94
|
-
const manifest = JSON.parse(readFileSync(join(skillsDir, `${
|
|
124
|
+
const directory = join(skillsDir, name);
|
|
125
|
+
const manifest = JSON.parse(readFileSync(join(skillsDir, `${name}.json`), "utf8"));
|
|
95
126
|
const expected = manifest.files && typeof manifest.files === "object" && !Array.isArray(manifest.files) ? manifest.files : null;
|
|
96
127
|
const actual = hashFiles(directory);
|
|
97
|
-
if (manifest.name !==
|
|
128
|
+
if (manifest.name !== name || !expected || typeof manifest.version !== "string" || skillVersion(actual) !== manifest.version || skillVersion(expected) !== manifest.version) throw new Error("The bundled skill does not match its manifest.");
|
|
98
129
|
return {
|
|
130
|
+
name,
|
|
99
131
|
directory,
|
|
100
132
|
version: manifest.version,
|
|
101
133
|
commit: typeof manifest.source?.commit === "string" ? manifest.source.commit : null,
|
|
102
134
|
files: actual
|
|
103
135
|
};
|
|
104
136
|
}
|
|
137
|
+
function readBundledConnectSkill(packageRoot) {
|
|
138
|
+
return readBundledSkill(packageRoot, CONNECT_SKILL_NAME);
|
|
139
|
+
}
|
|
105
140
|
/** Two skill copies declare the same helper dependencies. */
|
|
106
141
|
function sameDependencies(a, b) {
|
|
107
142
|
const digest = (path) => {
|
|
@@ -120,21 +155,21 @@ const STALE_LEFTOVER_MS = 6e4;
|
|
|
120
155
|
* process stopped between those renames, put the old copy back so the skill
|
|
121
156
|
* path is never left empty, and remove abandoned staging and retired copies.
|
|
122
157
|
*/
|
|
123
|
-
function recoverInterruptedInstall(root, target) {
|
|
158
|
+
function recoverInterruptedInstall(root, target, name) {
|
|
124
159
|
let entries;
|
|
125
160
|
try {
|
|
126
161
|
entries = readdirSync(root);
|
|
127
162
|
} catch {
|
|
128
163
|
return false;
|
|
129
164
|
}
|
|
130
|
-
const stale = (
|
|
165
|
+
const stale = (entry) => {
|
|
131
166
|
try {
|
|
132
|
-
return Date.now() - lstatSync(join(root,
|
|
167
|
+
return Date.now() - lstatSync(join(root, entry)).mtimeMs > STALE_LEFTOVER_MS;
|
|
133
168
|
} catch {
|
|
134
169
|
return false;
|
|
135
170
|
}
|
|
136
171
|
};
|
|
137
|
-
const retired = entries.filter((
|
|
172
|
+
const retired = entries.filter((entry) => entry.startsWith(`.${name}.retired-`)).filter(stale).sort((a, b) => lstatSync(join(root, b)).mtimeMs - lstatSync(join(root, a)).mtimeMs);
|
|
138
173
|
let recovered = false;
|
|
139
174
|
let missing = false;
|
|
140
175
|
try {
|
|
@@ -153,31 +188,31 @@ function recoverInterruptedInstall(root, target) {
|
|
|
153
188
|
} catch {
|
|
154
189
|
realDirectory = false;
|
|
155
190
|
}
|
|
156
|
-
for (const
|
|
157
|
-
const deps = join(root,
|
|
158
|
-
if (realDirectory && existsSync(deps) && !existsSync(join(target, "node_modules")) && sameDependencies(join(root,
|
|
191
|
+
for (const copy of retired) {
|
|
192
|
+
const deps = join(root, copy, "node_modules");
|
|
193
|
+
if (realDirectory && existsSync(deps) && !existsSync(join(target, "node_modules")) && sameDependencies(join(root, copy), target)) try {
|
|
159
194
|
renameSync(deps, join(target, "node_modules"));
|
|
160
195
|
} catch {}
|
|
161
196
|
}
|
|
162
|
-
for (const
|
|
197
|
+
for (const leftover of [...retired, ...entries.filter((entry) => entry.startsWith(`.${name}.staging-`)).filter(stale)]) rmSync(join(root, leftover), {
|
|
163
198
|
recursive: true,
|
|
164
199
|
force: true
|
|
165
200
|
});
|
|
166
201
|
return recovered;
|
|
167
202
|
}
|
|
168
|
-
function
|
|
203
|
+
function declaresSkill(directory, name) {
|
|
169
204
|
try {
|
|
170
205
|
const text = readFileSync(join(directory, "SKILL.md"), "utf8");
|
|
171
206
|
const frontmatter = /^---\r?\n([\s\S]*?)\r?\n---/.exec(text)?.[1] ?? "";
|
|
172
|
-
return
|
|
207
|
+
return new RegExp(`^name:\\s*["']?${name}["']?\\s*$`, "m").test(frontmatter);
|
|
173
208
|
} catch {
|
|
174
209
|
return false;
|
|
175
210
|
}
|
|
176
211
|
}
|
|
177
|
-
function otherCopies(target) {
|
|
212
|
+
function otherCopies(target, name) {
|
|
178
213
|
const root = dirname(target);
|
|
179
214
|
try {
|
|
180
|
-
return readdirSync(root, { withFileTypes: true }).filter((entry) => !entry.name.startsWith(".") && entry.name !==
|
|
215
|
+
return readdirSync(root, { withFileTypes: true }).filter((entry) => !entry.name.startsWith(".") && entry.name !== name && (entry.isDirectory() || entry.isSymbolicLink())).map((entry) => join(root, entry.name)).filter((directory) => declaresSkill(directory, name)).sort();
|
|
181
216
|
} catch {
|
|
182
217
|
return [];
|
|
183
218
|
}
|
|
@@ -186,7 +221,7 @@ function otherCopies(target) {
|
|
|
186
221
|
function installedVersion(target) {
|
|
187
222
|
try {
|
|
188
223
|
if (!statSync(target).isDirectory()) return null;
|
|
189
|
-
return
|
|
224
|
+
return skillVersion(hashFiles(target));
|
|
190
225
|
} catch {
|
|
191
226
|
return null;
|
|
192
227
|
}
|
|
@@ -196,19 +231,23 @@ function installedVersion(target) {
|
|
|
196
231
|
* left untouched. A different copy is replaced in one rename, never beside a
|
|
197
232
|
* second directory, and a symlink is replaced without touching its target.
|
|
198
233
|
*/
|
|
199
|
-
function
|
|
200
|
-
const
|
|
234
|
+
function installSkill(options) {
|
|
235
|
+
const name = options.bundle.name;
|
|
236
|
+
const target = skillTarget({
|
|
237
|
+
...options,
|
|
238
|
+
name
|
|
239
|
+
});
|
|
201
240
|
const base = {
|
|
202
241
|
runtime: options.runtime,
|
|
203
242
|
path: target,
|
|
204
243
|
version: options.bundle.version
|
|
205
244
|
};
|
|
206
245
|
const copies = () => {
|
|
207
|
-
const found = otherCopies(target);
|
|
246
|
+
const found = otherCopies(target, name);
|
|
208
247
|
return found.length ? { otherCopies: found } : {};
|
|
209
248
|
};
|
|
210
249
|
const root = dirname(target);
|
|
211
|
-
const recovered = recoverInterruptedInstall(root, target);
|
|
250
|
+
const recovered = recoverInterruptedInstall(root, target, name);
|
|
212
251
|
let existing = null;
|
|
213
252
|
try {
|
|
214
253
|
existing = lstatSync(target);
|
|
@@ -227,15 +266,15 @@ function installConnectSkill(options) {
|
|
|
227
266
|
...notes,
|
|
228
267
|
...copies()
|
|
229
268
|
};
|
|
230
|
-
const staging = join(root, `.${
|
|
231
|
-
const retired = join(root, `.${
|
|
269
|
+
const staging = join(root, `.${name}.staging-${randomUUID()}`);
|
|
270
|
+
const retired = join(root, `.${name}.retired-${randomUUID()}`);
|
|
232
271
|
try {
|
|
233
272
|
mkdirSync(root, { recursive: true });
|
|
234
273
|
for (const file of Object.keys(options.bundle.files)) {
|
|
235
274
|
mkdirSync(dirname(join(staging, file)), { recursive: true });
|
|
236
275
|
copyFileSync(join(options.bundle.directory, file), join(staging, file));
|
|
237
276
|
}
|
|
238
|
-
if (
|
|
277
|
+
if (skillVersion(hashFiles(staging)) !== options.bundle.version) throw new Error("Copied skill files do not match the bundle.");
|
|
239
278
|
let dependencies;
|
|
240
279
|
if (link === null && existing?.isDirectory() && existsSync(join(target, "node_modules"))) dependencies = sameDependencies(target, staging) ? "kept" : "reinstall_needed";
|
|
241
280
|
if (link !== null) unlinkSync(target);
|
|
@@ -1444,4 +1483,4 @@ async function openSessionNotifications(options) {
|
|
|
1444
1483
|
}
|
|
1445
1484
|
var ContactNoticeSuppressed = class extends Error {};
|
|
1446
1485
|
var ContactNoticeDeferred = class extends Error {};
|
|
1447
|
-
export { readBundledConnectSkill as S, NotificationOutcomeUnknownError as _, NotificationRetryError as a,
|
|
1486
|
+
export { readBundledConnectSkill as C, installedVersion as S, NotificationOutcomeUnknownError as _, NotificationRetryError as a, installSkill as b, readConversationStatusContent as c, SESSION_UUID as d, connectNativeSession as f, NativeSessionNotLoadedError as g, NativeSessionError as h, notificationReceiptPage as i, createListenHandler as l, NativeSessionDisconnectedError as m, notificationSenders as n, isRoutineNotificationContent as o, defaultSessionSocket as p, openSessionNotifications as r, notificationPartReader as s, notificationScope as t, readableDelivery as u, bundledSkillNames as v, readBundledSkill as w, installedConnectSkillFile as x, connectSkillTarget as y };
|
|
@@ -1,8 +1,8 @@
|
|
|
1
|
-
import {
|
|
2
|
-
import {
|
|
1
|
+
import { Qt as getSentEmail } from "../repeats-Dj_o6c-X-CraZzs4t.js";
|
|
2
|
+
import { N as readThreadContext, vn as createAuthenticatedCliApiClient } from "../api-command-Bab30eNp.js";
|
|
3
3
|
import { AUTO_SIGNAL_KIND_ENV, AUTO_WORKING_RENEW_MS, autoSignalsDisabled, clearWorkingSending, markWorkingSending, readAutoClaim, readWorkingLease, recordRenewer, stopWorkingLease, writeWorkingLease } from "./auto-signals.js";
|
|
4
4
|
import { _ as acquireListenLock } from "../shared-mail-files-BAQSGxxz.js";
|
|
5
|
-
import { t as sendSignal } from "../signal-command-
|
|
5
|
+
import { t as sendSignal } from "../signal-command-AOnn_Him.js";
|
|
6
6
|
import { join } from "node:path";
|
|
7
7
|
import { homedir } from "node:os";
|
|
8
8
|
// src/oclif/auto-signal-worker.ts
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { n as isPlainChatReply, o as scopedChatSenderTrust } from "../scoped-chat-
|
|
1
|
+
import { n as isPlainChatReply, o as scopedChatSenderTrust } from "../scoped-chat-YucNhX6U.js";
|
|
2
2
|
import { d as readMailJson, h as writeMailJson, i as mailId, l as privateMailDirectory, r as mailAddress } from "../shared-mail-files-BAQSGxxz.js";
|
|
3
3
|
import { existsSync, readFileSync, readdirSync, unlinkSync, writeFileSync } from "node:fs";
|
|
4
4
|
import { randomUUID } from "node:crypto";
|
|
@@ -0,0 +1,132 @@
|
|
|
1
|
+
import { t as COMMAND_RENAMES } from "../cli-command-names-BYbYdipl.js";
|
|
2
|
+
import { r as jsonOutputRequested } from "../json-output-xgN0ZLWP.js";
|
|
3
|
+
// src/oclif/command-not-found.ts
|
|
4
|
+
/** At most this many commands are suggested for one word. */
|
|
5
|
+
const MOST_SUGGESTED = 3;
|
|
6
|
+
/**
|
|
7
|
+
* The commands in another group named by the word typed where a subcommand
|
|
8
|
+
* was expected, said as a question (`email-rules list-objections`
|
|
9
|
+
* is `email-rule-oversight list-objections`), or none when there are
|
|
10
|
+
* none or too many to be a likely meaning. Only those words are looked up,
|
|
11
|
+
* never a value typed after them, which can be any word at all.
|
|
12
|
+
*/
|
|
13
|
+
function elsewhere(words, lookup) {
|
|
14
|
+
for (const word of words) {
|
|
15
|
+
const ids = lookup.named?.(word) ?? [];
|
|
16
|
+
if (ids.length === 0) continue;
|
|
17
|
+
return ids.length > MOST_SUGGESTED ? [] : [...ids];
|
|
18
|
+
}
|
|
19
|
+
return [];
|
|
20
|
+
}
|
|
21
|
+
/** Damerau distance also catches adjacent transpositions such as `lsit`. */
|
|
22
|
+
function distance(left, right) {
|
|
23
|
+
let previous = Array.from({ length: right.length + 1 }, (_, i) => i);
|
|
24
|
+
let before = previous;
|
|
25
|
+
for (let i = 0; i < left.length; i += 1) {
|
|
26
|
+
const current = [i + 1];
|
|
27
|
+
for (let j = 0; j < right.length; j += 1) {
|
|
28
|
+
current[j + 1] = Math.min((current[j] ?? 0) + 1, (previous[j + 1] ?? 0) + 1, (previous[j] ?? 0) + (left[i] === right[j] ? 0 : 1));
|
|
29
|
+
if (i > 0 && j > 0 && left[i] === right[j - 1] && left[i - 1] === right[j]) current[j + 1] = Math.min(current[j + 1] ?? 0, (before[j - 1] ?? 0) + 1);
|
|
30
|
+
}
|
|
31
|
+
before = previous;
|
|
32
|
+
previous = current;
|
|
33
|
+
}
|
|
34
|
+
return previous[right.length] ?? Number.POSITIVE_INFINITY;
|
|
35
|
+
}
|
|
36
|
+
function nearby(word, ids) {
|
|
37
|
+
if (!word || word.length > 80) return [];
|
|
38
|
+
const singular = (value) => value.length > 3 ? value.replace(/s$/, "") : value;
|
|
39
|
+
const name = singular(word.toLowerCase());
|
|
40
|
+
const maximum = Math.max(1, Math.min(2, Math.floor(name.length / 3)));
|
|
41
|
+
return ids.map((id) => {
|
|
42
|
+
const candidate = id.split(":").at(-1) ?? id;
|
|
43
|
+
return {
|
|
44
|
+
id,
|
|
45
|
+
score: name.length >= 3 && candidate.startsWith(`${word.toLowerCase()}-`) ? .5 : distance(name, singular(candidate))
|
|
46
|
+
};
|
|
47
|
+
}).filter(({ score }) => score <= maximum).sort((a, b) => a.score - b.score || a.id.localeCompare(b.id)).slice(0, MOST_SUGGESTED).map(({ id }) => id);
|
|
48
|
+
}
|
|
49
|
+
function suggestions(words, lookup, topic) {
|
|
50
|
+
const visible = lookup.visible ?? [];
|
|
51
|
+
if (topic) {
|
|
52
|
+
const depth = topic.split(":").length + 1;
|
|
53
|
+
const siblings = visible.filter((id) => id.startsWith(`${topic}:`) && id.split(":").length === depth);
|
|
54
|
+
const matches = nearby(words[0] ?? "", siblings);
|
|
55
|
+
if (matches.length > 0) return matches;
|
|
56
|
+
}
|
|
57
|
+
const exact = elsewhere(words, lookup);
|
|
58
|
+
if (exact.length > 0) return exact;
|
|
59
|
+
const roots = (lookup.roots ?? visible.filter((id) => !id.includes(":"))).filter((id) => id !== topic);
|
|
60
|
+
return nearby(topic ?? words[0] ?? "", roots);
|
|
61
|
+
}
|
|
62
|
+
function unknown(typed, ids, help, lookup) {
|
|
63
|
+
const commands = ids.map((id) => `primitive ${id.split(":").join(" ")}${lookup.find(id) ? "" : " --help"}`);
|
|
64
|
+
return {
|
|
65
|
+
code: "command_not_found",
|
|
66
|
+
message: `Unknown command "${typed}".${commands.length ? ` Did you mean ${commands.map((command) => `"${command}"`).join(" or ")}?` : ""} ${help}`,
|
|
67
|
+
...commands.length ? { details: { suggestions: commands } } : {}
|
|
68
|
+
};
|
|
69
|
+
}
|
|
70
|
+
/** A command owns its visibility; topic visibility applies only without one. */
|
|
71
|
+
function visibleEntries(commands, topics) {
|
|
72
|
+
const declared = new Set(commands.map((command) => command.id));
|
|
73
|
+
return [.../* @__PURE__ */ new Set([...commands.filter((command) => !command.hidden).map((command) => command.id), ...topics.filter((topic) => !declared.has(topic.name) && !topic.hidden).map((topic) => topic.name)])];
|
|
74
|
+
}
|
|
75
|
+
/**
|
|
76
|
+
* What to say for an id no command has. oclif joins every word before the
|
|
77
|
+
* first flag into the id while no command along the way takes arguments, so
|
|
78
|
+
* `emails list foo` arrives as `emails:list:foo`: when a leading part is a
|
|
79
|
+
* real command, the rest was an argument it does not take.
|
|
80
|
+
*/
|
|
81
|
+
function commandNotFoundMessage(id, lookup) {
|
|
82
|
+
const parts = id.split(":");
|
|
83
|
+
const typed = `primitive ${parts.join(" ")}`;
|
|
84
|
+
const replacement = Object.hasOwn(COMMAND_RENAMES, id) ? COMMAND_RENAMES[id] : void 0;
|
|
85
|
+
if (replacement && lookup.visible?.includes(replacement)) return unknown(typed, [replacement], "Run \"primitive --help\" to see the commands.", lookup);
|
|
86
|
+
for (let end = parts.length - 1; end > 0; end -= 1) {
|
|
87
|
+
const known = parts.slice(0, end).join(":");
|
|
88
|
+
const command = lookup.find(known);
|
|
89
|
+
const topic = lookup.hasSubcommands(known);
|
|
90
|
+
if (!command && !topic) continue;
|
|
91
|
+
const shown = `primitive ${parts.slice(0, end).join(" ")}`;
|
|
92
|
+
const rest = parts.slice(end).join(" ");
|
|
93
|
+
if (topic || !command) return unknown(typed, suggestions(parts.slice(end, end + 1), lookup, known), `Run "${shown} --help" to see the commands under it.`, lookup);
|
|
94
|
+
if (command.takesArguments) return {
|
|
95
|
+
code: "command_not_found",
|
|
96
|
+
message: `Unknown command "${parts.join(":")}". To pass "${rest}" to "${shown}", run "${shown} ${rest}".`
|
|
97
|
+
};
|
|
98
|
+
return {
|
|
99
|
+
code: "unexpected_argument",
|
|
100
|
+
message: `Unexpected argument "${rest}" for "${shown}", which takes no arguments. Run "${shown} --help" to see the flags it takes.`
|
|
101
|
+
};
|
|
102
|
+
}
|
|
103
|
+
return unknown(typed, suggestions(parts.slice(0, 2), lookup), "Run \"primitive --help\" to see the commands.", lookup);
|
|
104
|
+
}
|
|
105
|
+
/**
|
|
106
|
+
* Say what went wrong in plain words, and under --json as one JSON document
|
|
107
|
+
* on stdout like every other failure, instead of oclif's "command <id> not
|
|
108
|
+
* found" naming a command nobody typed.
|
|
109
|
+
*/
|
|
110
|
+
const hook = async (options) => {
|
|
111
|
+
const { config } = options;
|
|
112
|
+
const visible = visibleEntries(config.commands, config.topics);
|
|
113
|
+
const roots = visible.filter((id) => !id.includes(":"));
|
|
114
|
+
const error = commandNotFoundMessage(options.id, {
|
|
115
|
+
find: (id) => {
|
|
116
|
+
const command = config.findCommand(id);
|
|
117
|
+
return command ? { takesArguments: Object.keys(command.args ?? {}).length > 0 } : void 0;
|
|
118
|
+
},
|
|
119
|
+
hasSubcommands: (id) => config.commandIDs.some((other) => other.startsWith(`${id}:`)),
|
|
120
|
+
named: (word) => visible.filter((id) => id.split(":").at(-1) === word).sort(),
|
|
121
|
+
visible,
|
|
122
|
+
roots
|
|
123
|
+
});
|
|
124
|
+
if (jsonOutputRequested([...process.argv.slice(2), ...options.argv ?? []])) process.stdout.write(`${JSON.stringify({
|
|
125
|
+
error,
|
|
126
|
+
exit_code: 2
|
|
127
|
+
}, null, 2)}\n`);
|
|
128
|
+
else process.stderr.write(` › Error: ${error.message}\n`);
|
|
129
|
+
process.exitCode = 2;
|
|
130
|
+
return error.message;
|
|
131
|
+
};
|
|
132
|
+
export { commandNotFoundMessage, hook as default };
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
// src/oclif/command-stdin.ts
|
|
2
|
+
/** Only a command's explicit body, secret or hook reader may consume stdin. */
|
|
3
|
+
function ignoreArgumentStdin(command) {
|
|
4
|
+
for (const argument of Object.values(command.args ?? {})) argument.ignoreStdin = true;
|
|
5
|
+
}
|
|
6
|
+
const prerun = async ({ Command: command }) => {
|
|
7
|
+
ignoreArgumentStdin(command);
|
|
8
|
+
};
|
|
9
|
+
export { prerun as default, ignoreArgumentStdin };
|
package/dist/oclif/help.js
CHANGED
|
@@ -1,9 +1,12 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { n as HELP_GROUP_HEADERS, r as helpFlagGroup, t as HELP_GROUPS } from "../help-inputs-NGARVZL_.js";
|
|
2
|
+
import { CommandHelp, Help } from "@oclif/core";
|
|
2
3
|
// src/oclif/help.ts
|
|
3
4
|
const FULL_HELP_FLAG = "--help-full";
|
|
4
5
|
const NON_TTY_WIDTH = 100;
|
|
5
6
|
const MAX_FLAG_NAME_WIDTH = 32;
|
|
6
7
|
const EXAMPLE_LIMIT = 2;
|
|
8
|
+
const SHORT_HELP_MAX_LINES = 40;
|
|
9
|
+
const SHORT_HELP_MAX_BYTES = 3e3;
|
|
7
10
|
/**
|
|
8
11
|
* Commands whose `--help` text is read as a capability check by code already
|
|
9
12
|
* on users' machines: the bundled primitive-connect skill's preflight and
|
|
@@ -70,21 +73,61 @@ function formatShortHelp(command, { bin, subcommands = [], width }) {
|
|
|
70
73
|
const summary = render(command.summary ?? firstSentence(command.description ?? ""));
|
|
71
74
|
const flags = Object.entries(command.flags ?? {}).filter(([, flag]) => !flag.hidden).sort(([a], [b]) => a.localeCompare(b)).map(([name, flag]) => ({
|
|
72
75
|
name: flagName(name, flag),
|
|
76
|
+
group: flag.helpGroup ?? "command",
|
|
73
77
|
text: flagRule(flag) + render(firstSentence(flag.summary ?? flag.description ?? ""))
|
|
74
78
|
}));
|
|
75
79
|
const nameWidth = Math.min(MAX_FLAG_NAME_WIDTH, Math.max(0, ...flags.map(({ name }) => name.length)));
|
|
76
80
|
const listLine = (name, text) => clip(text ? ` ${name.padEnd(nameWidth)} ${text}` : ` ${name}`, width).slice(2);
|
|
77
81
|
const examples = (command.examples ?? []).flatMap((example) => exampleCommands(example, bin)).slice(0, EXAMPLE_LIMIT);
|
|
78
|
-
|
|
82
|
+
const described = (command.description ?? "").replaceAll(/\s+/g, " ").trim();
|
|
83
|
+
const more = summary !== "" && described.length > firstSentence(command.description ?? "").length;
|
|
84
|
+
const fullHelp = `${bin} ${command.id} ${FULL_HELP_FLAG}`;
|
|
85
|
+
const renderSections = (compactCommon) => HELP_GROUPS.flatMap((group) => {
|
|
86
|
+
const members = flags.filter((flag) => flag.group === group);
|
|
87
|
+
const rows = members.map(({ name, text }) => listLine(name, text));
|
|
88
|
+
if (group === "required") rows.push(...jsonInputRows(command.helpInputs).map(([name, text]) => listLine(name, text)));
|
|
89
|
+
const lines = section(HELP_GROUP_HEADERS[group], group === "common" && compactCommon ? compactFlagNames(members.map((flag) => flag.name), width - 2) : rows);
|
|
90
|
+
return group === "common" && compactCommon ? lines.slice(1) : lines;
|
|
91
|
+
});
|
|
92
|
+
const renderPage = (compactCommon) => [
|
|
79
93
|
...summary ? [summary] : [],
|
|
94
|
+
...more ? [`Summary only. Full description: \`${fullHelp}\`.`] : [],
|
|
80
95
|
...section("USAGE", [usageLine(command, bin)]),
|
|
81
|
-
...
|
|
96
|
+
...renderSections(compactCommon),
|
|
82
97
|
...section("COMMANDS", subcommands.map(({ id, summary: text }) => listLine(id, render(firstSentence(text ?? ""))))),
|
|
83
98
|
...section("EXAMPLES", examples),
|
|
84
|
-
"",
|
|
85
|
-
`Full help: ${bin} ${command.id} ${FULL_HELP_FLAG}`
|
|
99
|
+
...more ? [] : ["", `Full help: ${fullHelp}`]
|
|
86
100
|
].join("\n");
|
|
101
|
+
const page = renderPage(false);
|
|
102
|
+
return page.split("\n").length > SHORT_HELP_MAX_LINES || Buffer.byteLength(page) + 1 > SHORT_HELP_MAX_BYTES ? renderPage(true) : page;
|
|
87
103
|
}
|
|
104
|
+
function jsonInputRows(inputs) {
|
|
105
|
+
return (inputs?.requiredJsonFields ?? []).map((path) => [path, path === "$" ? "Request body: use command fields or JSON." : "JSON field: supply via --raw-body or --body-file."]);
|
|
106
|
+
}
|
|
107
|
+
function compactFlagNames(names, width) {
|
|
108
|
+
const lines = [];
|
|
109
|
+
for (const name of names) {
|
|
110
|
+
const last = lines.length - 1;
|
|
111
|
+
if (last < 0 || (lines[last]?.length ?? 0) + name.length + 2 > width) lines.push(name);
|
|
112
|
+
else lines[last] += ` ${name}`;
|
|
113
|
+
}
|
|
114
|
+
return lines;
|
|
115
|
+
}
|
|
116
|
+
var GroupedCommandHelp = class extends CommandHelp {
|
|
117
|
+
sections() {
|
|
118
|
+
return super.sections().map((section) => section.header !== "FLAGS" ? section : {
|
|
119
|
+
...section,
|
|
120
|
+
generate: ({ flags }) => HELP_GROUPS.map((group) => {
|
|
121
|
+
const rows = this.flags(flags.filter((flag) => flag.helpGroup === group)) ?? [];
|
|
122
|
+
if (group === "required") rows.push(...jsonInputRows(this.command.helpInputs));
|
|
123
|
+
return rows.length ? {
|
|
124
|
+
header: HELP_GROUP_HEADERS[group],
|
|
125
|
+
body: rows
|
|
126
|
+
} : void 0;
|
|
127
|
+
})
|
|
128
|
+
});
|
|
129
|
+
}
|
|
130
|
+
};
|
|
88
131
|
function terminalWidth() {
|
|
89
132
|
return process.stdout.isTTY && process.stdout.columns ? process.stdout.columns : NON_TTY_WIDTH;
|
|
90
133
|
}
|
|
@@ -94,13 +137,33 @@ function terminalWidth() {
|
|
|
94
137
|
*/
|
|
95
138
|
var PrimitiveHelp = class extends Help {
|
|
96
139
|
full = false;
|
|
140
|
+
CommandHelpClass = GroupedCommandHelp;
|
|
97
141
|
async showHelp(argv) {
|
|
98
142
|
this.full = argv.includes(FULL_HELP_FLAG);
|
|
99
143
|
await super.showHelp(argv);
|
|
100
144
|
}
|
|
101
145
|
async showCommandHelp(command) {
|
|
146
|
+
const loaded = await command.load();
|
|
147
|
+
const helpInputs = loaded.helpInputs;
|
|
148
|
+
const flagNames = new Set(Object.keys(command.flags ?? {}));
|
|
149
|
+
const flags = Object.fromEntries(Object.entries(command.flags ?? {}).map(([name, flag]) => {
|
|
150
|
+
const exactlyOne = loaded.flags?.[name]?.exactlyOne;
|
|
151
|
+
return [name, {
|
|
152
|
+
...flag,
|
|
153
|
+
exactlyOne,
|
|
154
|
+
helpGroup: helpFlagGroup(name, {
|
|
155
|
+
...flag,
|
|
156
|
+
exactlyOne
|
|
157
|
+
}, helpInputs, flagNames)
|
|
158
|
+
}];
|
|
159
|
+
}));
|
|
160
|
+
const grouped = {
|
|
161
|
+
...command,
|
|
162
|
+
flags,
|
|
163
|
+
helpInputs
|
|
164
|
+
};
|
|
102
165
|
if (this.full || FULL_HELP_COMMANDS.has(command.id)) {
|
|
103
|
-
await super.showCommandHelp(
|
|
166
|
+
await super.showCommandHelp(grouped);
|
|
104
167
|
return;
|
|
105
168
|
}
|
|
106
169
|
const depth = command.id.split(":").length;
|
|
@@ -108,14 +171,8 @@ var PrimitiveHelp = class extends Help {
|
|
|
108
171
|
id: sub.id.replaceAll(":", " "),
|
|
109
172
|
summary: sub.summary ?? sub.description
|
|
110
173
|
}));
|
|
111
|
-
const loaded = await command.load();
|
|
112
|
-
const flags = Object.fromEntries(Object.entries(command.flags ?? {}).map(([name, flag]) => [name, {
|
|
113
|
-
...flag,
|
|
114
|
-
exactlyOne: loaded.flags?.[name]?.exactlyOne
|
|
115
|
-
}]));
|
|
116
174
|
this.log(formatShortHelp({
|
|
117
|
-
...
|
|
118
|
-
flags,
|
|
175
|
+
...grouped,
|
|
119
176
|
id: command.id.replaceAll(":", " ")
|
|
120
177
|
}, {
|
|
121
178
|
bin: this.config.bin,
|