@feltdb/feltkit 0.1.1 → 0.2.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/dist/app.d.ts +106 -10
- package/dist/app.js +51 -0
- package/dist/app.js.map +1 -1
- package/dist/cli/main.js +218 -2
- package/dist/cli/main.js.map +1 -1
- package/dist/cli/skills.d.ts +39 -0
- package/dist/cli/skills.js +125 -0
- package/dist/cli/skills.js.map +1 -0
- package/dist/dashboard/assets/{index-BLnBFDJs.css → index--1Tqbv_A.css} +1 -1
- package/dist/dashboard/assets/index-Bm4qCYpv.js +15 -0
- package/dist/dashboard/index.html +2 -2
- package/dist/errors.d.ts +3 -1
- package/dist/errors.js +2 -0
- package/dist/errors.js.map +1 -1
- package/dist/index.d.ts +1 -1
- package/dist/runtime/activity.d.ts +21 -8
- package/dist/runtime/activity.js +17 -3
- package/dist/runtime/activity.js.map +1 -1
- package/dist/runtime/agent.d.ts +353 -0
- package/dist/runtime/agent.js +1345 -0
- package/dist/runtime/agent.js.map +1 -0
- package/dist/runtime/authority.d.ts +23 -3
- package/dist/runtime/authority.js +69 -5
- package/dist/runtime/authority.js.map +1 -1
- package/dist/runtime/changes.d.ts +16 -8
- package/dist/runtime/changes.js.map +1 -1
- package/dist/runtime/content.d.ts +33 -0
- package/dist/runtime/content.js +46 -0
- package/dist/runtime/content.js.map +1 -0
- package/dist/runtime/context.d.ts +26 -1
- package/dist/runtime/credentials.d.ts +42 -0
- package/dist/runtime/credentials.js +32 -0
- package/dist/runtime/credentials.js.map +1 -0
- package/dist/runtime/data.d.ts +8 -2
- package/dist/runtime/data.js +74 -9
- package/dist/runtime/data.js.map +1 -1
- package/dist/runtime/decisions.d.ts +131 -0
- package/dist/runtime/decisions.js +301 -0
- package/dist/runtime/decisions.js.map +1 -0
- package/dist/runtime/environment.js +11 -0
- package/dist/runtime/environment.js.map +1 -1
- package/dist/runtime/idempotency.d.ts +37 -0
- package/dist/runtime/idempotency.js +88 -0
- package/dist/runtime/idempotency.js.map +1 -0
- package/dist/runtime/instance.d.ts +8 -3
- package/dist/runtime/instance.js +27 -4
- package/dist/runtime/instance.js.map +1 -1
- package/dist/runtime/integrations.d.ts +120 -0
- package/dist/runtime/integrations.js +412 -0
- package/dist/runtime/integrations.js.map +1 -0
- package/dist/runtime/loader.d.ts +5 -1
- package/dist/runtime/loader.js +35 -13
- package/dist/runtime/loader.js.map +1 -1
- package/dist/runtime/projects.d.ts +1 -0
- package/dist/runtime/projects.js +6 -4
- package/dist/runtime/projects.js.map +1 -1
- package/dist/runtime/readiness.d.ts +29 -0
- package/dist/runtime/readiness.js +154 -0
- package/dist/runtime/readiness.js.map +1 -0
- package/dist/runtime/runtime.d.ts +50 -1
- package/dist/runtime/runtime.js +225 -9
- package/dist/runtime/runtime.js.map +1 -1
- package/dist/runtime/services.d.ts +186 -36
- package/dist/runtime/services.js +420 -152
- package/dist/runtime/services.js.map +1 -1
- package/dist/runtime/sessions.d.ts +7 -18
- package/dist/runtime/sessions.js +7 -5
- package/dist/runtime/sessions.js.map +1 -1
- package/dist/server/admin.d.ts +26 -0
- package/dist/server/admin.js +510 -8
- package/dist/server/admin.js.map +1 -1
- package/dist/server/index.d.ts +2 -0
- package/dist/server/index.js +13 -4
- package/dist/server/index.js.map +1 -1
- package/dist/server/management.d.ts +12 -0
- package/dist/server/management.js +177 -0
- package/dist/server/management.js.map +1 -0
- package/dist/server/mcp.d.ts +202 -0
- package/dist/server/mcp.js +62 -4
- package/dist/server/mcp.js.map +1 -1
- package/dist/server/operators.d.ts +77 -0
- package/dist/server/operators.js +162 -0
- package/dist/server/operators.js.map +1 -0
- package/dist/server/project.js +17 -4
- package/dist/server/project.js.map +1 -1
- package/dist/testing/index.js +3 -2
- package/dist/testing/index.js.map +1 -1
- package/package.json +18 -11
- package/skills/.claude-plugin/marketplace.json +16 -0
- package/skills/.claude-plugin/plugin.json +24 -0
- package/skills/README.md +44 -0
- package/skills/feltkit-agent/SKILL.md +84 -0
- package/skills/feltkit-build/SKILL.md +143 -0
- package/skills/feltkit-data/SKILL.md +79 -0
- package/skills/feltkit-operations/SKILL.md +72 -0
- package/skills/feltkit-services/SKILL.md +102 -0
- package/dist/dashboard/assets/index-CxJGCspE.js +0 -15
package/dist/app.d.ts
CHANGED
|
@@ -1,3 +1,5 @@
|
|
|
1
|
+
import type { ServicesConfig } from "./runtime/services.js";
|
|
2
|
+
import type { DecisionRuntimeOption } from "./runtime/decisions.js";
|
|
1
3
|
/**
|
|
2
4
|
* The application definition: what a developer writes.
|
|
3
5
|
*
|
|
@@ -56,16 +58,28 @@ export interface FeltKitOptions {
|
|
|
56
58
|
dev?: {
|
|
57
59
|
users?: DevUser[];
|
|
58
60
|
};
|
|
59
|
-
/**
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
61
|
+
/**
|
|
62
|
+
* AppPort Services, run on the application's FeltDB instance. Each enabled service
|
|
63
|
+
* gets its packaged management page in Studio (Services → Manage).
|
|
64
|
+
*
|
|
65
|
+
* files, notifications, configuration see the guarantees
|
|
66
|
+
* apiKeys: { roles } keys authenticate as an identity holding these roles
|
|
67
|
+
* webhooks signing secrets come from FELTKIT_CREDENTIAL_<ID>
|
|
68
|
+
* jobs: { handlers } job type → "<module>:<function>", run as the enqueuer
|
|
69
|
+
* schedules recurring jobs (needs jobs)
|
|
70
|
+
* intelligence provider/model configuration only
|
|
71
|
+
*/
|
|
72
|
+
services?: ServicesConfig;
|
|
73
|
+
/** The FeltKit agent. */
|
|
74
|
+
agent?: {
|
|
75
|
+
/**
|
|
76
|
+
* The model that makes decisions (`playbook: "decide"`, `ctx.agent.start`): any FeltDB
|
|
77
|
+
* `DecisionRuntime`, or a function of the environment returning one. When omitted, the
|
|
78
|
+
* environment's AppPort Services Intelligence selection is used.
|
|
79
|
+
*/
|
|
80
|
+
decisions?: DecisionRuntimeOption;
|
|
81
|
+
/** Per decision. Default 20 s. */
|
|
82
|
+
decisionTimeoutMs?: number;
|
|
69
83
|
};
|
|
70
84
|
activity?: {
|
|
71
85
|
/** What to record. Default: "all" in development/test, "writes" in production. */
|
|
@@ -91,6 +105,79 @@ export interface CapabilityExposure {
|
|
|
91
105
|
version?: number;
|
|
92
106
|
}
|
|
93
107
|
export type FunctionKind = "query" | "mutation";
|
|
108
|
+
/** One operation of an HTTP integration. */
|
|
109
|
+
export interface IntegrationOperation {
|
|
110
|
+
method: "GET" | "POST" | "PUT" | "PATCH" | "DELETE";
|
|
111
|
+
/** Path below baseUrl. `{field}` is filled from the input (and removed from the body). */
|
|
112
|
+
path: string;
|
|
113
|
+
description?: string;
|
|
114
|
+
input?: ShapeInput;
|
|
115
|
+
output: Schema;
|
|
116
|
+
/** "observation" reads (GET); "consequential" may change the external system. */
|
|
117
|
+
effect: "observation" | "consequential";
|
|
118
|
+
/** The permission that may invoke it. Discovery grants nothing. */
|
|
119
|
+
access: string;
|
|
120
|
+
/**
|
|
121
|
+
* The API deduplicates requests by this header (e.g. "Idempotency-Key"). FeltKit sends a
|
|
122
|
+
* stable key per request, so repeating *the same* request is safe.
|
|
123
|
+
*/
|
|
124
|
+
idempotencyHeader?: string;
|
|
125
|
+
/**
|
|
126
|
+
* How to confirm whether a consequential call took effect without repeating it: an
|
|
127
|
+
* observation of this integration, its input (values or { $input } / { $output } refs),
|
|
128
|
+
* and what its output must show (AppPort `StateVerification`). `$input` refers to this
|
|
129
|
+
* operation's declared input (AppPort checks it), so verify by a business key the API
|
|
130
|
+
* indexes. A NOT_FOUND answer means the effect did not happen.
|
|
131
|
+
*/
|
|
132
|
+
verify?: {
|
|
133
|
+
operation: string;
|
|
134
|
+
input: Record<string, unknown>;
|
|
135
|
+
expect: Array<{
|
|
136
|
+
at: string;
|
|
137
|
+
equals?: unknown;
|
|
138
|
+
exists?: true;
|
|
139
|
+
}>;
|
|
140
|
+
};
|
|
141
|
+
/** What the effect is, for the published contract (e.g. ["payment.created"]). */
|
|
142
|
+
effects?: string[];
|
|
143
|
+
/**
|
|
144
|
+
* A mutation ("<module>:<function>") run as the caller with the call's record
|
|
145
|
+
* ({ call: { id, state, determinedBy, input, output, error, … } }) when a call finishes —
|
|
146
|
+
* including `unknown` — and again when verification settles it. It may run more than
|
|
147
|
+
* once for one call; make it idempotent (key it by call.id).
|
|
148
|
+
*/
|
|
149
|
+
onOutcome?: string;
|
|
150
|
+
}
|
|
151
|
+
export interface IntegrationConfig<Ops extends Record<string, IntegrationOperation> = Record<string, IntegrationOperation>> {
|
|
152
|
+
description?: string;
|
|
153
|
+
/** A URL, or an environment variable (with a value used only in development and test). */
|
|
154
|
+
baseUrl: string | {
|
|
155
|
+
env: string;
|
|
156
|
+
development?: string;
|
|
157
|
+
};
|
|
158
|
+
/** A credential reference sent as `Authorization: Bearer <value>` (or `header`). Resolved server-side. */
|
|
159
|
+
credential?: string | {
|
|
160
|
+
ref: string;
|
|
161
|
+
header?: string;
|
|
162
|
+
scheme?: string;
|
|
163
|
+
};
|
|
164
|
+
/** Per call. Default 10 s. */
|
|
165
|
+
timeoutMs?: number;
|
|
166
|
+
/** A read-only path used to check the API is reachable (Studio, readiness). */
|
|
167
|
+
health?: {
|
|
168
|
+
path: string;
|
|
169
|
+
};
|
|
170
|
+
operations: Ops;
|
|
171
|
+
}
|
|
172
|
+
export type IntegrationDefinition<Ops extends Record<string, IntegrationOperation> = Record<string, IntegrationOperation>> = Readonly<IntegrationConfig<Ops>> & {
|
|
173
|
+
readonly name: string;
|
|
174
|
+
readonly operations: {
|
|
175
|
+
readonly [K in keyof Ops]: Readonly<Ops[K]> & {
|
|
176
|
+
readonly inputSchema: Schema;
|
|
177
|
+
readonly capability: string;
|
|
178
|
+
};
|
|
179
|
+
};
|
|
180
|
+
};
|
|
94
181
|
export interface FunctionConfig<Kind extends FunctionKind, A extends ShapeInput, R> {
|
|
95
182
|
args?: A;
|
|
96
183
|
/** Output contract. Required when the function is exposed as a capability. */
|
|
@@ -129,12 +216,21 @@ export declare class FeltKitApp {
|
|
|
129
216
|
readonly [APP] = true;
|
|
130
217
|
readonly options: Readonly<FeltKitOptions>;
|
|
131
218
|
readonly collections: Map<string, CollectionDefinition<ShapeInput>>;
|
|
219
|
+
readonly integrations: Map<string, IntegrationDefinition<Record<string, IntegrationOperation>>>;
|
|
132
220
|
constructor(options: FeltKitOptions);
|
|
133
221
|
get name(): string;
|
|
134
222
|
/** Declare a collection of records stored in the application's FeltDB instance. */
|
|
135
223
|
collection<S extends ShapeInput>(name: string, shape: S, options?: {
|
|
136
224
|
description?: string;
|
|
137
225
|
}): CollectionDefinition<S>;
|
|
226
|
+
/**
|
|
227
|
+
* Connect an existing HTTP API. Each operation becomes an AppPort capability named
|
|
228
|
+
* `<integration>.<operation>`, with its effect, the permission that may invoke it,
|
|
229
|
+
* whether the API deduplicates retries, and how to verify an outcome. Discovering it
|
|
230
|
+
* grants nothing. Calls are recorded as evidence before and after they are sent; an
|
|
231
|
+
* outcome that cannot be known is reported as such and verified, never re-sent.
|
|
232
|
+
*/
|
|
233
|
+
integration<Ops extends Record<string, IntegrationOperation>>(name: string, config: IntegrationConfig<Ops>): IntegrationDefinition<Ops>;
|
|
138
234
|
/** A read-only function. Its database handle cannot write. */
|
|
139
235
|
query<R>(handler: Handler<"query", R>): QueryDefinition<{}, Awaited<R>>;
|
|
140
236
|
query<A extends ShapeInput = {}, R = unknown>(config: FunctionConfig<"query", A, R>): QueryDefinition<Simplify<InferShape<A>>, Awaited<R>>;
|
package/dist/app.js
CHANGED
|
@@ -23,12 +23,16 @@ export const RESERVED_COLLECTIONS = new Set([
|
|
|
23
23
|
"jobs",
|
|
24
24
|
"job_schedules",
|
|
25
25
|
"job_audit_events",
|
|
26
|
+
"ConfigurationVariables",
|
|
27
|
+
"ConfigurationSecrets",
|
|
28
|
+
"ConfigurationAuditEvents",
|
|
26
29
|
]);
|
|
27
30
|
const RESERVED_PREFIXES = ["_feltkit", "_flow", "_feltdb", "_appport"];
|
|
28
31
|
export class FeltKitApp {
|
|
29
32
|
[APP] = true;
|
|
30
33
|
options;
|
|
31
34
|
collections = new Map();
|
|
35
|
+
integrations = new Map();
|
|
32
36
|
constructor(options) {
|
|
33
37
|
if (!options || typeof options.name !== "string" || !/^[a-z][a-z0-9-]{0,62}$/.test(options.name)) {
|
|
34
38
|
throw new TypeError(`feltkit({ name }) needs a lowercase name of letters, digits, and dashes (got ${JSON.stringify(options?.name)}).`);
|
|
@@ -73,6 +77,53 @@ export class FeltKitApp {
|
|
|
73
77
|
this.collections.set(name, definition);
|
|
74
78
|
return definition;
|
|
75
79
|
}
|
|
80
|
+
/**
|
|
81
|
+
* Connect an existing HTTP API. Each operation becomes an AppPort capability named
|
|
82
|
+
* `<integration>.<operation>`, with its effect, the permission that may invoke it,
|
|
83
|
+
* whether the API deduplicates retries, and how to verify an outcome. Discovering it
|
|
84
|
+
* grants nothing. Calls are recorded as evidence before and after they are sent; an
|
|
85
|
+
* outcome that cannot be known is reported as such and verified, never re-sent.
|
|
86
|
+
*/
|
|
87
|
+
integration(name, config) {
|
|
88
|
+
if (!/^[a-z][a-z0-9]{0,30}$/.test(name))
|
|
89
|
+
throw new TypeError(`Integration name "${name}" must be lowercase letters and digits (e.g. "payments").`);
|
|
90
|
+
if (this.integrations.has(name))
|
|
91
|
+
throw new TypeError(`Integration "${name}" is declared twice.`);
|
|
92
|
+
if (!config || typeof config.baseUrl === "undefined")
|
|
93
|
+
throw new TypeError(`Integration "${name}" needs a baseUrl (a URL, or { env: "NAME" }).`);
|
|
94
|
+
if (!config.operations || !Object.keys(config.operations).length)
|
|
95
|
+
throw new TypeError(`Integration "${name}" declares no operations.`);
|
|
96
|
+
const operations = {};
|
|
97
|
+
for (const [op, def] of Object.entries(config.operations)) {
|
|
98
|
+
const capability = `${name}.${op}`;
|
|
99
|
+
const check = validateName(capability);
|
|
100
|
+
if (!check.valid)
|
|
101
|
+
throw new TypeError(`Integration operation "${capability}" is not a valid AppPort name: ${check.reason}.`);
|
|
102
|
+
if (!["GET", "POST", "PUT", "PATCH", "DELETE"].includes(def.method))
|
|
103
|
+
throw new TypeError(`${capability}: method must be GET, POST, PUT, PATCH, or DELETE.`);
|
|
104
|
+
if (typeof def.path !== "string" || !def.path.startsWith("/"))
|
|
105
|
+
throw new TypeError(`${capability}: path must start with "/".`);
|
|
106
|
+
if (def.effect !== "observation" && def.effect !== "consequential")
|
|
107
|
+
throw new TypeError(`${capability}: effect must be "observation" or "consequential".`);
|
|
108
|
+
if (def.effect === "observation" && def.method !== "GET")
|
|
109
|
+
throw new TypeError(`${capability}: an observation must be a GET.`);
|
|
110
|
+
if (typeof def.access !== "string" || !def.access || def.access === "public")
|
|
111
|
+
throw new TypeError(`${capability}: access must name the permission that may invoke it (e.g. "${name}.write").`);
|
|
112
|
+
if (!def.output)
|
|
113
|
+
throw new TypeError(`${capability}: output schema is required (AppPort publishes and enforces it).`);
|
|
114
|
+
if (def.verify) {
|
|
115
|
+
const probe = config.operations[def.verify.operation];
|
|
116
|
+
if (!probe || probe.effect !== "observation")
|
|
117
|
+
throw new TypeError(`${capability}: verify.operation must name an observation of "${name}".`);
|
|
118
|
+
}
|
|
119
|
+
if (def.onOutcome !== undefined && !/^[\w/-]+:[\w]+$/.test(def.onOutcome))
|
|
120
|
+
throw new TypeError(`${capability}: onOutcome names a mutation as "<module>:<function>".`);
|
|
121
|
+
operations[op] = Object.freeze({ ...def, inputSchema: shapeToObjectSchema(def.input ?? {}), capability });
|
|
122
|
+
}
|
|
123
|
+
const definition = Object.freeze({ name, ...config, operations });
|
|
124
|
+
this.integrations.set(name, definition);
|
|
125
|
+
return definition;
|
|
126
|
+
}
|
|
76
127
|
query(input) {
|
|
77
128
|
return this.define("query", input);
|
|
78
129
|
}
|
package/dist/app.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"app.js","sourceRoot":"","sources":["../src/app.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"app.js","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C,KAAK,IAAI,CAAC;AAC9G,CAAC;AAED,MAAM,UAAU,sBAAsB,CAAC,KAAc;IACnD,OAAO,OAAO,KAAK,KAAK,QAAQ,IAAI,KAAK,KAAK,IAAI,IAAK,KAAiC,CAAC,UAAU,CAAC,KAAK,IAAI,CAAC;AAChH,CAAC"}
|
package/dist/cli/main.js
CHANGED
|
@@ -2,17 +2,23 @@
|
|
|
2
2
|
* The `feltkit` command.
|
|
3
3
|
*/
|
|
4
4
|
import { spawn } from "node:child_process";
|
|
5
|
-
import { existsSync, readdirSync } from "node:fs";
|
|
5
|
+
import { existsSync, readdirSync, readFileSync, writeFileSync } from "node:fs";
|
|
6
6
|
import { join, resolve } from "node:path";
|
|
7
7
|
import { FeltKitError, isFeltKitError } from "../errors.js";
|
|
8
8
|
import { resolveEnvironment } from "../runtime/environment.js";
|
|
9
9
|
import { loadSources } from "../runtime/loader.js";
|
|
10
10
|
import { readAdminToken, readRuntimeRecord } from "../runtime/projects.js";
|
|
11
|
+
import { loadBundle } from "../runtime/loader.js";
|
|
12
|
+
import { createGrant, operatorKey } from "../server/operators.js";
|
|
13
|
+
import { assessReadiness } from "../runtime/readiness.js";
|
|
14
|
+
import { EnvironmentCredentials } from "../runtime/credentials.js";
|
|
15
|
+
import { selectModel } from "../server/admin.js";
|
|
11
16
|
import { FeltKitRuntime, silentLogger } from "../runtime/runtime.js";
|
|
12
17
|
import { overviewPayload } from "../server/admin.js";
|
|
13
18
|
import { SDK_VERSION, build, codegen, doctor, startDev, startProduction } from "../server/project.js";
|
|
14
19
|
import { scaffold, ScaffoldError } from "create-feltkit";
|
|
15
20
|
import { deploy } from "./deploy.js";
|
|
21
|
+
import { checkSkills, installSkills, shippedSkills, skillsTarget } from "./skills.js";
|
|
16
22
|
import { c, line, printInspect, symbols } from "./output.js";
|
|
17
23
|
export function parseArgs(argv) {
|
|
18
24
|
const positional = [];
|
|
@@ -55,8 +61,13 @@ ${c.bold("Commands")}
|
|
|
55
61
|
inspect Show what the application is, where its state lives, and what it's doing
|
|
56
62
|
deploy Build a verified, self-contained deployment artifact
|
|
57
63
|
session <action> Create, list, or revoke sessions (agents, service accounts)
|
|
64
|
+
operator grant Sign a one-time production Studio sign-in for an operator
|
|
65
|
+
readiness Check what this environment has and lacks before production
|
|
66
|
+
model <action> Show or select the model that makes agent decisions
|
|
67
|
+
config <action> Export or import non-secret configuration between environments
|
|
58
68
|
codegen Regenerate feltkit/_generated/api.ts
|
|
59
69
|
doctor Check the project and installation for problems
|
|
70
|
+
skills <action> Install, update, or check the FeltKit skills for coding agents
|
|
60
71
|
|
|
61
72
|
${c.bold("Options")}
|
|
62
73
|
--port <n> Port for dev/start (default 3000)
|
|
@@ -73,6 +84,33 @@ const COMMAND_HELP = {
|
|
|
73
84
|
test: "feltkit test [files…]\n Runs node --test on tests/**/*.test.ts with FELTKIT_ENV=test.",
|
|
74
85
|
inspect: "feltkit inspect [--json] [--env development]\n Reads from the running server when there is one; otherwise opens the environment directly.",
|
|
75
86
|
deploy: "feltkit deploy [--out <dir>]\n Builds, verifies the build boots, and writes a deployable directory with a Dockerfile.",
|
|
87
|
+
skills: "feltkit skills install [--user] [--dir <path>] [--force]\n" +
|
|
88
|
+
" Copies the FeltKit skills into .claude/skills/ (or ~/.claude/skills/ with --user). Run again to update.\n" +
|
|
89
|
+
"feltkit skills check [--user] [--dir <path>] [--json]\n" +
|
|
90
|
+
" Validates the installed skills: present, well-formed, this SDK's version, unmodified.\n" +
|
|
91
|
+
"feltkit skills list\n" +
|
|
92
|
+
" The skills this package ships.",
|
|
93
|
+
readiness: "feltkit readiness [--env development|production] [--json]\n" +
|
|
94
|
+
" Real checks of the environment: storage, credentials, identity, roles, model, integrations, open uncertain\n" +
|
|
95
|
+
" outcomes, background work, the build; plus the operational requirements FeltKit does not provide.\n" +
|
|
96
|
+
" Exit code 1 when any check fails.",
|
|
97
|
+
model: "feltkit model show [--env development] [--json]\n" +
|
|
98
|
+
"feltkit model set --provider <id> --model <model> [--endpoint <url>] [--credential credential-ref:<id>] [--env production]\n" +
|
|
99
|
+
" Selects the environment's provider in AppPort Services Intelligence. Providers: openai, anthropic, opencode,\n" +
|
|
100
|
+
" ollama, custom (any OpenAI-compatible endpoint). The credential is a reference; its value goes in\n" +
|
|
101
|
+
" FELTKIT_CREDENTIAL_<ID> in that environment. Run it on the host, with the server stopped, for production.",
|
|
102
|
+
config: "feltkit config export [--env development] [--out <file>]\n" +
|
|
103
|
+
" Writes the environment's non-secret configuration as AppPort Services' versioned document\n" +
|
|
104
|
+
" (appport.configuration-export): variables, credential binding names and references, active webhook\n" +
|
|
105
|
+
" endpoints, enabled schedules. Secret values are never in it.\n" +
|
|
106
|
+
"feltkit config import <file> [--env production] [--dry-run] [--overwrite] [--json]\n" +
|
|
107
|
+
" Plans (--dry-run) or applies the document through AppPort Services' import. Credential bindings are never\n" +
|
|
108
|
+
" created: attach each listed one in the target and set its FELTKIT_CREDENTIAL_<ID>. Schedules are not imported\n" +
|
|
109
|
+
" (they run as their creator). Run it on the host, with the server stopped, for production. Exit code 1 on\n" +
|
|
110
|
+
" conflicts or failures.",
|
|
111
|
+
operator: "feltkit operator grant --id <id> --role <role>[,<role>] [--name <display name>] [--ttl <minutes>] [--env production] [--json]\n" +
|
|
112
|
+
" Signs a one-time grant with this environment's operator key (FELTKIT_OPERATOR_KEY, else .feltkit/<env>/operator-key).\n" +
|
|
113
|
+
" Paste it into Studio's sign-in; it becomes an operator session holding exactly these declared roles. Run it on the host.",
|
|
76
114
|
session: "feltkit session create --id <id> --role <role> [--type agent|user|service] [--label <text>] [--ttl <hours>] [--env development]\n" +
|
|
77
115
|
"feltkit session list [--env development]\n" +
|
|
78
116
|
"feltkit session revoke <ref> [--env development]",
|
|
@@ -89,6 +127,11 @@ async function withEnvironment(projectDir, envName, remote, local) {
|
|
|
89
127
|
const runtimeDir = join(projectDir, ".feltkit", envName);
|
|
90
128
|
const record = readRuntimeRecord(runtimeDir);
|
|
91
129
|
if (record) {
|
|
130
|
+
if (envName === "production") {
|
|
131
|
+
throw new FeltKitError("CONFIGURATION", `A production server is running (pid ${record.pid}). Its admin API answers verified operators only, not the admin token.`, {
|
|
132
|
+
hint: "Sign in to Studio with `feltkit operator grant --id <you> --role <role>`, or stop the server to inspect its state directly.",
|
|
133
|
+
});
|
|
134
|
+
}
|
|
92
135
|
const token = readAdminToken(runtimeDir);
|
|
93
136
|
if (!token)
|
|
94
137
|
throw new FeltKitError("CONFIGURATION", `A ${envName} server is running (pid ${record.pid}) but its admin token is missing.`);
|
|
@@ -165,6 +208,7 @@ export async function main(argv = process.argv.slice(2)) {
|
|
|
165
208
|
line(`${symbols.ok} Created ${c.bold(result.name)} in ${result.dir}\n`);
|
|
166
209
|
line(` cd ${dir}\n npm install\n npm run dev\n`);
|
|
167
210
|
line(c.dim("The dev server prints your app URL and a dashboard link. State lives in .feltkit/development/state."));
|
|
211
|
+
line(c.dim("Using a coding agent? `npx feltkit skills install` (after npm install) adds the FeltKit skills for Claude Code."));
|
|
168
212
|
return 0;
|
|
169
213
|
}
|
|
170
214
|
case "codegen": {
|
|
@@ -212,7 +256,7 @@ export async function main(argv = process.argv.slice(2)) {
|
|
|
212
256
|
line(` ${c.bold("App")} ${c.cyan(dev.server.url)}`);
|
|
213
257
|
if (dev.server.dashboardUrl)
|
|
214
258
|
line(` ${c.bold("Dashboard")} ${c.cyan(dev.server.dashboardUrl)}`);
|
|
215
|
-
line(` ${c.bold("AppPort")} ${dev.server.url}/appport ${c.dim(`(${overview.functions.filter((f) => f.capability).length} capabilities)`)}`);
|
|
259
|
+
line(` ${c.bold("AppPort")} ${dev.server.url}/appport ${c.dim(`(${overview.functions.filter((f) => f.capability).length + [...dev.runtime.app.integrations.values()].reduce((n, i) => n + Object.keys(i.operations).length, 0)} capabilities)`)}`);
|
|
216
260
|
line(` ${c.bold("MCP")} ${dev.server.url}/mcp ${c.dim("(agents; needs a session from `feltkit session create --type agent`)")}`);
|
|
217
261
|
line(` ${c.bold("State")} ${overview.instance.location} ${c.dim(`(FeltDB ${overview.instance.feltdbVersion}, ${overview.instance.mode})`)}`);
|
|
218
262
|
line(` ${c.bold("Functions")} ${overview.functions.length} from feltkit/${overview.collections.length ? ` ${c.dim("collections:")} ${overview.collections.map((x) => x.name).join(", ")}` : ""}`);
|
|
@@ -318,6 +362,178 @@ export async function main(argv = process.argv.slice(2)) {
|
|
|
318
362
|
line(COMMAND_HELP.session);
|
|
319
363
|
return 1;
|
|
320
364
|
}
|
|
365
|
+
case "readiness": {
|
|
366
|
+
const { value, source } = await withEnvironment(projectDir, envName, (record, token) => adminRequest(record, token, "/readiness"), (runtime) => assessReadiness(runtime, { projectDir, dashboard: process.env.FELTKIT_DASHBOARD === "1" }));
|
|
367
|
+
if (json)
|
|
368
|
+
line(JSON.stringify(value, null, 2));
|
|
369
|
+
else {
|
|
370
|
+
const mark = { pass: symbols.ok, fail: symbols.fail, warn: c.yellow("!"), external: c.dim("○") };
|
|
371
|
+
line(`${c.bold(`Readiness: ${value.application} (${value.environment.name})`)} ${c.dim(`— ${source}`)}\n`);
|
|
372
|
+
for (const area of [...new Set(value.checks.map((x) => x.area))]) {
|
|
373
|
+
line(c.bold(area));
|
|
374
|
+
for (const check of value.checks.filter((x) => x.area === area)) {
|
|
375
|
+
line(` ${mark[check.status]} ${check.title}: ${check.detail}`);
|
|
376
|
+
if (check.fix && check.status !== "pass")
|
|
377
|
+
line(c.dim(` → ${check.fix}`));
|
|
378
|
+
}
|
|
379
|
+
}
|
|
380
|
+
line(`\n${value.summary}`);
|
|
381
|
+
}
|
|
382
|
+
return value.counts.fail > 0 ? 1 : 0;
|
|
383
|
+
}
|
|
384
|
+
case "model": {
|
|
385
|
+
const action = positional[0];
|
|
386
|
+
if (action === "set") {
|
|
387
|
+
if (!flags.provider || !flags.model) {
|
|
388
|
+
line(COMMAND_HELP.model);
|
|
389
|
+
return 1;
|
|
390
|
+
}
|
|
391
|
+
const body = { provider: String(flags.provider), model: String(flags.model), ...(flags.endpoint ? { endpoint: String(flags.endpoint) } : {}), ...(flags.credential ? { credentialRef: String(flags.credential) } : {}) };
|
|
392
|
+
const { value, source } = await withEnvironment(projectDir, envName, (record, token) => adminRequest(record, token, "/models", { method: "POST", body: JSON.stringify(body) }).then((b) => b.status), async (runtime) => (await selectModel(runtime, body), runtime.models.status()));
|
|
393
|
+
if (json)
|
|
394
|
+
line(JSON.stringify(value, null, 2));
|
|
395
|
+
else {
|
|
396
|
+
line(`${symbols.ok} ${envName}: ${value.provider} / ${value.model}${value.endpoint ? ` at ${value.endpoint}` : ""} ${c.dim(`— ${source}`)}`);
|
|
397
|
+
for (const p of value.problems)
|
|
398
|
+
line(` ${symbols.fail} ${p.message}\n ${c.dim(`→ ${p.fix}`)}`);
|
|
399
|
+
}
|
|
400
|
+
return 0;
|
|
401
|
+
}
|
|
402
|
+
if (action === "show" || action === undefined) {
|
|
403
|
+
const { value } = await withEnvironment(projectDir, envName, (record, token) => adminRequest(record, token, "/models").then((b) => b.status), (runtime) => runtime.models.status());
|
|
404
|
+
if (json)
|
|
405
|
+
line(JSON.stringify(value, null, 2));
|
|
406
|
+
else {
|
|
407
|
+
line(value.ready ? `${symbols.ok} ${envName}: ${value.provider}${value.model ? ` / ${value.model}` : ""} (${value.source})` : `${symbols.fail} ${envName}: no usable model`);
|
|
408
|
+
for (const p of value.problems)
|
|
409
|
+
line(` ${p.message}\n ${c.dim(`→ ${p.fix}`)}`);
|
|
410
|
+
}
|
|
411
|
+
return value.ready ? 0 : 1;
|
|
412
|
+
}
|
|
413
|
+
line(COMMAND_HELP.model);
|
|
414
|
+
return 1;
|
|
415
|
+
}
|
|
416
|
+
case "config": {
|
|
417
|
+
const action = positional[0];
|
|
418
|
+
if (action === "export") {
|
|
419
|
+
const { value, source } = await withEnvironment(projectDir, envName, (record, token) => adminRequest(record, token, "/configuration/export"), (runtime) => runtime.services.exportConfiguration());
|
|
420
|
+
const text = `${JSON.stringify(value, null, 2)}\n`;
|
|
421
|
+
if (typeof flags.out === "string") {
|
|
422
|
+
writeFileSync(resolve(projectDir, flags.out), text);
|
|
423
|
+
line(`${symbols.ok} ${envName}: ${value.variables.length} variable(s), ${value.secrets.length} credential reference(s), ${value.webhookEndpoints.length} endpoint(s), ${value.schedules.length} schedule(s) → ${c.bold(flags.out)} ${c.dim(`— ${source}`)}`);
|
|
424
|
+
}
|
|
425
|
+
else
|
|
426
|
+
process.stdout.write(text);
|
|
427
|
+
return 0;
|
|
428
|
+
}
|
|
429
|
+
if (action === "import") {
|
|
430
|
+
// `--dry-run <file>` parses the file as the flag's value; accept either order.
|
|
431
|
+
const file = positional[1] ?? [flags["dry-run"], flags.overwrite].find((v) => typeof v === "string");
|
|
432
|
+
if (!file) {
|
|
433
|
+
line(COMMAND_HELP.config);
|
|
434
|
+
return 1;
|
|
435
|
+
}
|
|
436
|
+
let document;
|
|
437
|
+
try {
|
|
438
|
+
document = JSON.parse(readFileSync(resolve(projectDir, file), "utf8"));
|
|
439
|
+
}
|
|
440
|
+
catch (error) {
|
|
441
|
+
throw new FeltKitError("INVALID_ARGUMENT", `Could not read ${file} as JSON: ${error.message}`);
|
|
442
|
+
}
|
|
443
|
+
const options = { dryRun: flags["dry-run"] !== undefined && flags["dry-run"] !== false, overwrite: flags.overwrite !== undefined && flags.overwrite !== false };
|
|
444
|
+
const { value, source } = await withEnvironment(projectDir, envName, (record, token) => adminRequest(record, token, "/configuration/import", { method: "POST", body: JSON.stringify({ document, ...options }) }), (runtime) => runtime.services.importConfiguration(document, options));
|
|
445
|
+
if (json)
|
|
446
|
+
line(JSON.stringify(value, null, 2));
|
|
447
|
+
else {
|
|
448
|
+
line(`${c.bold(`${value.dryRun ? "Plan" : "Imported"}: ${envName}`)} ${c.dim(`(${value.environment}) — ${source}`)}`);
|
|
449
|
+
for (const item of value.items) {
|
|
450
|
+
const mark = item.error || item.action === "conflict" ? symbols.fail : item.action === "missing" || item.action === "skip" ? c.yellow("!") : symbols.ok;
|
|
451
|
+
line(` ${mark} ${item.kind} ${item.key}: ${item.action}${item.applied ? " (applied)" : ""}${item.reason ? c.dim(` — ${item.reason}`) : ""}${item.error ? ` — ${item.error.code}: ${item.error.message}` : ""}`);
|
|
452
|
+
}
|
|
453
|
+
const custody = new EnvironmentCredentials();
|
|
454
|
+
for (const missing of value.missingSecrets) {
|
|
455
|
+
const variable = custody.describe(missing.sourceCredentialRef).variable;
|
|
456
|
+
line(` ${c.yellow("!")} attach credential ${missing.name}${missing.required ? " (required)" : ""} in ${envName}; the source used ${missing.sourceCredentialRef}${variable ? ` (${variable})` : ""}`);
|
|
457
|
+
}
|
|
458
|
+
line(c.dim(`\n${Object.entries(value.summary).map(([k, n]) => `${k} ${n}`).join(" · ")}${value.dryRun ? " · nothing was written" : ""}`));
|
|
459
|
+
}
|
|
460
|
+
return value.summary.failed > 0 || value.summary.conflict > 0 ? 1 : 0;
|
|
461
|
+
}
|
|
462
|
+
line(COMMAND_HELP.config);
|
|
463
|
+
return 1;
|
|
464
|
+
}
|
|
465
|
+
case "operator": {
|
|
466
|
+
if (positional[0] !== "grant" || !flags.id || !flags.role) {
|
|
467
|
+
line(COMMAND_HELP.operator);
|
|
468
|
+
return 1;
|
|
469
|
+
}
|
|
470
|
+
const env = String(flags.env ?? "production");
|
|
471
|
+
// The application's declared roles: from the production build when there is one, else the sources.
|
|
472
|
+
const bundle = join(projectDir, ".feltkit", "build", "functions.mjs");
|
|
473
|
+
const project = existsSync(bundle) ? await loadBundle(bundle) : await loadSources(projectDir);
|
|
474
|
+
const roles = String(flags.role).split(",").map((r) => r.trim()).filter(Boolean);
|
|
475
|
+
const declared = project.app.options.roles ?? {};
|
|
476
|
+
const unknown = roles.filter((r) => !declared[r]);
|
|
477
|
+
if (unknown.length)
|
|
478
|
+
throw new FeltKitError("INVALID_ARGUMENT", `Unknown role(s) ${unknown.join(", ")}. Declared roles: ${Object.keys(declared).join(", ") || "(none)"}.`);
|
|
479
|
+
const environment = resolveEnvironment({ projectDir, appName: project.app.name, name: env });
|
|
480
|
+
const ttlMs = flags.ttl ? Number(flags.ttl) * 60_000 : undefined;
|
|
481
|
+
const grant = createGrant(operatorKey(environment.runtimeDir), {
|
|
482
|
+
application: project.app.name,
|
|
483
|
+
environment: environment.name,
|
|
484
|
+
subject: String(flags.id),
|
|
485
|
+
roles,
|
|
486
|
+
...(flags.name ? { name: String(flags.name) } : {}),
|
|
487
|
+
...(ttlMs ? { ttlMs } : {}),
|
|
488
|
+
});
|
|
489
|
+
if (json)
|
|
490
|
+
line(JSON.stringify({ grant, subject: String(flags.id), roles, environment: environment.name }, null, 2));
|
|
491
|
+
else {
|
|
492
|
+
line(`${symbols.ok} One-time Studio sign-in for ${c.bold(String(flags.id))} (roles: ${roles.join(", ")}) in ${environment.name}`);
|
|
493
|
+
line(`\n ${grant}\n`);
|
|
494
|
+
line(c.dim(`Paste it into Studio (/_feltkit/) within ${Math.round((ttlMs ?? 600_000) / 60_000)} minutes. It works once. Anyone holding it can sign in as this operator: send it privately.`));
|
|
495
|
+
}
|
|
496
|
+
return 0;
|
|
497
|
+
}
|
|
498
|
+
case "skills": {
|
|
499
|
+
const action = positional[0];
|
|
500
|
+
const target = skillsTarget({ projectDir, user: flags.user === true, ...(flags.dir ? { dir: String(flags.dir) } : {}) });
|
|
501
|
+
if (action === "install" || action === "update") {
|
|
502
|
+
const result = installSkills(target, { force: flags.force === true });
|
|
503
|
+
if (json)
|
|
504
|
+
line(JSON.stringify(result, null, 2));
|
|
505
|
+
else {
|
|
506
|
+
for (const skill of result.installed)
|
|
507
|
+
line(`${symbols.ok} ${skill} ${c.dim(`${result.version} → ${join(target, skill)}`)}`);
|
|
508
|
+
for (const skip of result.skipped)
|
|
509
|
+
line(`${symbols.fail} ${skip.skill}: ${skip.reason}`);
|
|
510
|
+
line(c.dim("\nGuidance for coding agents; they grant no permission. Check with `feltkit skills check`."));
|
|
511
|
+
}
|
|
512
|
+
return result.skipped.length ? 1 : 0;
|
|
513
|
+
}
|
|
514
|
+
if (action === "check") {
|
|
515
|
+
const result = checkSkills(target);
|
|
516
|
+
if (json)
|
|
517
|
+
line(JSON.stringify(result, null, 2));
|
|
518
|
+
else if (result.ok)
|
|
519
|
+
line(`${symbols.ok} ${result.skills.length} FeltKit skills installed in ${target} for ${result.version}`);
|
|
520
|
+
else
|
|
521
|
+
for (const p of result.problems)
|
|
522
|
+
line(`${symbols.fail} ${p.skill}: ${p.problem}`);
|
|
523
|
+
return result.ok ? 0 : 1;
|
|
524
|
+
}
|
|
525
|
+
if (action === "list") {
|
|
526
|
+
const { version, skills } = shippedSkills();
|
|
527
|
+
if (json)
|
|
528
|
+
line(JSON.stringify({ version, skills }, null, 2));
|
|
529
|
+
else
|
|
530
|
+
for (const skill of skills)
|
|
531
|
+
line(` ${skill} ${c.dim(version)}`);
|
|
532
|
+
return 0;
|
|
533
|
+
}
|
|
534
|
+
line(COMMAND_HELP.skills);
|
|
535
|
+
return 1;
|
|
536
|
+
}
|
|
321
537
|
default:
|
|
322
538
|
line(`${symbols.fail} Unknown command "${command}".\n`);
|
|
323
539
|
line(HELP);
|