@feltdb/core 0.6.9 → 0.6.11

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 (122) hide show
  1. package/dist/cli/application-lifecycle.js +112 -0
  2. package/dist/cli/application.js +10 -0
  3. package/dist/cli/commands.js +407 -119
  4. package/dist/cli/development-session.js +54 -0
  5. package/dist/cli/index.js +1 -1
  6. package/dist/cli/workspace-integration.js +146 -20
  7. package/dist/collection.d.ts +110 -2
  8. package/dist/collection.d.ts.map +1 -1
  9. package/dist/collection.js +228 -3
  10. package/dist/create/cli.js +4 -2
  11. package/dist/create/create.js +42 -6
  12. package/dist/create/frameworks.js +18 -0
  13. package/dist/create/package-versions.js +1 -1
  14. package/dist/create/server-source/crates/feltdb/src/bin/feltdb_node.rs +408 -178
  15. package/dist/create/server-source/crates/feltdb/src/lib.rs +49 -5
  16. package/dist/create/server-source/crates/feltdb/src/multi_operation_transaction.rs +659 -0
  17. package/dist/create/server-source/crates/feltdb/src/p1_application_atomicity.rs +285 -0
  18. package/dist/create/server-source/crates/feltdb/src/p1_atomicity_acceptance.rs +582 -0
  19. package/dist/create/server-source/crates/feltdb-server/src/main.rs +141 -0
  20. package/dist/create/workspace-initialization.js +4 -5
  21. package/dist/db.d.ts +63 -1
  22. package/dist/db.d.ts.map +1 -1
  23. package/dist/db.js +145 -4
  24. package/dist/development-runtime-bridge.d.ts +60 -0
  25. package/dist/development-runtime-bridge.d.ts.map +1 -0
  26. package/dist/development-runtime-bridge.js +171 -0
  27. package/dist/embedded-transaction.d.ts +77 -0
  28. package/dist/embedded-transaction.d.ts.map +1 -0
  29. package/dist/embedded-transaction.js +102 -0
  30. package/dist/feltdb.d.ts +49 -1
  31. package/dist/feltdb.d.ts.map +1 -1
  32. package/dist/file-db.d.ts +33 -0
  33. package/dist/file-db.d.ts.map +1 -1
  34. package/dist/file-db.js +128 -4
  35. package/dist/freshness.d.ts +119 -0
  36. package/dist/freshness.d.ts.map +1 -0
  37. package/dist/freshness.js +115 -0
  38. package/dist/http-db.d.ts +48 -0
  39. package/dist/http-db.d.ts.map +1 -1
  40. package/dist/http-db.js +77 -1
  41. package/dist/index-backend.d.ts +8 -0
  42. package/dist/index-backend.d.ts.map +1 -1
  43. package/dist/index-backend.js +13 -0
  44. package/dist/index-core.d.ts +80 -0
  45. package/dist/index-core.d.ts.map +1 -0
  46. package/dist/index-core.js +74 -0
  47. package/dist/index-manager.d.ts +11 -0
  48. package/dist/index-manager.d.ts.map +1 -1
  49. package/dist/index-manager.js +30 -13
  50. package/dist/index-types.d.ts +17 -0
  51. package/dist/index-types.d.ts.map +1 -1
  52. package/dist/index.browser.d.ts +14 -0
  53. package/dist/index.browser.d.ts.map +1 -0
  54. package/dist/index.browser.js +13 -0
  55. package/dist/index.d.ts +8 -59
  56. package/dist/index.d.ts.map +1 -1
  57. package/dist/index.js +11 -54
  58. package/dist/indexeddb-db.d.ts +32 -0
  59. package/dist/indexeddb-db.d.ts.map +1 -1
  60. package/dist/indexeddb-db.js +151 -1
  61. package/dist/memory-db.d.ts +26 -0
  62. package/dist/memory-db.d.ts.map +1 -1
  63. package/dist/memory-db.js +86 -0
  64. package/dist/runtime-registry.d.ts +32 -0
  65. package/dist/runtime-registry.d.ts.map +1 -0
  66. package/dist/runtime-registry.js +38 -0
  67. package/dist/studio/app.d.ts +2 -1
  68. package/dist/studio/app.d.ts.map +1 -1
  69. package/dist/studio/components/StateExplorer.d.ts +2 -1
  70. package/dist/studio/components/StateExplorer.d.ts.map +1 -1
  71. package/dist/studio/components/index.js +1 -1
  72. package/dist/studio/{components-9kDSWiGL.js → components-C5p2TfIU.js} +25 -14
  73. package/dist/studio/index.js +234 -160
  74. package/dist/studio-app/assets/{feltdb_wasm-B4wq4mqp.js → feltdb_wasm-CJv3wHzi.js} +1 -1
  75. package/dist/studio-app/assets/feltdb_wasm_bg-C8TG8r2n.wasm +0 -0
  76. package/dist/studio-app/assets/index-DospFFYE.js +28 -0
  77. package/dist/studio-app/index.html +1 -1
  78. package/dist/transaction.d.ts +98 -0
  79. package/dist/transaction.d.ts.map +1 -0
  80. package/dist/transaction.js +86 -0
  81. package/dist/wasm/feltdb_wasm_bg.wasm +0 -0
  82. package/dist/workspace/browser.d.ts +22 -0
  83. package/dist/workspace/browser.d.ts.map +1 -0
  84. package/dist/workspace/browser.js +17 -0
  85. package/dist/workspace/development-node.d.ts +16 -0
  86. package/dist/workspace/development-node.d.ts.map +1 -1
  87. package/dist/workspace/development-node.js +85 -1
  88. package/dist/workspace/git-identity.d.ts +35 -0
  89. package/dist/workspace/git-identity.d.ts.map +1 -0
  90. package/dist/workspace/git-identity.js +81 -0
  91. package/dist/workspace/index.d.ts +12 -2
  92. package/dist/workspace/index.d.ts.map +1 -1
  93. package/dist/workspace/index.js +7 -1
  94. package/dist/workspace/investigation-analysis.d.ts +47 -0
  95. package/dist/workspace/investigation-analysis.d.ts.map +1 -0
  96. package/dist/workspace/investigation-analysis.js +181 -0
  97. package/dist/workspace/investigation-lifecycle-manager.d.ts +88 -0
  98. package/dist/workspace/investigation-lifecycle-manager.d.ts.map +1 -0
  99. package/dist/workspace/investigation-lifecycle-manager.js +259 -0
  100. package/dist/workspace/investigation-supervisor.d.ts +100 -0
  101. package/dist/workspace/investigation-supervisor.d.ts.map +1 -0
  102. package/dist/workspace/investigation-supervisor.js +238 -0
  103. package/dist/workspace/runtime-investigation.d.ts +5 -1
  104. package/dist/workspace/runtime-investigation.d.ts.map +1 -1
  105. package/dist/workspace/runtime-investigation.js +50 -21
  106. package/dist/workspace/runtime-observation.d.ts +82 -0
  107. package/dist/workspace/runtime-observation.d.ts.map +1 -0
  108. package/dist/workspace/runtime-observation.js +170 -0
  109. package/dist/workspace/runtime-observer.d.ts +57 -0
  110. package/dist/workspace/runtime-observer.d.ts.map +1 -0
  111. package/dist/workspace/runtime-observer.js +272 -0
  112. package/dist/workspace/workspace-connection.d.ts.map +1 -1
  113. package/dist/workspace/workspace-connection.js +14 -5
  114. package/dist/workspace/workspace-identity.d.ts +1 -1
  115. package/dist/workspace/workspace-identity.d.ts.map +1 -1
  116. package/dist/workspace/workspace-identity.js +4 -4
  117. package/dist/workspace/workspace-types.d.ts +208 -0
  118. package/dist/workspace/workspace-types.d.ts.map +1 -1
  119. package/package.json +12 -4
  120. package/dist/create/server-source/crates/feltdb/src/phase_1c_three_node.rs +0 -523
  121. package/dist/studio-app/assets/feltdb_wasm_bg-Ceyi7l21.wasm +0 -0
  122. package/dist/studio-app/assets/index-BF45M757.js +0 -28
@@ -0,0 +1,100 @@
1
+ /**
2
+ * Runtime investigation supervisor.
3
+ *
4
+ * Reads durable runtime observations out of the Development Workspace, opens
5
+ * investigations for the ones that represent actionable defects, builds the
6
+ * evidence and the finding, produces the agent-executable remediation
7
+ * contract, tracks the repository change, and verifies the outcome against a
8
+ * later runtime observation.
9
+ *
10
+ * The architectural boundary is enforced here: this supervisor observes,
11
+ * investigates, contracts, verifies, and remembers. It never edits source and
12
+ * it never decides that a defect is fixed on any basis other than a runtime
13
+ * observation.
14
+ */
15
+ import type { RemediationContract, RepositoryIdentity, RuntimeInvestigation, RuntimeRequestObservation, VerificationCriterion } from './workspace-types.js';
16
+ import { InvestigationLifecycleManager } from './investigation-lifecycle-manager.js';
17
+ export interface SupervisorOptions {
18
+ /** Directory containing `.feltdb/`. */
19
+ projectDir: string;
20
+ /** Workspace authority endpoint. */
21
+ endpoint: string;
22
+ workspaceId: string;
23
+ /** Directory the coding agent will modify. Defaults to the application directory. */
24
+ repositoryDir?: string;
25
+ }
26
+ /** The artifact handed to the coding agent. */
27
+ export interface AgentHandoffArtifact {
28
+ investigationId: string;
29
+ /** Machine-readable contract. */
30
+ contract: RemediationContract;
31
+ /** Human-readable briefing. */
32
+ markdown: string;
33
+ /** Where the artifact was written for the agent to pick up. */
34
+ jsonPath: string;
35
+ markdownPath: string;
36
+ }
37
+ export declare class RuntimeInvestigationSupervisor {
38
+ readonly investigations: InvestigationLifecycleManager;
39
+ private readonly options;
40
+ private connection;
41
+ private readonly seenObservations;
42
+ constructor(options: SupervisorOptions);
43
+ connect(): Promise<void>;
44
+ disconnect(): Promise<void>;
45
+ private require;
46
+ /** Every runtime observation the workspace has persisted. */
47
+ observations(): Promise<RuntimeRequestObservation[]>;
48
+ /**
49
+ * Wait for a runtime observation matching a verification criterion.
50
+ *
51
+ * Returns undefined on timeout, which is what produces an INCONCLUSIVE
52
+ * verification rather than a false VERIFIED.
53
+ */
54
+ awaitObservation(criterion: VerificationCriterion, options?: {
55
+ after: number;
56
+ timeoutMs?: number;
57
+ intervalMs?: number;
58
+ }): Promise<RuntimeRequestObservation | undefined>;
59
+ /**
60
+ * Open investigations for actionable defects that do not have one yet.
61
+ *
62
+ * Successful requests are persisted as observations but never open an
63
+ * investigation.
64
+ */
65
+ ingestObservations(): Promise<RuntimeInvestigation[]>;
66
+ /**
67
+ * Drive a single observation through investigation and analysis.
68
+ *
69
+ * Ends in PROPOSED with evidence, a finding, and a remediation contract, and
70
+ * with the repository baseline recorded so the change can be attributed.
71
+ */
72
+ openInvestigation(observation: RuntimeRequestObservation): RuntimeInvestigation;
73
+ /** Repository state, used as the remediation baseline. */
74
+ repositoryIdentity(): RepositoryIdentity;
75
+ /** Source files that exist on disk and could implement the observed route. */
76
+ private relevantSource;
77
+ /**
78
+ * Write the agent handoff artifact.
79
+ *
80
+ * FeltDB stops here: it produces a complete, machine-readable engineering
81
+ * contract and hands it over. Inspecting the repository and editing source
82
+ * is the coding agent's job, not FeltDB's.
83
+ */
84
+ writeAgentHandoff(investigationId: string): AgentHandoffArtifact;
85
+ /** Whether the repository moved since the investigation baseline. */
86
+ detectRepositoryChange(investigationId: string): RuntimeInvestigation;
87
+ /**
88
+ * Verify the contract against the runtime.
89
+ *
90
+ * Waits for a matching runtime observation produced after the code change
91
+ * and evaluates it. No observation means INCONCLUSIVE.
92
+ */
93
+ verify(investigationId: string, options?: {
94
+ after: number;
95
+ timeoutMs?: number;
96
+ }): Promise<RuntimeInvestigation>;
97
+ /** One-line description of why an investigation exists. */
98
+ describe(investigation: RuntimeInvestigation): string;
99
+ }
100
+ //# sourceMappingURL=investigation-supervisor.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"investigation-supervisor.d.ts","sourceRoot":"","sources":["../../src/workspace/investigation-supervisor.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;GAaG;AAIH,OAAO,KAAK,EACV,mBAAmB,EACnB,kBAAkB,EAClB,oBAAoB,EACpB,yBAAyB,EACzB,qBAAqB,EACtB,MAAM,sBAAsB,CAAC;AAW9B,OAAO,EAAE,6BAA6B,EAAE,MAAM,sCAAsC,CAAC;AAKrF,MAAM,WAAW,iBAAiB;IAChC,uCAAuC;IACvC,UAAU,EAAE,MAAM,CAAC;IACnB,oCAAoC;IACpC,QAAQ,EAAE,MAAM,CAAC;IACjB,WAAW,EAAE,MAAM,CAAC;IACpB,qFAAqF;IACrF,aAAa,CAAC,EAAE,MAAM,CAAC;CACxB;AAED,+CAA+C;AAC/C,MAAM,WAAW,oBAAoB;IACnC,eAAe,EAAE,MAAM,CAAC;IACxB,iCAAiC;IACjC,QAAQ,EAAE,mBAAmB,CAAC;IAC9B,+BAA+B;IAC/B,QAAQ,EAAE,MAAM,CAAC;IACjB,+DAA+D;IAC/D,QAAQ,EAAE,MAAM,CAAC;IACjB,YAAY,EAAE,MAAM,CAAC;CACtB;AAED,qBAAa,8BAA8B;IACzC,QAAQ,CAAC,cAAc,EAAE,6BAA6B,CAAC;IACvD,OAAO,CAAC,QAAQ,CAAC,OAAO,CAAoB;IAC5C,OAAO,CAAC,UAAU,CAA+C;IACjE,OAAO,CAAC,QAAQ,CAAC,gBAAgB,CAAqB;gBAE1C,OAAO,EAAE,iBAAiB;IAYhC,OAAO,IAAI,OAAO,CAAC,IAAI,CAAC;IASxB,UAAU,IAAI,OAAO,CAAC,IAAI,CAAC;IAKjC,OAAO,CAAC,OAAO;IAKf,6DAA6D;IACvD,YAAY,IAAI,OAAO,CAAC,yBAAyB,EAAE,CAAC;IAK1D;;;;;OAKG;IACG,gBAAgB,CACpB,SAAS,EAAE,qBAAqB,EAChC,OAAO,GAAE;QAAE,KAAK,EAAE,MAAM,CAAC;QAAC,SAAS,CAAC,EAAE,MAAM,CAAC;QAAC,UAAU,CAAC,EAAE,MAAM,CAAA;KAAiB,GACjF,OAAO,CAAC,yBAAyB,GAAG,SAAS,CAAC;IAcjD;;;;;OAKG;IACG,kBAAkB,IAAI,OAAO,CAAC,oBAAoB,EAAE,CAAC;IAW3D;;;;;OAKG;IACH,iBAAiB,CAAC,WAAW,EAAE,yBAAyB,GAAG,oBAAoB;IAmB/E,0DAA0D;IAC1D,kBAAkB,IAAI,kBAAkB;IAIxC,8EAA8E;IAC9E,OAAO,CAAC,cAAc;IAMtB;;;;;;OAMG;IACH,iBAAiB,CAAC,eAAe,EAAE,MAAM,GAAG,oBAAoB;IA8DhE,qEAAqE;IACrE,sBAAsB,CAAC,eAAe,EAAE,MAAM,GAAG,oBAAoB;IAWrE;;;;;OAKG;IACG,MAAM,CACV,eAAe,EAAE,MAAM,EACvB,OAAO,GAAE;QAAE,KAAK,EAAE,MAAM,CAAC;QAAC,SAAS,CAAC,EAAE,MAAM,CAAA;KAAiB,GAC5D,OAAO,CAAC,oBAAoB,CAAC;IAUhC,2DAA2D;IAC3D,QAAQ,CAAC,aAAa,EAAE,oBAAoB,GAAG,MAAM;CAGtD"}
@@ -0,0 +1,238 @@
1
+ /**
2
+ * Runtime investigation supervisor.
3
+ *
4
+ * Reads durable runtime observations out of the Development Workspace, opens
5
+ * investigations for the ones that represent actionable defects, builds the
6
+ * evidence and the finding, produces the agent-executable remediation
7
+ * contract, tracks the repository change, and verifies the outcome against a
8
+ * later runtime observation.
9
+ *
10
+ * The architectural boundary is enforced here: this supervisor observes,
11
+ * investigates, contracts, verifies, and remembers. It never edits source and
12
+ * it never decides that a defect is fixed on any basis other than a runtime
13
+ * observation.
14
+ */
15
+ import fs from 'node:fs';
16
+ import path from 'node:path';
17
+ import { RUNTIME_OBSERVATION_COLLECTION, isActionableRuntimeDefect } from './runtime-observation.js';
18
+ import { collectEvidence, candidateSourcePaths, deriveFinding, recommendChanges, resolveRelevantSource, summarizeDefect, verificationContractFor, } from './investigation-analysis.js';
19
+ import { InvestigationLifecycleManager } from './investigation-lifecycle-manager.js';
20
+ import { captureRepositoryIdentity } from './git-identity.js';
21
+ import { agentRemediationHandoff } from './runtime-investigation.js';
22
+ import { connectDevelopmentWorkspace } from './workspace-connection.js';
23
+ export class RuntimeInvestigationSupervisor {
24
+ constructor(options) {
25
+ this.connection = null;
26
+ this.seenObservations = new Set();
27
+ this.options = options;
28
+ this.investigations = new InvestigationLifecycleManager(options.projectDir);
29
+ // Observations already turned into investigations must not re-open on a
30
+ // restart, so the seen set is rebuilt from durable state.
31
+ for (const investigation of this.investigations.listInvestigations()) {
32
+ for (const observationId of investigation.observationIds || [investigation.observationId]) {
33
+ this.seenObservations.add(observationId);
34
+ }
35
+ }
36
+ }
37
+ async connect() {
38
+ if (this.connection)
39
+ return;
40
+ this.connection = await connectDevelopmentWorkspace({
41
+ workspaceId: this.options.workspaceId,
42
+ endpoint: this.options.endpoint,
43
+ clientType: 'agent',
44
+ });
45
+ }
46
+ async disconnect() {
47
+ await this.connection?.disconnect();
48
+ this.connection = null;
49
+ }
50
+ require() {
51
+ if (!this.connection)
52
+ throw new Error('Supervisor is not connected to the workspace');
53
+ return this.connection;
54
+ }
55
+ /** Every runtime observation the workspace has persisted. */
56
+ async observations() {
57
+ const records = await this.require().query(RUNTIME_OBSERVATION_COLLECTION);
58
+ return records.sort((left, right) => left.timestamp - right.timestamp);
59
+ }
60
+ /**
61
+ * Wait for a runtime observation matching a verification criterion.
62
+ *
63
+ * Returns undefined on timeout, which is what produces an INCONCLUSIVE
64
+ * verification rather than a false VERIFIED.
65
+ */
66
+ async awaitObservation(criterion, options = { after: 0 }) {
67
+ const deadline = Date.now() + (options.timeoutMs ?? 10000);
68
+ const interval = options.intervalMs ?? 100;
69
+ while (Date.now() < deadline) {
70
+ const match = (await this.observations()).find(observation => observation.timestamp > options.after
71
+ && observation.method.toUpperCase() === criterion.method.toUpperCase()
72
+ && samePath(observation.url, criterion.url));
73
+ if (match)
74
+ return match;
75
+ await delay(interval);
76
+ }
77
+ return undefined;
78
+ }
79
+ /**
80
+ * Open investigations for actionable defects that do not have one yet.
81
+ *
82
+ * Successful requests are persisted as observations but never open an
83
+ * investigation.
84
+ */
85
+ async ingestObservations() {
86
+ const opened = [];
87
+ for (const observation of await this.observations()) {
88
+ if (this.seenObservations.has(observation.observationId))
89
+ continue;
90
+ this.seenObservations.add(observation.observationId);
91
+ if (!isActionableRuntimeDefect(observation))
92
+ continue;
93
+ opened.push(this.openInvestigation(observation));
94
+ }
95
+ return opened;
96
+ }
97
+ /**
98
+ * Drive a single observation through investigation and analysis.
99
+ *
100
+ * Ends in PROPOSED with evidence, a finding, and a remediation contract, and
101
+ * with the repository baseline recorded so the change can be attributed.
102
+ */
103
+ openInvestigation(observation) {
104
+ const created = this.investigations.createInvestigation(observation, this.options.workspaceId);
105
+ const evidence = collectEvidence(created.id, observation);
106
+ this.investigations.transitionToInvestigating(created.id, evidence);
107
+ const finding = deriveFinding(created.id, observation, evidence);
108
+ this.investigations.transitionToFinding(created.id, finding);
109
+ const contract = {
110
+ investigationId: created.id,
111
+ originalObservation: observation,
112
+ finding: finding.statement,
113
+ evidence: evidence.map(item => item.statement),
114
+ relevantSource: this.relevantSource(observation.url),
115
+ recommendedChanges: recommendChanges(observation),
116
+ verificationCriteria: verificationContractFor(observation),
117
+ };
118
+ return this.investigations.sendToAgent(created.id, contract, this.repositoryIdentity());
119
+ }
120
+ /** Repository state, used as the remediation baseline. */
121
+ repositoryIdentity() {
122
+ return captureRepositoryIdentity(this.options.repositoryDir || this.options.projectDir);
123
+ }
124
+ /** Source files that exist on disk and could implement the observed route. */
125
+ relevantSource(url) {
126
+ const root = this.options.repositoryDir || this.options.projectDir;
127
+ const existing = candidateSourcePaths(url).filter(candidate => fs.existsSync(path.join(root, candidate)));
128
+ return resolveRelevantSource(url, existing);
129
+ }
130
+ /**
131
+ * Write the agent handoff artifact.
132
+ *
133
+ * FeltDB stops here: it produces a complete, machine-readable engineering
134
+ * contract and hands it over. Inspecting the repository and editing source
135
+ * is the coding agent's job, not FeltDB's.
136
+ */
137
+ writeAgentHandoff(investigationId) {
138
+ const investigation = this.investigations.loadInvestigation(investigationId);
139
+ if (!investigation?.remediationContract) {
140
+ throw new Error(`Investigation ${investigationId} has no remediation contract`);
141
+ }
142
+ const contract = investigation.remediationContract;
143
+ // Handoff artifacts live beside the investigation store, never inside it:
144
+ // a `<id>.agent.json` in the store would be read back as an investigation.
145
+ const directory = path.join(this.options.projectDir, '.feltdb', 'handoff');
146
+ fs.mkdirSync(directory, { recursive: true });
147
+ const jsonPath = path.join(directory, `${investigationId}.agent.json`);
148
+ const markdownPath = path.join(directory, `${investigationId}.agent.md`);
149
+ const markdown = [
150
+ `# FeltDB Investigation ${investigationId}`,
151
+ '',
152
+ '## Observation',
153
+ `${contract.originalObservation.method} ${contract.originalObservation.url} -> HTTP ${contract.originalObservation.status}`,
154
+ `Observed by: ${contract.originalObservation.browser || 'unknown'} (${contract.originalObservation.runtime || 'unknown'})`,
155
+ '',
156
+ '## Evidence (observed by the runtime)',
157
+ ...(investigation.evidence || []).map(item => `- [${item.kind}] ${item.statement}`),
158
+ '',
159
+ '## Finding (FeltDB analysis, not an observation)',
160
+ contract.finding,
161
+ `Confidence: ${investigation.finding?.confidence || 'unknown'}`,
162
+ '',
163
+ '## Relevant source',
164
+ ...(contract.relevantSource.length > 0
165
+ ? contract.relevantSource.map(item => `- ${item.file}${item.line ? `:${item.line}` : ''}`)
166
+ : ['- (no route file matched; locate the handler for this path)']),
167
+ '',
168
+ '## Recommended change',
169
+ ...contract.recommendedChanges.map(item => `- ${item}`),
170
+ '',
171
+ '## Verification contract',
172
+ ...contract.verificationCriteria.map(item => `- ${item.kind}: ${item.method} ${item.url} must return one of [${(item.expectedStatuses || []).join(', ')}]`),
173
+ '',
174
+ 'FeltDB verifies this contract against a real runtime observation after you change the code.',
175
+ 'A passing build, a passing test, or a commit does not satisfy it.',
176
+ ].join('\n');
177
+ fs.writeFileSync(jsonPath, JSON.stringify({
178
+ investigationId,
179
+ workspaceId: investigation.workspaceId,
180
+ // The agent needs to know which repository the source paths are relative
181
+ // to; without it the contract would not be independently actionable.
182
+ repositoryDir: path.resolve(this.options.repositoryDir || this.options.projectDir),
183
+ observation: contract.originalObservation,
184
+ evidence: investigation.evidence || [],
185
+ finding: investigation.finding,
186
+ relevantSource: contract.relevantSource,
187
+ recommendedChanges: contract.recommendedChanges,
188
+ verificationContract: contract.verificationCriteria,
189
+ instructions: agentRemediationHandoff(contract),
190
+ }, null, 2), 'utf8');
191
+ fs.writeFileSync(markdownPath, `${markdown}\n`, 'utf8');
192
+ return { investigationId, contract, markdown, jsonPath, markdownPath };
193
+ }
194
+ /** Whether the repository moved since the investigation baseline. */
195
+ detectRepositoryChange(investigationId) {
196
+ const repositoryDir = this.options.repositoryDir || this.options.projectDir;
197
+ const investigation = this.investigations.loadInvestigation(investigationId);
198
+ if (!investigation)
199
+ throw new Error(`Investigation ${investigationId} not found`);
200
+ const started = investigation.remediationState === 'SENT_TO_AGENT'
201
+ ? this.investigations.markImplementing(investigationId)
202
+ : investigation;
203
+ void started;
204
+ return this.investigations.detectRepositoryChange(investigationId, repositoryDir);
205
+ }
206
+ /**
207
+ * Verify the contract against the runtime.
208
+ *
209
+ * Waits for a matching runtime observation produced after the code change
210
+ * and evaluates it. No observation means INCONCLUSIVE.
211
+ */
212
+ async verify(investigationId, options = { after: 0 }) {
213
+ const investigation = this.investigations.loadInvestigation(investigationId);
214
+ if (!investigation?.remediationContract) {
215
+ throw new Error(`Investigation ${investigationId} has no remediation contract`);
216
+ }
217
+ const criterion = investigation.remediationContract.verificationCriteria.find(item => item.kind === 'primary');
218
+ const observation = await this.awaitObservation(criterion, options);
219
+ return this.investigations.recordVerification(investigationId, investigation.remediationContract, observation);
220
+ }
221
+ /** One-line description of why an investigation exists. */
222
+ describe(investigation) {
223
+ return investigation.originalObservation ? summarizeDefect(investigation.originalObservation) : investigation.id;
224
+ }
225
+ }
226
+ function samePath(actual, expected) {
227
+ try {
228
+ const left = new URL(actual, 'http://localhost');
229
+ const right = new URL(expected, 'http://localhost');
230
+ return left.origin === right.origin && left.pathname === right.pathname && left.search === right.search;
231
+ }
232
+ catch {
233
+ return actual === expected;
234
+ }
235
+ }
236
+ function delay(ms) {
237
+ return new Promise(resolve => setTimeout(resolve, ms));
238
+ }
@@ -1,11 +1,15 @@
1
1
  import type { InvestigationState, RemediationContract, RemediationState, RuntimeInvestigation, RuntimeRequestObservation, VerificationAttempt, VerificationState, WorkspaceActivity } from './workspace-types.js';
2
+ /** Canonical FeltDB investigation collection. */
3
+ export declare const RUNTIME_INVESTIGATION_COLLECTION = "runtime_investigation";
4
+ /** External/legacy DevTools collection retained without migration. */
5
+ export declare const LEGACY_RUNTIME_INVESTIGATION_COLLECTION = "runtime_investigations";
2
6
  export declare function transitionInvestigation(investigation: RuntimeInvestigation, next: InvestigationState): RuntimeInvestigation;
3
7
  export declare function transitionRemediation(investigation: RuntimeInvestigation, next: RemediationState): RuntimeInvestigation;
4
8
  export declare function transitionVerification(investigation: RuntimeInvestigation, next: VerificationState): RuntimeInvestigation;
5
9
  export declare function createRemediationContract(input: Omit<RemediationContract, 'id' | 'observationId' | 'createdAt' | 'updatedAt'>): RemediationContract;
6
10
  export declare function classifyWorkspaceActivity(investigationId: string, paths: string[]): WorkspaceActivity;
7
11
  export declare function evaluateVerification(contract: RemediationContract, observation?: RuntimeRequestObservation, verificationId?: string): VerificationAttempt;
8
- export declare const RUNTIME_INVESTIGATION_INSTRUCTIONS = "Your job:\nInvestigate this runtime observation only.\nDetermine whether it represents an actual defect, identify the most likely root cause, inspect the relevant source, reproduce the behavior when possible, and propose a fix.\nInvestigation is read-only.\nDo NOT:\n- modify source files\n- modify configuration files\n- modify package.json\n- modify .gitignore\n- install dependencies\n- run migrations\n- generate code\n- apply patches\n- commit changes\n- create a PR\n- execute the proposed fix\nYou MAY:\n- inspect source files\n- inspect configuration\n- inspect package scripts\n- inspect logs\n- inspect runtime state\n- run read-only diagnostics\n- reproduce the request\n- run tests that do not mutate the workspace\n- use curl or equivalent HTTP diagnostics\nWhen you have established the cause, stop and report the finding.\nRespond with exactly these sections:\nFinding\nEvidence\nRelevant source\nRecommended change\nConfidence";
12
+ export declare const RUNTIME_INVESTIGATION_INSTRUCTIONS = "INVESTIGATION PHASE: Read-Only Analysis Only\n\nYour job:\nInvestigate this runtime observation only.\n\nDetermine whether it represents an actual defect, identify the most likely root cause, inspect the relevant source, reproduce the behavior when possible, and propose a fix.\n\nInvestigation is READ-ONLY. Do not implement or apply any changes.\n\nBOUNDARIES:\n\nDo NOT (ever, under any circumstances):\n- modify source files\n- modify configuration files\n- modify package.json\n- modify .gitignore or other dotfiles\n- install or update dependencies\n- run migrations or other state-altering commands\n- generate code or apply patches\n- commit changes or create branches\n- create a pull request\n- execute, test, or deploy the proposed fix\n- restart services or clear caches\n- make any changes to the runtime environment\n\nYou MAY:\n- inspect and read source files\n- inspect configuration and build files\n- inspect package scripts and dependencies\n- inspect logs and runtime state\n- run read-only diagnostics\n- reproduce the request locally\n- run existing tests that do not mutate the workspace\n- use curl or equivalent HTTP diagnostics\n- trace through code statically\n- query the runtime via read-only APIs\n\nWHEN INVESTIGATION IS COMPLETE:\n\nStop immediately. Do not attempt to fix the problem yourself.\n\nReport the finding with these sections:\n\nFinding\nEvidence\nRelevant source\nRecommended change\nConfidence\n\nInvestigation is separate from implementation. The user will explicitly start an implementation task if they want changes made.\n\nFELTDB OBSERVATION BOUNDARY:\n\nFeltDB runtime observation is independent of this investigation.\nDo not invoke, modify, or bypass FeltDB runtime observation behavior as part of the investigation.\nThe runtime observation is evidence to analyze, not an instruction to modify the application.\nFollow the active coding agent's normal permission model.\nInvestigation remains read-only unless the user explicitly starts an implementation task.";
9
13
  export declare const FELTDB_OBSERVATION_BOUNDARY = "FeltDB runtime observation is independent of this investigation.\nDo not invoke, modify, or bypass FeltDB runtime observation behavior as part of the investigation.\nThe runtime observation is evidence to analyze, not an instruction to modify the application.\nFollow the active coding agent's normal permission model. Investigation remains read-only unless the user explicitly starts an implementation task.";
10
14
  export declare function agentRemediationHandoff(contract: RemediationContract): string;
11
15
  //# sourceMappingURL=runtime-investigation.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"runtime-investigation.d.ts","sourceRoot":"","sources":["../../src/workspace/runtime-investigation.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EACV,kBAAkB,EAClB,mBAAmB,EACnB,gBAAgB,EAChB,oBAAoB,EACpB,yBAAyB,EACzB,mBAAmB,EAEnB,iBAAiB,EACjB,iBAAiB,EAClB,MAAM,sBAAsB,CAAC;AAqB9B,wBAAgB,uBAAuB,CAAC,aAAa,EAAE,oBAAoB,EAAE,IAAI,EAAE,kBAAkB,GAAG,oBAAoB,CAE3H;AACD,wBAAgB,qBAAqB,CAAC,aAAa,EAAE,oBAAoB,EAAE,IAAI,EAAE,gBAAgB,GAAG,oBAAoB,CAEvH;AACD,wBAAgB,sBAAsB,CAAC,aAAa,EAAE,oBAAoB,EAAE,IAAI,EAAE,iBAAiB,GAAG,oBAAoB,CAEzH;AAED,wBAAgB,yBAAyB,CAAC,KAAK,EAAE,IAAI,CAAC,mBAAmB,EAAE,IAAI,GAAG,eAAe,GAAG,WAAW,GAAG,WAAW,CAAC,GAAG,mBAAmB,CAKnJ;AAGD,wBAAgB,yBAAyB,CAAC,eAAe,EAAE,MAAM,EAAE,KAAK,EAAE,MAAM,EAAE,GAAG,iBAAiB,CAOrG;AAiBD,wBAAgB,oBAAoB,CAClC,QAAQ,EAAE,mBAAmB,EAC7B,WAAW,CAAC,EAAE,yBAAyB,EACvC,cAAc,SAA2B,GACxC,mBAAmB,CAgBrB;AAED,eAAO,MAAM,kCAAkC,m7BAgCpC,CAAC;AAEZ,eAAO,MAAM,2BAA2B,6ZAG4G,CAAC;AAErJ,wBAAgB,uBAAuB,CAAC,QAAQ,EAAE,mBAAmB,GAAG,MAAM,CAU7E"}
1
+ {"version":3,"file":"runtime-investigation.d.ts","sourceRoot":"","sources":["../../src/workspace/runtime-investigation.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EACV,kBAAkB,EAClB,mBAAmB,EACnB,gBAAgB,EAChB,oBAAoB,EACpB,yBAAyB,EACzB,mBAAmB,EAEnB,iBAAiB,EACjB,iBAAiB,EAClB,MAAM,sBAAsB,CAAC;AAE9B,iDAAiD;AACjD,eAAO,MAAM,gCAAgC,0BAA0B,CAAC;AACxE,sEAAsE;AACtE,eAAO,MAAM,uCAAuC,2BAA2B,CAAC;AAqBhF,wBAAgB,uBAAuB,CAAC,aAAa,EAAE,oBAAoB,EAAE,IAAI,EAAE,kBAAkB,GAAG,oBAAoB,CAE3H;AACD,wBAAgB,qBAAqB,CAAC,aAAa,EAAE,oBAAoB,EAAE,IAAI,EAAE,gBAAgB,GAAG,oBAAoB,CAEvH;AACD,wBAAgB,sBAAsB,CAAC,aAAa,EAAE,oBAAoB,EAAE,IAAI,EAAE,iBAAiB,GAAG,oBAAoB,CAEzH;AAED,wBAAgB,yBAAyB,CAAC,KAAK,EAAE,IAAI,CAAC,mBAAmB,EAAE,IAAI,GAAG,eAAe,GAAG,WAAW,GAAG,WAAW,CAAC,GAAG,mBAAmB,CAKnJ;AAGD,wBAAgB,yBAAyB,CAAC,eAAe,EAAE,MAAM,EAAE,KAAK,EAAE,MAAM,EAAE,GAAG,iBAAiB,CAOrG;AAiBD,wBAAgB,oBAAoB,CAClC,QAAQ,EAAE,mBAAmB,EAC7B,WAAW,CAAC,EAAE,yBAAyB,EACvC,cAAc,SAA2B,GACxC,mBAAmB,CAgBrB;AAED,eAAO,MAAM,kCAAkC,o+DAyD2C,CAAC;AAE3F,eAAO,MAAM,2BAA2B,6ZAG4G,CAAC;AAErJ,wBAAgB,uBAAuB,CAAC,QAAQ,EAAE,mBAAmB,GAAG,MAAM,CAU7E"}
@@ -1,3 +1,7 @@
1
+ /** Canonical FeltDB investigation collection. */
2
+ export const RUNTIME_INVESTIGATION_COLLECTION = 'runtime_investigation';
3
+ /** External/legacy DevTools collection retained without migration. */
4
+ export const LEGACY_RUNTIME_INVESTIGATION_COLLECTION = 'runtime_investigations';
1
5
  const INVESTIGATION_TRANSITIONS = {
2
6
  OBSERVED: ['INVESTIGATING'], INVESTIGATING: ['FINDING'], FINDING: ['PROPOSED'], PROPOSED: [],
3
7
  };
@@ -78,39 +82,64 @@ export function evaluateVerification(contract, observation, verificationId = uni
78
82
  summary: fixed ? 'The primary verification contract succeeded.' : 'The original defect remains reproducible.',
79
83
  };
80
84
  }
81
- export const RUNTIME_INVESTIGATION_INSTRUCTIONS = `Your job:
85
+ export const RUNTIME_INVESTIGATION_INSTRUCTIONS = `INVESTIGATION PHASE: Read-Only Analysis Only
86
+
87
+ Your job:
82
88
  Investigate this runtime observation only.
89
+
83
90
  Determine whether it represents an actual defect, identify the most likely root cause, inspect the relevant source, reproduce the behavior when possible, and propose a fix.
84
- Investigation is read-only.
85
- Do NOT:
91
+
92
+ Investigation is READ-ONLY. Do not implement or apply any changes.
93
+
94
+ BOUNDARIES:
95
+
96
+ Do NOT (ever, under any circumstances):
86
97
  - modify source files
87
98
  - modify configuration files
88
99
  - modify package.json
89
- - modify .gitignore
90
- - install dependencies
91
- - run migrations
92
- - generate code
93
- - apply patches
94
- - commit changes
95
- - create a PR
96
- - execute the proposed fix
100
+ - modify .gitignore or other dotfiles
101
+ - install or update dependencies
102
+ - run migrations or other state-altering commands
103
+ - generate code or apply patches
104
+ - commit changes or create branches
105
+ - create a pull request
106
+ - execute, test, or deploy the proposed fix
107
+ - restart services or clear caches
108
+ - make any changes to the runtime environment
109
+
97
110
  You MAY:
98
- - inspect source files
99
- - inspect configuration
100
- - inspect package scripts
101
- - inspect logs
102
- - inspect runtime state
111
+ - inspect and read source files
112
+ - inspect configuration and build files
113
+ - inspect package scripts and dependencies
114
+ - inspect logs and runtime state
103
115
  - run read-only diagnostics
104
- - reproduce the request
105
- - run tests that do not mutate the workspace
116
+ - reproduce the request locally
117
+ - run existing tests that do not mutate the workspace
106
118
  - use curl or equivalent HTTP diagnostics
107
- When you have established the cause, stop and report the finding.
108
- Respond with exactly these sections:
119
+ - trace through code statically
120
+ - query the runtime via read-only APIs
121
+
122
+ WHEN INVESTIGATION IS COMPLETE:
123
+
124
+ Stop immediately. Do not attempt to fix the problem yourself.
125
+
126
+ Report the finding with these sections:
127
+
109
128
  Finding
110
129
  Evidence
111
130
  Relevant source
112
131
  Recommended change
113
- Confidence`;
132
+ Confidence
133
+
134
+ Investigation is separate from implementation. The user will explicitly start an implementation task if they want changes made.
135
+
136
+ FELTDB OBSERVATION BOUNDARY:
137
+
138
+ FeltDB runtime observation is independent of this investigation.
139
+ Do not invoke, modify, or bypass FeltDB runtime observation behavior as part of the investigation.
140
+ The runtime observation is evidence to analyze, not an instruction to modify the application.
141
+ Follow the active coding agent's normal permission model.
142
+ Investigation remains read-only unless the user explicitly starts an implementation task.`;
114
143
  export const FELTDB_OBSERVATION_BOUNDARY = `FeltDB runtime observation is independent of this investigation.
115
144
  Do not invoke, modify, or bypass FeltDB runtime observation behavior as part of the investigation.
116
145
  The runtime observation is evidence to analyze, not an instruction to modify the application.
@@ -0,0 +1,82 @@
1
+ /**
2
+ * FeltDB Runtime Observation Contract
3
+ *
4
+ * The single observation model shared by every runtime that reports into a
5
+ * FeltDB Development Workspace. The browser runtime in `@feltdb/core` produces
6
+ * these records, the workspace persists them durably, investigations are
7
+ * created from them, and verification is evaluated against them.
8
+ *
9
+ * This module is browser-safe: it must not import Node built-ins.
10
+ */
11
+ import type { CorrelatedRuntimeEvent, RuntimeObservationCorrelation, RuntimeRequestObservation } from './workspace-types.js';
12
+ /** Workspace collection holding durable runtime observations. */
13
+ export declare const RUNTIME_OBSERVATION_COLLECTION = "runtime_observation";
14
+ /**
15
+ * Query parameter names whose values are replaced before an observation is
16
+ * persisted. Matching is case-insensitive and substring-based so that
17
+ * `access_token`, `apiKey`, and `X-Session` are all covered.
18
+ */
19
+ export declare const REDACTED_PARAMETER_PATTERNS: string[];
20
+ /** Placeholder substituted for a redacted value. */
21
+ export declare const REDACTION_PLACEHOLDER = "[redacted]";
22
+ /**
23
+ * Redact sensitive values from a URL while preserving the parts verification
24
+ * depends on: origin, pathname, and the set of query parameter names.
25
+ *
26
+ * FeltDB never captures request or response bodies, and never captures
27
+ * `Authorization` or `Cookie` headers, so URL redaction is the only place
28
+ * where credential material can reach a persisted observation.
29
+ */
30
+ export declare function redactUrl(url: string): string;
31
+ /** Redact a free-text runtime message that may embed a URL or credential. */
32
+ export declare function redactMessage(message: string): string;
33
+ /** Browser family and engine derived from a user agent string. */
34
+ export declare function describeBrowser(userAgent: string): {
35
+ browser: string;
36
+ engine: string;
37
+ };
38
+ /**
39
+ * Whether an observation represents an actionable runtime defect.
40
+ *
41
+ * FeltDB does not open an investigation for every request. Only these
42
+ * qualify:
43
+ * - a server-error response (HTTP >= 500)
44
+ * - a request that produced no response at all (network failure)
45
+ * - a client-error response correlated with a runtime or console error
46
+ *
47
+ * Successful requests, redirects, and bare 4xx responses (which are usually
48
+ * intentional application behavior) do not open investigations.
49
+ */
50
+ export declare function isActionableRuntimeDefect(observation: RuntimeRequestObservation): boolean;
51
+ /** Human-readable reason an observation was treated as actionable. */
52
+ export declare function describeDefect(observation: RuntimeRequestObservation): string;
53
+ /** Generate a workspace-unique observation identifier. */
54
+ export declare function createObservationId(): string;
55
+ /** Generate a correlation identifier for a single in-flight request. */
56
+ export declare function createCorrelationId(): string;
57
+ export interface RuntimeObservationInput {
58
+ method: string;
59
+ url: string;
60
+ status: number;
61
+ startedAt: number;
62
+ completedAt: number;
63
+ workspaceId?: string;
64
+ sessionId?: string;
65
+ runtimeInstanceId?: string;
66
+ correlation?: RuntimeObservationCorrelation;
67
+ page?: string;
68
+ userAgent?: string;
69
+ correlationId?: string;
70
+ correlatedEvents?: CorrelatedRuntimeEvent[];
71
+ networkFailure?: boolean;
72
+ requestCharacteristics?: Record<string, unknown>;
73
+ responseCharacteristics?: Record<string, unknown>;
74
+ }
75
+ /**
76
+ * Build a redacted runtime observation.
77
+ *
78
+ * All redaction is applied here so that no caller can persist an unredacted
79
+ * observation by accident.
80
+ */
81
+ export declare function createRuntimeObservation(input: RuntimeObservationInput): RuntimeRequestObservation;
82
+ //# sourceMappingURL=runtime-observation.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"runtime-observation.d.ts","sourceRoot":"","sources":["../../src/workspace/runtime-observation.ts"],"names":[],"mappings":"AAAA;;;;;;;;;GASG;AAEH,OAAO,KAAK,EACV,sBAAsB,EACtB,6BAA6B,EAC7B,yBAAyB,EAC1B,MAAM,sBAAsB,CAAC;AAE9B,iEAAiE;AACjE,eAAO,MAAM,8BAA8B,wBAAwB,CAAC;AAEpE;;;;GAIG;AACH,eAAO,MAAM,2BAA2B,UAGvC,CAAC;AAEF,oDAAoD;AACpD,eAAO,MAAM,qBAAqB,eAAe,CAAC;AAOlD;;;;;;;GAOG;AACH,wBAAgB,SAAS,CAAC,GAAG,EAAE,MAAM,GAAG,MAAM,CAgB7C;AAED,6EAA6E;AAC7E,wBAAgB,aAAa,CAAC,OAAO,EAAE,MAAM,GAAG,MAAM,CAErD;AAED,kEAAkE;AAClE,wBAAgB,eAAe,CAAC,SAAS,EAAE,MAAM,GAAG;IAAE,OAAO,EAAE,MAAM,CAAC;IAAC,MAAM,EAAE,MAAM,CAAA;CAAE,CAatF;AAED;;;;;;;;;;;GAWG;AACH,wBAAgB,yBAAyB,CAAC,WAAW,EAAE,yBAAyB,GAAG,OAAO,CAQzF;AAED,sEAAsE;AACtE,wBAAgB,cAAc,CAAC,WAAW,EAAE,yBAAyB,GAAG,MAAM,CAI7E;AAID,0DAA0D;AAC1D,wBAAgB,mBAAmB,IAAI,MAAM,CAG5C;AAED,wEAAwE;AACxE,wBAAgB,mBAAmB,IAAI,MAAM,CAE5C;AAED,MAAM,WAAW,uBAAuB;IACtC,MAAM,EAAE,MAAM,CAAC;IACf,GAAG,EAAE,MAAM,CAAC;IACZ,MAAM,EAAE,MAAM,CAAC;IACf,SAAS,EAAE,MAAM,CAAC;IAClB,WAAW,EAAE,MAAM,CAAC;IACpB,WAAW,CAAC,EAAE,MAAM,CAAC;IACrB,SAAS,CAAC,EAAE,MAAM,CAAC;IACnB,iBAAiB,CAAC,EAAE,MAAM,CAAC;IAC3B,WAAW,CAAC,EAAE,6BAA6B,CAAC;IAC5C,IAAI,CAAC,EAAE,MAAM,CAAC;IACd,SAAS,CAAC,EAAE,MAAM,CAAC;IACnB,aAAa,CAAC,EAAE,MAAM,CAAC;IACvB,gBAAgB,CAAC,EAAE,sBAAsB,EAAE,CAAC;IAC5C,cAAc,CAAC,EAAE,OAAO,CAAC;IACzB,sBAAsB,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,CAAC;IACjD,uBAAuB,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,CAAC;CACnD;AAcD;;;;;GAKG;AACH,wBAAgB,wBAAwB,CAAC,KAAK,EAAE,uBAAuB,GAAG,yBAAyB,CAiClG"}