@ekanos/cli 0.28.1 → 0.30.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 +14 -5
- package/dist/auth/ekanos-api.d.ts +8 -1
- package/dist/auth/ekanos-api.js +14 -2
- package/dist/auth/ekanos-api.js.map +1 -1
- package/dist/bin.js +9 -1
- package/dist/bin.js.map +1 -1
- package/dist/commands/dev.js +5 -5
- package/dist/commands/dev.js.map +1 -1
- package/dist/commands/feedback.d.ts +38 -0
- package/dist/commands/feedback.js +234 -0
- package/dist/commands/feedback.js.map +1 -0
- package/dist/commands/publish.js +1 -1
- package/dist/commands/publish.js.map +1 -1
- package/dist/commands/sources.js +4 -1
- package/dist/commands/sources.js.map +1 -1
- package/dist/commands/status.js +1 -1
- package/dist/commands/status.js.map +1 -1
- package/dist/commands/validate.js +2 -2
- package/dist/commands/validate.js.map +1 -1
- package/dist/context.d.ts +11 -1
- package/dist/context.js +12 -1
- package/dist/context.js.map +1 -1
- package/dist/feedback-api.d.ts +70 -0
- package/dist/feedback-api.js +111 -0
- package/dist/feedback-api.js.map +1 -0
- package/dist/feedback-context.d.ts +31 -0
- package/dist/feedback-context.js +209 -0
- package/dist/feedback-context.js.map +1 -0
- package/dist/feedback-updates.d.ts +16 -0
- package/dist/feedback-updates.js +174 -0
- package/dist/feedback-updates.js.map +1 -0
- package/dist/http-trace.d.ts +19 -0
- package/dist/http-trace.js +47 -0
- package/dist/http-trace.js.map +1 -0
- package/dist/index.d.ts +18 -0
- package/dist/index.js +172 -13
- package/dist/index.js.map +1 -1
- package/dist/last-error.d.ts +17 -0
- package/dist/last-error.js +56 -0
- package/dist/last-error.js.map +1 -0
- package/dist/toolchain-api.d.ts +2 -1
- package/dist/toolchain-api.js +2 -2
- package/dist/toolchain-api.js.map +1 -1
- package/dist/toolchain-resolve.d.ts +4 -0
- package/dist/toolchain-resolve.js +11 -7
- package/dist/toolchain-resolve.js.map +1 -1
- package/dist/update-notice.d.ts +31 -8
- package/dist/update-notice.js +161 -31
- package/dist/update-notice.js.map +1 -1
- package/package.json +2 -2
- package/templates/AGENTS.md.tmpl +19 -0
- package/templates/claude-skill.md.tmpl +18 -0
- package/templates/experience/package.json.tmpl +4 -4
- package/templates/package.json.tmpl +4 -4
- package/templates/skills/build-agent/SKILL.md +18 -0
- package/templates/skills/build-integration/SKILL.md +18 -0
|
@@ -0,0 +1,174 @@
|
|
|
1
|
+
import * as fs from 'node:fs';
|
|
2
|
+
import * as path from 'node:path';
|
|
3
|
+
import { CredentialStore, normalizeHost, resolveEkanosHome, } from './auth/credential-store.js';
|
|
4
|
+
import { isPlaintextRemoteHost } from './auth/host-trust.js';
|
|
5
|
+
import { cliVersion, compareVersions } from './compatibility.js';
|
|
6
|
+
import { ackFeedbackUpdates, fetchFeedbackUpdates } from './feedback-api.js';
|
|
7
|
+
import { reachedWithSession } from './http-trace.js';
|
|
8
|
+
import { cli } from './invocation.js';
|
|
9
|
+
/**
|
|
10
|
+
* "The fix for your report shipped": told once, after an ordinary command.
|
|
11
|
+
*
|
|
12
|
+
* Same discipline as the toolchain notice (`update-notice.ts`): this must be
|
|
13
|
+
* INVISIBLE on failure and never slow a command. So it starts at the
|
|
14
|
+
* beginning of a run, alongside the command, against the one obvious host
|
|
15
|
+
* (`EKANOS_HOST`, else the only stored login), and at the end it speaks only
|
|
16
|
+
* if the command reached that host with a session AND the answer is already
|
|
17
|
+
* in. Otherwise it is abandoned (aborted) and asked again next run; nothing
|
|
18
|
+
* waits on it. It never refreshes a session (that would race the command's
|
|
19
|
+
* own refresh), asks at most every six hours, and every failure is silent.
|
|
20
|
+
*
|
|
21
|
+
* Each update is printed once. What was printed is remembered in
|
|
22
|
+
* `~/.ekanos/feedback-updates.json` (beside `update-check.json`, mode 0600)
|
|
23
|
+
* and acknowledged to the host at the start of a later run, so the
|
|
24
|
+
* acknowledgement never costs this run a round trip either.
|
|
25
|
+
*/
|
|
26
|
+
const FILENAME = 'feedback-updates.json';
|
|
27
|
+
const DIR_MODE = 0o700;
|
|
28
|
+
const FILE_MODE = 0o600;
|
|
29
|
+
export const FEEDBACK_UPDATES_TTL_MS = 6 * 60 * 60 * 1000;
|
|
30
|
+
const MAX_REMEMBERED = 200;
|
|
31
|
+
function statePath(env) {
|
|
32
|
+
return path.join(resolveEkanosHome(env), '.ekanos', FILENAME);
|
|
33
|
+
}
|
|
34
|
+
function readState(env) {
|
|
35
|
+
try {
|
|
36
|
+
const parsed = JSON.parse(fs.readFileSync(statePath(env), 'utf8'));
|
|
37
|
+
const candidate = parsed;
|
|
38
|
+
if (typeof candidate.checkedAt === 'number' &&
|
|
39
|
+
Array.isArray(candidate.shown) &&
|
|
40
|
+
Array.isArray(candidate.pendingAck)) {
|
|
41
|
+
return {
|
|
42
|
+
checkedAt: candidate.checkedAt,
|
|
43
|
+
shown: candidate.shown.filter((id) => typeof id === 'string'),
|
|
44
|
+
pendingAck: candidate.pendingAck.filter((id) => typeof id === 'string'),
|
|
45
|
+
};
|
|
46
|
+
}
|
|
47
|
+
}
|
|
48
|
+
catch (_a) {
|
|
49
|
+
// Missing or corrupt: start over. A courtesy, not a record.
|
|
50
|
+
}
|
|
51
|
+
return { checkedAt: 0, shown: [], pendingAck: [] };
|
|
52
|
+
}
|
|
53
|
+
function writeState(env, state) {
|
|
54
|
+
const target = statePath(env);
|
|
55
|
+
try {
|
|
56
|
+
fs.mkdirSync(path.dirname(target), { recursive: true, mode: DIR_MODE });
|
|
57
|
+
const tmp = `${target}.${process.pid}.tmp`;
|
|
58
|
+
fs.writeFileSync(tmp, JSON.stringify(state), { mode: FILE_MODE });
|
|
59
|
+
fs.renameSync(tmp, target);
|
|
60
|
+
}
|
|
61
|
+
catch (_a) {
|
|
62
|
+
// Best effort: the next run asks again.
|
|
63
|
+
}
|
|
64
|
+
}
|
|
65
|
+
/** The one host this check will try, with its stored session; else null. */
|
|
66
|
+
function obviousHostSession(env) {
|
|
67
|
+
var _a;
|
|
68
|
+
try {
|
|
69
|
+
const store = new CredentialStore({ home: resolveEkanosHome(env) });
|
|
70
|
+
const fromEnv = (_a = env.EKANOS_HOST) === null || _a === void 0 ? void 0 : _a.trim();
|
|
71
|
+
const hosts = store.hosts();
|
|
72
|
+
const host = fromEnv
|
|
73
|
+
? normalizeHost(fromEnv)
|
|
74
|
+
: hosts.length === 1
|
|
75
|
+
? hosts[0]
|
|
76
|
+
: null;
|
|
77
|
+
if (!host || isPlaintextRemoteHost(host))
|
|
78
|
+
return null;
|
|
79
|
+
const session = store.read(host);
|
|
80
|
+
return session ? { host, token: session.accessToken } : null;
|
|
81
|
+
}
|
|
82
|
+
catch (_b) {
|
|
83
|
+
return null;
|
|
84
|
+
}
|
|
85
|
+
}
|
|
86
|
+
export function startFeedbackUpdatesCheck(params) {
|
|
87
|
+
var _a;
|
|
88
|
+
const { env } = params;
|
|
89
|
+
if (env.EKANOS_NO_UPDATE_CHECK)
|
|
90
|
+
return null;
|
|
91
|
+
const target = obviousHostSession(env);
|
|
92
|
+
if (!target)
|
|
93
|
+
return null;
|
|
94
|
+
const now = (_a = params.now) !== null && _a !== void 0 ? _a : Date.now();
|
|
95
|
+
const state = readState(env);
|
|
96
|
+
const due = now - state.checkedAt >= FEEDBACK_UPDATES_TTL_MS;
|
|
97
|
+
if (!due && state.pendingAck.length === 0)
|
|
98
|
+
return null;
|
|
99
|
+
const controller = new AbortController();
|
|
100
|
+
let outcome = null;
|
|
101
|
+
const settled = (async () => {
|
|
102
|
+
const result = { acked: [], updates: null };
|
|
103
|
+
if (state.pendingAck.length > 0) {
|
|
104
|
+
try {
|
|
105
|
+
await ackFeedbackUpdates(target.host, target.token, state.pendingAck.slice(0, 50), controller.signal);
|
|
106
|
+
result.acked = state.pendingAck.slice(0, 50);
|
|
107
|
+
}
|
|
108
|
+
catch (_a) {
|
|
109
|
+
// Kept pending; acknowledged on a later run.
|
|
110
|
+
}
|
|
111
|
+
}
|
|
112
|
+
if (due) {
|
|
113
|
+
try {
|
|
114
|
+
result.updates = await fetchFeedbackUpdates(target.host, target.token, controller.signal);
|
|
115
|
+
}
|
|
116
|
+
catch (_b) {
|
|
117
|
+
// Silent: asked again on a later run.
|
|
118
|
+
}
|
|
119
|
+
}
|
|
120
|
+
outcome = result;
|
|
121
|
+
})().catch(() => undefined);
|
|
122
|
+
return {
|
|
123
|
+
settled,
|
|
124
|
+
finish(ctx) {
|
|
125
|
+
const ready = outcome;
|
|
126
|
+
controller.abort();
|
|
127
|
+
if (!ready)
|
|
128
|
+
return;
|
|
129
|
+
const next = {
|
|
130
|
+
checkedAt: state.checkedAt,
|
|
131
|
+
shown: state.shown,
|
|
132
|
+
pendingAck: state.pendingAck.filter((id) => !ready.acked.includes(id)),
|
|
133
|
+
};
|
|
134
|
+
// Speak only after a command that really used this host's session.
|
|
135
|
+
if (ready.updates && reachedWithSession(target.host)) {
|
|
136
|
+
next.checkedAt = now;
|
|
137
|
+
const fresh = ready.updates.filter((update) => !state.shown.includes(update.id));
|
|
138
|
+
for (const update of fresh) {
|
|
139
|
+
ctx.warn(describeUpdate(update, cliVersion(), cli()));
|
|
140
|
+
}
|
|
141
|
+
const ids = ready.updates.map((update) => update.id);
|
|
142
|
+
next.shown = [...state.shown, ...fresh.map((u) => u.id)].slice(-MAX_REMEMBERED);
|
|
143
|
+
next.pendingAck = [...new Set([...next.pendingAck, ...ids])].slice(-MAX_REMEMBERED);
|
|
144
|
+
}
|
|
145
|
+
if (next.checkedAt !== state.checkedAt ||
|
|
146
|
+
next.pendingAck.length !== state.pendingAck.length ||
|
|
147
|
+
next.shown.length !== state.shown.length) {
|
|
148
|
+
writeState(env, next);
|
|
149
|
+
}
|
|
150
|
+
},
|
|
151
|
+
};
|
|
152
|
+
}
|
|
153
|
+
/** Host text, made safe for a terminal line. */
|
|
154
|
+
function clean(text, max) {
|
|
155
|
+
// oxlint-disable-next-line no-control-regex
|
|
156
|
+
const flat = text.replace(/[\u0000-\u001f\u007f-\u009f]+/g, ' ').trim();
|
|
157
|
+
return flat.length > max ? `${flat.slice(0, max - 1)}…` : flat;
|
|
158
|
+
}
|
|
159
|
+
/** One stderr line about one shipped fix. */
|
|
160
|
+
export function describeUpdate(update, installed, invocation) {
|
|
161
|
+
const lead = `Your report #${update.number} (${clean(update.excerpt, 80)})`;
|
|
162
|
+
const note = update.note ? ` Note: ${clean(update.note, 300)}` : '';
|
|
163
|
+
if (update.fix.kind === 'host') {
|
|
164
|
+
return `${lead} is fixed on the host: retry.${note}`;
|
|
165
|
+
}
|
|
166
|
+
if (compareVersions(installed, update.fix.version) >= 0) {
|
|
167
|
+
return `${lead} is fixed in your version: retry.${note}`;
|
|
168
|
+
}
|
|
169
|
+
const upgrade = invocation === 'npx @ekanos/cli'
|
|
170
|
+
? '`npx @ekanos/cli@latest`'
|
|
171
|
+
: '`npm i -g @ekanos/cli@latest`';
|
|
172
|
+
return `${lead} is fixed in @ekanos/cli ${update.fix.version}: upgrade with ${upgrade}.${note}`;
|
|
173
|
+
}
|
|
174
|
+
//# sourceMappingURL=feedback-updates.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"feedback-updates.js","sourceRoot":"","sources":["../src/feedback-updates.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,MAAM,SAAS,CAAC;AAC9B,OAAO,KAAK,IAAI,MAAM,WAAW,CAAC;AAElC,OAAO,EACL,eAAe,EACf,aAAa,EACb,iBAAiB,GAClB,MAAM,yBAAyB,CAAC;AACjC,OAAO,EAAE,qBAAqB,EAAE,MAAM,mBAAmB,CAAC;AAC1D,OAAO,EAAE,UAAU,EAAE,eAAe,EAAE,MAAM,iBAAiB,CAAC;AAE9D,OAAO,EAAE,kBAAkB,EAAE,oBAAoB,EAAE,MAAM,gBAAgB,CAAC;AAC1E,OAAO,EAAE,kBAAkB,EAAE,MAAM,cAAc,CAAC;AAClD,OAAO,EAAmB,GAAG,EAAE,MAAM,cAAc,CAAC;AAEpD;;;;;;;;;;;;;;;;GAgBG;AAEH,MAAM,QAA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,CAAC,CAAC,CAAC,IAAI,CAAC;AACjE,CAAC;AAED,6CAA6C;AAC7C,MAAM,UAAU,cAAc,CAC5B,MAAsB,EACtB,SAAiB,EACjB,UAAsB;IAEtB,MAAM,IAAI,GAAG,gBAAgB,MAAM,CAAC,MAAM,KAAK,KAAK,CAAC,MAAM,CAAC,OAAO,EAAE,EAAE,CAAC,GAAG,CAAC;IAC5E,MAAM,IAAI,GAAG,MAAM,CAAC,IAAI,CAAC,CAAC,CAAC,UAAU,KAAK,CAAC,MAAM,CAAC,IAAI,EAAE,GAAG,CAAC,EAAE,CAAC,CAAC,CAAC,EAAE,CAAC;IACpE,IAAI,MAAM,CAAC,GAAG,CAAC,IAAI,KAAK,MAAM,EAAE,CAAC;QAC/B,OAAO,GAAG,IAAI,gCAAgC,IAAI,EAAE,CAAC;IACvD,CAAC;IACD,IAAI,eAAe,CAAC,SAAS,EAAE,MAAM,CAAC,GAAG,CAAC,OAAO,CAAC,IAAI,CAAC,EAAE,CAAC;QACxD,OAAO,GAAG,IAAI,oCAAoC,IAAI,EAAE,CAAC;IAC3D,CAAC;IACD,MAAM,OAAO,GACX,UAAU,KAAK,iBAAiB;QAC9B,CAAC,CAAC,0BAA0B;QAC5B,CAAC,CAAC,+BAA+B,CAAC;IACtC,OAAO,GAAG,IAAI,4BAA4B,MAAM,CAAC,GAAG,CAAC,OAAO,kBAAkB,OAAO,IAAI,IAAI,EAAE,CAAC;AAClG,CAAC","sourcesContent":["import type { FeedbackUpdate } from '@ekanos/integration-schema';\nimport * as fs from 'node:fs';\nimport * as path from 'node:path';\n\nimport {\n CredentialStore,\n normalizeHost,\n resolveEkanosHome,\n} from './auth/credential-store';\nimport { isPlaintextRemoteHost } from './auth/host-trust';\nimport { cliVersion, compareVersions } from './compatibility';\nimport type { CliContext } from './context';\nimport { ackFeedbackUpdates, fetchFeedbackUpdates } from './feedback-api';\nimport { reachedWithSession } from './http-trace';\nimport { type Invocation, cli } from './invocation';\n\n/**\n * \"The fix for your report shipped\": told once, after an ordinary command.\n *\n * Same discipline as the toolchain notice (`update-notice.ts`): this must be\n * INVISIBLE on failure and never slow a command. So it starts at the\n * beginning of a run, alongside the command, against the one obvious host\n * (`EKANOS_HOST`, else the only stored login), and at the end it speaks only\n * if the command reached that host with a session AND the answer is already\n * in. Otherwise it is abandoned (aborted) and asked again next run; nothing\n * waits on it. It never refreshes a session (that would race the command's\n * own refresh), asks at most every six hours, and every failure is silent.\n *\n * Each update is printed once. What was printed is remembered in\n * `~/.ekanos/feedback-updates.json` (beside `update-check.json`, mode 0600)\n * and acknowledged to the host at the start of a later run, so the\n * acknowledgement never costs this run a round trip either.\n */\n\nconst FILENAME = 'feedback-updates.json';\nconst DIR_MODE = 0o700;\nconst FILE_MODE = 0o600;\nexport const FEEDBACK_UPDATES_TTL_MS = 6 * 60 * 60 * 1000;\nconst MAX_REMEMBERED = 200;\n\ninterface State {\n checkedAt: number;\n /** Ids printed on this machine, so a failed ack never prints one twice. */\n shown: string[];\n /** Printed but not yet acknowledged to the host. */\n pendingAck: string[];\n}\n\ninterface Outcome {\n acked: string[];\n updates: FeedbackUpdate[] | null;\n}\n\nfunction statePath(env: Record<string, string | undefined>): string {\n return path.join(resolveEkanosHome(env), '.ekanos', FILENAME);\n}\n\nfunction readState(env: Record<string, string | undefined>): State {\n try {\n const parsed: unknown = JSON.parse(fs.readFileSync(statePath(env), 'utf8'));\n const candidate = parsed as Partial<State>;\n if (\n typeof candidate.checkedAt === 'number' &&\n Array.isArray(candidate.shown) &&\n Array.isArray(candidate.pendingAck)\n ) {\n return {\n checkedAt: candidate.checkedAt,\n shown: candidate.shown.filter((id) => typeof id === 'string'),\n pendingAck: candidate.pendingAck.filter((id) => typeof id === 'string'),\n };\n }\n } catch {\n // Missing or corrupt: start over. A courtesy, not a record.\n }\n return { checkedAt: 0, shown: [], pendingAck: [] };\n}\n\nfunction writeState(env: Record<string, string | undefined>, state: State) {\n const target = statePath(env);\n try {\n fs.mkdirSync(path.dirname(target), { recursive: true, mode: DIR_MODE });\n const tmp = `${target}.${process.pid}.tmp`;\n fs.writeFileSync(tmp, JSON.stringify(state), { mode: FILE_MODE });\n fs.renameSync(tmp, target);\n } catch {\n // Best effort: the next run asks again.\n }\n}\n\n/** The one host this check will try, with its stored session; else null. */\nfunction obviousHostSession(\n env: Record<string, string | undefined>,\n): { host: string; token: string } | null {\n try {\n const store = new CredentialStore({ home: resolveEkanosHome(env) });\n const fromEnv = env.EKANOS_HOST?.trim();\n const hosts = store.hosts();\n const host = fromEnv\n ? normalizeHost(fromEnv)\n : hosts.length === 1\n ? hosts[0]!\n : null;\n if (!host || isPlaintextRemoteHost(host)) return null;\n const session = store.read(host);\n return session ? { host, token: session.accessToken } : null;\n } catch {\n return null;\n }\n}\n\nexport interface FeedbackUpdatesCheck {\n /** Print what is ready, remember it, and let go of anything still in flight. */\n finish(ctx: CliContext): void;\n /** Settles when the background work does (tests). */\n readonly settled: Promise<void>;\n}\n\nexport function startFeedbackUpdatesCheck(params: {\n env: Record<string, string | undefined>;\n now?: number;\n}): FeedbackUpdatesCheck | null {\n const { env } = params;\n if (env.EKANOS_NO_UPDATE_CHECK) return null;\n\n const target = obviousHostSession(env);\n if (!target) return null;\n\n const now = params.now ?? Date.now();\n const state = readState(env);\n const due = now - state.checkedAt >= FEEDBACK_UPDATES_TTL_MS;\n if (!due && state.pendingAck.length === 0) return null;\n\n const controller = new AbortController();\n let outcome: Outcome | null = null;\n\n const settled = (async () => {\n const result: Outcome = { acked: [], updates: null };\n if (state.pendingAck.length > 0) {\n try {\n await ackFeedbackUpdates(\n target.host,\n target.token,\n state.pendingAck.slice(0, 50),\n controller.signal,\n );\n result.acked = state.pendingAck.slice(0, 50);\n } catch {\n // Kept pending; acknowledged on a later run.\n }\n }\n if (due) {\n try {\n result.updates = await fetchFeedbackUpdates(\n target.host,\n target.token,\n controller.signal,\n );\n } catch {\n // Silent: asked again on a later run.\n }\n }\n outcome = result;\n })().catch(() => undefined);\n\n return {\n settled,\n finish(ctx) {\n const ready = outcome;\n controller.abort();\n if (!ready) return;\n\n const next: State = {\n checkedAt: state.checkedAt,\n shown: state.shown,\n pendingAck: state.pendingAck.filter((id) => !ready.acked.includes(id)),\n };\n\n // Speak only after a command that really used this host's session.\n if (ready.updates && reachedWithSession(target.host)) {\n next.checkedAt = now;\n const fresh = ready.updates.filter(\n (update) => !state.shown.includes(update.id),\n );\n for (const update of fresh) {\n ctx.warn(describeUpdate(update, cliVersion(), cli()));\n }\n const ids = ready.updates.map((update) => update.id);\n next.shown = [...state.shown, ...fresh.map((u) => u.id)].slice(\n -MAX_REMEMBERED,\n );\n next.pendingAck = [...new Set([...next.pendingAck, ...ids])].slice(\n -MAX_REMEMBERED,\n );\n }\n\n if (\n next.checkedAt !== state.checkedAt ||\n next.pendingAck.length !== state.pendingAck.length ||\n next.shown.length !== state.shown.length\n ) {\n writeState(env, next);\n }\n },\n };\n}\n\n/** Host text, made safe for a terminal line. */\nfunction clean(text: string, max: number): string {\n // oxlint-disable-next-line no-control-regex\n const flat = text.replace(/[\\u0000-\\u001f\\u007f-\\u009f]+/g, ' ').trim();\n return flat.length > max ? `${flat.slice(0, max - 1)}…` : flat;\n}\n\n/** One stderr line about one shipped fix. */\nexport function describeUpdate(\n update: FeedbackUpdate,\n installed: string,\n invocation: Invocation,\n): string {\n const lead = `Your report #${update.number} (${clean(update.excerpt, 80)})`;\n const note = update.note ? ` Note: ${clean(update.note, 300)}` : '';\n if (update.fix.kind === 'host') {\n return `${lead} is fixed on the host: retry.${note}`;\n }\n if (compareVersions(installed, update.fix.version) >= 0) {\n return `${lead} is fixed in your version: retry.${note}`;\n }\n const upgrade =\n invocation === 'npx @ekanos/cli'\n ? '`npx @ekanos/cli@latest`'\n : '`npm i -g @ekanos/cli@latest`';\n return `${lead} is fixed in @ekanos/cli ${update.fix.version}: upgrade with ${upgrade}.${note}`;\n}\n"]}
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* What the host answered during this run, for a feedback report about it:
|
|
3
|
+
* the last response's status and request id, and which hosts this run
|
|
4
|
+
* reached with a session. Never a URL path, a query, a header value other
|
|
5
|
+
* than the request id, or a body.
|
|
6
|
+
*
|
|
7
|
+
* `request()` in `auth/ekanos-api.ts` records every host call here; `run()`
|
|
8
|
+
* resets it once per invocation.
|
|
9
|
+
*/
|
|
10
|
+
export interface HttpTraceEntry {
|
|
11
|
+
origin: string;
|
|
12
|
+
status: number;
|
|
13
|
+
requestId: string | null;
|
|
14
|
+
}
|
|
15
|
+
export declare function resetHttpTrace(): void;
|
|
16
|
+
export declare function recordHttpResponse(url: string, response: Response, withSession: boolean): void;
|
|
17
|
+
export declare function lastHttpResponse(): HttpTraceEntry | null;
|
|
18
|
+
/** Whether this run reached `host` with a session. */
|
|
19
|
+
export declare function reachedWithSession(host: string): boolean;
|
|
@@ -0,0 +1,47 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* What the host answered during this run, for a feedback report about it:
|
|
3
|
+
* the last response's status and request id, and which hosts this run
|
|
4
|
+
* reached with a session. Never a URL path, a query, a header value other
|
|
5
|
+
* than the request id, or a body.
|
|
6
|
+
*
|
|
7
|
+
* `request()` in `auth/ekanos-api.ts` records every host call here; `run()`
|
|
8
|
+
* resets it once per invocation.
|
|
9
|
+
*/
|
|
10
|
+
let last = null;
|
|
11
|
+
const authenticated = new Set();
|
|
12
|
+
export function resetHttpTrace() {
|
|
13
|
+
last = null;
|
|
14
|
+
authenticated.clear();
|
|
15
|
+
}
|
|
16
|
+
/** The request id a host gives, in the shape a report may carry. */
|
|
17
|
+
function requestIdOf(headers) {
|
|
18
|
+
var _a;
|
|
19
|
+
if (typeof (headers === null || headers === void 0 ? void 0 : headers.get) !== 'function')
|
|
20
|
+
return null;
|
|
21
|
+
const raw = (_a = headers.get('x-request-id')) !== null && _a !== void 0 ? _a : headers.get('x-vercel-id');
|
|
22
|
+
return raw && /^[A-Za-z0-9:_.-]{1,160}$/.test(raw) ? raw : null;
|
|
23
|
+
}
|
|
24
|
+
export function recordHttpResponse(url, response, withSession) {
|
|
25
|
+
let origin;
|
|
26
|
+
try {
|
|
27
|
+
origin = new URL(url).origin;
|
|
28
|
+
}
|
|
29
|
+
catch (_a) {
|
|
30
|
+
return;
|
|
31
|
+
}
|
|
32
|
+
last = {
|
|
33
|
+
origin,
|
|
34
|
+
status: response.status,
|
|
35
|
+
requestId: requestIdOf(response.headers),
|
|
36
|
+
};
|
|
37
|
+
if (withSession)
|
|
38
|
+
authenticated.add(origin.toLowerCase());
|
|
39
|
+
}
|
|
40
|
+
export function lastHttpResponse() {
|
|
41
|
+
return last;
|
|
42
|
+
}
|
|
43
|
+
/** Whether this run reached `host` with a session. */
|
|
44
|
+
export function reachedWithSession(host) {
|
|
45
|
+
return authenticated.has(host.toLowerCase());
|
|
46
|
+
}
|
|
47
|
+
//# sourceMappingURL=http-trace.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"http-trace.js","sourceRoot":"","sources":["../src/http-trace.ts"],"names":[],"mappings":"AAAA;;;;;;;;GAQG;AAQH,IAAI,IAAI,GAA0B,IAAI,CAAC;AACvC,MAAM,aAAa,GAAG,IAAI,GAAG,EAAU,CAAC;AAExC,MAAM,UAAU,cAAc;IAC5B,IAAI,GAAG,IAAI,CAAC;IACZ,aAAa,CAAC,KAAK,EAAE,CAAC;AACxB,CAAC;AAED,oEAAoE;AACpE,SAAS,WAAW,CAAC,OAA4B;;IAC/C,IAAI,QAAO,OAAO,aAAP,OAAO,uBAAP,OAAO,CAAE,GAAG,CAAA,KAAK,UAAU;QAAE,OAAO,IAAI,CAAC;IACpD,MAAM,GAAG,SAAG,OAAO,CAAC,GAAG,CAAC,cAAc,CAAC,mCAAI,OAAO,CAAC,GAAG,CAAC,aAAa,CAAC,CAAC;IACtE,OAAO,GAAG,IAAI,0BAA0B,CAAC,IAAI,CAAC,GAAG,CAAC,CAAC,CAAC,CAAC,GAAG,CAAC,CAAC,CAAC,IAAI,CAAC;AAClE,CAAC;AAED,MAAM,UAAU,kBAAkB,CAChC,GAAW,EACX,QAAkB,EAClB,WAAoB;IAEpB,IAAI,MAAc,CAAC;IACnB,IAAI,CAAC;QACH,MAAM,GAAG,IAAI,GAAG,CAAC,GAAG,CAAC,CAAC,MAAM,CAAC;IAC/B,CAAC;eAAO,CAAC;QACP,OAAO;IACT,CAAC;IACD,IAAI,GAAG;QACL,MAAM;QACN,MAAM,EAAE,QAAQ,CAAC,MAAM;QACvB,SAAS,EAAE,WAAW,CAAC,QAAQ,CAAC,OAAO,CAAC;KACzC,CAAC;IACF,IAAI,WAAW;QAAE,aAAa,CAAC,GAAG,CAAC,MAAM,CAAC,WAAW,EAAE,CAAC,CAAC;AAC3D,CAAC;AAED,MAAM,UAAU,gBAAgB;IAC9B,OAAO,IAAI,CAAC;AACd,CAAC;AAED,sDAAsD;AACtD,MAAM,UAAU,kBAAkB,CAAC,IAAY;IAC7C,OAAO,aAAa,CAAC,GAAG,CAAC,IAAI,CAAC,WAAW,EAAE,CAAC,CAAC;AAC/C,CAAC","sourcesContent":["/**\n * What the host answered during this run, for a feedback report about it:\n * the last response's status and request id, and which hosts this run\n * reached with a session. Never a URL path, a query, a header value other\n * than the request id, or a body.\n *\n * `request()` in `auth/ekanos-api.ts` records every host call here; `run()`\n * resets it once per invocation.\n */\n\nexport interface HttpTraceEntry {\n origin: string;\n status: number;\n requestId: string | null;\n}\n\nlet last: HttpTraceEntry | null = null;\nconst authenticated = new Set<string>();\n\nexport function resetHttpTrace(): void {\n last = null;\n authenticated.clear();\n}\n\n/** The request id a host gives, in the shape a report may carry. */\nfunction requestIdOf(headers: Headers | undefined): string | null {\n if (typeof headers?.get !== 'function') return null;\n const raw = headers.get('x-request-id') ?? headers.get('x-vercel-id');\n return raw && /^[A-Za-z0-9:_.-]{1,160}$/.test(raw) ? raw : null;\n}\n\nexport function recordHttpResponse(\n url: string,\n response: Response,\n withSession: boolean,\n): void {\n let origin: string;\n try {\n origin = new URL(url).origin;\n } catch {\n return;\n }\n last = {\n origin,\n status: response.status,\n requestId: requestIdOf(response.headers),\n };\n if (withSession) authenticated.add(origin.toLowerCase());\n}\n\nexport function lastHttpResponse(): HttpTraceEntry | null {\n return last;\n}\n\n/** Whether this run reached `host` with a session. */\nexport function reachedWithSession(host: string): boolean {\n return authenticated.has(host.toLowerCase());\n}\n"]}
|
package/dist/index.d.ts
CHANGED
|
@@ -50,6 +50,24 @@ export interface RunOptions {
|
|
|
50
50
|
* so a test can assert an exact `relativeTime` string deterministically.
|
|
51
51
|
*/
|
|
52
52
|
now?: Date;
|
|
53
|
+
/**
|
|
54
|
+
* Record a failed command in `~/.ekanos/last-error.json` for `ekanos
|
|
55
|
+
* feedback --last-error`. `bin.ts` turns it on; a test opts in with its
|
|
56
|
+
* own `EKANOS_HOME`, so no test writes to the real home.
|
|
57
|
+
*/
|
|
58
|
+
recordLastError?: boolean;
|
|
59
|
+
/**
|
|
60
|
+
* Check, in the background, for fixes to the caller's own reports that
|
|
61
|
+
* have shipped (`feedback-updates.ts`). `bin.ts` turns it on; a test opts
|
|
62
|
+
* in, so no other test's stubbed fetch sees the extra call.
|
|
63
|
+
*/
|
|
64
|
+
feedbackUpdates?: boolean;
|
|
65
|
+
/**
|
|
66
|
+
* Check, in the background, for a newer `@ekanos/cli` and announce it
|
|
67
|
+
* after the command (`update-notice.ts`). `bin.ts` turns it on; a test
|
|
68
|
+
* opts in, so no other test's stubbed fetch sees the extra calls.
|
|
69
|
+
*/
|
|
70
|
+
updateCheck?: boolean;
|
|
53
71
|
}
|
|
54
72
|
/**
|
|
55
73
|
* The single entry point. Resolves the agent-native envelope once, dispatches
|
package/dist/index.js
CHANGED
|
@@ -18,6 +18,7 @@ import { runApps } from './commands/apps.js';
|
|
|
18
18
|
import { runAudiences } from './commands/audiences.js';
|
|
19
19
|
import { runCatalog } from './commands/catalog.js';
|
|
20
20
|
import { runDev } from './commands/dev.js';
|
|
21
|
+
import { runFeedback } from './commands/feedback.js';
|
|
21
22
|
import { EXPERIENCE_COMMANDS } from './commands/index-experience.js';
|
|
22
23
|
import { runInit } from './commands/init.js';
|
|
23
24
|
import { runKnowledge } from './commands/knowledge.js';
|
|
@@ -39,12 +40,18 @@ import { runUse } from './commands/use.js';
|
|
|
39
40
|
import { runValidate } from './commands/validate.js';
|
|
40
41
|
import { runWhoami } from './commands/whoami.js';
|
|
41
42
|
import { runWorkflows } from './commands/workflows.js';
|
|
43
|
+
import { cliVersion } from './compatibility.js';
|
|
42
44
|
import { CliContext } from './context.js';
|
|
43
45
|
import { SDK_DOCS_URL, docsPage } from './docs-links.js';
|
|
44
46
|
import { preconditionError, toCliError, usageError } from './errors.js';
|
|
45
|
-
import {
|
|
47
|
+
import { commandPathOf, flagNamesOf } from './feedback-context.js';
|
|
48
|
+
import { startFeedbackUpdatesCheck, } from './feedback-updates.js';
|
|
49
|
+
import { lastHttpResponse, resetHttpTrace } from './http-trace.js';
|
|
50
|
+
import { cli, detectInvocation, setInvocation, } from './invocation.js';
|
|
51
|
+
import { writeLastError } from './last-error.js';
|
|
46
52
|
import { parseArgv } from './parse-argv.js';
|
|
47
53
|
import { unknownCommand } from './unknown-command.js';
|
|
54
|
+
import { startUpdateCheck } from './update-notice.js';
|
|
48
55
|
export { CliContext } from './context.js';
|
|
49
56
|
export { EXIT_CODES, ERROR_CODES } from './exit-codes.js';
|
|
50
57
|
const GLOBAL_SPECS = {
|
|
@@ -772,6 +779,23 @@ const COMMAND_SPECS = {
|
|
|
772
779
|
description: 'With --wait: give up after this many minutes (default 30; exit 11)',
|
|
773
780
|
},
|
|
774
781
|
},
|
|
782
|
+
feedback: {
|
|
783
|
+
host: HOST,
|
|
784
|
+
source: SOURCE,
|
|
785
|
+
dir: DIR,
|
|
786
|
+
kind: {
|
|
787
|
+
type: 'string',
|
|
788
|
+
description: 'bug|confusing|missing|other (default: bug with --last-error, else other)',
|
|
789
|
+
},
|
|
790
|
+
'last-error': {
|
|
791
|
+
type: 'boolean',
|
|
792
|
+
description: "Attach the last failed command's context: its path, flag names, codes, the host's status and request id",
|
|
793
|
+
},
|
|
794
|
+
command: {
|
|
795
|
+
type: 'string',
|
|
796
|
+
description: 'The ekanos command it is about; only its path and flag names are sent, never values',
|
|
797
|
+
},
|
|
798
|
+
},
|
|
775
799
|
upgrade: {
|
|
776
800
|
dir: DIR,
|
|
777
801
|
host: HOST,
|
|
@@ -822,6 +846,8 @@ const POSITIONAL_COMMANDS = {
|
|
|
822
846
|
workflows: ['subcommand', 'workflow-or-verb', 'id'],
|
|
823
847
|
// `triggers <key> add event <trigger-key>` is the longest form: five tokens.
|
|
824
848
|
agents: ['subcommand', 'key-or-path', 'action', 'arg', 'value'],
|
|
849
|
+
// `feedback "<message>"`, or `feedback list`.
|
|
850
|
+
feedback: ['message'],
|
|
825
851
|
};
|
|
826
852
|
for (const command of EXPERIENCE_COMMANDS) {
|
|
827
853
|
COMMAND_SPECS[command.name] = command.specs;
|
|
@@ -883,7 +909,10 @@ const USAGE = [
|
|
|
883
909
|
' roles delete <role> [--yes] (owner, admin and member are system',
|
|
884
910
|
" roles: never changed or deleted; a held role isn't deleted) |",
|
|
885
911
|
' people [--search <text>] [--page <n>] (everyone with access, one',
|
|
886
|
-
' row per person, with their teams and role on each)',
|
|
912
|
+
' row per person, with their teams and role on each) |',
|
|
913
|
+
' feedback [status|enable|disable] (whether "ekanos feedback"',
|
|
914
|
+
' reports reach Vastly from this Source; on unless its Source',
|
|
915
|
+
' admin turns it off; each change is in the Admin Audit log)',
|
|
887
916
|
" audiences A source's audiences, for its Source admin (they replace product",
|
|
888
917
|
' scopes): list | show <audience> | create <name> [--products a,b |',
|
|
889
918
|
' --all-entitled] [--description <text>] [--default] [--widgets',
|
|
@@ -1134,17 +1163,26 @@ const USAGE = [
|
|
|
1134
1163
|
' first, each package gated, artifacts under .ekanos/publish/)',
|
|
1135
1164
|
' upgrade Move this toolchain to a coherent target version, with',
|
|
1136
1165
|
' verify-and-rollback (--check --yes --no-verify --host <url>)',
|
|
1166
|
+
' feedback Report a problem to Vastly: "<what you tried, what happened,',
|
|
1167
|
+
' what you expected>" (or piped on stdin) [--kind',
|
|
1168
|
+
' bug|confusing|missing|other] [--last-error] (attach the last',
|
|
1169
|
+
" failed command: its path, flag names, codes, the host's status",
|
|
1170
|
+
' and request id) [--command "<the ekanos command>"] [--source',
|
|
1171
|
+
' <slug>] | list (your own reports, and any fix that shipped).',
|
|
1172
|
+
' Never sends argument or flag values, files or the environment;',
|
|
1173
|
+
' the message is redacted first. Nothing is ever sent on its own.',
|
|
1137
1174
|
'',
|
|
1138
1175
|
'Keeping the toolchain current:',
|
|
1139
|
-
'
|
|
1140
|
-
' background (
|
|
1141
|
-
'
|
|
1176
|
+
' Every command except init, login, logout and upgrade checks for a newer',
|
|
1177
|
+
' @ekanos/cli in the background (at most every 4 hours, never blocking,',
|
|
1178
|
+
' silenced by EKANOS_NO_UPDATE_CHECK) and says so once on stderr when one',
|
|
1179
|
+
' exists. Run "ekanos upgrade --check" any time a',
|
|
1142
1180
|
' validate finding smells like version skew (an unrecognized-key error you',
|
|
1143
1181
|
' are confident is correct) — it is read-only and safe to run freely. A',
|
|
1144
1182
|
' bare "ekanos upgrade" MUTATES the project (installs the target versions,',
|
|
1145
1183
|
' verifies with validate + the test script, rolls back on any failure).',
|
|
1146
1184
|
'',
|
|
1147
|
-
'Host resolution (logout, whoami, status, sources, catalog, apps, teams, names, reviewers, routes, agents, skills, knowledge, runs, approvals, workflows, use, publish, upgrade):',
|
|
1185
|
+
'Host resolution (logout, whoami, status, sources, catalog, apps, teams, names, reviewers, routes, agents, skills, knowledge, runs, approvals, workflows, use, publish, upgrade, feedback):',
|
|
1148
1186
|
' --host, else EKANOS_HOST, else the "host" field in ekanos.json, else the',
|
|
1149
1187
|
' sole stored login. "ekanos publish" saves host and source to ekanos.json.',
|
|
1150
1188
|
' "ekanos login" never reads ekanos.json for a host (--host, else',
|
|
@@ -1166,6 +1204,37 @@ const USAGE = [
|
|
|
1166
1204
|
' --version Print the CLI version',
|
|
1167
1205
|
' --help Show this help',
|
|
1168
1206
|
].join('\n');
|
|
1207
|
+
/** Commands whose failures are the partner's own code, not the CLI's. */
|
|
1208
|
+
const NOT_REPORTED_CODES = new Set(['validation', 'gate_failed']);
|
|
1209
|
+
/**
|
|
1210
|
+
* The commands after which a fix update may be shown: the ones that reach
|
|
1211
|
+
* the host with a session. Never the auth verbs, which change the session
|
|
1212
|
+
* the check would use.
|
|
1213
|
+
*/
|
|
1214
|
+
const NO_UPDATE_CHECK_COMMANDS = new Set([
|
|
1215
|
+
'init',
|
|
1216
|
+
'validate',
|
|
1217
|
+
'dev',
|
|
1218
|
+
'test',
|
|
1219
|
+
'login',
|
|
1220
|
+
'logout',
|
|
1221
|
+
'upgrade',
|
|
1222
|
+
]);
|
|
1223
|
+
/**
|
|
1224
|
+
* The commands the toolchain check (`update-notice.ts`) skips; every other
|
|
1225
|
+
* command runs it. Not `NO_UPDATE_CHECK_COMMANDS`: that set also skips the
|
|
1226
|
+
* commands that never reach the host with a session (`validate`, `dev`,
|
|
1227
|
+
* `test`), which the fix check needs and this one does not. `init` writes
|
|
1228
|
+
* the versions it scaffolds with; `login` and `logout` change the session
|
|
1229
|
+
* this check would use; `upgrade` resolves the target itself and is the fix.
|
|
1230
|
+
*/
|
|
1231
|
+
const NO_TOOLCHAIN_CHECK_COMMANDS = new Set([
|
|
1232
|
+
'init',
|
|
1233
|
+
'login',
|
|
1234
|
+
'logout',
|
|
1235
|
+
'upgrade',
|
|
1236
|
+
]);
|
|
1237
|
+
const REPORT_HINT = () => `${cli()} feedback --last-error "<what you were trying to do>"`;
|
|
1169
1238
|
/**
|
|
1170
1239
|
* The single entry point. Resolves the agent-native envelope once, dispatches
|
|
1171
1240
|
* to a verb, and guarantees exactly one terminal emission (success or error).
|
|
@@ -1173,17 +1242,83 @@ const USAGE = [
|
|
|
1173
1242
|
* `process.exit`, so this stays fully testable.
|
|
1174
1243
|
*/
|
|
1175
1244
|
export async function run(argv, options = {}) {
|
|
1176
|
-
var _a, _b
|
|
1245
|
+
var _a, _b;
|
|
1246
|
+
var _c, _d, _e, _f;
|
|
1177
1247
|
const jsonFlag = scanJsonFlag(argv);
|
|
1178
|
-
setInvocation((
|
|
1248
|
+
setInvocation((_c = options.invocation) !== null && _c !== void 0 ? _c : detectInvocation((_d = options.env) !== null && _d !== void 0 ? _d : process.env), COMMANDS);
|
|
1179
1249
|
const ctx = new CliContext({
|
|
1180
1250
|
jsonFlag,
|
|
1181
1251
|
stdout: options.stdout,
|
|
1182
1252
|
stderr: options.stderr,
|
|
1183
1253
|
env: options.env,
|
|
1184
1254
|
});
|
|
1185
|
-
const cwd = (
|
|
1186
|
-
const env = (
|
|
1255
|
+
const cwd = (_e = options.cwd) !== null && _e !== void 0 ? _e : process.cwd();
|
|
1256
|
+
const env = (_f = options.env) !== null && _f !== void 0 ? _f : process.env;
|
|
1257
|
+
resetHttpTrace();
|
|
1258
|
+
const trace = {
|
|
1259
|
+
command: null,
|
|
1260
|
+
positionals: [],
|
|
1261
|
+
reportHinted: false,
|
|
1262
|
+
updates: null,
|
|
1263
|
+
toolchain: null,
|
|
1264
|
+
};
|
|
1265
|
+
const exitCode = await dispatch(argv, options, ctx, cwd, env, trace);
|
|
1266
|
+
if (exitCode !== 0 && trace.command !== 'feedback') {
|
|
1267
|
+
afterFailure(argv, options, ctx, env, trace, exitCode);
|
|
1268
|
+
}
|
|
1269
|
+
try {
|
|
1270
|
+
(_a = trace.toolchain) === null || _a === void 0 ? void 0 : _a.finish(ctx);
|
|
1271
|
+
}
|
|
1272
|
+
catch (_g) {
|
|
1273
|
+
// A courtesy: it never changes how a run ends.
|
|
1274
|
+
}
|
|
1275
|
+
try {
|
|
1276
|
+
(_b = trace.updates) === null || _b === void 0 ? void 0 : _b.finish(ctx);
|
|
1277
|
+
}
|
|
1278
|
+
catch (_h) {
|
|
1279
|
+
// A courtesy: it never changes how a run ends.
|
|
1280
|
+
}
|
|
1281
|
+
return exitCode;
|
|
1282
|
+
}
|
|
1283
|
+
/**
|
|
1284
|
+
* A command failed: tell an agent how to report it (the `claude-code-hint`
|
|
1285
|
+
* line, written only to agents and with `--json`, as every hint is), and
|
|
1286
|
+
* remember the failure for `ekanos feedback --last-error`. Neither sends
|
|
1287
|
+
* anything anywhere.
|
|
1288
|
+
*/
|
|
1289
|
+
function afterFailure(argv, options, ctx, env, trace, exitCode) {
|
|
1290
|
+
var _a;
|
|
1291
|
+
var _b, _c, _d, _e;
|
|
1292
|
+
const code = (_b = (_a = ctx.failure) === null || _a === void 0 ? void 0 : _a.code) !== null && _b !== void 0 ? _b : null;
|
|
1293
|
+
if (!trace.reportHinted &&
|
|
1294
|
+
trace.command !== 'test' &&
|
|
1295
|
+
!(code && NOT_REPORTED_CODES.has(code))) {
|
|
1296
|
+
ctx.emitClaudeCodeHint({
|
|
1297
|
+
tool: 'ekanos',
|
|
1298
|
+
error: code !== null && code !== void 0 ? code : 'failed',
|
|
1299
|
+
exitCode,
|
|
1300
|
+
report: REPORT_HINT(),
|
|
1301
|
+
});
|
|
1302
|
+
}
|
|
1303
|
+
if (!options.recordLastError)
|
|
1304
|
+
return;
|
|
1305
|
+
const http = lastHttpResponse();
|
|
1306
|
+
writeLastError(env, {
|
|
1307
|
+
failedAt: new Date().toISOString(),
|
|
1308
|
+
cliVersion: cliVersion(),
|
|
1309
|
+
host: (_c = http === null || http === void 0 ? void 0 : http.origin) !== null && _c !== void 0 ? _c : null,
|
|
1310
|
+
command: trace.command
|
|
1311
|
+
? commandPathOf([trace.command, ...trace.positionals])
|
|
1312
|
+
: null,
|
|
1313
|
+
flags: flagNamesOf(argv),
|
|
1314
|
+
errorCode: code && /^[a-z_]{1,40}$/.test(code) ? code : null,
|
|
1315
|
+
exitCode: Math.max(0, Math.min(255, exitCode)),
|
|
1316
|
+
httpStatus: (_d = http === null || http === void 0 ? void 0 : http.status) !== null && _d !== void 0 ? _d : null,
|
|
1317
|
+
requestId: (_e = http === null || http === void 0 ? void 0 : http.requestId) !== null && _e !== void 0 ? _e : null,
|
|
1318
|
+
});
|
|
1319
|
+
}
|
|
1320
|
+
async function dispatch(argv, options, ctx, cwd, env, trace) {
|
|
1321
|
+
var _a, _b;
|
|
1187
1322
|
try {
|
|
1188
1323
|
// `--version` is global and verb-independent, so it is answered before the
|
|
1189
1324
|
// command is even resolved: `ekanos --version` and `ekanos validate
|
|
@@ -1203,20 +1338,31 @@ export async function run(argv, options = {}) {
|
|
|
1203
1338
|
error: 'unknown-command',
|
|
1204
1339
|
commands: COMMANDS,
|
|
1205
1340
|
help: 'ekanos --help',
|
|
1341
|
+
report: REPORT_HINT(),
|
|
1206
1342
|
});
|
|
1343
|
+
trace.reportHinted = true;
|
|
1207
1344
|
throw usageError(`Unknown command or flag "${argv[0]}".`, `Run one of: ${COMMANDS.join(', ')}. See "ekanos --help".`);
|
|
1208
1345
|
}
|
|
1209
1346
|
if (!COMMANDS.includes(command)) {
|
|
1210
1347
|
const unknown = unknownCommand(command, rest, COMMANDS);
|
|
1211
|
-
ctx.emitClaudeCodeHint(Object.assign(Object.assign({ tool: 'ekanos', error: 'unknown-command', given: command }, (unknown.suggestion ? { suggestion: unknown.suggestion } : {})), { commands: COMMANDS, help: 'ekanos --help' }));
|
|
1348
|
+
ctx.emitClaudeCodeHint(Object.assign(Object.assign({ tool: 'ekanos', error: 'unknown-command', given: command }, (unknown.suggestion ? { suggestion: unknown.suggestion } : {})), { commands: COMMANDS, help: 'ekanos --help', report: REPORT_HINT() }));
|
|
1349
|
+
trace.reportHinted = true;
|
|
1212
1350
|
throw unknown.error;
|
|
1213
1351
|
}
|
|
1352
|
+
trace.command = command;
|
|
1214
1353
|
const specs = Object.assign(Object.assign({}, GLOBAL_SPECS), COMMAND_SPECS[command]);
|
|
1215
1354
|
const parsed = parseArgv(rest, specs);
|
|
1355
|
+
trace.positionals = parsed.positionals;
|
|
1216
1356
|
if (parsed.flags.help === true) {
|
|
1217
1357
|
return emitCommandHelp(ctx, command);
|
|
1218
1358
|
}
|
|
1219
|
-
|
|
1359
|
+
if (options.updateCheck && !NO_TOOLCHAIN_CHECK_COMMANDS.has(command)) {
|
|
1360
|
+
trace.toolchain = startUpdateCheck({ env });
|
|
1361
|
+
}
|
|
1362
|
+
if (options.feedbackUpdates && !NO_UPDATE_CHECK_COMMANDS.has(command)) {
|
|
1363
|
+
trace.updates = startFeedbackUpdatesCheck({ env });
|
|
1364
|
+
}
|
|
1365
|
+
const positionalNames = (_a = POSITIONAL_COMMANDS[command]) !== null && _a !== void 0 ? _a : [];
|
|
1220
1366
|
if (positionalNames.length === 0 && parsed.positionals.length > 0) {
|
|
1221
1367
|
throw usageError(`"${command}" takes no positional arguments (got "${parsed.positionals[0]}").`, `Pass options as flags, e.g. "--dir <path>". See "ekanos ${command} --help".`);
|
|
1222
1368
|
}
|
|
@@ -1227,7 +1373,7 @@ export async function run(argv, options = {}) {
|
|
|
1227
1373
|
`argument${positionalNames.length === 1 ? '' : 's'} (${usage}), ` +
|
|
1228
1374
|
`got ${parsed.positionals.length}.`, `e.g. "ekanos ${command} ${usage}". See "ekanos ${command} --help".`);
|
|
1229
1375
|
}
|
|
1230
|
-
const dir = (
|
|
1376
|
+
const dir = (_b = parsed.flags.dir) !== null && _b !== void 0 ? _b : cwd;
|
|
1231
1377
|
if (REPO_ROOT_REFUSED.has(command) && isRepoRoot(path.resolve(dir))) {
|
|
1232
1378
|
throw preconditionError(`"${command}" works on one package, and ${dir} is a repo root.`, `Run it inside a package (cd integrations/<slug> or cd experiences/<slug>), or use "ekanos publish --all" for the whole repo.`);
|
|
1233
1379
|
}
|
|
@@ -1539,6 +1685,19 @@ export async function run(argv, options = {}) {
|
|
|
1539
1685
|
stdinIsTTY: options.stdinIsTTY,
|
|
1540
1686
|
confirm: options.confirm,
|
|
1541
1687
|
});
|
|
1688
|
+
case 'feedback':
|
|
1689
|
+
return await runFeedback(ctx, {
|
|
1690
|
+
host: parsed.flags.host,
|
|
1691
|
+
source: parsed.flags.source,
|
|
1692
|
+
positionals: parsed.positionals,
|
|
1693
|
+
kind: parsed.flags.kind,
|
|
1694
|
+
lastError: parsed.flags['last-error'] === true,
|
|
1695
|
+
command: parsed.flags.command,
|
|
1696
|
+
dir,
|
|
1697
|
+
env,
|
|
1698
|
+
stdinIsTTY: options.stdinIsTTY,
|
|
1699
|
+
readStdin: options.readStdin,
|
|
1700
|
+
});
|
|
1542
1701
|
case 'upgrade':
|
|
1543
1702
|
return await runUpgrade(ctx, {
|
|
1544
1703
|
dir,
|