primcli 3.0.0-preview.2 → 3.0.0-preview.4

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.
@@ -1,3 +1,4 @@
1
+ import { Flags } from "@oclif/core";
1
2
  import { format } from "node:util";
2
3
  // src/oclif/json-output.ts
3
4
  /**
@@ -22,6 +23,11 @@ import { format } from "node:util";
22
23
  * line per result on stdout, and on failure one more JSON line carrying
23
24
  * `error` and `exit_code`.
24
25
  */
26
+ /**
27
+ * The `--json` flag for a hand-rolled command whose output is already JSON.
28
+ * Declaring it is enough: the registry guards every command that has it.
29
+ */
30
+ const JSON_OUTPUT_FLAG = Flags.boolean({ description: "Print exactly one JSON document on stdout, on success and on failure, and nothing on stderr. A failure prints the error with exit_code." });
25
31
  const GUARDED = Symbol.for("primitive.cli.jsonOutputGuard");
26
32
  /** True when `--json` appears before any `--` separator. */
27
33
  function jsonOutputRequested(argv) {
@@ -318,4 +324,4 @@ function guardJsonOutputCommands(commands) {
318
324
  if (flags && "json" in flags || enableJsonFlag === true) guardJsonOutput(command);
319
325
  }
320
326
  }
321
- export { jsonOutputRequested as n, runStreamingJson as r, guardJsonOutputCommands as t };
327
+ export { runStreamingJson as i, guardJsonOutputCommands as n, jsonOutputRequested as r, JSON_OUTPUT_FLAG as t };
@@ -1,12 +1,12 @@
1
1
  import { B as parseOwnerMemberAddress, F as agentProfilesDirectory, I as connectedAgentIdentity, L as connectedApiBaseUrl, M as AgentConnectionSetupError, N as agentProfileDirectory, P as agentProfileName, R as loadConnectedAgentProfile, U as saveConnectedAgentProfile, V as profileAlreadyConnectedMessage, W as PrimitiveApiClient, b as loadCliCredentials, j as AGENT_PROFILE_ENV, z as parseConnectedAgentProfile } from "./cli-config-Ms_0vNjq.js";
2
- import { $t as listAgentContacts, Cn as putAgentContact, Fn as searchEmails, Lt as getEmail, Mt as getAgentContactPolicy, Nt as getContact, Qt as listAgentConnections, Rn as sendEmail, Tn as putContact, Xt as inviteAgentConnection, _n as listSentEmails, bt as deleteContact, in as listDomains, ir as __exportAll, tn as listContacts, wn as putAgentContactPolicy, yt as deleteAgentContact } from "./repeats-Dj_o6c-X-BzXj5ICh.js";
3
- import { Ft as refuseOrgSelectionForProfile, Pt as refreshStoredCliCredentials, St as detectAgentRuntime, _t as defaultConnectionName, ht as cliInvocation } from "./api-command-B37DPKFA.js";
2
+ import { $t as listAgentConnections, Dn as putAgentContactPolicy, En as putAgentContact, Nt as getAgentContactPolicy, On as putContact, Pt as getContact, Rn as searchEmails, Rt as getEmail, Vn as sendEmail, Zt as inviteAgentConnection, an as listDomains, bn as listSentEmails, bt as deleteAgentContact, en as listAgentContacts, nn as listContacts, sr as __exportAll, xt as deleteContact } from "./repeats-Dj_o6c-X-BwGkVE7e.js";
3
+ import { $t as refuseOrgSelectionForProfile, It as detectAgentRuntime, Qt as refreshStoredCliCredentials, jt as defaultConnectionName, kt as cliInvocation } from "./api-command-BFfgKPTp.js";
4
4
  import { _ as acquireListenLock, b as listenLockHeld, c as mailTime, d as readMailJson, f as removeMailFile, g as ListenStateError, h as writeMailJson, i as mailId, l as privateMailDirectory, o as mailObject, p as syncMailDirectory, r as mailAddress, s as mailString } from "./shared-mail-files-BAQSGxxz.js";
5
- import { S as readBundledConnectSkill, a as NotificationRetryError, d as SESSION_UUID, f as connectNativeSession, m as NativeSessionDisconnectedError, p as defaultSessionSocket, t as notificationScope, y as installConnectSkill } from "./notify-session-Bo8WgG3q.js";
5
+ import { S as readBundledConnectSkill, a as NotificationRetryError, d as SESSION_UUID, f as connectNativeSession, m as NativeSessionDisconnectedError, p as defaultSessionSocket, t as notificationScope, y as installConnectSkill } from "./notify-session-aMGIFmeu.js";
6
6
  import { l as stopBackgroundListen, r as backgroundListenStatus } from "./listen-background-C0F9gNDD.js";
7
7
  import { t as readSharedMailOwner } from "./shared-mail-watch-BAPMsFNv.js";
8
8
  import { withoutOrgSelection } from "./oclif/global-org-flag.js";
9
- import { o as scopedChatSenderTrust } from "./scoped-chat-TJlyUTi7.js";
9
+ import { o as scopedChatSenderTrust } from "./scoped-chat-B-J3sdNS.js";
10
10
  import { accessSync, chmodSync, closeSync, constants, copyFileSync, existsSync, fsyncSync, lstatSync, mkdirSync, openSync, readFileSync, readdirSync, realpathSync, renameSync, rmSync, rmdirSync, statSync, unlinkSync, writeFileSync } from "node:fs";
11
11
  import { createHash, randomUUID } from "node:crypto";
12
12
  import { basename, delimiter, dirname, isAbsolute, join, resolve } from "node:path";
@@ -1,5 +1,5 @@
1
- import { Dt as downloadEmailAttachmentPart, J as parseWebhookEvent, K as isEmailReceivedEvent, c as classifySignalContent, q as isTrustedSender } from "./repeats-Dj_o6c-X-BzXj5ICh.js";
2
- import { E as wakeReadCommand, T as skillFirstLine, V as wakeInteractionSentence } from "./api-command-B37DPKFA.js";
1
+ import { J as isTrustedSender, Ot as downloadEmailAttachmentPart, Y as parseWebhookEvent, c as classifySignalContent, q as isEmailReceivedEvent } from "./repeats-Dj_o6c-X-BwGkVE7e.js";
2
+ import { B as wakeReadCommand, tt as wakeInteractionSentence, z as skillFirstLine } from "./api-command-BFfgKPTp.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";
@@ -1,8 +1,8 @@
1
- import { qt as getSentEmail } from "../repeats-Dj_o6c-X-BzXj5ICh.js";
2
- import { Mt as createAuthenticatedCliApiClient, x as readThreadContext } from "../api-command-B37DPKFA.js";
1
+ import { Jt as getSentEmail } from "../repeats-Dj_o6c-X-BwGkVE7e.js";
2
+ import { F as readThreadContext, Xt as createAuthenticatedCliApiClient } from "../api-command-BFfgKPTp.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-BO93dM2Q.js";
5
+ import { t as sendSignal } from "../signal-command-DEArW9g5.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-TJlyUTi7.js";
1
+ import { n as isPlainChatReply, o as scopedChatSenderTrust } from "../scoped-chat-B-J3sdNS.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,62 @@
1
+ import { r as jsonOutputRequested } from "../json-output-DWrJMakZ.js";
2
+ // src/oclif/command-not-found.ts
3
+ /**
4
+ * What to say for an id no command has. oclif joins every word before the
5
+ * first flag into the id while no command along the way takes arguments, so
6
+ * `emails list foo` arrives as `emails:list:foo`: when a leading part is a
7
+ * real command, the rest was an argument it does not take.
8
+ */
9
+ function commandNotFoundMessage(id, lookup) {
10
+ const parts = id.split(":");
11
+ const typed = `primitive ${parts.join(" ")}`;
12
+ for (let end = parts.length - 1; end > 0; end -= 1) {
13
+ const known = parts.slice(0, end).join(":");
14
+ const command = lookup.find(known);
15
+ const topic = lookup.hasSubcommands(known);
16
+ if (!command && !topic) continue;
17
+ const shown = `primitive ${parts.slice(0, end).join(" ")}`;
18
+ const rest = parts.slice(end).join(" ");
19
+ if (topic || !command) return {
20
+ code: "command_not_found",
21
+ message: `Unknown command "${typed}". Run "${shown} --help" to see the commands under it.`
22
+ };
23
+ if (command.takesArguments) return {
24
+ code: "command_not_found",
25
+ message: `Unknown command "${parts.join(":")}". To pass "${rest}" to "${shown}", run "${shown} ${rest}".`
26
+ };
27
+ return {
28
+ code: "unexpected_argument",
29
+ message: `Unexpected argument "${rest}" for "${shown}", which takes no arguments. Run "${shown} --help" to see the flags it takes.`
30
+ };
31
+ }
32
+ return {
33
+ code: "command_not_found",
34
+ message: `Unknown command "${typed}". Run "primitive --help" to see the commands.`
35
+ };
36
+ }
37
+ /**
38
+ * Say what went wrong in plain words, and under --json as one JSON document
39
+ * on stdout like every other failure, instead of oclif's "command <id> not
40
+ * found" naming a command nobody typed.
41
+ */
42
+ const hook = async (options) => {
43
+ const { config } = options;
44
+ const { code, message } = commandNotFoundMessage(options.id, {
45
+ find: (id) => {
46
+ const command = config.findCommand(id);
47
+ return command ? { takesArguments: Object.keys(command.args ?? {}).length > 0 } : void 0;
48
+ },
49
+ hasSubcommands: (id) => config.commandIDs.some((other) => other.startsWith(`${id}:`))
50
+ });
51
+ if (jsonOutputRequested([...process.argv.slice(2), ...options.argv ?? []])) process.stdout.write(`${JSON.stringify({
52
+ error: {
53
+ code,
54
+ message
55
+ },
56
+ exit_code: 2
57
+ }, null, 2)}\n`);
58
+ else process.stderr.write(` › Error: ${message}\n`);
59
+ process.exitCode = 2;
60
+ return message;
61
+ };
62
+ export { commandNotFoundMessage, hook as default };