@lumenflow/kernel 3.0.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.
Files changed (127) hide show
  1. package/LICENSE.md +190 -0
  2. package/README.md +26 -0
  3. package/dist/canonical-json.d.ts +7 -0
  4. package/dist/canonical-json.d.ts.map +1 -0
  5. package/dist/canonical-json.js +50 -0
  6. package/dist/canonical-json.js.map +1 -0
  7. package/dist/event-kinds.d.ts +32 -0
  8. package/dist/event-kinds.d.ts.map +1 -0
  9. package/dist/event-kinds.js +49 -0
  10. package/dist/event-kinds.js.map +1 -0
  11. package/dist/event-store/index.d.ts +64 -0
  12. package/dist/event-store/index.d.ts.map +1 -0
  13. package/dist/event-store/index.js +634 -0
  14. package/dist/event-store/index.js.map +1 -0
  15. package/dist/evidence/evidence-store.d.ts +78 -0
  16. package/dist/evidence/evidence-store.d.ts.map +1 -0
  17. package/dist/evidence/evidence-store.js +409 -0
  18. package/dist/evidence/evidence-store.js.map +1 -0
  19. package/dist/evidence/fs-helpers.d.ts +13 -0
  20. package/dist/evidence/fs-helpers.d.ts.map +1 -0
  21. package/dist/evidence/fs-helpers.js +38 -0
  22. package/dist/evidence/fs-helpers.js.map +1 -0
  23. package/dist/evidence/index.d.ts +3 -0
  24. package/dist/evidence/index.d.ts.map +1 -0
  25. package/dist/evidence/index.js +5 -0
  26. package/dist/evidence/index.js.map +1 -0
  27. package/dist/index.d.ts +17 -0
  28. package/dist/index.d.ts.map +1 -0
  29. package/dist/index.js +19 -0
  30. package/dist/index.js.map +1 -0
  31. package/dist/kernel.schemas.d.ts +642 -0
  32. package/dist/kernel.schemas.d.ts.map +1 -0
  33. package/dist/kernel.schemas.js +331 -0
  34. package/dist/kernel.schemas.js.map +1 -0
  35. package/dist/pack/hash.d.ts +7 -0
  36. package/dist/pack/hash.d.ts.map +1 -0
  37. package/dist/pack/hash.js +56 -0
  38. package/dist/pack/hash.js.map +1 -0
  39. package/dist/pack/index.d.ts +4 -0
  40. package/dist/pack/index.d.ts.map +1 -0
  41. package/dist/pack/index.js +6 -0
  42. package/dist/pack/index.js.map +1 -0
  43. package/dist/pack/manifest.d.ts +100 -0
  44. package/dist/pack/manifest.d.ts.map +1 -0
  45. package/dist/pack/manifest.js +50 -0
  46. package/dist/pack/manifest.js.map +1 -0
  47. package/dist/pack/pack-loader.d.ts +108 -0
  48. package/dist/pack/pack-loader.d.ts.map +1 -0
  49. package/dist/pack/pack-loader.js +282 -0
  50. package/dist/pack/pack-loader.js.map +1 -0
  51. package/dist/policy/approval-event.d.ts +29 -0
  52. package/dist/policy/approval-event.d.ts.map +1 -0
  53. package/dist/policy/approval-event.js +17 -0
  54. package/dist/policy/approval-event.js.map +1 -0
  55. package/dist/policy/index.d.ts +3 -0
  56. package/dist/policy/index.d.ts.map +1 -0
  57. package/dist/policy/index.js +5 -0
  58. package/dist/policy/index.js.map +1 -0
  59. package/dist/policy/policy-engine.d.ts +52 -0
  60. package/dist/policy/policy-engine.d.ts.map +1 -0
  61. package/dist/policy/policy-engine.js +83 -0
  62. package/dist/policy/policy-engine.js.map +1 -0
  63. package/dist/runtime/index.d.ts +2 -0
  64. package/dist/runtime/index.d.ts.map +1 -0
  65. package/dist/runtime/index.js +4 -0
  66. package/dist/runtime/index.js.map +1 -0
  67. package/dist/runtime/kernel-runtime.d.ts +170 -0
  68. package/dist/runtime/kernel-runtime.d.ts.map +1 -0
  69. package/dist/runtime/kernel-runtime.js +751 -0
  70. package/dist/runtime/kernel-runtime.js.map +1 -0
  71. package/dist/sandbox/bwrap-invocation.d.ts +13 -0
  72. package/dist/sandbox/bwrap-invocation.d.ts.map +1 -0
  73. package/dist/sandbox/bwrap-invocation.js +105 -0
  74. package/dist/sandbox/bwrap-invocation.js.map +1 -0
  75. package/dist/sandbox/index.d.ts +5 -0
  76. package/dist/sandbox/index.d.ts.map +1 -0
  77. package/dist/sandbox/index.js +7 -0
  78. package/dist/sandbox/index.js.map +1 -0
  79. package/dist/sandbox/profile.d.ts +32 -0
  80. package/dist/sandbox/profile.d.ts.map +1 -0
  81. package/dist/sandbox/profile.js +101 -0
  82. package/dist/sandbox/profile.js.map +1 -0
  83. package/dist/sandbox/subprocess-dispatcher.d.ts +38 -0
  84. package/dist/sandbox/subprocess-dispatcher.d.ts.map +1 -0
  85. package/dist/sandbox/subprocess-dispatcher.js +145 -0
  86. package/dist/sandbox/subprocess-dispatcher.js.map +1 -0
  87. package/dist/sandbox/tool-runner-worker.d.ts +54 -0
  88. package/dist/sandbox/tool-runner-worker.d.ts.map +1 -0
  89. package/dist/sandbox/tool-runner-worker.js +159 -0
  90. package/dist/sandbox/tool-runner-worker.js.map +1 -0
  91. package/dist/shared-constants.d.ts +48 -0
  92. package/dist/shared-constants.d.ts.map +1 -0
  93. package/dist/shared-constants.js +49 -0
  94. package/dist/shared-constants.js.map +1 -0
  95. package/dist/state-machine/index.d.ts +30 -0
  96. package/dist/state-machine/index.d.ts.map +1 -0
  97. package/dist/state-machine/index.js +92 -0
  98. package/dist/state-machine/index.js.map +1 -0
  99. package/dist/tool-host/builtins/capabilities.d.ts +20 -0
  100. package/dist/tool-host/builtins/capabilities.d.ts.map +1 -0
  101. package/dist/tool-host/builtins/capabilities.js +211 -0
  102. package/dist/tool-host/builtins/capabilities.js.map +1 -0
  103. package/dist/tool-host/builtins/index.d.ts +2 -0
  104. package/dist/tool-host/builtins/index.d.ts.map +1 -0
  105. package/dist/tool-host/builtins/index.js +4 -0
  106. package/dist/tool-host/builtins/index.js.map +1 -0
  107. package/dist/tool-host/index.d.ts +5 -0
  108. package/dist/tool-host/index.d.ts.map +1 -0
  109. package/dist/tool-host/index.js +7 -0
  110. package/dist/tool-host/index.js.map +1 -0
  111. package/dist/tool-host/scope-intersection.d.ts +10 -0
  112. package/dist/tool-host/scope-intersection.d.ts.map +1 -0
  113. package/dist/tool-host/scope-intersection.js +188 -0
  114. package/dist/tool-host/scope-intersection.js.map +1 -0
  115. package/dist/tool-host/subprocess-dispatcher.d.ts +14 -0
  116. package/dist/tool-host/subprocess-dispatcher.d.ts.map +1 -0
  117. package/dist/tool-host/subprocess-dispatcher.js +14 -0
  118. package/dist/tool-host/subprocess-dispatcher.js.map +1 -0
  119. package/dist/tool-host/tool-host.d.ts +42 -0
  120. package/dist/tool-host/tool-host.d.ts.map +1 -0
  121. package/dist/tool-host/tool-host.js +395 -0
  122. package/dist/tool-host/tool-host.js.map +1 -0
  123. package/dist/tool-host/tool-registry.d.ts +9 -0
  124. package/dist/tool-host/tool-registry.d.ts.map +1 -0
  125. package/dist/tool-host/tool-registry.js +28 -0
  126. package/dist/tool-host/tool-registry.js.map +1 -0
  127. package/package.json +71 -0
package/LICENSE.md 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 owner
52
+ or by an individual or Legal Entity authorized to submit on behalf of
53
+ 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 2026 HellmAI
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,26 @@
1
+ # @lumenflow/kernel
2
+
3
+ Domain-agnostic runtime primitives and contracts for LumenFlow.
4
+
5
+ ## What It Provides
6
+
7
+ - Kernel schemas and canonical JSON hashing utilities
8
+ - Kernel runtime, event store, and state machine primitives
9
+ - Pack loading and policy engine integration points
10
+ - Sandbox and tool-host execution contracts
11
+
12
+ ## Entry Points
13
+
14
+ - `@lumenflow/kernel`
15
+ - `@lumenflow/kernel/schemas`
16
+ - `@lumenflow/kernel/canonical-json`
17
+ - `@lumenflow/kernel/event-kinds`
18
+ - `@lumenflow/kernel/event-store`
19
+ - `@lumenflow/kernel/evidence`
20
+ - `@lumenflow/kernel/pack`
21
+ - `@lumenflow/kernel/policy`
22
+ - `@lumenflow/kernel/runtime`
23
+ - `@lumenflow/kernel/sandbox`
24
+ - `@lumenflow/kernel/shared-constants`
25
+ - `@lumenflow/kernel/state-machine`
26
+ - `@lumenflow/kernel/tool-host`
@@ -0,0 +1,7 @@
1
+ export declare function canonicalStringify(source: unknown): string;
2
+ /**
3
+ * Deterministic hash for YAML/object content:
4
+ * parse -> recursive key sort -> compact JSON -> UTF-8 SHA-256 hex.
5
+ */
6
+ export declare function canonical_json(source: unknown): string;
7
+ //# sourceMappingURL=canonical-json.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"canonical-json.d.ts","sourceRoot":"","sources":["../src/canonical-json.ts"],"names":[],"mappings":"AAwCA,wBAAgB,kBAAkB,CAAC,MAAM,EAAE,OAAO,GAAG,MAAM,CAI1D;AAED;;;GAGG;AACH,wBAAgB,cAAc,CAAC,MAAM,EAAE,OAAO,GAAG,MAAM,CAGtD"}
@@ -0,0 +1,50 @@
1
+ // Copyright (c) 2026 Hellmai Ltd
2
+ // SPDX-License-Identifier: Apache-2.0
3
+ import { createHash } from 'node:crypto';
4
+ import { parse as parseYaml } from 'yaml';
5
+ import { SHA256_ALGORITHM, UTF8_ENCODING } from './shared-constants.js';
6
+ // eslint-disable-next-line sonarjs/function-return-type -- recursive JSON canonicalization requires a union return type.
7
+ function toCanonicalValue(value) {
8
+ let normalized;
9
+ if (value === null) {
10
+ normalized = null;
11
+ }
12
+ else if (typeof value === 'boolean' || typeof value === 'number' || typeof value === 'string') {
13
+ normalized = value;
14
+ }
15
+ else if (value instanceof Date) {
16
+ normalized = value.toISOString();
17
+ }
18
+ else if (Array.isArray(value)) {
19
+ normalized = value.map((item) => toCanonicalValue(item));
20
+ }
21
+ else if (typeof value === 'object') {
22
+ const objectValue = value;
23
+ const entries = Object.keys(objectValue)
24
+ .sort((left, right) => left.localeCompare(right))
25
+ .map((key) => [key, toCanonicalValue(objectValue[key])]);
26
+ const sorted = {};
27
+ for (const [key, entryValue] of entries) {
28
+ sorted[key] = entryValue;
29
+ }
30
+ normalized = sorted;
31
+ }
32
+ else {
33
+ throw new TypeError(`Unsupported value in canonical_json input: ${String(value)}`);
34
+ }
35
+ return normalized;
36
+ }
37
+ export function canonicalStringify(source) {
38
+ const parsed = typeof source === 'string' ? parseYaml(source) : source;
39
+ const canonical = toCanonicalValue(parsed);
40
+ return JSON.stringify(canonical);
41
+ }
42
+ /**
43
+ * Deterministic hash for YAML/object content:
44
+ * parse -> recursive key sort -> compact JSON -> UTF-8 SHA-256 hex.
45
+ */
46
+ export function canonical_json(source) {
47
+ const canonical = canonicalStringify(source);
48
+ return createHash(SHA256_ALGORITHM).update(canonical, UTF8_ENCODING).digest('hex');
49
+ }
50
+ //# sourceMappingURL=canonical-json.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"canonical-json.js","sourceRoot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AAM,GAAsC,EAAE,CAAC;QACrD,KAAK,MAAM,CAAC,GAAG,EAAE,UAAU,CAAC,IAAI,OAAO,EAAE,CAAC;YACxC,MAAM,CAAC,GAAG,CAAC,GAAG,UAAU,CAAC;QAC3B,CAAC;QACD,UAAU,GAAG,MAAM,CAAC;IACtB,CAAC;SAAM,CAAC;QACN,MAAM,IAAI,SAAS,CAAC,8CAA8C,MAAM,CAAC,KAAK,CAAC,EAAE,CAAC,CAAC;IACrF,CAAC;IAED,OAAO,UAAU,CAAC;AACpB,CAAC;AAED,MAAM,UAAU,kBAAkB,CAAC,MAAe;IAChD,MAAM,MAAM,GAAG,OAAO,MAAM,KAAK,QAAQ,CAAC,CAAC,CAAC,SAAS,CAAC,MAAM,CAAC,CAAC,CAAC,CAAC,MAAM,CAAC;IACvE,MAAM,SAAS,GAAG,gBAAgB,CAAC,MAAM,CAAC,CAAC;IAC3C,OAAO,IAAI,CAAC,SAAS,CAAC,SAAS,CAAC,CAAC;AACnC,CAAC;AAED;;;GAGG;AACH,MAAM,UAAU,cAAc,CAAC,MAAe;IAC5C,MAAM,SAAS,GAAG,kBAAkB,CAAC,MAAM,CAAC,CAAC;IAC7C,OAAO,UAAU,CAAC,gBAAgB,CAAC,CAAC,MAAM,CAAC,SAAS,EAAE,aAAa,CAAC,CAAC,MAAM,CAAC,KAAK,CAAC,CAAC;AACrF,CAAC"}
@@ -0,0 +1,32 @@
1
+ export declare const KERNEL_EVENT_KINDS: {
2
+ readonly TASK_CREATED: "task_created";
3
+ readonly TASK_CLAIMED: "task_claimed";
4
+ readonly TASK_BLOCKED: "task_blocked";
5
+ readonly TASK_UNBLOCKED: "task_unblocked";
6
+ readonly TASK_WAITING: "task_waiting";
7
+ readonly TASK_RESUMED: "task_resumed";
8
+ readonly TASK_COMPLETED: "task_completed";
9
+ readonly TASK_RELEASED: "task_released";
10
+ readonly TASK_DELEGATED: "task_delegated";
11
+ readonly RUN_STARTED: "run_started";
12
+ readonly RUN_PAUSED: "run_paused";
13
+ readonly RUN_FAILED: "run_failed";
14
+ readonly RUN_SUCCEEDED: "run_succeeded";
15
+ readonly WORKSPACE_UPDATED: "workspace_updated";
16
+ readonly WORKSPACE_WARNING: "workspace_warning";
17
+ readonly SPEC_TAMPERED: "spec_tampered";
18
+ readonly CHECKPOINT: "checkpoint";
19
+ };
20
+ export type KernelEventKind = (typeof KERNEL_EVENT_KINDS)[keyof typeof KERNEL_EVENT_KINDS];
21
+ export declare const TASK_EVENT_KINDS: readonly ["task_created", "task_claimed", "task_blocked", "task_unblocked", "task_waiting", "task_resumed", "task_completed", "task_released", "task_delegated"];
22
+ export type TaskEventKind = (typeof TASK_EVENT_KINDS)[number];
23
+ export declare const RUN_LIFECYCLE_EVENT_KINDS: readonly ["run_started", "run_paused", "run_failed", "run_succeeded"];
24
+ export type RunLifecycleEventKind = (typeof RUN_LIFECYCLE_EVENT_KINDS)[number];
25
+ export declare function isTaskEventKind(kind: string): kind is TaskEventKind;
26
+ export declare function isRunLifecycleEventKind(kind: string): kind is RunLifecycleEventKind;
27
+ export declare const TOOL_TRACE_KINDS: {
28
+ readonly TOOL_CALL_STARTED: "tool_call_started";
29
+ readonly TOOL_CALL_FINISHED: "tool_call_finished";
30
+ };
31
+ export type ToolTraceKind = (typeof TOOL_TRACE_KINDS)[keyof typeof TOOL_TRACE_KINDS];
32
+ //# sourceMappingURL=event-kinds.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"event-kinds.d.ts","sourceRoot":"","sources":["../src/event-kinds.ts"],"names":[],"mappings":"AAAA,eAAO,MAAM,kBAAkB;;;;;;;;;;;;;;;;;;CAkBrB,CAAC;AAEX,MAAM,MAAM,eAAe,GAAG,CAAC,OAAO,kBAAkB,CAAC,CAAC,MAAM,OAAO,kBAAkB,CAAC,CAAC;AAE3F,eAAO,MAAM,gBAAgB,kKAUnB,CAAC;AAEX,MAAM,MAAM,aAAa,GAAG,CAAC,OAAO,gBAAgB,CAAC,CAAC,MAAM,CAAC,CAAC;AAE9D,eAAO,MAAM,yBAAyB,uEAK5B,CAAC;AAEX,MAAM,MAAM,qBAAqB,GAAG,CAAC,OAAO,yBAAyB,CAAC,CAAC,MAAM,CAAC,CAAC;AAK/E,wBAAgB,eAAe,CAAC,IAAI,EAAE,MAAM,GAAG,IAAI,IAAI,aAAa,CAEnE;AAED,wBAAgB,uBAAuB,CAAC,IAAI,EAAE,MAAM,GAAG,IAAI,IAAI,qBAAqB,CAEnF;AAED,eAAO,MAAM,gBAAgB;;;CAGnB,CAAC;AAEX,MAAM,MAAM,aAAa,GAAG,CAAC,OAAO,gBAAgB,CAAC,CAAC,MAAM,OAAO,gBAAgB,CAAC,CAAC"}
@@ -0,0 +1,49 @@
1
+ export const KERNEL_EVENT_KINDS = {
2
+ TASK_CREATED: 'task_created',
3
+ TASK_CLAIMED: 'task_claimed',
4
+ TASK_BLOCKED: 'task_blocked',
5
+ TASK_UNBLOCKED: 'task_unblocked',
6
+ TASK_WAITING: 'task_waiting',
7
+ TASK_RESUMED: 'task_resumed',
8
+ TASK_COMPLETED: 'task_completed',
9
+ TASK_RELEASED: 'task_released',
10
+ TASK_DELEGATED: 'task_delegated',
11
+ RUN_STARTED: 'run_started',
12
+ RUN_PAUSED: 'run_paused',
13
+ RUN_FAILED: 'run_failed',
14
+ RUN_SUCCEEDED: 'run_succeeded',
15
+ WORKSPACE_UPDATED: 'workspace_updated',
16
+ WORKSPACE_WARNING: 'workspace_warning',
17
+ SPEC_TAMPERED: 'spec_tampered',
18
+ CHECKPOINT: 'checkpoint',
19
+ };
20
+ export const TASK_EVENT_KINDS = [
21
+ KERNEL_EVENT_KINDS.TASK_CREATED,
22
+ KERNEL_EVENT_KINDS.TASK_CLAIMED,
23
+ KERNEL_EVENT_KINDS.TASK_BLOCKED,
24
+ KERNEL_EVENT_KINDS.TASK_UNBLOCKED,
25
+ KERNEL_EVENT_KINDS.TASK_WAITING,
26
+ KERNEL_EVENT_KINDS.TASK_RESUMED,
27
+ KERNEL_EVENT_KINDS.TASK_COMPLETED,
28
+ KERNEL_EVENT_KINDS.TASK_RELEASED,
29
+ KERNEL_EVENT_KINDS.TASK_DELEGATED,
30
+ ];
31
+ export const RUN_LIFECYCLE_EVENT_KINDS = [
32
+ KERNEL_EVENT_KINDS.RUN_STARTED,
33
+ KERNEL_EVENT_KINDS.RUN_PAUSED,
34
+ KERNEL_EVENT_KINDS.RUN_FAILED,
35
+ KERNEL_EVENT_KINDS.RUN_SUCCEEDED,
36
+ ];
37
+ const TASK_EVENT_KIND_SET = new Set(TASK_EVENT_KINDS);
38
+ const RUN_LIFECYCLE_EVENT_KIND_SET = new Set(RUN_LIFECYCLE_EVENT_KINDS);
39
+ export function isTaskEventKind(kind) {
40
+ return TASK_EVENT_KIND_SET.has(kind);
41
+ }
42
+ export function isRunLifecycleEventKind(kind) {
43
+ return RUN_LIFECYCLE_EVENT_KIND_SET.has(kind);
44
+ }
45
+ export const TOOL_TRACE_KINDS = {
46
+ TOOL_CALL_STARTED: 'tool_call_started',
47
+ TOOL_CALL_FINISHED: 'tool_call_finished',
48
+ };
49
+ //# sourceMappingURL=event-kinds.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"event-kinds.js","sourceRoot":"","sources":["../src/event-kinds.ts"],"names":[],"mappings":"AAAA,MAAM,CAAC,MAAM,kBAAkB,GAAG;IAChC,YAAY,EAAE,cAAc;IAC5B,YAAY,EAAE,cAAc;IAC5B,YAAY,EAAE,cAAc;IAC5B,cAAc,EAAE,gBAAgB;IAChC,YAAY,EAAE,cAAc;IAC5B,YAAY,EAAE,cAAc;IAC5B,cAAc,EAAE,gBAAgB;IAChC,aAAa,EAAE,eAAe;IAC9B,cAAc,EAAE,gBAAgB;IAChC,WAAW,EAAE,aAAa;IAC1B,UAAU,EAAE,YAAY;IACxB,UAAU,EAAE,YAAY;IACxB,aAAa,EAAE,eAAe;IAC9B,iBAAiB,EAAE,mBAAmB;IACtC,iBAAiB,EAAE,mBAAmB;IACtC,aAAa,EAAE,eAAe;IAC9B,UAAU,EAAE,YAAY;CAChB,CAAC;AAIX,MAAM,CAAC,MAAM,gBAAgB,GAAG;IAC9B,kBAAkB,CAAC,YAAY;IAC/B,kBAAkB,CAAC,YAAY;IAC/B,kBAAkB,CAAC,YAAY;IAC/B,kBAAkB,CAAC,cAAc;IACjC,kBAAkB,CAAC,YAAY;IAC/B,kBAAkB,CAAC,YAAY;IAC/B,kBAAkB,CAAC,cAAc;IACjC,kBAAkB,CAAC,aAAa;IAChC,kBAAkB,CAAC,cAAc;CACzB,CAAC;AAIX,MAAM,CAAC,MAAM,yBAAyB,GAAG;IACvC,kBAAkB,CAAC,WAAW;IAC9B,kBAAkB,CAAC,UAAU;IAC7B,kBAAkB,CAAC,UAAU;IAC7B,kBAAkB,CAAC,aAAa;CACxB,CAAC;AAIX,MAAM,mBAAmB,GAAG,IAAI,GAAG,CAAS,gBAAgB,CAAC,CAAC;AAC9D,MAAM,4BAA4B,GAAG,IAAI,GAAG,CAAS,yBAAyB,CAAC,CAAC;AAEhF,MAAM,UAAU,eAAe,CAAC,IAAY;IAC1C,OAAO,mBAAmB,CAAC,GAAG,CAAC,IAAI,CAAC,CAAC;AACvC,CAAC;AAED,MAAM,UAAU,uBAAuB,CAAC,IAAY;IAClD,OAAO,4BAA4B,CAAC,GAAG,CAAC,IAAI,CAAC,CAAC;AAChD,CAAC;AAED,MAAM,CAAC,MAAM,gBAAgB,GAAG;IAC9B,iBAAiB,EAAE,mBAAmB;IACtC,kBAAkB,EAAE,oBAAoB;CAChC,CAAC"}
@@ -0,0 +1,64 @@
1
+ import { type KernelEvent, type TaskSpec, type TaskState } from '../kernel.schemas.js';
2
+ type EventKind = KernelEvent['kind'];
3
+ export interface ReplayFilter {
4
+ taskId?: string;
5
+ kind?: EventKind | EventKind[];
6
+ sinceTimestamp?: string;
7
+ untilTimestamp?: string;
8
+ /** ISO timestamp cursor: exclusive lower bound. Only events after this timestamp are returned. */
9
+ cursor?: string;
10
+ /** Maximum number of events to return. Default: 100, max: 500. */
11
+ limit?: number;
12
+ }
13
+ export interface ReplayResult {
14
+ events: KernelEvent[];
15
+ /** Timestamp of the last returned event, or null if no more events remain. */
16
+ nextCursor: string | null;
17
+ }
18
+ export interface Disposable {
19
+ dispose(): void;
20
+ }
21
+ export interface EventStoreOptions {
22
+ eventsFilePath: string;
23
+ lockFilePath: string;
24
+ lockRetryDelayMs?: number;
25
+ lockMaxRetries?: number;
26
+ taskSpecLoader?: (taskId: string) => Promise<TaskSpec | null>;
27
+ }
28
+ type EventSubscriber = (event: KernelEvent) => void | Promise<void>;
29
+ export declare function verifyTaskSpecHash(taskSpec: TaskSpec, events: KernelEvent[]): void;
30
+ export declare function projectTaskState(taskSpec: TaskSpec, events: KernelEvent[]): TaskState;
31
+ export declare class EventStore {
32
+ private readonly eventsFilePath;
33
+ private readonly lockFilePath;
34
+ private readonly lockRetryDelayMs;
35
+ private readonly lockMaxRetries;
36
+ private readonly taskSpecLoader?;
37
+ private indexesHydrated;
38
+ private orderedEvents;
39
+ private byTask;
40
+ private byKind;
41
+ private byTimestamp;
42
+ constructor(options: EventStoreOptions);
43
+ append(event: KernelEvent): Promise<void>;
44
+ appendAll(events: KernelEvent[]): Promise<void>;
45
+ replay(filter?: ReplayFilter): Promise<ReplayResult>;
46
+ subscribe(filter: ReplayFilter | undefined, callback: EventSubscriber): Disposable;
47
+ project(taskId: string): Promise<TaskState>;
48
+ getByTask(taskId: string): KernelEvent[];
49
+ getByKind(kind: EventKind): KernelEvent[];
50
+ getByTimestamp(timestamp: string): KernelEvent[];
51
+ private buildLockMetadata;
52
+ private parseLockMetadata;
53
+ private isProcessAlive;
54
+ private recoverStaleLockIfNeeded;
55
+ private cleanupLockHandle;
56
+ private reloadFromDisk;
57
+ private getCurrentFileSize;
58
+ private readTailFromOffset;
59
+ private resetIndexes;
60
+ private applyEventToIndexes;
61
+ private withFileLock;
62
+ }
63
+ export {};
64
+ //# sourceMappingURL=index.d.ts.map
@@ -0,0 +1 @@
1
+ {"version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