@m6d/cortex-cli 1.3.0 → 1.5.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/package.json +1 -1
- package/src/cli.ts +2 -2
- package/src/commands/new.ts +3 -3
- package/src/commands/swagger.ts +1 -1
- package/src/config/load.ts +1 -1
- package/src/config/validate.ts +1 -1
- package/src/contracts/runtime/index.ts +99 -4
- package/src/scaffold/features.ts +1 -1
- package/src/scaffold/files.ts +1 -2
- package/src/ui/report.ts +1 -1
package/package.json
CHANGED
package/src/cli.ts
CHANGED
|
@@ -6,7 +6,7 @@ import { registerNew } from "@/commands/new";
|
|
|
6
6
|
import { registerSwagger } from "@/commands/swagger";
|
|
7
7
|
import * as report from "@/ui/report";
|
|
8
8
|
|
|
9
|
-
// Discovery is this exact name in the cwd, with no upward walk
|
|
9
|
+
// Discovery is this exact name in the cwd, with no upward walk,
|
|
10
10
|
// so the flag's default *is* the discovery rule. The second argument is what help
|
|
11
11
|
// prints — without it commander would JSON.stringify the path and show quotes.
|
|
12
12
|
const DEFAULT_CONFIG = "./cortex.config.ts";
|
|
@@ -28,7 +28,7 @@ const program = new Command()
|
|
|
28
28
|
.helpCommand(false)
|
|
29
29
|
// Commander appends ` [options]` to any command that has some. Left in, the
|
|
30
30
|
// first command to grow a flag widens the whole list and the two-group screen
|
|
31
|
-
//
|
|
31
|
+
// stops matching. `cortex <command> --help` lists them.
|
|
32
32
|
.configureHelp({
|
|
33
33
|
subcommandTerm: function (cmd) {
|
|
34
34
|
return new Help().subcommandTerm(cmd).replace(" [options]", "");
|
package/src/commands/new.ts
CHANGED
|
@@ -68,7 +68,7 @@ type Options = {
|
|
|
68
68
|
async function scaffold(name: string | undefined, options: Options) {
|
|
69
69
|
const { verbose, databasePassed } = options;
|
|
70
70
|
|
|
71
|
-
// No TTY ⇒ never prompt and behave as `--yes
|
|
71
|
+
// No TTY ⇒ never prompt and behave as `--yes`. On Bun a
|
|
72
72
|
// piped stdin reports `undefined` rather than `false`, which is why this
|
|
73
73
|
// compares against `true`.
|
|
74
74
|
const interactive = process.stdin.isTTY === true && options.yes !== true;
|
|
@@ -229,7 +229,7 @@ async function install(cwd: string) {
|
|
|
229
229
|
}
|
|
230
230
|
|
|
231
231
|
function step(command: string, annotation?: string) {
|
|
232
|
-
// 27
|
|
232
|
+
// 27 aligns the annotation column across all report rows.
|
|
233
233
|
return annotation ? ` ${command.padEnd(27)}${annotation}\n` : ` ${command}\n`;
|
|
234
234
|
}
|
|
235
235
|
|
|
@@ -294,7 +294,7 @@ function isInsideWorkTree(target: string) {
|
|
|
294
294
|
|
|
295
295
|
function missingName(): never {
|
|
296
296
|
// No TTY ⇒ never prompt, so a missing required argument is a hard error
|
|
297
|
-
//
|
|
297
|
+
// With a TTY this branch is only reached under `--yes`,
|
|
298
298
|
// which answers every question including the one that has no default.
|
|
299
299
|
report.fail({
|
|
300
300
|
what:
|
package/src/commands/swagger.ts
CHANGED
|
@@ -8,7 +8,7 @@ import { validateConfig } from "@/config/validate";
|
|
|
8
8
|
import { extractEndpoints } from "@/swagger/extract-endpoints";
|
|
9
9
|
import * as report from "@/ui/report";
|
|
10
10
|
|
|
11
|
-
/** A convention, not config: `KnowledgeConfig` has no `domainsDir
|
|
11
|
+
/** A convention, not config: `KnowledgeConfig` has no `domainsDir`. */
|
|
12
12
|
const DEFAULT_DOMAINS_DIR = "src/domains";
|
|
13
13
|
|
|
14
14
|
/** Only the parts of a loaded config `swagger` reads to report its inputs. */
|
package/src/config/load.ts
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
/**
|
|
2
|
-
* Config discovery and loading
|
|
2
|
+
* Config discovery and loading. Env needs no step of its own:
|
|
3
3
|
* discovery is cwd-only and Bun's `.env` auto-load is cwd-relative, so the two
|
|
4
4
|
* are always colocated and `process.env` is populated before the config
|
|
5
5
|
* evaluates.
|
package/src/config/validate.ts
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
/**
|
|
2
|
-
* One generic rule
|
|
2
|
+
* One generic rule: a key present with an `undefined` value
|
|
3
3
|
* is a failure, listed by full path. It is essentially always the
|
|
4
4
|
* `process.env["X"]!` pattern, where `!` silences the type error and `undefined`
|
|
5
5
|
* flows on to fail far from its cause. Absent keys are fine — that is how
|
|
@@ -7,10 +7,10 @@ import { z } from "zod";
|
|
|
7
7
|
* payloads the runtime's parser then fills defaults into.
|
|
8
8
|
*/
|
|
9
9
|
|
|
10
|
-
/**
|
|
10
|
+
/** The `:id` path param, validated on both sides of the wire. */
|
|
11
11
|
export const AGENT_SLUG_PATTERN = /^[a-z0-9][a-z0-9-]{0,62}$/;
|
|
12
12
|
|
|
13
|
-
/**
|
|
13
|
+
/** Tool names become `tools.<name>()` sandbox bindings on the server. */
|
|
14
14
|
export const TOOL_NAME_PATTERN = /^[a-zA-Z_$][a-zA-Z0-9_$]*$/;
|
|
15
15
|
|
|
16
16
|
export const PROMPT_VARIABLES = ["userName", "channel", "locale", "utcTime", "timezone"] as const;
|
|
@@ -90,7 +90,7 @@ export const knowledgeChunkSchema = z.object({
|
|
|
90
90
|
});
|
|
91
91
|
|
|
92
92
|
/**
|
|
93
|
-
*
|
|
93
|
+
* Present on signatures of `embedded` tools — flows
|
|
94
94
|
* the end user completes in an embedded surface inside the chat widget. The
|
|
95
95
|
* tool's endpoint fields act as the *initiate* call (returns the embed URL);
|
|
96
96
|
* the result the page reports back is relayed as-is — verifying it is the
|
|
@@ -132,7 +132,6 @@ export const runtimeAgentConfigSchema = z.object({
|
|
|
132
132
|
agentId: agentSlugSchema,
|
|
133
133
|
systemPrompt: z.string(),
|
|
134
134
|
promptVariables: z.array(z.enum(PROMPT_VARIABLES)),
|
|
135
|
-
catalogBlurb: z.string(),
|
|
136
135
|
defaultLocale: localeSchema,
|
|
137
136
|
metaTools: z.object({
|
|
138
137
|
searchKnowledge: z.boolean(),
|
|
@@ -253,9 +252,105 @@ export const runtimeErrorSchema = z.object({
|
|
|
253
252
|
}),
|
|
254
253
|
});
|
|
255
254
|
|
|
255
|
+
/*
|
|
256
|
+
* Fleet sync: `@m6d/cortex-server` mirrors thread/message/usage activity into
|
|
257
|
+
* cc via `POST /api/runtime/sync` batches. Upserts are idempotent on
|
|
258
|
+
* (serverId, id); an empty batch is the heartbeat.
|
|
259
|
+
*/
|
|
260
|
+
|
|
261
|
+
const tokenCountSchema = z.number().int().nonnegative();
|
|
262
|
+
|
|
263
|
+
/** Mirrors the zero-dep `TokenUsage` shape in `wire/index.ts` (wire must stay import-free). */
|
|
264
|
+
export const tokenUsageSchema = z.object({
|
|
265
|
+
input: z.object({
|
|
266
|
+
noCache: tokenCountSchema,
|
|
267
|
+
cacheRead: tokenCountSchema,
|
|
268
|
+
cacheWrite: tokenCountSchema,
|
|
269
|
+
total: tokenCountSchema,
|
|
270
|
+
}),
|
|
271
|
+
output: z.object({
|
|
272
|
+
reasoning: tokenCountSchema,
|
|
273
|
+
text: tokenCountSchema,
|
|
274
|
+
total: tokenCountSchema,
|
|
275
|
+
}),
|
|
276
|
+
total: tokenCountSchema,
|
|
277
|
+
});
|
|
278
|
+
|
|
279
|
+
export const MESSAGE_ROLES = ["system", "user", "assistant", "tool"] as const;
|
|
280
|
+
|
|
281
|
+
export const syncEventSchema = z.discriminatedUnion("type", [
|
|
282
|
+
z.object({
|
|
283
|
+
type: z.literal("thread.upsert"),
|
|
284
|
+
id: z.uuid(),
|
|
285
|
+
agentSlug: agentSlugSchema,
|
|
286
|
+
userId: z.string().max(255),
|
|
287
|
+
title: z.string().max(256).nullable(),
|
|
288
|
+
isTest: z.boolean(),
|
|
289
|
+
createdAt: z.iso.datetime(),
|
|
290
|
+
updatedAt: z.iso.datetime(),
|
|
291
|
+
}),
|
|
292
|
+
z.object({
|
|
293
|
+
type: z.literal("thread.delete"),
|
|
294
|
+
id: z.uuid(),
|
|
295
|
+
}),
|
|
296
|
+
z.object({
|
|
297
|
+
type: z.literal("message.upsert"),
|
|
298
|
+
id: z.string().max(128),
|
|
299
|
+
threadId: z.uuid(),
|
|
300
|
+
role: z.enum(MESSAGE_ROLES),
|
|
301
|
+
text: z.string().nullable(),
|
|
302
|
+
ordinal: z.number().int(),
|
|
303
|
+
content: z.looseObject({}),
|
|
304
|
+
createdAt: z.iso.datetime(),
|
|
305
|
+
}),
|
|
306
|
+
z.object({
|
|
307
|
+
type: z.literal("usage.record"),
|
|
308
|
+
id: z.uuid(),
|
|
309
|
+
messageId: z.string().max(128),
|
|
310
|
+
threadId: z.uuid(),
|
|
311
|
+
stepNumber: z.number().int(),
|
|
312
|
+
tokenUsage: tokenUsageSchema,
|
|
313
|
+
// Stamped by the event constructor: llm_requests has no timestamp
|
|
314
|
+
// column, but the mirror needs one for time-bucketed usage stats.
|
|
315
|
+
createdAt: z.iso.datetime(),
|
|
316
|
+
}),
|
|
317
|
+
]);
|
|
318
|
+
|
|
319
|
+
/*
|
|
320
|
+
* `epoch` identifies the sending database's generation (a UUIDv7 minted into
|
|
321
|
+
* the server DB's `sync_meta` row): a recreated database gets a new epoch, so
|
|
322
|
+
* cc can tell a legitimately restarted outbox sequence from a stale batch.
|
|
323
|
+
* v7 uuids are time-ordered, so cc also rejects batches from a superseded
|
|
324
|
+
* (lexicographically lower) epoch outright.
|
|
325
|
+
* `seq` is the batch's highest outbox row id; batches are contiguous
|
|
326
|
+
* id-ordered outbox prefixes, so within one epoch cc keeps a per-server
|
|
327
|
+
* high-water mark and discards batches at or below it — a stale in-flight
|
|
328
|
+
* batch (an expired flusher lease, a replay after a lost ack) can never
|
|
329
|
+
* overwrite newer mirrored state. Heartbeats carry no events and nothing to
|
|
330
|
+
* fence, so `seq` exists only on the non-empty branch.
|
|
331
|
+
*/
|
|
332
|
+
export const syncRequestSchema = z.union([
|
|
333
|
+
z.object({
|
|
334
|
+
events: z.array(syncEventSchema).min(1).max(500),
|
|
335
|
+
epoch: z.uuid(),
|
|
336
|
+
seq: z.number().int().positive(),
|
|
337
|
+
}),
|
|
338
|
+
z.object({
|
|
339
|
+
events: z.array(syncEventSchema).length(0),
|
|
340
|
+
epoch: z.uuid(),
|
|
341
|
+
}),
|
|
342
|
+
]);
|
|
343
|
+
|
|
344
|
+
export const syncResponseSchema = z.object({
|
|
345
|
+
accepted: z.number().int(),
|
|
346
|
+
});
|
|
347
|
+
|
|
256
348
|
export type ToolEmbed = z.infer<typeof toolEmbedSchema>;
|
|
257
349
|
export type RuntimeAgentConfig = z.infer<typeof runtimeAgentConfigSchema>;
|
|
258
350
|
export type ResolveRequest = z.input<typeof resolveRequestSchema>;
|
|
259
351
|
export type ResolveResponse = z.infer<typeof resolveResponseSchema>;
|
|
260
352
|
export type SearchRequest = z.input<typeof searchRequestSchema>;
|
|
261
353
|
export type ExecuteRequest = z.input<typeof executeRequestSchema>;
|
|
354
|
+
export type SyncEvent = z.infer<typeof syncEventSchema>;
|
|
355
|
+
export type SyncRequest = z.input<typeof syncRequestSchema>;
|
|
356
|
+
export type SyncResponse = z.infer<typeof syncResponseSchema>;
|
package/src/scaffold/features.ts
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
/**
|
|
2
|
-
* The five features `cortex new` toggles
|
|
2
|
+
* The five features `cortex new` toggles. A feature is not a
|
|
3
3
|
* config key: it is a bundle of a `cortex.config.ts` fragment, a block of env
|
|
4
4
|
* keys, and sometimes a compose service. Fragments concatenate — there is no
|
|
5
5
|
* merge engine — so every field here is plain text that gets joined.
|
package/src/scaffold/files.ts
CHANGED
|
@@ -2,8 +2,7 @@
|
|
|
2
2
|
* Every file `cortex new` writes, as one pure function. The tooling configs are
|
|
3
3
|
* inlined rather than pulled from `@m6d/eslint-config`, `@m6d/prettier-config`
|
|
4
4
|
* and `@m6d/tsconfig`: those are `private: true` at `0.0.0` and resolvable only
|
|
5
|
-
* through this workspace, and a standalone scaffold has no workspace.
|
|
6
|
-
* docs/design/cortex-cli.md §7.5-§7.6.
|
|
5
|
+
* through this workspace, and a standalone scaffold has no workspace.
|
|
7
6
|
*/
|
|
8
7
|
|
|
9
8
|
import { FEATURE_NAMES, FEATURES, type Feature } from "@/scaffold/features";
|
package/src/ui/report.ts
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
/**
|
|
2
2
|
* The output grammar, shared by every command that runs against a project.
|
|
3
|
-
*
|
|
3
|
+
* The report layout is deliberately frozen; this file is the only
|
|
4
4
|
* place that knows the box characters.
|
|
5
5
|
*/
|
|
6
6
|
|