@eddacraft/kindling-adapter-pocketflow 0.1.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/LICENSE ADDED
@@ -0,0 +1,190 @@
1
+ Apache License
2
+ Version 2.0, January 2004
3
+ http://www.apache.org/licenses/
4
+
5
+ TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION
6
+
7
+ 1. Definitions.
8
+
9
+ "License" shall mean the terms and conditions for use, reproduction,
10
+ and distribution as defined by Sections 1 through 9 of this document.
11
+
12
+ "Licensor" shall mean the copyright owner or entity authorized by
13
+ the copyright owner that is granting the License.
14
+
15
+ "Legal Entity" shall mean the union of the acting entity and all
16
+ other entities that control, are controlled by, or are under common
17
+ control with that entity. For the purposes of this definition,
18
+ "control" means (i) the power, direct or indirect, to cause the
19
+ direction or management of such entity, whether by contract or
20
+ otherwise, or (ii) ownership of fifty percent (50%) or more of the
21
+ outstanding shares, or (iii) beneficial ownership of such entity.
22
+
23
+ "You" (or "Your") shall mean an individual or Legal Entity
24
+ exercising permissions granted by this License.
25
+
26
+ "Source" form shall mean the preferred form for making modifications,
27
+ including but not limited to software source code, documentation
28
+ source, and configuration files.
29
+
30
+ "Object" form shall mean any form resulting from mechanical
31
+ transformation or translation of a Source form, including but
32
+ not limited to compiled object code, generated documentation,
33
+ and conversions to other media types.
34
+
35
+ "Work" shall mean the work of authorship, whether in Source or
36
+ Object form, made available under the License, as indicated by a
37
+ copyright notice that is included in or attached to the work
38
+ (an example is provided in the Appendix below).
39
+
40
+ "Derivative Works" shall mean any work, whether in Source or Object
41
+ form, that is based on (or derived from) the Work and for which the
42
+ editorial revisions, annotations, elaborations, or other modifications
43
+ represent, as a whole, an original work of authorship. For the purposes
44
+ of this License, Derivative Works shall not include works that remain
45
+ separable from, or merely link (or bind by name) to the interfaces of,
46
+ the Work and Derivative Works thereof.
47
+
48
+ "Contribution" shall mean any work of authorship, including
49
+ the original version of the Work and any modifications or additions
50
+ to that Work or Derivative Works thereof, that is intentionally
51
+ submitted to the Licensor for inclusion in the Work by the copyright
52
+ owner or by an individual or Legal Entity authorized to submit on behalf
53
+ of the copyright owner. For the purposes of this definition, "submitted"
54
+ means any form of electronic, verbal, or written communication sent
55
+ to the Licensor or its representatives, including but not limited to
56
+ communication on electronic mailing lists, source code control systems,
57
+ and issue tracking systems that are managed by, or on behalf of, the
58
+ Licensor for the purpose of discussing and improving the Work, but
59
+ excluding communication that is conspicuously marked or otherwise
60
+ designated in writing by the copyright owner as "Not a Contribution."
61
+
62
+ "Contributor" shall mean Licensor and any individual or Legal Entity
63
+ on behalf of whom a Contribution has been received by Licensor and
64
+ subsequently incorporated within the Work.
65
+
66
+ 2. Grant of Copyright License. Subject to the terms and conditions of
67
+ this License, each Contributor hereby grants to You a perpetual,
68
+ worldwide, non-exclusive, no-charge, royalty-free, irrevocable
69
+ copyright license to reproduce, prepare Derivative Works of,
70
+ publicly display, publicly perform, sublicense, and distribute the
71
+ Work and such Derivative Works in Source or Object form.
72
+
73
+ 3. Grant of Patent License. Subject to the terms and conditions of
74
+ this License, each Contributor hereby grants to You a perpetual,
75
+ worldwide, non-exclusive, no-charge, royalty-free, irrevocable
76
+ (except as stated in this section) patent license to make, have made,
77
+ use, offer to sell, sell, import, and otherwise transfer the Work,
78
+ where such license applies only to those patent claims licensable
79
+ by such Contributor that are necessarily infringed by their
80
+ Contribution(s) alone or by combination of their Contribution(s)
81
+ with the Work to which such Contribution(s) was submitted. If You
82
+ institute patent litigation against any entity (including a
83
+ cross-claim or counterclaim in a lawsuit) alleging that the Work
84
+ or a Contribution incorporated within the Work constitutes direct
85
+ or contributory patent infringement, then any patent licenses
86
+ granted to You under this License for that Work shall terminate
87
+ as of the date such litigation is filed.
88
+
89
+ 4. Redistribution. You may reproduce and distribute copies of the
90
+ Work or Derivative Works thereof in any medium, with or without
91
+ modifications, and in Source or Object form, provided that You
92
+ meet the following conditions:
93
+
94
+ (a) You must give any other recipients of the Work or
95
+ Derivative Works a copy of this License; and
96
+
97
+ (b) You must cause any modified files to carry prominent notices
98
+ stating that You changed the files; and
99
+
100
+ (c) You must retain, in the Source form of any Derivative Works
101
+ that You distribute, all copyright, patent, trademark, and
102
+ attribution notices from the Source form of the Work,
103
+ excluding those notices that do not pertain to any part of
104
+ the Derivative Works; and
105
+
106
+ (d) If the Work includes a "NOTICE" text file as part of its
107
+ distribution, then any Derivative Works that You distribute must
108
+ include a readable copy of the attribution notices contained
109
+ within such NOTICE file, excluding those notices that do not
110
+ pertain to any part of the Derivative Works, in at least one
111
+ of the following places: within a NOTICE text file distributed
112
+ as part of the Derivative Works; within the Source form or
113
+ documentation, if provided along with the Derivative Works; or,
114
+ within a display generated by the Derivative Works, if and
115
+ wherever such third-party notices normally appear. The contents
116
+ of the NOTICE file are for informational purposes only and
117
+ do not modify the License. You may add Your own attribution
118
+ notices within Derivative Works that You distribute, alongside
119
+ or as an addendum to the NOTICE text from the Work, provided
120
+ that such additional attribution notices cannot be construed
121
+ as modifying the License.
122
+
123
+ You may add Your own copyright statement to Your modifications and
124
+ may provide additional or different license terms and conditions
125
+ for use, reproduction, or distribution of Your modifications, or
126
+ for any such Derivative Works as a whole, provided Your use,
127
+ reproduction, and distribution of the Work otherwise complies with
128
+ the conditions stated in this License.
129
+
130
+ 5. Submission of Contributions. Unless You explicitly state otherwise,
131
+ any Contribution intentionally submitted for inclusion in the Work
132
+ by You to the Licensor shall be under the terms and conditions of
133
+ this License, without any additional terms or conditions.
134
+ Notwithstanding the above, nothing herein shall supersede or modify
135
+ the terms of any separate license agreement you may have executed
136
+ with Licensor regarding such Contributions.
137
+
138
+ 6. Trademarks. This License does not grant permission to use the trade
139
+ names, trademarks, service marks, or product names of the Licensor,
140
+ except as required for reasonable and customary use in describing the
141
+ origin of the Work and reproducing the content of the NOTICE file.
142
+
143
+ 7. Disclaimer of Warranty. Unless required by applicable law or
144
+ agreed to in writing, Licensor provides the Work (and each
145
+ Contributor provides its Contributions) on an "AS IS" BASIS,
146
+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
147
+ implied, including, without limitation, any warranties or conditions
148
+ of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A
149
+ PARTICULAR PURPOSE. You are solely responsible for determining the
150
+ appropriateness of using or redistributing the Work and assume any
151
+ risks associated with Your exercise of permissions under this License.
152
+
153
+ 8. Limitation of Liability. In no event and under no legal theory,
154
+ whether in tort (including negligence), contract, or otherwise,
155
+ unless required by applicable law (such as deliberate and grossly
156
+ negligent acts) or agreed to in writing, shall any Contributor be
157
+ liable to You for damages, including any direct, indirect, special,
158
+ incidental, or consequential damages of any character arising as a
159
+ result of this License or out of the use or inability to use the
160
+ Work (including but not limited to damages for loss of goodwill,
161
+ work stoppage, computer failure or malfunction, or any and all
162
+ other commercial damages or losses), even if such Contributor
163
+ has been advised of the possibility of such damages.
164
+
165
+ 9. Accepting Warranty or Additional Liability. While redistributing
166
+ the Work or Derivative Works thereof, You may choose to offer,
167
+ and charge a fee for, acceptance of support, warranty, indemnity,
168
+ or other liability obligations and/or rights consistent with this
169
+ License. However, in accepting such obligations, You may act only
170
+ on Your own behalf and on Your sole responsibility, not on behalf
171
+ of any other Contributor, and only if You agree to indemnify,
172
+ defend, and hold each Contributor harmless for any liability
173
+ incurred by, or claims asserted against, such Contributor by reason
174
+ of your accepting any such warranty or additional liability.
175
+
176
+ END OF TERMS AND CONDITIONS
177
+
178
+ Copyright 2025 EddaCraft
179
+
180
+ Licensed under the Apache License, Version 2.0 (the "License");
181
+ you may not use this file except in compliance with the License.
182
+ You may obtain a copy of the License at
183
+
184
+ http://www.apache.org/licenses/LICENSE-2.0
185
+
186
+ Unless required by applicable law or agreed to in writing, software
187
+ distributed under the License is distributed on an "AS IS" BASIS,
188
+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
189
+ See the License for the specific language governing permissions and
190
+ limitations under the License.
package/README.md ADDED
@@ -0,0 +1,163 @@
1
+ # @eddacraft/kindling-adapter-pocketflow
2
+
3
+ PocketFlow workflow adapter for Kindling - capture node executions with intent and confidence.
4
+
5
+ [![npm version](https://img.shields.io/npm/v/@eddacraft/kindling-adapter-pocketflow.svg)](https://www.npmjs.com/package/@eddacraft/kindling-adapter-pocketflow)
6
+ [![License](https://img.shields.io/badge/license-Apache%202.0-blue.svg)](../../LICENSE)
7
+
8
+ ## Installation
9
+
10
+ ```bash
11
+ npm install @eddacraft/kindling-adapter-pocketflow
12
+ ```
13
+
14
+ ## Overview
15
+
16
+ `@eddacraft/kindling-adapter-pocketflow` integrates Kindling with PocketFlow workflows:
17
+
18
+ - **Node-Level Capsules** - Each node execution creates a capsule
19
+ - **Automatic Capture** - Records `node_start`, `node_output`, `node_error`, `node_end` events
20
+ - **Intent Inference** - Derives capsule intent from node names
21
+ - **Confidence Tracking** - Records success/failure confidence
22
+
23
+ ## Usage
24
+
25
+ ### Node Adapter
26
+
27
+ ```typescript
28
+ import { NodeAdapter, NodeStatus } from '@eddacraft/kindling-adapter-pocketflow';
29
+ import { SqliteKindlingStore } from '@eddacraft/kindling-store-sqlite';
30
+
31
+ const store = new SqliteKindlingStore(db);
32
+ const adapter = new NodeAdapter({
33
+ store,
34
+ repoId: '/home/user/my-project',
35
+ });
36
+
37
+ // When a node starts
38
+ adapter.onNodeStart({
39
+ node: { id: 'test-1', name: 'run-integration-tests' },
40
+ status: NodeStatus.Running,
41
+ input: { testPattern: '**/*.test.ts' },
42
+ });
43
+
44
+ // When a node produces output
45
+ adapter.onNodeOutput({
46
+ node: { id: 'test-1', name: 'run-integration-tests' },
47
+ output: { passed: 42, failed: 0 },
48
+ });
49
+
50
+ // When a node ends
51
+ adapter.onNodeEnd({
52
+ node: { id: 'test-1', name: 'run-integration-tests' },
53
+ status: NodeStatus.Success,
54
+ output: { passed: 42, failed: 0, duration: 3500 },
55
+ });
56
+ ```
57
+
58
+ ### Flow Integration
59
+
60
+ ```typescript
61
+ import { KindlingFlow, KindlingNode } from '@eddacraft/kindling-adapter-pocketflow';
62
+
63
+ // Extend KindlingNode for automatic capture
64
+ class MyTestNode extends KindlingNode {
65
+ async exec(input: TestInput): Promise<TestOutput> {
66
+ const results = await runTests(input.pattern);
67
+ return { passed: results.passed, failed: results.failed };
68
+ }
69
+ }
70
+
71
+ // Create a flow
72
+ const flow = new KindlingFlow({
73
+ store,
74
+ repoId: '/repo',
75
+ });
76
+
77
+ flow.addNode('test', new MyTestNode());
78
+ flow.addNode('deploy', new DeployNode());
79
+ flow.connect('test', 'deploy', 'success');
80
+
81
+ // Run the flow (capsules created automatically)
82
+ await flow.run({ pattern: '**/*.test.ts' });
83
+ ```
84
+
85
+ ## Captured Events
86
+
87
+ | Event | When | Content |
88
+ | ------------- | --------------------- | ------------------------------ |
89
+ | `node_start` | Node begins execution | Node ID, name, input |
90
+ | `node_output` | Node produces output | Output data |
91
+ | `node_error` | Node throws error | Error message, stack |
92
+ | `node_end` | Node completes | Final status, output, duration |
93
+
94
+ ## Intent Inference
95
+
96
+ Node names are parsed to infer capsule intent:
97
+
98
+ | Node Name | Inferred Intent |
99
+ | ------------------- | --------------- |
100
+ | `run-tests` | `test` |
101
+ | `build-app` | `build` |
102
+ | `deploy-production` | `deploy` |
103
+ | `fix-auth-bug` | `debug` |
104
+ | `implement-feature` | `implement` |
105
+
106
+ ## Confidence Scoring
107
+
108
+ Confidence is tracked based on node success/failure history:
109
+
110
+ ```typescript
111
+ // First run: neutral confidence
112
+ {
113
+ confidence: 0.5;
114
+ }
115
+
116
+ // Consistent success: higher confidence
117
+ {
118
+ confidence: 0.85;
119
+ }
120
+
121
+ // Recent failures: lower confidence
122
+ {
123
+ confidence: 0.3;
124
+ }
125
+ ```
126
+
127
+ ## Configuration
128
+
129
+ ```typescript
130
+ interface NodeAdapterOptions {
131
+ store: KindlingStore;
132
+ repoId: string;
133
+ agentId?: string;
134
+ userId?: string;
135
+
136
+ // Intent inference
137
+ intentMapping?: Record<string, string>;
138
+
139
+ // Confidence tracking
140
+ confidenceWindow?: number; // Default: 10 runs
141
+ }
142
+ ```
143
+
144
+ ## PocketFlow Concepts
145
+
146
+ PocketFlow is a minimalist workflow framework:
147
+
148
+ - **Node** - `prep -> exec -> post` lifecycle
149
+ - **Flow** - Orchestrates nodes via action-based transitions
150
+ - **Shared Store** - Global state accessible by all nodes
151
+ - **BatchNode/BatchFlow** - Process arrays of items
152
+
153
+ See the [PocketFlow documentation](./vendor/pocketflow/docs/) for details.
154
+
155
+ ## Related Packages
156
+
157
+ - [`@eddacraft/kindling-core`](../kindling-core) - Domain types and capsule lifecycle
158
+ - [`@eddacraft/kindling-store-sqlite`](../kindling-store-sqlite) - SQLite persistence
159
+ - [`@eddacraft/kindling-adapter-opencode`](../kindling-adapter-opencode) - OpenCode session adapter
160
+
161
+ ## License
162
+
163
+ Apache-2.0
@@ -0,0 +1,12 @@
1
+ /**
2
+ * Kindling PocketFlow Adapter
3
+ *
4
+ * PocketFlow workflow integration for node-level capsules.
5
+ * Captures node execution lifecycle as observations with intent
6
+ * inference and confidence tracking.
7
+ */
8
+ export { KindlingNode, KindlingFlow, type KindlingNodeContext, type NodeMetadata, type PocketFlowStore, } from './pocketflow/lifecycle.js';
9
+ export { inferIntent, type IntentMapping, DEFAULT_INTENT_PATTERNS, } from './pocketflow/intent.js';
10
+ export { ConfidenceTracker, calculateConfidence, type ConfidenceConfig, type ConfidenceState, type ExecutionResult, } from './pocketflow/confidence.js';
11
+ export { BaseNode, Node, Flow } from './pocketflow/lifecycle.js';
12
+ //# sourceMappingURL=index.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA;;;;;;GAMG;AAGH,OAAO,EACL,YAAY,EACZ,YAAY,EACZ,KAAK,mBAAmB,EACxB,KAAK,YAAY,EACjB,KAAK,eAAe,GACrB,MAAM,2BAA2B,CAAC;AAGnC,OAAO,EACL,WAAW,EACX,KAAK,aAAa,EAClB,uBAAuB,GACxB,MAAM,wBAAwB,CAAC;AAGhC,OAAO,EACL,iBAAiB,EACjB,mBAAmB,EACnB,KAAK,gBAAgB,EACrB,KAAK,eAAe,EACpB,KAAK,eAAe,GACrB,MAAM,4BAA4B,CAAC;AAGpC,OAAO,EAAE,QAAQ,EAAE,IAAI,EAAE,IAAI,EAAE,MAAM,2BAA2B,CAAC"}
package/dist/index.js ADDED
@@ -0,0 +1,16 @@
1
+ /**
2
+ * Kindling PocketFlow Adapter
3
+ *
4
+ * PocketFlow workflow integration for node-level capsules.
5
+ * Captures node execution lifecycle as observations with intent
6
+ * inference and confidence tracking.
7
+ */
8
+ // Core lifecycle classes
9
+ export { KindlingNode, KindlingFlow, } from './pocketflow/lifecycle.js';
10
+ // Intent inference
11
+ export { inferIntent, DEFAULT_INTENT_PATTERNS, } from './pocketflow/intent.js';
12
+ // Confidence tracking
13
+ export { ConfidenceTracker, calculateConfidence, } from './pocketflow/confidence.js';
14
+ // Base PocketFlow classes (re-exported for convenience)
15
+ export { BaseNode, Node, Flow } from './pocketflow/lifecycle.js';
16
+ //# sourceMappingURL=index.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA;;;;;;GAMG;AAEH,yBAAyB;AACzB,OAAO,EACL,YAAY,EACZ,YAAY,GAIb,MAAM,2BAA2B,CAAC;AAEnC,mBAAmB;AACnB,OAAO,EACL,WAAW,EAEX,uBAAuB,GACxB,MAAM,wBAAwB,CAAC;AAEhC,sBAAsB;AACtB,OAAO,EACL,iBAAiB,EACjB,mBAAmB,GAIpB,MAAM,4BAA4B,CAAC;AAEpC,wDAAwD;AACxD,OAAO,EAAE,QAAQ,EAAE,IAAI,EAAE,IAAI,EAAE,MAAM,2BAA2B,CAAC"}
@@ -0,0 +1,123 @@
1
+ /**
2
+ * Confidence Tracking
3
+ *
4
+ * Tracks execution history and calculates confidence scores for nodes.
5
+ * Confidence reflects how reliable a node's output is for retrieval and reuse.
6
+ */
7
+ /**
8
+ * Result of a single node execution
9
+ */
10
+ export interface ExecutionResult {
11
+ /** Whether the execution succeeded */
12
+ success: boolean;
13
+ /** Timestamp of the execution */
14
+ timestamp: number;
15
+ /** Optional error message if failed */
16
+ error?: string;
17
+ }
18
+ /**
19
+ * Confidence state for a single node
20
+ */
21
+ export interface ConfidenceState {
22
+ /** Node identifier */
23
+ nodeId: string;
24
+ /** Current confidence score (0.0 - 1.0) */
25
+ confidence: number;
26
+ /** Total successful executions */
27
+ successCount: number;
28
+ /** Total failed executions */
29
+ failureCount: number;
30
+ /** Consecutive failures (resets on success) */
31
+ consecutiveFailures: number;
32
+ /** Recent execution history (newest first) */
33
+ history: ExecutionResult[];
34
+ /** Last updated timestamp */
35
+ updatedAt: number;
36
+ }
37
+ /**
38
+ * Configuration for confidence calculation
39
+ */
40
+ export interface ConfidenceConfig {
41
+ /** Maximum history entries to keep (default: 10) */
42
+ historySize: number;
43
+ /** Base confidence for new nodes (default: 0.5) */
44
+ baseConfidence: number;
45
+ /** Confidence increase per success (default: 0.1) */
46
+ successIncrement: number;
47
+ /** Confidence decrease per failure (default: 0.15) */
48
+ failureDecrement: number;
49
+ /** Minimum confidence floor (default: 0.1) */
50
+ minConfidence: number;
51
+ /** Maximum confidence ceiling (default: 0.95) */
52
+ maxConfidence: number;
53
+ /** Weight for recent executions vs older ones (default: 0.7) */
54
+ recencyWeight: number;
55
+ }
56
+ /**
57
+ * Calculates confidence score from execution history.
58
+ *
59
+ * The algorithm considers:
60
+ * - Overall success rate
61
+ * - Recent execution trends (weighted more heavily)
62
+ * - Consecutive failure penalty
63
+ *
64
+ * @param state - Current confidence state
65
+ * @param config - Confidence calculation config
66
+ * @returns Confidence score between 0.0 and 1.0
67
+ */
68
+ export declare function calculateConfidence(state: Pick<ConfidenceState, 'successCount' | 'failureCount' | 'consecutiveFailures' | 'history'>, config?: ConfidenceConfig): number;
69
+ /**
70
+ * Tracks confidence across multiple nodes.
71
+ *
72
+ * @example
73
+ * ```typescript
74
+ * const tracker = new ConfidenceTracker();
75
+ *
76
+ * // Record successful execution
77
+ * tracker.recordSuccess('run-tests');
78
+ *
79
+ * // Record failed execution
80
+ * tracker.recordFailure('deploy-prod', 'Connection timeout');
81
+ *
82
+ * // Get confidence for a node
83
+ * const confidence = tracker.getConfidence('run-tests'); // 0.6
84
+ *
85
+ * // Get full state for observation provenance
86
+ * const state = tracker.getState('run-tests');
87
+ * ```
88
+ */
89
+ export declare class ConfidenceTracker {
90
+ private states;
91
+ private config;
92
+ constructor(config?: Partial<ConfidenceConfig>);
93
+ /**
94
+ * Records a successful execution for a node
95
+ */
96
+ recordSuccess(nodeId: string): ConfidenceState;
97
+ /**
98
+ * Records a failed execution for a node
99
+ */
100
+ recordFailure(nodeId: string, error?: string): ConfidenceState;
101
+ /**
102
+ * Gets the current confidence score for a node
103
+ */
104
+ getConfidence(nodeId: string): number;
105
+ /**
106
+ * Gets the full confidence state for a node
107
+ */
108
+ getState(nodeId: string): ConfidenceState | undefined;
109
+ /**
110
+ * Gets provenance metadata suitable for embedding in observations
111
+ */
112
+ getProvenanceMetadata(nodeId: string): Record<string, unknown>;
113
+ /**
114
+ * Resets tracking for a specific node
115
+ */
116
+ reset(nodeId: string): void;
117
+ /**
118
+ * Clears all tracking data
119
+ */
120
+ clear(): void;
121
+ private getOrCreateState;
122
+ }
123
+ //# sourceMappingURL=confidence.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"confidence.d.ts","sourceRoot":"","sources":["../../src/pocketflow/confidence.ts"],"names":[],"mappings":"AAAA;;;;;GAKG;AAEH;;GAEG;AACH,MAAM,WAAW,eAAe;IAC9B,sCAAsC;IACtC,OAAO,EAAE,OAAO,CAAC;IACjB,iCAAiC;IACjC,SAAS,EAAE,MAAM,CAAC;IAClB,uCAAuC;IACvC,KAAK,CAAC,EAAE,MAAM,CAAC;CAChB;AAED;;GAEG;AACH,MAAM,WAAW,eAAe;IAC9B,sBAAsB;IACtB,MAAM,EAAE,MA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;OAEG;IACH,QAAQ,CAAC,MAAM,EAAE,MAAM,GAAG,eAAe,GAAG,SAAS;IAIrD;;OAEG;IACH,qBAAqB,CAAC,MAAM,EAAE,MAAM,GAAG,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC;IAkB9D;;OAEG;IACH,KAAK,CAAC,MAAM,EAAE,MAAM,GAAG,IAAI;IAI3B;;OAEG;IACH,KAAK,IAAI,IAAI;IAIb,OAAO,CAAC,gBAAgB;CAgBzB"}
@@ -0,0 +1,176 @@
1
+ /**
2
+ * Confidence Tracking
3
+ *
4
+ * Tracks execution history and calculates confidence scores for nodes.
5
+ * Confidence reflects how reliable a node's output is for retrieval and reuse.
6
+ */
7
+ const DEFAULT_CONFIG = {
8
+ historySize: 10,
9
+ baseConfidence: 0.5,
10
+ successIncrement: 0.1,
11
+ failureDecrement: 0.15,
12
+ minConfidence: 0.1,
13
+ maxConfidence: 0.95,
14
+ recencyWeight: 0.7,
15
+ };
16
+ /**
17
+ * Calculates confidence score from execution history.
18
+ *
19
+ * The algorithm considers:
20
+ * - Overall success rate
21
+ * - Recent execution trends (weighted more heavily)
22
+ * - Consecutive failure penalty
23
+ *
24
+ * @param state - Current confidence state
25
+ * @param config - Confidence calculation config
26
+ * @returns Confidence score between 0.0 and 1.0
27
+ */
28
+ export function calculateConfidence(state, config = DEFAULT_CONFIG) {
29
+ const total = state.successCount + state.failureCount;
30
+ // New node with no history - return base confidence
31
+ if (total === 0) {
32
+ return config.baseConfidence;
33
+ }
34
+ // Calculate overall success rate
35
+ const overallRate = state.successCount / total;
36
+ // Calculate recent success rate (weighted more heavily)
37
+ const recentHistory = state.history.slice(0, Math.min(5, state.history.length));
38
+ const recentSuccesses = recentHistory.filter(r => r.success).length;
39
+ const recentRate = recentHistory.length > 0 ? recentSuccesses / recentHistory.length : overallRate;
40
+ // Blend overall and recent rates
41
+ const blendedRate = (overallRate * (1 - config.recencyWeight)) + (recentRate * config.recencyWeight);
42
+ // Apply consecutive failure penalty
43
+ const failurePenalty = Math.min(state.consecutiveFailures * 0.1, 0.3);
44
+ // Calculate final confidence
45
+ let confidence = blendedRate - failurePenalty;
46
+ // Clamp to configured bounds
47
+ confidence = Math.max(config.minConfidence, Math.min(config.maxConfidence, confidence));
48
+ return Math.round(confidence * 100) / 100; // Round to 2 decimal places
49
+ }
50
+ /**
51
+ * Tracks confidence across multiple nodes.
52
+ *
53
+ * @example
54
+ * ```typescript
55
+ * const tracker = new ConfidenceTracker();
56
+ *
57
+ * // Record successful execution
58
+ * tracker.recordSuccess('run-tests');
59
+ *
60
+ * // Record failed execution
61
+ * tracker.recordFailure('deploy-prod', 'Connection timeout');
62
+ *
63
+ * // Get confidence for a node
64
+ * const confidence = tracker.getConfidence('run-tests'); // 0.6
65
+ *
66
+ * // Get full state for observation provenance
67
+ * const state = tracker.getState('run-tests');
68
+ * ```
69
+ */
70
+ export class ConfidenceTracker {
71
+ states = new Map();
72
+ config;
73
+ constructor(config = {}) {
74
+ this.config = { ...DEFAULT_CONFIG, ...config };
75
+ }
76
+ /**
77
+ * Records a successful execution for a node
78
+ */
79
+ recordSuccess(nodeId) {
80
+ const state = this.getOrCreateState(nodeId);
81
+ state.successCount++;
82
+ state.consecutiveFailures = 0;
83
+ state.history.unshift({
84
+ success: true,
85
+ timestamp: Date.now(),
86
+ });
87
+ // Trim history to configured size
88
+ if (state.history.length > this.config.historySize) {
89
+ state.history = state.history.slice(0, this.config.historySize);
90
+ }
91
+ state.confidence = calculateConfidence(state, this.config);
92
+ state.updatedAt = Date.now();
93
+ return state;
94
+ }
95
+ /**
96
+ * Records a failed execution for a node
97
+ */
98
+ recordFailure(nodeId, error) {
99
+ const state = this.getOrCreateState(nodeId);
100
+ state.failureCount++;
101
+ state.consecutiveFailures++;
102
+ state.history.unshift({
103
+ success: false,
104
+ timestamp: Date.now(),
105
+ error,
106
+ });
107
+ // Trim history to configured size
108
+ if (state.history.length > this.config.historySize) {
109
+ state.history = state.history.slice(0, this.config.historySize);
110
+ }
111
+ state.confidence = calculateConfidence(state, this.config);
112
+ state.updatedAt = Date.now();
113
+ return state;
114
+ }
115
+ /**
116
+ * Gets the current confidence score for a node
117
+ */
118
+ getConfidence(nodeId) {
119
+ const state = this.states.get(nodeId);
120
+ return state?.confidence ?? this.config.baseConfidence;
121
+ }
122
+ /**
123
+ * Gets the full confidence state for a node
124
+ */
125
+ getState(nodeId) {
126
+ return this.states.get(nodeId);
127
+ }
128
+ /**
129
+ * Gets provenance metadata suitable for embedding in observations
130
+ */
131
+ getProvenanceMetadata(nodeId) {
132
+ const state = this.states.get(nodeId);
133
+ if (!state) {
134
+ return {
135
+ confidence: this.config.baseConfidence,
136
+ isNewNode: true,
137
+ };
138
+ }
139
+ return {
140
+ confidence: state.confidence,
141
+ successCount: state.successCount,
142
+ failureCount: state.failureCount,
143
+ consecutiveFailures: state.consecutiveFailures,
144
+ historyLength: state.history.length,
145
+ };
146
+ }
147
+ /**
148
+ * Resets tracking for a specific node
149
+ */
150
+ reset(nodeId) {
151
+ this.states.delete(nodeId);
152
+ }
153
+ /**
154
+ * Clears all tracking data
155
+ */
156
+ clear() {
157
+ this.states.clear();
158
+ }
159
+ getOrCreateState(nodeId) {
160
+ let state = this.states.get(nodeId);
161
+ if (!state) {
162
+ state = {
163
+ nodeId,
164
+ confidence: this.config.baseConfidence,
165
+ successCount: 0,
166
+ failureCount: 0,
167
+ consecutiveFailures: 0,
168
+ history: [],
169
+ updatedAt: Date.now(),
170
+ };
171
+ this.states.set(nodeId, state);
172
+ }
173
+ return state;
174
+ }
175
+ }
176
+ //# sourceMappingURL=confidence.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"confidence.js","sourceRoot":"","sources":["../../src/pocketflow/confidence.ts"],"names":[],"mappings":"AAAA;;;;;GAKG;AAsDH,MAAM,cAAc,GAAqB;IACvC,WAAW,EAAE,EAAE;IACf,cAAc,EAAE,GAAG;IACnB,gBAAgB,EAAE,GAAG;IACrB,gBAAgB,EAAE,IAAI;IACtB,aAAa,EA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;aAChB,CAAC;QACJ,CAAC;QAED,OAAO;YACL,UAAU,EAAE,KAAK,CAAC,UAAU;YAC5B,YAAY,EAAE,KAAK,CAAC,YAAY;YAChC,YAAY,EAAE,KAAK,CAAC,YAAY;YAChC,mBAAmB,EAAE,KAAK,CAAC,mBAAmB;YAC9C,aAAa,EAAE,KAAK,CAAC,OAAO,CAAC,MAAM;SACpC,CAAC;IACJ,CAAC;IAED;;OAEG;IACH,KAAK,CAAC,MAAc;QAClB,IAAI,CAAC,MAAM,CAAC,MAAM,CAAC,MAAM,CAAC,CAAC;IAC7B,CAAC;IAED;;OAEG;IACH,KAAK;QACH,IAAI,CAAC,MAAM,CAAC,KAAK,EAAE,CAAC;IACtB,CAAC;IAEO,gBAAgB,CAAC,MAAc;QACrC,IAAI,KAAK,GAAG,IAAI,CAAC,MAAM,CAAC,GAAG,CAAC,MAAM,CAAC,CAAC;QACpC,IAAI,CAAC,KAAK,EAAE,CAAC;YACX,KAAK,GAAG;gBACN,MAAM;gBACN,UAAU,EAAE,IAAI,CAAC,MAAM,CAAC,cAAc;gBACtC,YAAY,EAAE,CAAC;gBACf,YAAY,EAAE,CAAC;gBACf,mBAAmB,EAAE,CAAC;gBACtB,OAAO,EAAE,EAAE;gBACX,SAAS,EAAE,IAAI,CAAC,GAAG,EAAE;aACtB,CAAC;YACF,IAAI,CAAC,MAAM,CAAC,GAAG,CAAC,MAAM,EAAE,KAAK,CAAC,CAAC;QACjC,CAAC;QACD,OAAO,KAAK,CAAC;IACf,CAAC;CACF"}
@@ -0,0 +1,39 @@
1
+ /**
2
+ * Intent Inference
3
+ *
4
+ * Derives semantic intent from node names using pattern matching.
5
+ * Intent categorizes what a node is trying to accomplish, enabling
6
+ * smarter retrieval and context organization.
7
+ */
8
+ /**
9
+ * Mapping from keyword patterns to intent strings
10
+ */
11
+ export interface IntentMapping {
12
+ /** Keywords that indicate this intent (matched against node name) */
13
+ keywords: string[];
14
+ /** The intent string to return when matched */
15
+ intent: string;
16
+ }
17
+ /**
18
+ * Default intent patterns based on common development workflows
19
+ */
20
+ export declare const DEFAULT_INTENT_PATTERNS: IntentMapping[];
21
+ /**
22
+ * Infers intent from a node name using pattern matching.
23
+ *
24
+ * @param nodeName - The name of the node (e.g., "run-tests", "deployProduction", "fix_auth_bug")
25
+ * @param patterns - Custom patterns to use (defaults to DEFAULT_INTENT_PATTERNS)
26
+ * @returns The inferred intent string, or "general" if no pattern matches
27
+ *
28
+ * @example
29
+ * ```typescript
30
+ * inferIntent('run-tests') // → 'test'
31
+ * inferIntent('buildApp') // → 'build'
32
+ * inferIntent('deploy_production') // → 'deploy'
33
+ * inferIntent('fixAuthBug') // → 'debug'
34
+ * inferIntent('implementFeatureX') // → 'feature'
35
+ * inferIntent('unknownNode') // → 'general'
36
+ * ```
37
+ */
38
+ export declare function inferIntent(nodeName: string, patterns?: IntentMapping[]): string;
39
+ //# sourceMappingURL=intent.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"intent.d.ts","sourceRoot":"","sources":["../../src/pocketflow/intent.ts"],"names":[],"mappings":"AAAA;;;;;;GAMG;AAEH;;GAEG;AACH,MAAM,WAAW,aAAa;IAC5B,qEAAqE;IACrE,QAAQ,EAAE,MAAM,EAAE,CAAC;IACnB,+CAA+C;IAC/C,MAAM,EAAE,MAAM,CAAC;CAChB;AAED;;GAEG;AACH,eAAO,MAAM,uBAAuB,EAAE,aAAa,EA0ClD,CAAC;AAmBF;;;;;;;;;;;;;;;;GAgBG;AACH,wBAAgB,WAAW,CACzB,QAAQ,EAAE,MAAM,EAChB,QAAQ,GAAE,aAAa,EAA4B,GAClD,MAAM,CAuBR"}
@@ -0,0 +1,94 @@
1
+ /**
2
+ * Intent Inference
3
+ *
4
+ * Derives semantic intent from node names using pattern matching.
5
+ * Intent categorizes what a node is trying to accomplish, enabling
6
+ * smarter retrieval and context organization.
7
+ */
8
+ /**
9
+ * Default intent patterns based on common development workflows
10
+ */
11
+ export const DEFAULT_INTENT_PATTERNS = [
12
+ // Testing
13
+ { keywords: ['test', 'spec', 'check', 'verify', 'validate', 'assert'], intent: 'test' },
14
+ // Building/Compilation
15
+ { keywords: ['build', 'compile', 'bundle', 'pack', 'transpile'], intent: 'build' },
16
+ // Deployment
17
+ { keywords: ['deploy', 'publish', 'release', 'ship', 'push-to'], intent: 'deploy' },
18
+ // Debugging/Fixing
19
+ { keywords: ['fix', 'debug', 'repair', 'patch', 'hotfix', 'troubleshoot'], intent: 'debug' },
20
+ // Feature implementation
21
+ { keywords: ['implement', 'add', 'create', 'feature', 'develop', 'make'], intent: 'feature' },
22
+ // Refactoring
23
+ { keywords: ['refactor', 'restructure', 'reorganize', 'cleanup', 'clean-up'], intent: 'refactor' },
24
+ // Data processing
25
+ { keywords: ['process', 'transform', 'convert', 'parse', 'extract', 'load', 'etl'], intent: 'process' },
26
+ // Analysis/Research
27
+ { keywords: ['analyze', 'analyse', 'research', 'investigate', 'explore', 'scan'], intent: 'analyze' },
28
+ // Generation
29
+ { keywords: ['generate', 'gen', 'scaffold', 'template', 'init', 'setup'], intent: 'generate' },
30
+ // Communication/API
31
+ { keywords: ['fetch', 'request', 'call', 'api', 'http', 'send', 'receive'], intent: 'communicate' },
32
+ // Storage/Persistence
33
+ { keywords: ['save', 'store', 'persist', 'write', 'cache', 'backup'], intent: 'store' },
34
+ // Retrieval
35
+ { keywords: ['read', 'get', 'fetch', 'load', 'retrieve', 'query'], intent: 'retrieve' },
36
+ // Cleanup/Maintenance
37
+ { keywords: ['clean', 'clear', 'remove', 'delete', 'prune', 'gc'], intent: 'cleanup' },
38
+ // Monitoring/Logging
39
+ { keywords: ['log', 'monitor', 'track', 'metric', 'observe', 'report'], intent: 'monitor' },
40
+ ];
41
+ /**
42
+ * Normalizes a node name for pattern matching.
43
+ * Converts camelCase, PascalCase, snake_case, and kebab-case to space-separated words.
44
+ */
45
+ function normalizeNodeName(name) {
46
+ return name
47
+ // Insert space before uppercase letters (camelCase/PascalCase)
48
+ .replace(/([a-z])([A-Z])/g, '$1 $2')
49
+ // Replace underscores and hyphens with spaces
50
+ .replace(/[_-]/g, ' ')
51
+ // Convert to lowercase
52
+ .toLowerCase()
53
+ // Collapse multiple spaces
54
+ .replace(/\s+/g, ' ')
55
+ .trim();
56
+ }
57
+ /**
58
+ * Infers intent from a node name using pattern matching.
59
+ *
60
+ * @param nodeName - The name of the node (e.g., "run-tests", "deployProduction", "fix_auth_bug")
61
+ * @param patterns - Custom patterns to use (defaults to DEFAULT_INTENT_PATTERNS)
62
+ * @returns The inferred intent string, or "general" if no pattern matches
63
+ *
64
+ * @example
65
+ * ```typescript
66
+ * inferIntent('run-tests') // → 'test'
67
+ * inferIntent('buildApp') // → 'build'
68
+ * inferIntent('deploy_production') // → 'deploy'
69
+ * inferIntent('fixAuthBug') // → 'debug'
70
+ * inferIntent('implementFeatureX') // → 'feature'
71
+ * inferIntent('unknownNode') // → 'general'
72
+ * ```
73
+ */
74
+ export function inferIntent(nodeName, patterns = DEFAULT_INTENT_PATTERNS) {
75
+ const normalized = normalizeNodeName(nodeName);
76
+ // Handle empty or whitespace-only input
77
+ if (!normalized) {
78
+ return 'general';
79
+ }
80
+ const words = normalized.split(' ').filter(w => w.length > 0);
81
+ // Check each pattern's keywords against the normalized words
82
+ for (const pattern of patterns) {
83
+ for (const keyword of pattern.keywords) {
84
+ // Check if any word starts with the keyword (prefix match)
85
+ // This handles cases like "testing" matching "test"
86
+ // Require minimum word length of 2 to avoid false positives
87
+ if (words.some(word => word.length >= 2 && (word.startsWith(keyword) || keyword.startsWith(word)))) {
88
+ return pattern.intent;
89
+ }
90
+ }
91
+ }
92
+ return 'general';
93
+ }
94
+ //# sourceMappingURL=intent.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"intent.js","sourceRoot":"","sources":["../../src/pocketflow/intent.ts"],"names":[],"mappings":"AAAA;;;;;;GAMG;AAYH;;GAEG;AACH,MAAM,CAAC,MAAM,uBAAuB,GAAoB;IACtD,UAAU;IACV,EAAE,QAAQ,EAAE,C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,iBAAiB,CAAC,QAAQ,CAAC,CAAC;IAE/C,wCAAwC;IACxC,IAAI,CAAC,UAAU,EAAE,CAAC;QAChB,OAAO,SAAS,CAAC;IACnB,CAAC;IAED,MAAM,KAAK,GAAG,UAAU,CAAC,KAAK,CAAC,GAAG,CAAC,CAAC,MAAM,CAAC,CAAC,CAAC,EAAE,CAAC,CAAC,CAAC,MAAM,GAAG,CAAC,CAAC,CAAC;IAE9D,6DAA6D;IAC7D,KAAK,MAAM,OAAO,IAAI,QAAQ,EAAE,CAAC;QAC/B,KAAK,MAAM,OAAO,IAAI,OAAO,CAAC,QAAQ,EAAE,CAAC;YACvC,2DAA2D;YAC3D,oDAAoD;YACpD,4DAA4D;YAC5D,IAAI,KAAK,CAAC,IAAI,CAAC,IAAI,CAAC,EAAE,CAAC,IAAI,CAAC,MAAM,IAAI,CAAC,IAAI,CAAC,IAAI,CAAC,UAAU,CAAC,OAAO,CAAC,IAAI,OAAO,CAAC,UAAU,CAAC,IAAI,CAAC,CAAC,CAAC,EAAE,CAAC;gBACnG,OAAO,OAAO,CAAC,MAAM,CAAC;YACxB,CAAC;QACH,CAAC;IACH,CAAC;IAED,OAAO,SAAS,CAAC;AACnB,CAAC"}
@@ -0,0 +1,69 @@
1
+ import type { Observation, Capsule, ScopeIds } from '@eddacraft/kindling-core';
2
+ export interface PocketFlowStore {
3
+ insertObservation(observation: Observation): void;
4
+ createCapsule(capsule: Capsule): void;
5
+ closeCapsule(capsuleId: string, closedAt?: number): void;
6
+ attachObservationToCapsule(capsuleId: string, observationId: string): void;
7
+ }
8
+ export interface KindlingNodeContext {
9
+ store: PocketFlowStore;
10
+ scopeIds: ScopeIds;
11
+ capsuleId?: string;
12
+ }
13
+ export interface NodeMetadata {
14
+ name: string;
15
+ intent?: string;
16
+ }
17
+ type NonIterableObject = Partial<Record<string, unknown>> & {
18
+ [Symbol.iterator]?: never;
19
+ };
20
+ export declare class BaseNode<S = unknown, P extends NonIterableObject = NonIterableObject> {
21
+ protected _params: P;
22
+ protected _successors: Map<string, BaseNode>;
23
+ prep(_shared: S): Promise<unknown>;
24
+ exec(_prepRes: unknown): Promise<unknown>;
25
+ post(_shared: S, _prepRes: unknown, _execRes: unknown): Promise<string | undefined>;
26
+ protected _exec(prepRes: unknown): Promise<unknown>;
27
+ _run(shared: S): Promise<string | undefined>;
28
+ run(shared: S): Promise<string | undefined>;
29
+ setParams(params: P): this;
30
+ next<T extends BaseNode>(node: T): T;
31
+ on(action: string, node: BaseNode): this;
32
+ getNextNode(action?: string): BaseNode | undefined;
33
+ clone(): this;
34
+ }
35
+ export declare class Node<S = unknown, P extends NonIterableObject = NonIterableObject> extends BaseNode<S, P> {
36
+ maxRetries: number;
37
+ wait: number;
38
+ currentRetry: number;
39
+ constructor(maxRetries?: number, wait?: number);
40
+ execFallback(_prepRes: unknown, error: Error): Promise<unknown>;
41
+ protected _exec(prepRes: unknown): Promise<unknown>;
42
+ }
43
+ export declare class Flow<S = unknown, P extends NonIterableObject = NonIterableObject> extends BaseNode<S, P> {
44
+ start: BaseNode;
45
+ constructor(start: BaseNode);
46
+ protected _orchestrate(shared: S, params?: P): Promise<void>;
47
+ _run(shared: S): Promise<string | undefined>;
48
+ exec(_prepRes: unknown): Promise<unknown>;
49
+ }
50
+ export declare class KindlingNode<S extends KindlingNodeContext = KindlingNodeContext, P extends NonIterableObject = NonIterableObject> extends Node<S, P> {
51
+ protected metadata: NodeMetadata;
52
+ private nodeStartTime?;
53
+ private capsuleId?;
54
+ private sharedContext?;
55
+ constructor(metadata: NodeMetadata, maxRetries?: number, wait?: number);
56
+ prep(shared: S): Promise<unknown>;
57
+ post(shared: S, _prepRes: unknown, execRes: unknown): Promise<string | undefined>;
58
+ execFallback(_prepRes: unknown, error: Error): Promise<unknown>;
59
+ }
60
+ export declare class KindlingFlow<S extends KindlingNodeContext = KindlingNodeContext, P extends NonIterableObject = NonIterableObject> extends Flow<S, P> {
61
+ protected flowMetadata: NodeMetadata;
62
+ private flowCapsuleId?;
63
+ private flowStartTime?;
64
+ constructor(start: KindlingNode<S, P>, metadata: NodeMetadata);
65
+ prep(shared: S): Promise<unknown>;
66
+ post(shared: S, _prepRes: unknown, _execRes: unknown): Promise<string | undefined>;
67
+ }
68
+ export {};
69
+ //# sourceMappingURL=lifecycle.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"lifecycle.d.ts","sourceRoot":"","sources":["../../src/pocketflow/lifecycle.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,WAAW,EAAmB,OAAO,EAAE,QAAQ,EAAE,MAAM,0BAA0B,CAAC;AAEhG,MAAM,WAAW,eAAe;IAC9B,iBAAiB,CAAC,WAAW,EAAE,WAAW,GAAG,IAAI,CAAC;IAClD,aAAa,CAAC,OAAO,EAAE,OAAO,GAAG,IAAI,CAAC;IACtC,YAAY,CAAC,SAAS,EAAE,MAAM,EAAE,QAAQ,CAAC,EAAE,MAAM,GAAG,IAAI,CAAC;IACzD,0BAA0B,CAAC,SAAS,EAAE,MAAM,EAAE,aAAa,EAAE,MAAM,GAAG,IAAI,CAAC;CAC5E;AAmBD,MAAM,WAAW,mBAAmB;IAClC,KAAK,EAAE,eAAe,CAAC;IACvB,QAAQ,EAAE,QAAQ,CAAC;IACnB,SAAS,CAAC,EAAE,MAAM,CAAC;CACpB;AAED,MAAM,WAAW,YAAY;IAC3B,IAAI,EAAE,MAAM,CAAC;IACb,MAAM,CAAC,EAAE,MAAM,CAAC;CACjB;AAED,KAAK,iBAAiB,GAAG,OAAO,CAAC,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,CAAC,GAAG;IAAE,CAAC,MAAM,CAAC,QAAQ,CAAC,CAAC,EAAE,KAAK,CAAA;CAAE,CAAC;AAqB1F,qBAAa,QAAQ,CAAC,CAAC,GAAG,OAAO,EAAE,CAAC,SAAS,iBAAiB,GAAG,iBAAiB;IAChF,SAAS,CAAC,OAAO,EAAE,CAAC,CAAW;IAC/B,SAAS,CAAC,WAAW,EAAE,GAAG,C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AG,iBAAiB,CAC/C,SAAQ,IAAI,CAAC,CAAC,EAAE,CAAC,CAAC;IAClB,SAAS,CAAC,YAAY,EAAE,YAAY,CAAC;IACrC,OAAO,CAAC,aAAa,CAAC,CAAS;IAC/B,OAAO,CAAC,aAAa,CAAC,CAAS;gBAEnB,KAAK,EAAE,YAAY,CAAC,CAAC,EAAE,CAAC,CAAC,EAAE,QAAQ,EAAE,YAAY;IAK9C,IAAI,CAAC,MAAM,EAAE,CAAC,GAAG,OAAO,CAAC,OAAO,CAAC;IAoCjC,IAAI,CACjB,MAAM,EAAE,CAAC,EACT,QAAQ,EAAE,OAAO,EACjB,QAAQ,EAAE,OAAO,GAChB,OAAO,CAAC,MAAM,GAAG,SAAS,CAAC;CAwB/B"}
@@ -0,0 +1,276 @@
1
+ import { randomUUID } from 'node:crypto';
2
+ function createObservation(kind, content, provenance, scopeIds) {
3
+ return {
4
+ id: randomUUID(),
5
+ kind,
6
+ content,
7
+ provenance,
8
+ ts: Date.now(),
9
+ scopeIds,
10
+ redacted: false,
11
+ };
12
+ }
13
+ function truncateOutput(output, maxLength = 2000) {
14
+ let str;
15
+ if (output === undefined) {
16
+ str = 'undefined';
17
+ }
18
+ else if (typeof output === 'string') {
19
+ str = output;
20
+ }
21
+ else if (typeof output === 'bigint') {
22
+ str = output.toString();
23
+ }
24
+ else {
25
+ try {
26
+ str = JSON.stringify(output) ?? 'undefined';
27
+ }
28
+ catch {
29
+ str = '[unserializable]';
30
+ }
31
+ }
32
+ if (str.length <= maxLength)
33
+ return str;
34
+ return str.substring(0, maxLength) + '... [truncated]';
35
+ }
36
+ export class BaseNode {
37
+ _params = {};
38
+ _successors = new Map();
39
+ async prep(_shared) {
40
+ return undefined;
41
+ }
42
+ async exec(_prepRes) {
43
+ return undefined;
44
+ }
45
+ async post(_shared, _prepRes, _execRes) {
46
+ return undefined;
47
+ }
48
+ async _exec(prepRes) {
49
+ return await this.exec(prepRes);
50
+ }
51
+ async _run(shared) {
52
+ const p = await this.prep(shared);
53
+ const e = await this._exec(p);
54
+ return await this.post(shared, p, e);
55
+ }
56
+ async run(shared) {
57
+ if (this._successors.size > 0) {
58
+ console.warn("Node won't run successors. Use Flow.");
59
+ }
60
+ return await this._run(shared);
61
+ }
62
+ setParams(params) {
63
+ this._params = params;
64
+ return this;
65
+ }
66
+ next(node) {
67
+ this.on('default', node);
68
+ return node;
69
+ }
70
+ on(action, node) {
71
+ if (this._successors.has(action)) {
72
+ console.warn(`Overwriting successor for action '${action}'`);
73
+ }
74
+ this._successors.set(action, node);
75
+ return this;
76
+ }
77
+ getNextNode(action = 'default') {
78
+ const nextAction = action || 'default';
79
+ const next = this._successors.get(nextAction);
80
+ if (!next && this._successors.size > 0) {
81
+ console.warn(`Flow ends: '${nextAction}' not found in [${Array.from(this._successors.keys())}]`);
82
+ }
83
+ return next;
84
+ }
85
+ clone() {
86
+ const clonedNode = Object.create(Object.getPrototypeOf(this));
87
+ Object.assign(clonedNode, this);
88
+ clonedNode._params = { ...this._params };
89
+ clonedNode._successors = new Map(this._successors);
90
+ return clonedNode;
91
+ }
92
+ }
93
+ export class Node extends BaseNode {
94
+ maxRetries;
95
+ wait;
96
+ currentRetry = 0;
97
+ constructor(maxRetries = 1, wait = 0) {
98
+ super();
99
+ this.maxRetries = maxRetries;
100
+ this.wait = wait;
101
+ }
102
+ async execFallback(_prepRes, error) {
103
+ throw error;
104
+ }
105
+ async _exec(prepRes) {
106
+ for (this.currentRetry = 0; this.currentRetry < this.maxRetries; this.currentRetry++) {
107
+ try {
108
+ return await this.exec(prepRes);
109
+ }
110
+ catch (e) {
111
+ if (this.currentRetry === this.maxRetries - 1) {
112
+ return await this.execFallback(prepRes, e);
113
+ }
114
+ if (this.wait > 0) {
115
+ await new Promise((resolve) => setTimeout(resolve, this.wait * 1000));
116
+ }
117
+ }
118
+ }
119
+ return undefined;
120
+ }
121
+ }
122
+ export class Flow extends BaseNode {
123
+ start;
124
+ constructor(start) {
125
+ super();
126
+ this.start = start;
127
+ }
128
+ async _orchestrate(shared, params) {
129
+ let current = this.start.clone();
130
+ const p = params || this._params;
131
+ while (current) {
132
+ current.setParams(p);
133
+ const action = await current._run(shared);
134
+ current = current.getNextNode(action ?? 'default');
135
+ current = current?.clone();
136
+ }
137
+ }
138
+ async _run(shared) {
139
+ const pr = await this.prep(shared);
140
+ await this._orchestrate(shared);
141
+ return await this.post(shared, pr, undefined);
142
+ }
143
+ async exec(_prepRes) {
144
+ throw new Error("Flow can't exec.");
145
+ }
146
+ }
147
+ export class KindlingNode extends Node {
148
+ metadata;
149
+ nodeStartTime;
150
+ capsuleId;
151
+ sharedContext;
152
+ constructor(metadata, maxRetries = 1, wait = 0) {
153
+ super(maxRetries, wait);
154
+ this.metadata = metadata;
155
+ }
156
+ async prep(shared) {
157
+ this.nodeStartTime = Date.now();
158
+ this.sharedContext = shared;
159
+ const capsuleId = randomUUID();
160
+ const now = Date.now();
161
+ const capsule = {
162
+ id: capsuleId,
163
+ type: 'pocketflow_node',
164
+ intent: this.metadata.intent || 'general',
165
+ status: 'open',
166
+ openedAt: now,
167
+ scopeIds: shared.scopeIds,
168
+ observationIds: [],
169
+ };
170
+ shared.store.createCapsule(capsule);
171
+ this.capsuleId = capsuleId;
172
+ shared.capsuleId = capsuleId;
173
+ const obs = createObservation('node_start', `Node "${this.metadata.name}" started`, {
174
+ nodeName: this.metadata.name,
175
+ intent: this.metadata.intent,
176
+ params: this._params,
177
+ }, shared.scopeIds);
178
+ shared.store.insertObservation(obs);
179
+ shared.store.attachObservationToCapsule(this.capsuleId, obs.id);
180
+ return undefined;
181
+ }
182
+ async post(shared, _prepRes, execRes) {
183
+ const duration = this.nodeStartTime ? Date.now() - this.nodeStartTime : 0;
184
+ if (this.capsuleId) {
185
+ const outputObs = createObservation('node_output', truncateOutput(execRes), {
186
+ nodeName: this.metadata.name,
187
+ outputType: typeof execRes,
188
+ duration,
189
+ }, shared.scopeIds);
190
+ shared.store.insertObservation(outputObs);
191
+ shared.store.attachObservationToCapsule(this.capsuleId, outputObs.id);
192
+ const endObs = createObservation('node_end', `Node "${this.metadata.name}" completed successfully`, {
193
+ nodeName: this.metadata.name,
194
+ duration,
195
+ status: 'success',
196
+ }, shared.scopeIds);
197
+ shared.store.insertObservation(endObs);
198
+ shared.store.attachObservationToCapsule(this.capsuleId, endObs.id);
199
+ shared.store.closeCapsule(this.capsuleId, Date.now());
200
+ }
201
+ return undefined;
202
+ }
203
+ async execFallback(_prepRes, error) {
204
+ if (this.capsuleId && this.sharedContext) {
205
+ const duration = this.nodeStartTime ? Date.now() - this.nodeStartTime : 0;
206
+ const shared = this.sharedContext;
207
+ const errorObs = createObservation('node_error', `Node "${this.metadata.name}" failed: ${error.message}`, {
208
+ nodeName: this.metadata.name,
209
+ errorType: error.name,
210
+ errorMessage: error.message,
211
+ stack: error.stack,
212
+ retryCount: this.currentRetry,
213
+ }, shared.scopeIds);
214
+ shared.store.insertObservation(errorObs);
215
+ shared.store.attachObservationToCapsule(this.capsuleId, errorObs.id);
216
+ const endObs = createObservation('node_end', `Node "${this.metadata.name}" failed after ${this.currentRetry + 1} attempt(s)`, {
217
+ nodeName: this.metadata.name,
218
+ duration,
219
+ status: 'error',
220
+ }, shared.scopeIds);
221
+ shared.store.insertObservation(endObs);
222
+ shared.store.attachObservationToCapsule(this.capsuleId, endObs.id);
223
+ shared.store.closeCapsule(this.capsuleId, Date.now());
224
+ }
225
+ throw error;
226
+ }
227
+ }
228
+ export class KindlingFlow extends Flow {
229
+ flowMetadata;
230
+ flowCapsuleId;
231
+ flowStartTime;
232
+ constructor(start, metadata) {
233
+ super(start);
234
+ this.flowMetadata = metadata;
235
+ }
236
+ async prep(shared) {
237
+ this.flowStartTime = Date.now();
238
+ const capsuleId = randomUUID();
239
+ const now = Date.now();
240
+ const capsule = {
241
+ id: capsuleId,
242
+ type: 'pocketflow_node',
243
+ intent: this.flowMetadata.intent || 'workflow',
244
+ status: 'open',
245
+ openedAt: now,
246
+ scopeIds: shared.scopeIds,
247
+ observationIds: [],
248
+ };
249
+ shared.store.createCapsule(capsule);
250
+ this.flowCapsuleId = capsuleId;
251
+ const obs = createObservation('node_start', `Flow "${this.flowMetadata.name}" started`, {
252
+ nodeName: this.flowMetadata.name,
253
+ nodeType: 'flow',
254
+ intent: this.flowMetadata.intent,
255
+ }, shared.scopeIds);
256
+ shared.store.insertObservation(obs);
257
+ shared.store.attachObservationToCapsule(this.flowCapsuleId, obs.id);
258
+ return undefined;
259
+ }
260
+ async post(shared, _prepRes, _execRes) {
261
+ const duration = this.flowStartTime ? Date.now() - this.flowStartTime : 0;
262
+ if (this.flowCapsuleId) {
263
+ const endObs = createObservation('node_end', `Flow "${this.flowMetadata.name}" completed`, {
264
+ nodeName: this.flowMetadata.name,
265
+ nodeType: 'flow',
266
+ duration,
267
+ status: 'success',
268
+ }, shared.scopeIds);
269
+ shared.store.insertObservation(endObs);
270
+ shared.store.attachObservationToCapsule(this.flowCapsuleId, endObs.id);
271
+ shared.store.closeCapsule(this.flowCapsuleId, Date.now());
272
+ }
273
+ return undefined;
274
+ }
275
+ }
276
+ //# sourceMappingURL=lifecycle.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"lifecycle.js","sourceRoot":"","sources":["../../src/pocketflow/lifecycle.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,UAAU,EAAE,MAAM,aAAa,CAAC;AAUzC,SAAS,iBAAiB,CACxB,IAAqB,EACrB,OAAe,EACf,UAAmC,EACnC,QAAkB;IAElB,OAAO;QACL,EAAE,EAAE,UAAU,EAAE;QAChB,IAAI;QACJ,OAAO;QACP,UAAU;QACV,EAAE,EAAE,IAAI,CAAC,GAAG,EAAE;QACd,QAAQ;QACR,QAAQ,EAAE,KAAK;KAChB,CAAC;AACJ,CAAC;AAeD,SAAS,cAAc,CAAC,MAAe,EAAE,YAAoB,IAAI;IAC/D,IAAI,GAAW,CAAC;IAChB,IAAI,MAAM,KAAK,SAAS,EAAE,CAAC;QACzB,GAAG,GAAG,WAAW,CAAC;IACp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AM;SACjC,EACD,MAAM,CAAC,QAAQ,CAChB,CAAC;QAEF,MAAM,CAAC,KAAK,CAAC,iBAAiB,CAAC,GAAG,CAAC,CAAC;QACpC,MAAM,CAAC,KAAK,CAAC,0BAA0B,CAAC,IAAI,CAAC,aAAa,EAAE,GAAG,CAAC,EAAE,CAAC,CAAC;QAEpE,OAAO,SAAS,CAAC;IACnB,CAAC;IAEQ,KAAK,CAAC,IAAI,CACjB,MAAS,EACT,QAAiB,EACjB,QAAiB;QAEjB,MAAM,QAAQ,GAAG,IAAI,CAAC,aAAa,CAAC,CAAC,CAAC,IAAI,CAAC,GAAG,EAAE,GAAG,IAAI,CAAC,aAAa,CAAC,CAAC,CAAC,CAAC,CAAC;QAE1E,IAAI,IAAI,CAAC,aAAa,EAAE,CAAC;YACvB,MAAM,MAAM,GAAG,iBAAiB,CAC9B,UAAU,EACV,SAAS,IAAI,CAAC,YAAY,CAAC,IAAI,aAAa,EAC5C;gBACE,QAAQ,EAAE,IAAI,CAAC,YAAY,CAAC,IAAI;gBAChC,QAAQ,EAAE,MAAM;gBAChB,QAAQ;gBACR,MAAM,EAAE,SAAS;aAClB,EACD,MAAM,CAAC,QAAQ,CAChB,CAAC;YAEF,MAAM,CAAC,KAAK,CAAC,iBAAiB,CAAC,MAAM,CAAC,CAAC;YACvC,MAAM,CAAC,KAAK,CAAC,0BAA0B,CAAC,IAAI,CAAC,aAAa,EAAE,MAAM,CAAC,EAAE,CAAC,CAAC;YAEvE,MAAM,CAAC,KAAK,CAAC,YAAY,CAAC,IAAI,CAAC,aAAa,EAAE,IAAI,CAAC,GAAG,EAAE,CAAC,CAAC;QAC5D,CAAC;QAED,OAAO,SAAS,CAAC;IACnB,CAAC;CACF"}
package/package.json ADDED
@@ -0,0 +1,58 @@
1
+ {
2
+ "name": "@eddacraft/kindling-adapter-pocketflow",
3
+ "version": "0.1.0",
4
+ "description": "PocketFlow workflow adapter for Kindling - capture node executions with intent and confidence",
5
+ "type": "module",
6
+ "main": "./dist/index.js",
7
+ "types": "./dist/index.d.ts",
8
+ "exports": {
9
+ ".": {
10
+ "types": "./dist/index.d.ts",
11
+ "import": "./dist/index.js"
12
+ }
13
+ },
14
+ "files": [
15
+ "dist",
16
+ "!dist/test"
17
+ ],
18
+ "keywords": [
19
+ "kindling",
20
+ "pocketflow",
21
+ "adapter",
22
+ "workflow",
23
+ "nodes",
24
+ "agent",
25
+ "ai",
26
+ "memory"
27
+ ],
28
+ "author": "EddaCraft <hello@eddacraft.ai>",
29
+ "homepage": "https://github.com/EddaCraft/kindling/tree/main/packages/kindling-adapter-pocketflow#readme",
30
+ "repository": {
31
+ "type": "git",
32
+ "url": "git+https://github.com/EddaCraft/kindling.git",
33
+ "directory": "packages/kindling-adapter-pocketflow"
34
+ },
35
+ "bugs": {
36
+ "url": "https://github.com/EddaCraft/kindling/issues"
37
+ },
38
+ "license": "Apache-2.0",
39
+ "dependencies": {
40
+ "@eddacraft/kindling-core": "0.1.0"
41
+ },
42
+ "devDependencies": {
43
+ "@types/node": "^20.11.0",
44
+ "typescript": "^5.3.0",
45
+ "vitest": "^3.2.4"
46
+ },
47
+ "publishConfig": {
48
+ "access": "public"
49
+ },
50
+ "scripts": {
51
+ "build": "tsc --build",
52
+ "test": "vitest run",
53
+ "test:watch": "vitest",
54
+ "type-check": "tsc --noEmit",
55
+ "lint": "eslint src",
56
+ "clean": "rm -rf dist"
57
+ }
58
+ }