@feltdb/core 0.8.0 → 0.8.2

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.
Files changed (85) hide show
  1. package/dist/application-development.d.ts +7 -2
  2. package/dist/application-development.d.ts.map +1 -1
  3. package/dist/application-development.js +7 -13
  4. package/dist/application-manifest.d.ts +1 -0
  5. package/dist/application-manifest.d.ts.map +1 -1
  6. package/dist/application-manifest.js +1 -1
  7. package/dist/application-understanding.d.ts +76 -0
  8. package/dist/application-understanding.d.ts.map +1 -0
  9. package/dist/application-understanding.js +282 -0
  10. package/dist/cli/ai-model-config.js +3 -3
  11. package/dist/cli/commands.js +131 -38
  12. package/dist/cli/proposal-client.js +5 -1
  13. package/dist/cli/publish-engine.js +1 -1
  14. package/dist/cli/repository-evidence.js +55 -0
  15. package/dist/cli/source-sync.js +190 -75
  16. package/dist/convergence.d.ts +55 -0
  17. package/dist/convergence.d.ts.map +1 -0
  18. package/dist/convergence.js +63 -0
  19. package/dist/create/managed-account.js +1 -0
  20. package/dist/create/package-versions.js +1 -1
  21. package/dist/create/server-source/crates/feltdb/src/application.rs +23 -0
  22. package/dist/create/server-source/crates/feltdb/src/authority.rs +349 -0
  23. package/dist/create/server-source/crates/feltdb/src/bin/feltdb-authority-client.rs +32 -0
  24. package/dist/create/server-source/crates/feltdb/src/bin/feltdb-authority.rs +19 -0
  25. package/dist/create/server-source/crates/feltdb/src/lib.rs +444 -189
  26. package/dist/create/server-source/crates/feltdb/src/state_contract.rs +244 -51
  27. package/dist/create/server-source/crates/feltdb/tests/authority_process.rs +297 -0
  28. package/dist/create/server-source/crates/feltdb-server/src/auth.rs +41 -11
  29. package/dist/create/server-source/crates/feltdb-server/src/connections.rs +14 -0
  30. package/dist/create/server-source/crates/feltdb-server/src/key_management.rs +8 -3
  31. package/dist/create/server-source/crates/feltdb-server/src/main.rs +1262 -173
  32. package/dist/create/server-source/crates/feltdb-server/src/tenancy.rs +142 -1
  33. package/dist/create/template/default-project/src/context/AuthContext.tsx +9 -1
  34. package/dist/create/template/default-project/src/pages/SignUp.tsx +1 -1
  35. package/dist/flowspec.d.ts.map +1 -1
  36. package/dist/flowspec.js +6 -1
  37. package/dist/http-client.d.ts +32 -1
  38. package/dist/http-client.d.ts.map +1 -1
  39. package/dist/http-client.js +14 -2
  40. package/dist/http-db.d.ts +6 -0
  41. package/dist/http-db.d.ts.map +1 -1
  42. package/dist/http-db.js +30 -4
  43. package/dist/index-core.d.ts +3 -0
  44. package/dist/index-core.d.ts.map +1 -1
  45. package/dist/index-core.js +3 -0
  46. package/dist/intent.d.ts +98 -0
  47. package/dist/intent.d.ts.map +1 -0
  48. package/dist/intent.js +343 -0
  49. package/dist/module-intent.d.ts +19 -5
  50. package/dist/module-intent.d.ts.map +1 -1
  51. package/dist/module-intent.js +211 -62
  52. package/dist/module.d.ts +41 -12
  53. package/dist/module.d.ts.map +1 -1
  54. package/dist/module.js +543 -38
  55. package/dist/proposal.d.ts +13 -1
  56. package/dist/proposal.d.ts.map +1 -1
  57. package/dist/proposal.js +21 -4
  58. package/dist/state-contract.d.ts +4 -1
  59. package/dist/state-contract.d.ts.map +1 -1
  60. package/dist/state-contract.js +1 -1
  61. package/dist/studio/components/AskFeltDB.d.ts.map +1 -1
  62. package/dist/studio/components/ProposalBrowser.d.ts +1 -1
  63. package/dist/studio/components/ProposalBrowser.d.ts.map +1 -1
  64. package/dist/studio/components/index.js +1 -1
  65. package/dist/studio/{components-CNSNrmA9.js → components-Duq2xQWt.js} +251 -193
  66. package/dist/studio/index.js +1 -1
  67. package/dist/studio/studio.css +1 -1
  68. package/dist/studio/utils/proposal-api.d.ts +4 -1
  69. package/dist/studio/utils/proposal-api.d.ts.map +1 -1
  70. package/dist/studio/utils/proposal-api.js +3 -0
  71. package/dist/studio-app/assets/{feltdb_wasm-CSB6KVgw.js → feltdb_wasm-DB8cX151.js} +1 -1
  72. package/dist/studio-app/assets/feltdb_wasm_bg-ClhDHp0S.wasm +0 -0
  73. package/dist/studio-app/assets/index-B0k4UAlI.js +29 -0
  74. package/dist/studio-app/assets/{index-yazaWMUN.css → index-Cd_NPw14.css} +1 -1
  75. package/dist/studio-app/index.html +2 -2
  76. package/dist/wasm/feltdb_wasm_bg.wasm +0 -0
  77. package/dist/workspace/local-development-authority.d.ts +2 -0
  78. package/dist/workspace/local-development-authority.d.ts.map +1 -1
  79. package/dist/workspace/local-development-authority.js +65 -2
  80. package/package.json +1 -1
  81. package/dist/studio-app/assets/dist-CCOk39Uc.js +0 -1
  82. package/dist/studio-app/assets/feltdb_wasm_bg-Dd1fnO9U.wasm +0 -0
  83. package/dist/studio-app/assets/index-Bncji3aN.js +0 -43
  84. package/dist/studio-app/assets/lib-B2_7fcn7.js +0 -69
  85. package/dist/studio-app/assets/worker-CARZ5g7K.js +0 -69
@@ -0,0 +1,98 @@
1
+ import type { ApplicationUnderstanding, ObservedEvidenceInput } from "./application-understanding.js";
2
+ import { type FeltDBContractSnapshot } from "./application-development.js";
3
+ import { type ModuleImplementationPlan } from "./module-intent.js";
4
+ import { FeltDBProposalService, type FeltDBProposalPreviewArtifact, type FeltDBProposalRecord, type ProposalContext, type ProposalStore } from "./proposal.js";
5
+ export declare const FELTDB_INTENT_COLLECTION = "_feltdb.Intent";
6
+ export declare const FELTDB_INTENT_EVENT_COLLECTION = "_feltdb.IntentEvent";
7
+ export type IntentStatus = "received" | "resolving" | "understanding" | "planning" | "proposal_created" | "completed" | "blocked" | "failed";
8
+ export interface IntentAmbiguity {
9
+ code: "requires_selection" | "module_not_available" | "clarification_required";
10
+ message: string;
11
+ candidates: string[];
12
+ }
13
+ export interface Intent {
14
+ id: string;
15
+ application_id: string;
16
+ environment: string;
17
+ raw_request: string;
18
+ action: "implement" | "extend" | "unknown";
19
+ target: "module" | "billing" | "unknown";
20
+ module?: string;
21
+ module_version?: string;
22
+ parent_intent_id?: string;
23
+ contract_hash: string;
24
+ flow_hash: string;
25
+ status: IntentStatus;
26
+ ambiguities: IntentAmbiguity[];
27
+ created_at: string;
28
+ understanding?: ApplicationUnderstanding;
29
+ plan?: ImplementationPlan;
30
+ proposal_id?: string;
31
+ }
32
+ export interface IntentEvent {
33
+ id: string;
34
+ intent_id: string;
35
+ status: IntentStatus;
36
+ created_at: string;
37
+ metadata: Record<string, string>;
38
+ }
39
+ export interface ConfidenceRule {
40
+ claim: string;
41
+ minimum_confidence: number;
42
+ allowed_authority: Array<"authoritative" | "observed" | "inferred">;
43
+ clarification: "block" | "warn";
44
+ }
45
+ export declare const DEFAULT_CONFIDENCE_POLICY: ConfidenceRule[];
46
+ export interface ImplementationPlan {
47
+ intent: Intent;
48
+ module: ModuleImplementationPlan["module"];
49
+ already_installed: boolean;
50
+ state_changes: ModuleImplementationPlan["applicationModels"];
51
+ relationships: string[];
52
+ events: string[];
53
+ workflows: string[];
54
+ capabilities: string[];
55
+ authorization: ModuleImplementationPlan["authorization"];
56
+ configuration: string[];
57
+ secrets: string[];
58
+ dependencies: ModuleImplementationPlan["dependencies"];
59
+ ownership: Record<string, string>;
60
+ assumptions: ApplicationUnderstanding["assumptions"];
61
+ evidence: string[];
62
+ source_plan: {
63
+ files: Array<{
64
+ path: string;
65
+ operation: "add" | "modify" | "delete";
66
+ role?: string;
67
+ }>;
68
+ };
69
+ warnings: string[];
70
+ }
71
+ export interface IntentExecutionResult {
72
+ intent: Intent;
73
+ understanding?: ApplicationUnderstanding;
74
+ plan?: ImplementationPlan;
75
+ proposal?: FeltDBProposalRecord;
76
+ preview?: FeltDBProposalPreviewArtifact;
77
+ blockers: string[];
78
+ warnings: string[];
79
+ }
80
+ export declare function resolveIntent(request: string, context: {
81
+ snapshot: FeltDBContractSnapshot;
82
+ flowHash: string;
83
+ parentIntentId?: string;
84
+ }): Intent;
85
+ export declare function validateImplementationPlan(plan: ImplementationPlan, understanding: ApplicationUnderstanding, policy?: ConfidenceRule[]): string[];
86
+ export declare class IntentService {
87
+ private store;
88
+ private context;
89
+ private proposals;
90
+ private observations?;
91
+ constructor(store: ProposalStore, context: () => Promise<ProposalContext>, proposals: FeltDBProposalService, observations?: (() => ObservedEvidenceInput[] | Promise<ObservedEvidenceInput[]>) | undefined);
92
+ execute(rawRequest: string, actor?: string): Promise<IntentExecutionResult>;
93
+ list(): Promise<Intent[]>;
94
+ get(id: string): Promise<Intent>;
95
+ history(id: string): Promise<IntentEvent[]>;
96
+ private event;
97
+ }
98
+ //# sourceMappingURL=intent.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"intent.d.ts","sourceRoot":"","sources":["../src/intent.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EACV,wBAAwB,EACxB,qBAAqB,EACtB,MAAM,gCAAgC,CAAC;AACxC,OAAO,EAEL,KAAK,sBAAsB,EAC5B,MAAM,8BAA8B,CAAC;AACtC,OAAO,EAGL,KAAK,wBAAwB,EAC9B,MAAM,oBAAoB,CAAC;AAE5B,OAAO,EACL,qBAAqB,EACrB,KAAK,6BAA6B,EAClC,KAAK,oBAAoB,EACzB,KAAK,eAAe,EACpB,KAAK,aAAa,EACnB,MAAM,eAAe,CAAC;AAGvB,eAAO,MAAM,wBAAwB,mBAAmB,CAAC;AACzD,eAAO,MAAM,8BAA8B,wBAAwB,CAAC;AACpE,MAAM,MAAM,YAAY,GACpB,UAAU,GACV,WAAW,GACX,eAAe,GACf,UAAU,GACV,kBAAkB,GAClB,WAAW,GACX,SAAS,GACT,QAAQ,CAAC;AACb,MAAM,WAAW,eAAe;IAC9B,IAAI,EACA,oBAAoB,GACpB,sBAAsB,GACtB,wBAAwB,CAAC;IAC7B,OAAO,EAAE,MAAM,CAAC;IAChB,UAAU,EAAE,MAAM,EAAE,CAAC;CACtB;AACD,MAAM,WAAW,MAAM;IACrB,EAAE,EAAE,MAAM,CAAC;IACX,cAAc,EAAE,MAAM,CAAC;IACvB,WAAW,EAAE,MAAM,CAAC;IACpB,WAAW,EAAE,MAAM,CAAC;IACpB,MAAM,EAAE,WAAW,GAAG,QAAQ,GAAG,SAAS,CAA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OAAO,CAAC,OAAO;IACf,OAAO,CAAC,SAAS;IACjB,OAAO,CAAC,YAAY,CAAC;gBAHb,KAAK,EAAE,aAAa,EACpB,OAAO,EAAE,MAAM,OAAO,CAAC,eAAe,CAAC,EACvC,SAAS,EAAE,qBAAqB,EAChC,YAAY,CAAC,GAAE,MACnB,qBAAqB,EAAE,GACvB,OAAO,CAAC,qBAAqB,EAAE,CAAC,aAAA;IAEhC,OAAO,CACX,UAAU,EAAE,MAAM,EAClB,KAAK,SAAc,GAClB,OAAO,CAAC,qBAAqB,CAAC;IAiK3B,IAAI;IAGJ,GAAG,CAAC,EAAE,EAAE,MAAM;IAKd,OAAO,CAAC,EAAE,EAAE,MAAM;YAKV,KAAK;CAcpB"}
package/dist/intent.js ADDED
@@ -0,0 +1,343 @@
1
+ import { flowSourceHash, } from "./application-development.js";
2
+ import { createModuleImplementationProposal, resolveModuleIntent, } from "./module-intent.js";
3
+ import { listFeltDBModules, resolveFeltDBModule } from "./module.js";
4
+ import { diffFlowSpec, parseFlowSpec } from "./flowspec.js";
5
+ export const FELTDB_INTENT_COLLECTION = "_feltdb.Intent";
6
+ export const FELTDB_INTENT_EVENT_COLLECTION = "_feltdb.IntentEvent";
7
+ export const DEFAULT_CONFIDENCE_POLICY = [
8
+ {
9
+ claim: "module.owner",
10
+ minimum_confidence: 0.9,
11
+ allowed_authority: ["authoritative", "observed", "inferred"],
12
+ clarification: "block",
13
+ },
14
+ {
15
+ claim: "payment.authority",
16
+ minimum_confidence: 1,
17
+ allowed_authority: ["authoritative"],
18
+ clarification: "block",
19
+ },
20
+ ];
21
+ export function resolveIntent(request, context) {
22
+ const raw = request.trim();
23
+ let resolved;
24
+ const ambiguities = [];
25
+ try {
26
+ resolved = resolveModuleIntent(raw);
27
+ }
28
+ catch (error) {
29
+ const message = error instanceof Error ? error.message : String(error);
30
+ ambiguities.push({
31
+ code: message.startsWith("MODULE_NOT_AVAILABLE")
32
+ ? "module_not_available"
33
+ : "requires_selection",
34
+ message,
35
+ candidates: listFeltDBModules().map((value) => value.id),
36
+ });
37
+ }
38
+ if (!resolved && !ambiguities.length)
39
+ ambiguities.push({
40
+ code: "requires_selection",
41
+ message: "Intent target is not deterministically resolvable.",
42
+ candidates: listFeltDBModules().map((value) => value.id),
43
+ });
44
+ return {
45
+ id: `in_${crypto.randomUUID().replaceAll("-", "")}`,
46
+ application_id: context.snapshot.application.application_id,
47
+ environment: context.snapshot.application.environment,
48
+ raw_request: raw,
49
+ action: resolved?.action ?? "unknown",
50
+ target: resolved ? "module" : "unknown",
51
+ module: resolved?.module,
52
+ module_version: resolved?.version,
53
+ parent_intent_id: context.parentIntentId,
54
+ contract_hash: context.snapshot.contract_hash,
55
+ flow_hash: context.flowHash,
56
+ status: ambiguities.length ? "blocked" : "resolving",
57
+ ambiguities,
58
+ created_at: new Date().toISOString(),
59
+ };
60
+ }
61
+ export function validateImplementationPlan(plan, understanding, policy = DEFAULT_CONFIDENCE_POLICY) {
62
+ const blockers = [];
63
+ const registered = resolveFeltDBModule({
64
+ name: plan.module.id,
65
+ provider: plan.module.provider,
66
+ version: plan.module.version,
67
+ });
68
+ if (registered.version !== plan.module.version)
69
+ blockers.push("module_version_mismatch");
70
+ const moduleModels = new Map(registered.models.map((value) => [value.name, value]));
71
+ for (const model of plan.state_changes) {
72
+ const authoritative = moduleModels.get(model.name);
73
+ if (model.ownership === "external-authoritative" &&
74
+ (!authoritative || authoritative.ownership !== model.ownership))
75
+ blockers.push(`invalid_module_model:${model.name}`);
76
+ }
77
+ for (const capability of plan.capabilities)
78
+ if (!registered.capabilities.includes(capability))
79
+ blockers.push(`undeclared_capability:${capability}`);
80
+ const declaredEvents = new Set(registered.reconciliation.map((value) => value.event));
81
+ for (const event of plan.events)
82
+ if (!declaredEvents.has(event))
83
+ blockers.push(`undeclared_event:${event}`);
84
+ const declaredWorkflows = new Set(registered.reconciliation.map((value) => value.workflow));
85
+ for (const workflow of plan.workflows)
86
+ if (!declaredWorkflows.has(workflow))
87
+ blockers.push(`undeclared_workflow:${workflow}`);
88
+ const declaredConfiguration = new Set(registered.configuration.map((value) => value.name));
89
+ for (const name of plan.configuration)
90
+ if (!declaredConfiguration.has(name))
91
+ blockers.push(`undeclared_configuration:${name}`);
92
+ const declaredSecrets = new Set(registered.secrets.map((value) => value.name));
93
+ for (const name of plan.secrets)
94
+ if (!declaredSecrets.has(name))
95
+ blockers.push(`undeclared_secret:${name}`);
96
+ for (const rule of policy) {
97
+ if (rule.claim === "payment.authority") {
98
+ if (!plan.module.models.some((value) => value.ownership === "external-authoritative"))
99
+ blockers.push("external_authority_not_module_authoritative");
100
+ continue;
101
+ }
102
+ const claim = rule.claim === "module.owner"
103
+ ? plan.module.placement.owner_claim
104
+ : rule.claim;
105
+ const inference = understanding.inferences.find((value) => value.claim === claim);
106
+ if (!inference ||
107
+ !inference.evidence.length ||
108
+ inference.confidence < rule.minimum_confidence ||
109
+ !rule.allowed_authority.includes(inference.authority))
110
+ blockers.push(`${claim}_confidence`);
111
+ }
112
+ if (plan.secrets.some((value) => /[=:]|sk_live|sk_test|whsec_/i.test(value)))
113
+ blockers.push("secret_value_in_plan");
114
+ for (const relationship of plan.relationships)
115
+ if (!relationship.includes(" -> "))
116
+ blockers.push(`invalid_relationship:${relationship}`);
117
+ return [...new Set(blockers)];
118
+ }
119
+ function canonicalPlan(intent, implementation, understanding) {
120
+ const artifacts = implementation.module.source_artifacts.map((value) => ({
121
+ path: value.path,
122
+ operation: (implementation.alreadyInstalled ? "modify" : "add"),
123
+ role: value.role,
124
+ }));
125
+ return {
126
+ intent: { ...intent },
127
+ module: implementation.module,
128
+ already_installed: implementation.alreadyInstalled,
129
+ state_changes: implementation.applicationModels,
130
+ relationships: implementation.relationships,
131
+ events: implementation.events,
132
+ workflows: implementation.workflows,
133
+ capabilities: implementation.capabilities,
134
+ authorization: implementation.authorization,
135
+ configuration: implementation.configuration,
136
+ secrets: implementation.secrets,
137
+ dependencies: implementation.dependencies,
138
+ ownership: {
139
+ [implementation.primaryApplicationModel]: implementation.owner,
140
+ },
141
+ assumptions: understanding.assumptions,
142
+ evidence: understanding.evidence.map((value) => value.id),
143
+ source_plan: {
144
+ files: [
145
+ {
146
+ path: "feltdb.flow",
147
+ operation: "modify",
148
+ role: "application-contract",
149
+ },
150
+ {
151
+ path: "src/feltdb/generated-contract.ts",
152
+ operation: "modify",
153
+ role: "generated-contract",
154
+ },
155
+ ...artifacts,
156
+ ],
157
+ },
158
+ warnings: implementation.warnings,
159
+ };
160
+ }
161
+ export class IntentService {
162
+ store;
163
+ context;
164
+ proposals;
165
+ observations;
166
+ constructor(store, context, proposals, observations) {
167
+ this.store = store;
168
+ this.context = context;
169
+ this.proposals = proposals;
170
+ this.observations = observations;
171
+ }
172
+ async execute(rawRequest, actor = "developer") {
173
+ const context = await this.context();
174
+ const prior = await this.store.list(FELTDB_INTENT_COLLECTION);
175
+ const proposalHistory = await this.proposals.list();
176
+ let resolvedModule;
177
+ try {
178
+ resolvedModule = resolveModuleIntent(rawRequest);
179
+ }
180
+ catch { }
181
+ const parentProposal = resolvedModule
182
+ ? proposalHistory
183
+ .filter((value) => value.metadata.module === resolvedModule.module &&
184
+ value.status === "applied")
185
+ .at(-1)
186
+ : undefined;
187
+ const parentIntent = parentProposal
188
+ ? prior.find((value) => value.id === parentProposal.metadata.intent_id)
189
+ : undefined;
190
+ const intent = resolveIntent(rawRequest, {
191
+ snapshot: context.snapshot,
192
+ flowHash: await flowSourceHash(context.source),
193
+ parentIntentId: parentIntent?.id,
194
+ });
195
+ await this.store.create(FELTDB_INTENT_COLLECTION, intent.id, intent);
196
+ await this.event(intent, "received");
197
+ if (intent.ambiguities.length) {
198
+ await this.event(intent, "blocked");
199
+ return {
200
+ intent,
201
+ blockers: intent.ambiguities.map((value) => value.code),
202
+ warnings: [],
203
+ };
204
+ }
205
+ const moduleIntent = resolveModuleIntent(rawRequest);
206
+ const convergence = await this.store.list("_feltdb.Convergence");
207
+ const convergenceEvidence = convergence
208
+ .filter((value) => value.proposal_id === parentProposal?.id)
209
+ .slice(-5)
210
+ .flatMap((value) => (value.findings ?? [])
211
+ .slice(0, 20)
212
+ .map((finding) => ({
213
+ source: "proposal_history",
214
+ claim: `convergence.${finding.claim}`,
215
+ value: finding.status,
216
+ source_ref: `proposal:${value.proposal_id}`,
217
+ })));
218
+ const observed = [
219
+ ...(context.observations ?? []),
220
+ ...((await this.observations?.()) ?? []),
221
+ ...convergenceEvidence,
222
+ ];
223
+ let generated;
224
+ try {
225
+ generated = await createModuleImplementationProposal({
226
+ intent: rawRequest,
227
+ snapshot: context.snapshot,
228
+ currentFlow: context.source,
229
+ observations: observed,
230
+ });
231
+ }
232
+ catch (error) {
233
+ const message = error instanceof Error ? error.message : String(error);
234
+ intent.status = "blocked";
235
+ intent.ambiguities.push({
236
+ code: message.startsWith("CLARIFICATION_REQUIRED")
237
+ ? "clarification_required"
238
+ : "requires_selection",
239
+ message,
240
+ candidates: [],
241
+ });
242
+ await this.store.replace(FELTDB_INTENT_COLLECTION, intent.id, intent);
243
+ await this.event(intent, "blocked", { reason: message });
244
+ return { intent, blockers: [message], warnings: [] };
245
+ }
246
+ const understanding = generated.understanding;
247
+ intent.status = "understanding";
248
+ intent.understanding = understanding;
249
+ await this.store.replace(FELTDB_INTENT_COLLECTION, intent.id, intent);
250
+ await this.event(intent, "understanding");
251
+ const plan = canonicalPlan(intent, generated.implementation, understanding);
252
+ intent.plan = plan;
253
+ const blockers = validateImplementationPlan(plan, understanding);
254
+ if (blockers.length) {
255
+ intent.status = "blocked";
256
+ await this.store.replace(FELTDB_INTENT_COLLECTION, intent.id, intent);
257
+ await this.event(intent, "blocked");
258
+ return { intent, understanding, plan, blockers, warnings: plan.warnings };
259
+ }
260
+ const diff = diffFlowSpec(parseFlowSpec(context.source), parseFlowSpec(generated.proposedFlow));
261
+ if (plan.already_installed &&
262
+ diff.added.length === 0 &&
263
+ diff.removed.length === 0 &&
264
+ diff.changed.length === 0) {
265
+ intent.status = "completed";
266
+ await this.store.replace(FELTDB_INTENT_COLLECTION, intent.id, intent);
267
+ await this.event(intent, "completed", { result: "already_converged" });
268
+ return {
269
+ intent,
270
+ understanding,
271
+ plan,
272
+ blockers: [],
273
+ warnings: [
274
+ "The requested module is already installed and converged. No proposal created.",
275
+ ],
276
+ };
277
+ }
278
+ intent.status = "planning";
279
+ await this.store.replace(FELTDB_INTENT_COLLECTION, intent.id, intent);
280
+ await this.event(intent, "planning");
281
+ let proposal = await this.proposals.create({
282
+ application_id: intent.application_id,
283
+ environment: intent.environment,
284
+ base_contract_hash: generated.baseContractHash,
285
+ base_flow_hash: generated.baseFlowHash,
286
+ proposed_flow: generated.proposedFlow,
287
+ summary: generated.summary,
288
+ warnings: generated.warnings,
289
+ actor,
290
+ metadata: {
291
+ created_from: "intent-engine",
292
+ intent_id: intent.id,
293
+ module: moduleIntent.module,
294
+ module_version: moduleIntent.version,
295
+ },
296
+ parent_proposal_id: parentProposal?.id,
297
+ understanding,
298
+ contract_diff: generated.changes,
299
+ source_plan: plan.source_plan,
300
+ });
301
+ await this.proposals.validate(proposal.id, "feltdb-validator");
302
+ const preview = await this.proposals.preview(proposal.id, actor);
303
+ proposal = preview.proposal;
304
+ intent.status = "proposal_created";
305
+ intent.proposal_id = proposal.id;
306
+ await this.store.replace(FELTDB_INTENT_COLLECTION, intent.id, intent);
307
+ await this.event(intent, "proposal_created", { proposal_id: proposal.id });
308
+ intent.status = "completed";
309
+ await this.store.replace(FELTDB_INTENT_COLLECTION, intent.id, intent);
310
+ await this.event(intent, "completed");
311
+ return {
312
+ intent,
313
+ understanding,
314
+ plan,
315
+ proposal,
316
+ preview,
317
+ blockers: [],
318
+ warnings: plan.warnings,
319
+ };
320
+ }
321
+ async list() {
322
+ return this.store.list(FELTDB_INTENT_COLLECTION);
323
+ }
324
+ async get(id) {
325
+ const value = await this.store.get(FELTDB_INTENT_COLLECTION, id);
326
+ if (!value)
327
+ throw new Error("INTENT_NOT_FOUND");
328
+ return value;
329
+ }
330
+ async history(id) {
331
+ return (await this.store.list(FELTDB_INTENT_EVENT_COLLECTION)).filter((value) => value.intent_id === id);
332
+ }
333
+ async event(intent, status, metadata = {}) {
334
+ const value = {
335
+ id: `ie_${crypto.randomUUID().replaceAll("-", "")}`,
336
+ intent_id: intent.id,
337
+ status,
338
+ created_at: new Date().toISOString(),
339
+ metadata,
340
+ };
341
+ await this.store.create(FELTDB_INTENT_EVENT_COLLECTION, value.id, value);
342
+ }
343
+ }
@@ -1,7 +1,8 @@
1
- import type { FeltDBContractSnapshot, FeltDBFlowProposal } from './application-development.js';
2
- import { type FeltDBModuleDefinition, type FeltDBModuleOwnership } from './module.js';
1
+ import type { FeltDBContractSnapshot, FeltDBFlowProposal } from "./application-development.js";
2
+ import { type FeltDBModuleDefinition, type FeltDBModuleOwnership } from "./module.js";
3
+ import { type ApplicationUnderstanding, type ObservedEvidenceInput } from "./application-understanding.js";
3
4
  export interface ModuleIntent {
4
- action: 'implement' | 'extend';
5
+ action: "implement" | "extend";
5
6
  module: string;
6
7
  provider: string;
7
8
  version: string;
@@ -12,26 +13,39 @@ export interface ModuleImplementationPlan {
12
13
  module: FeltDBModuleDefinition;
13
14
  alreadyInstalled: boolean;
14
15
  owner: string;
16
+ ownerClaim: string;
17
+ primaryApplicationModel: string;
15
18
  applicationModels: Array<{
16
19
  name: string;
17
20
  ownership: FeltDBModuleOwnership;
18
21
  purpose: string;
22
+ fields: Array<{
23
+ name: string;
24
+ type: string;
25
+ optional?: boolean;
26
+ }>;
19
27
  }>;
20
28
  relationships: string[];
21
29
  events: string[];
22
30
  workflows: string[];
23
31
  capabilities: string[];
24
- authorization: FeltDBModuleDefinition['authorization'];
32
+ authorization: FeltDBModuleDefinition["authorization"];
25
33
  configuration: string[];
26
34
  secrets: string[];
35
+ dependencies: Array<{
36
+ name: string;
37
+ status: "satisfied" | "missing";
38
+ evidence: string[];
39
+ }>;
27
40
  stateFlow: string[];
28
41
  warnings: string[];
29
42
  }
30
43
  export declare function resolveModuleIntent(value: string): ModuleIntent | undefined;
31
- export declare function planModuleImplementation(intent: ModuleIntent, snapshot: FeltDBContractSnapshot, currentFlow: string): ModuleImplementationPlan;
44
+ export declare function planModuleImplementation(intent: ModuleIntent, snapshot: FeltDBContractSnapshot, currentFlow: string, understanding: ApplicationUnderstanding): ModuleImplementationPlan;
32
45
  export declare function createModuleImplementationProposal(input: {
33
46
  intent: string;
34
47
  snapshot: FeltDBContractSnapshot;
35
48
  currentFlow: string;
49
+ observations?: ObservedEvidenceInput[];
36
50
  }): Promise<FeltDBFlowProposal>;
37
51
  //# sourceMappingURL=module-intent.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"module-intent.d.ts","sourceRoot":"","sources":["../src/module-intent.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,sBAAsB,EAAE,kBAAkB,EAAE,MAAM,8BAA8B,CAAC;AAE/F,OAAO,EAA6D,KAAK,sBAAsB,EAAE,KAAK,qBAAqB,EAAE,MAAM,aAAa,CAAC;AAEjJ,MAAM,WAAW,YAAY;IAAG,MAAM,EAAE,WAAW,GAAG,QAAQ,CAAC;IAAC,MAAM,EAAE,MAAM,CAAC;IAAC,QAAQ,EAAE,MAAM,CAAC;IAAC,OAAO,EAAE,MAAM,CAAC;IAAC,QAAQ,EAAE,MAAM,CAAA;CAAE;AACrI,MAAM,WAAW,wBAAwB;IACvC,MAAM,EAAE,YAAY,CAAC;IAAC,MAAM,EAAE,sBAAsB,CAAC;IAAC,gBAAgB,EAAE,OAAO,CAAC;IAAC,KAAK,EAAE,MAAM,CAAC;IAC/F,iBAAiB,EAAE,KAAK,CAAC;QAAE,IAAI,EAAE,MAAM,CAAC;QAAC,SAAS,EAAE,qBAAqB,CAAC;QAAC,OAAO,EAAE,MAAM,CAAA;KAAE,CAAC,CAAC;IAC9F,aAAa,EAAE,MAAM,EAAE,CAAC;IAAC,MAAM,EAAE,MAAM,EAAE,CAAC;IAAC,SAAS,EAAE,MAAM,EAAE,CAAC;IAAC,YAAY,EAAE,MAA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