@ekanos/cli 0.28.1 → 0.29.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 +5 -1
- 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 +4 -1
- package/dist/bin.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/sources.js +4 -1
- package/dist/commands/sources.js.map +1 -1
- package/dist/context.d.ts +10 -0
- package/dist/context.js +10 -0
- 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 +12 -0
- package/dist/index.js +143 -10
- 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/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,209 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* What `ekanos feedback` may say about a command: its path in the CLI's own
|
|
3
|
+
* words and the NAMES of its flags. Never an argument, a flag's value, a
|
|
4
|
+
* file's contents or an environment value — this module is the one place a
|
|
5
|
+
* command line is reduced to that, for a recorded failure and for
|
|
6
|
+
* `--command` alike.
|
|
7
|
+
*/
|
|
8
|
+
/**
|
|
9
|
+
* The words a command path is made of: the CLI's commands and the verbs and
|
|
10
|
+
* areas under them. A token that is not one of these ends the path, so a
|
|
11
|
+
* team, a product, an email or a key never joins it. A slug that happens to
|
|
12
|
+
* be one of these words says nothing more than the word.
|
|
13
|
+
*/
|
|
14
|
+
const COMMAND_WORDS = new Set([
|
|
15
|
+
// Commands.
|
|
16
|
+
'init',
|
|
17
|
+
'validate',
|
|
18
|
+
'dev',
|
|
19
|
+
'test',
|
|
20
|
+
'login',
|
|
21
|
+
'logout',
|
|
22
|
+
'whoami',
|
|
23
|
+
'status',
|
|
24
|
+
'sources',
|
|
25
|
+
'catalog',
|
|
26
|
+
'apps',
|
|
27
|
+
'teams',
|
|
28
|
+
'reviewers',
|
|
29
|
+
'routes',
|
|
30
|
+
'agents',
|
|
31
|
+
'skills',
|
|
32
|
+
'knowledge',
|
|
33
|
+
'runs',
|
|
34
|
+
'approvals',
|
|
35
|
+
'workflows',
|
|
36
|
+
'use',
|
|
37
|
+
'publish',
|
|
38
|
+
'upgrade',
|
|
39
|
+
'feedback',
|
|
40
|
+
// Areas and verbs.
|
|
41
|
+
'add',
|
|
42
|
+
'app',
|
|
43
|
+
'apply',
|
|
44
|
+
'approve',
|
|
45
|
+
'archive',
|
|
46
|
+
'attach',
|
|
47
|
+
'cancel',
|
|
48
|
+
'confirm',
|
|
49
|
+
'connect',
|
|
50
|
+
'create',
|
|
51
|
+
'default',
|
|
52
|
+
'define',
|
|
53
|
+
'delete',
|
|
54
|
+
'detach',
|
|
55
|
+
'disable',
|
|
56
|
+
'disconnect',
|
|
57
|
+
'edit',
|
|
58
|
+
'effect',
|
|
59
|
+
'enable',
|
|
60
|
+
'events',
|
|
61
|
+
'groups',
|
|
62
|
+
'health',
|
|
63
|
+
'invite',
|
|
64
|
+
'leave',
|
|
65
|
+
'links',
|
|
66
|
+
'list',
|
|
67
|
+
'llm-key',
|
|
68
|
+
'mcp',
|
|
69
|
+
'members',
|
|
70
|
+
'options',
|
|
71
|
+
'overrides',
|
|
72
|
+
'people',
|
|
73
|
+
'pin',
|
|
74
|
+
'policy',
|
|
75
|
+
'products',
|
|
76
|
+
'pull',
|
|
77
|
+
'push',
|
|
78
|
+
'refresh',
|
|
79
|
+
'reject',
|
|
80
|
+
'remove',
|
|
81
|
+
'rename',
|
|
82
|
+
'replay',
|
|
83
|
+
'resend',
|
|
84
|
+
'role',
|
|
85
|
+
'roles',
|
|
86
|
+
'rollback',
|
|
87
|
+
'rotate',
|
|
88
|
+
'scope',
|
|
89
|
+
'scopes',
|
|
90
|
+
'search',
|
|
91
|
+
'set',
|
|
92
|
+
'show',
|
|
93
|
+
'start',
|
|
94
|
+
'tags',
|
|
95
|
+
'token',
|
|
96
|
+
'triggers',
|
|
97
|
+
'unarchive',
|
|
98
|
+
'unpin',
|
|
99
|
+
'unrouted',
|
|
100
|
+
'unset',
|
|
101
|
+
'update',
|
|
102
|
+
'webhook',
|
|
103
|
+
'workspace',
|
|
104
|
+
]);
|
|
105
|
+
const MAX_PATH_WORDS = 4;
|
|
106
|
+
const FLAG_NAME = /^--[a-z0-9][a-z0-9-]{0,47}$/;
|
|
107
|
+
/**
|
|
108
|
+
* `teams connect` from `["teams", "connect", "acme", "linear"]`: the command
|
|
109
|
+
* and the words after it that are the CLI's own, up to the first that is not.
|
|
110
|
+
*/
|
|
111
|
+
export function commandPathOf(tokens) {
|
|
112
|
+
const words = [];
|
|
113
|
+
for (const token of tokens) {
|
|
114
|
+
if (words.length === MAX_PATH_WORDS || !COMMAND_WORDS.has(token))
|
|
115
|
+
break;
|
|
116
|
+
words.push(token);
|
|
117
|
+
}
|
|
118
|
+
return words.length > 0 ? words.join(' ') : null;
|
|
119
|
+
}
|
|
120
|
+
/**
|
|
121
|
+
* The names of the flags in an argv, in order, once each: `--set a=b` gives
|
|
122
|
+
* `--set`, `--source=acme` gives `--source`. A token after `--` is the
|
|
123
|
+
* passthrough's, not a flag of this CLI, and is never read.
|
|
124
|
+
*/
|
|
125
|
+
export function flagNamesOf(argv) {
|
|
126
|
+
const names = [];
|
|
127
|
+
for (const token of argv) {
|
|
128
|
+
if (token === '--')
|
|
129
|
+
break;
|
|
130
|
+
if (!token.startsWith('--'))
|
|
131
|
+
continue;
|
|
132
|
+
const name = token.split('=')[0].toLowerCase();
|
|
133
|
+
if (FLAG_NAME.test(name) && !names.includes(name))
|
|
134
|
+
names.push(name);
|
|
135
|
+
if (names.length === 40)
|
|
136
|
+
break;
|
|
137
|
+
}
|
|
138
|
+
return names;
|
|
139
|
+
}
|
|
140
|
+
/** The leading words of an argv that are not flags, and not values of one. */
|
|
141
|
+
function bareTokens(argv) {
|
|
142
|
+
const tokens = [];
|
|
143
|
+
for (const token of argv) {
|
|
144
|
+
if (token === '--' || token.startsWith('-'))
|
|
145
|
+
break;
|
|
146
|
+
tokens.push(token);
|
|
147
|
+
}
|
|
148
|
+
return tokens;
|
|
149
|
+
}
|
|
150
|
+
/**
|
|
151
|
+
* A command line someone typed (`--command "ekanos teams connect acme
|
|
152
|
+
* linear --set clientId=x"`), reduced to its path and flag names. A leading
|
|
153
|
+
* `ekanos`, `npx @ekanos/cli[@version]` or package-runner prefix is dropped.
|
|
154
|
+
*/
|
|
155
|
+
export function describeCommandLine(line) {
|
|
156
|
+
const tokens = line
|
|
157
|
+
.trim()
|
|
158
|
+
.split(/\s+/)
|
|
159
|
+
.filter(Boolean)
|
|
160
|
+
.map((token) => token.replace(/^["']|["']$/g, ''));
|
|
161
|
+
const start = tokens.findIndex((token) => COMMAND_WORDS.has(token));
|
|
162
|
+
const relevant = start === -1 ? [] : tokens.slice(start);
|
|
163
|
+
// Only what follows a recognized command counts: a prefix such as
|
|
164
|
+
// `npx @ekanos/cli` is not part of it.
|
|
165
|
+
return {
|
|
166
|
+
command: commandPathOf(bareTokens(relevant)),
|
|
167
|
+
flags: flagNamesOf(relevant),
|
|
168
|
+
};
|
|
169
|
+
}
|
|
170
|
+
/** Which coding agent is running this CLI, by its marker; never the value. */
|
|
171
|
+
export function detectFeedbackAgent(env) {
|
|
172
|
+
if (env.CLAUDECODE === '1')
|
|
173
|
+
return 'claude-code';
|
|
174
|
+
if (env.CODEX_SANDBOX)
|
|
175
|
+
return 'codex';
|
|
176
|
+
if (env.CURSOR_AGENT === '1')
|
|
177
|
+
return 'cursor';
|
|
178
|
+
if (env.GEMINI_CLI === '1')
|
|
179
|
+
return 'gemini-cli';
|
|
180
|
+
if (env.AI_AGENT)
|
|
181
|
+
return 'other';
|
|
182
|
+
return null;
|
|
183
|
+
}
|
|
184
|
+
/** `darwin-arm64`, `linux-x64`. */
|
|
185
|
+
export function osLabel() {
|
|
186
|
+
const label = `${process.platform}-${process.arch}`.toLowerCase();
|
|
187
|
+
return /^[a-z0-9_-]{1,40}$/.test(label) ? label : null;
|
|
188
|
+
}
|
|
189
|
+
export function nodeVersion() {
|
|
190
|
+
const version = process.versions.node;
|
|
191
|
+
return /^\d+\.\d+\.\d+$/.test(version) ? version : null;
|
|
192
|
+
}
|
|
193
|
+
/** A context with nothing about a command: what a plain report carries. */
|
|
194
|
+
export function baseFeedbackContext(input) {
|
|
195
|
+
return {
|
|
196
|
+
cliVersion: input.cliVersion,
|
|
197
|
+
command: null,
|
|
198
|
+
flags: [],
|
|
199
|
+
errorCode: null,
|
|
200
|
+
exitCode: null,
|
|
201
|
+
httpStatus: null,
|
|
202
|
+
requestId: null,
|
|
203
|
+
agent: detectFeedbackAgent(input.env),
|
|
204
|
+
os: osLabel(),
|
|
205
|
+
node: nodeVersion(),
|
|
206
|
+
failedAt: null,
|
|
207
|
+
};
|
|
208
|
+
}
|
|
209
|
+
//# sourceMappingURL=feedback-context.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"feedback-context.js","sourceRoot":"","sources":["../src/feedback-context.ts"],"names":[],"mappings":"AAKA;;;;;;GAMG;AAEH;;;;;GAKG;AACH,MAAM,a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,EAAE,CAAC;IAClE,OAAO,oBAAoB,CAAC,IAAI,CAAC,KAAK,CAAC,CAAC,CAAC,CAAC,KAAK,CAAC,CAAC,CAAC,IAAI,CAAC;AACzD,CAAC;AAED,MAAM,UAAU,WAAW;IACzB,MAAM,OAAO,GAAG,OAAO,CAAC,QAAQ,CAAC,IAAI,CAAC;IACtC,OAAO,iBAAiB,CAAC,IAAI,CAAC,OAAO,CAAC,CAAC,CAAC,CAAC,OAAO,CAAC,CAAC,CAAC,IAAI,CAAC;AAC1D,CAAC;AAED,2EAA2E;AAC3E,MAAM,UAAU,mBAAmB,CAAC,KAGnC;IACC,OAAO;QACL,UAAU,EAAE,KAAK,CAAC,UAAU;QAC5B,OAAO,EAAE,IAAI;QACb,KAAK,EAAE,EAAE;QACT,SAAS,EAAE,IAAI;QACf,QAAQ,EAAE,IAAI;QACd,UAAU,EAAE,IAAI;QAChB,SAAS,EAAE,IAAI;QACf,KAAK,EAAE,mBAAmB,CAAC,KAAK,CAAC,GAAG,CAAC;QACrC,EAAE,EAAE,OAAO,EAAE;QACb,IAAI,EAAE,WAAW,EAAE;QACnB,QAAQ,EAAE,IAAI;KACf,CAAC;AACJ,CAAC","sourcesContent":["import type {\n FeedbackAgent,\n FeedbackContext,\n} from '@ekanos/integration-schema';\n\n/**\n * What `ekanos feedback` may say about a command: its path in the CLI's own\n * words and the NAMES of its flags. Never an argument, a flag's value, a\n * file's contents or an environment value — this module is the one place a\n * command line is reduced to that, for a recorded failure and for\n * `--command` alike.\n */\n\n/**\n * The words a command path is made of: the CLI's commands and the verbs and\n * areas under them. A token that is not one of these ends the path, so a\n * team, a product, an email or a key never joins it. A slug that happens to\n * be one of these words says nothing more than the word.\n */\nconst COMMAND_WORDS = new Set([\n // Commands.\n 'init',\n 'validate',\n 'dev',\n 'test',\n 'login',\n 'logout',\n 'whoami',\n 'status',\n 'sources',\n 'catalog',\n 'apps',\n 'teams',\n 'reviewers',\n 'routes',\n 'agents',\n 'skills',\n 'knowledge',\n 'runs',\n 'approvals',\n 'workflows',\n 'use',\n 'publish',\n 'upgrade',\n 'feedback',\n // Areas and verbs.\n 'add',\n 'app',\n 'apply',\n 'approve',\n 'archive',\n 'attach',\n 'cancel',\n 'confirm',\n 'connect',\n 'create',\n 'default',\n 'define',\n 'delete',\n 'detach',\n 'disable',\n 'disconnect',\n 'edit',\n 'effect',\n 'enable',\n 'events',\n 'groups',\n 'health',\n 'invite',\n 'leave',\n 'links',\n 'list',\n 'llm-key',\n 'mcp',\n 'members',\n 'options',\n 'overrides',\n 'people',\n 'pin',\n 'policy',\n 'products',\n 'pull',\n 'push',\n 'refresh',\n 'reject',\n 'remove',\n 'rename',\n 'replay',\n 'resend',\n 'role',\n 'roles',\n 'rollback',\n 'rotate',\n 'scope',\n 'scopes',\n 'search',\n 'set',\n 'show',\n 'start',\n 'tags',\n 'token',\n 'triggers',\n 'unarchive',\n 'unpin',\n 'unrouted',\n 'unset',\n 'update',\n 'webhook',\n 'workspace',\n]);\n\nconst MAX_PATH_WORDS = 4;\nconst FLAG_NAME = /^--[a-z0-9][a-z0-9-]{0,47}$/;\n\n/**\n * `teams connect` from `[\"teams\", \"connect\", \"acme\", \"linear\"]`: the command\n * and the words after it that are the CLI's own, up to the first that is not.\n */\nexport function commandPathOf(tokens: readonly string[]): string | null {\n const words: string[] = [];\n for (const token of tokens) {\n if (words.length === MAX_PATH_WORDS || !COMMAND_WORDS.has(token)) break;\n words.push(token);\n }\n return words.length > 0 ? words.join(' ') : null;\n}\n\n/**\n * The names of the flags in an argv, in order, once each: `--set a=b` gives\n * `--set`, `--source=acme` gives `--source`. A token after `--` is the\n * passthrough's, not a flag of this CLI, and is never read.\n */\nexport function flagNamesOf(argv: readonly string[]): string[] {\n const names: string[] = [];\n for (const token of argv) {\n if (token === '--') break;\n if (!token.startsWith('--')) continue;\n const name = token.split('=')[0]!.toLowerCase();\n if (FLAG_NAME.test(name) && !names.includes(name)) names.push(name);\n if (names.length === 40) break;\n }\n return names;\n}\n\n/** The leading words of an argv that are not flags, and not values of one. */\nfunction bareTokens(argv: readonly string[]): string[] {\n const tokens: string[] = [];\n for (const token of argv) {\n if (token === '--' || token.startsWith('-')) break;\n tokens.push(token);\n }\n return tokens;\n}\n\n/**\n * A command line someone typed (`--command \"ekanos teams connect acme\n * linear --set clientId=x\"`), reduced to its path and flag names. A leading\n * `ekanos`, `npx @ekanos/cli[@version]` or package-runner prefix is dropped.\n */\nexport function describeCommandLine(line: string): {\n command: string | null;\n flags: string[];\n} {\n const tokens = line\n .trim()\n .split(/\\s+/)\n .filter(Boolean)\n .map((token) => token.replace(/^[\"']|[\"']$/g, ''));\n const start = tokens.findIndex((token) => COMMAND_WORDS.has(token));\n const relevant = start === -1 ? [] : tokens.slice(start);\n // Only what follows a recognized command counts: a prefix such as\n // `npx @ekanos/cli` is not part of it.\n return {\n command: commandPathOf(bareTokens(relevant)),\n flags: flagNamesOf(relevant),\n };\n}\n\n/** Which coding agent is running this CLI, by its marker; never the value. */\nexport function detectFeedbackAgent(\n env: Readonly<Record<string, string | undefined>>,\n): FeedbackAgent | null {\n if (env.CLAUDECODE === '1') return 'claude-code';\n if (env.CODEX_SANDBOX) return 'codex';\n if (env.CURSOR_AGENT === '1') return 'cursor';\n if (env.GEMINI_CLI === '1') return 'gemini-cli';\n if (env.AI_AGENT) return 'other';\n return null;\n}\n\n/** `darwin-arm64`, `linux-x64`. */\nexport function osLabel(): string | null {\n const label = `${process.platform}-${process.arch}`.toLowerCase();\n return /^[a-z0-9_-]{1,40}$/.test(label) ? label : null;\n}\n\nexport function nodeVersion(): string | null {\n const version = process.versions.node;\n return /^\\d+\\.\\d+\\.\\d+$/.test(version) ? version : null;\n}\n\n/** A context with nothing about a command: what a plain report carries. */\nexport function baseFeedbackContext(input: {\n cliVersion: string;\n env: Readonly<Record<string, string | undefined>>;\n}): FeedbackContext {\n return {\n cliVersion: input.cliVersion,\n command: null,\n flags: [],\n errorCode: null,\n exitCode: null,\n httpStatus: null,\n requestId: null,\n agent: detectFeedbackAgent(input.env),\n os: osLabel(),\n node: nodeVersion(),\n failedAt: null,\n };\n}\n"]}
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
import type { FeedbackUpdate } from '@ekanos/integration-schema';
|
|
2
|
+
import type { CliContext } from './context.js';
|
|
3
|
+
import { type Invocation } from './invocation.js';
|
|
4
|
+
export declare const FEEDBACK_UPDATES_TTL_MS: number;
|
|
5
|
+
export interface FeedbackUpdatesCheck {
|
|
6
|
+
/** Print what is ready, remember it, and let go of anything still in flight. */
|
|
7
|
+
finish(ctx: CliContext): void;
|
|
8
|
+
/** Settles when the background work does (tests). */
|
|
9
|
+
readonly settled: Promise<void>;
|
|
10
|
+
}
|
|
11
|
+
export declare function startFeedbackUpdatesCheck(params: {
|
|
12
|
+
env: Record<string, string | undefined>;
|
|
13
|
+
now?: number;
|
|
14
|
+
}): FeedbackUpdatesCheck | null;
|
|
15
|
+
/** One stderr line about one shipped fix. */
|
|
16
|
+
export declare function describeUpdate(update: FeedbackUpdate, installed: string, invocation: Invocation): string;
|
|
@@ -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;A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AC,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,18 @@ 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;
|
|
53
65
|
}
|
|
54
66
|
/**
|
|
55
67
|
* The single entry point. Resolves the agent-native envelope once, dispatches
|