@atom-workflow-agent/workflow-planner 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.
Files changed (64) hide show
  1. package/LICENSE +201 -0
  2. package/README.md +39 -0
  3. package/README.zh-CN.md +39 -0
  4. package/dist/capabilities/capability-coverage-resolver.d.ts +5 -0
  5. package/dist/capabilities/capability-coverage-resolver.d.ts.map +1 -0
  6. package/dist/capabilities/capability-coverage-resolver.js +229 -0
  7. package/dist/capabilities/capability-coverage-resolver.js.map +1 -0
  8. package/dist/catalog/planner-catalog.d.ts +14 -0
  9. package/dist/catalog/planner-catalog.d.ts.map +1 -0
  10. package/dist/catalog/planner-catalog.js +47 -0
  11. package/dist/catalog/planner-catalog.js.map +1 -0
  12. package/dist/draft/planner-draft-normalizer.d.ts +20 -0
  13. package/dist/draft/planner-draft-normalizer.d.ts.map +1 -0
  14. package/dist/draft/planner-draft-normalizer.js +534 -0
  15. package/dist/draft/planner-draft-normalizer.js.map +1 -0
  16. package/dist/evaluation/planning-quality.d.ts +80 -0
  17. package/dist/evaluation/planning-quality.d.ts.map +1 -0
  18. package/dist/evaluation/planning-quality.js +120 -0
  19. package/dist/evaluation/planning-quality.js.map +1 -0
  20. package/dist/index.d.ts +13 -0
  21. package/dist/index.d.ts.map +1 -0
  22. package/dist/index.js +13 -0
  23. package/dist/index.js.map +1 -0
  24. package/dist/model/planning-model-port.d.ts +41 -0
  25. package/dist/model/planning-model-port.d.ts.map +1 -0
  26. package/dist/model/planning-model-port.js +16 -0
  27. package/dist/model/planning-model-port.js.map +1 -0
  28. package/dist/planning/planning-controller.d.ts +77 -0
  29. package/dist/planning/planning-controller.d.ts.map +1 -0
  30. package/dist/planning/planning-controller.js +773 -0
  31. package/dist/planning/planning-controller.js.map +1 -0
  32. package/dist/store/local-plan-store.d.ts +57 -0
  33. package/dist/store/local-plan-store.d.ts.map +1 -0
  34. package/dist/store/local-plan-store.js +190 -0
  35. package/dist/store/local-plan-store.js.map +1 -0
  36. package/dist/store/plan-storage-layout.d.ts +14 -0
  37. package/dist/store/plan-storage-layout.d.ts.map +1 -0
  38. package/dist/store/plan-storage-layout.js +25 -0
  39. package/dist/store/plan-storage-layout.js.map +1 -0
  40. package/dist/validation/planning-draft-validator.d.ts +20 -0
  41. package/dist/validation/planning-draft-validator.d.ts.map +1 -0
  42. package/dist/validation/planning-draft-validator.js +76 -0
  43. package/dist/validation/planning-draft-validator.js.map +1 -0
  44. package/dist/workspace/map-aggregate-schema.d.ts +8 -0
  45. package/dist/workspace/map-aggregate-schema.d.ts.map +1 -0
  46. package/dist/workspace/map-aggregate-schema.js +20 -0
  47. package/dist/workspace/map-aggregate-schema.js.map +1 -0
  48. package/dist/workspace/planning-frontier.d.ts +15 -0
  49. package/dist/workspace/planning-frontier.d.ts.map +1 -0
  50. package/dist/workspace/planning-frontier.js +185 -0
  51. package/dist/workspace/planning-frontier.js.map +1 -0
  52. package/dist/workspace/planning-workspace-service.d.ts +72 -0
  53. package/dist/workspace/planning-workspace-service.d.ts.map +1 -0
  54. package/dist/workspace/planning-workspace-service.js +528 -0
  55. package/dist/workspace/planning-workspace-service.js.map +1 -0
  56. package/dist/workspace/semantic-plan-compiler.d.ts +19 -0
  57. package/dist/workspace/semantic-plan-compiler.d.ts.map +1 -0
  58. package/dist/workspace/semantic-plan-compiler.js +643 -0
  59. package/dist/workspace/semantic-plan-compiler.js.map +1 -0
  60. package/dist/workspace/strict-binding-validator.d.ts +9 -0
  61. package/dist/workspace/strict-binding-validator.d.ts.map +1 -0
  62. package/dist/workspace/strict-binding-validator.js +232 -0
  63. package/dist/workspace/strict-binding-validator.js.map +1 -0
  64. package/package.json +53 -0
package/LICENSE ADDED
@@ -0,0 +1,201 @@
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 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
+ APPENDIX: How to apply the Apache License to your work.
179
+
180
+ To apply the Apache License to your work, attach the following
181
+ boilerplate notice, with the fields enclosed by brackets "[]"
182
+ replaced with your own identifying information. (Don't include
183
+ the brackets!) The text should be enclosed in the appropriate
184
+ comment syntax for the file format. We also recommend that a
185
+ file or class name and description of purpose be included on the
186
+ same "printed page" as the copyright notice for easier
187
+ identification within third-party archives.
188
+
189
+ Copyright [yyyy] [name of copyright owner]
190
+
191
+ Licensed under the Apache License, Version 2.0 (the "License");
192
+ you may not use this file except in compliance with the License.
193
+ You may obtain a copy of the License at
194
+
195
+ http://www.apache.org/licenses/LICENSE-2.0
196
+
197
+ Unless required by applicable law or agreed to in writing, software
198
+ distributed under the License is distributed on an "AS IS" BASIS,
199
+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
200
+ See the License for the specific language governing permissions and
201
+ limitations under the License.
package/README.md ADDED
@@ -0,0 +1,39 @@
1
+ # @atom-workflow-agent/workflow-planner
2
+
3
+ [English](README.md) | [简体中文](README.zh-CN.md)
4
+
5
+ Catalog-aware planning that turns goals into globally valid workflow revisions.
6
+
7
+ ## Responsibilities
8
+
9
+ - Resolves capability coverage before graph generation and reports missing Atoms early.
10
+ - Lets the model select exact Atom keys and map business roles to exact top-level fields; the Runtime supplies and validates authoritative Atom Schemas.
11
+ - Applies semantic planning transactions to immutable workspace revisions.
12
+ - Performs strict automatic binding, normalization, compiler validation, rollback, and checkpoint recovery.
13
+ - Accepts any model adapter through `PlanningModelPort`; Planner core does not depend on ACP.
14
+
15
+ Capability preflight never asks the model to reproduce JSON Schema. The compact Catalog Index contains field names, descriptions, required flags, and all applicable JSON value types. A covered requirement references those fields; a genuinely absent executable capability uses a separate `missing` resolution. Control-flow terminals and literal bindings are not capabilities.
16
+
17
+ Control structure and control execution remain distinct: a Decision container is not a capability, but the Atom that computes its branch from runtime data is. Such selector Atoms must pass the same exact-key and exact-field coverage check as every other executed Atom.
18
+
19
+ ## Boundaries
20
+
21
+ - Does not execute Atoms, mutate frozen revisions, or store Run evidence.
22
+
23
+ ## Main entry points
24
+
25
+ - `PlanningController`
26
+ - `PlanningModelPort`
27
+ - `buildPlannerCatalog`
28
+ - `PlanningWorkspaceService`
29
+ - `resolveCapabilityCoverage`
30
+ - `LocalPlanStore`
31
+
32
+ ## Development
33
+
34
+ ```bash
35
+ pnpm --filter @atom-workflow-agent/workflow-planner typecheck
36
+ pnpm --filter @atom-workflow-agent/workflow-planner test
37
+ ```
38
+
39
+ See the project [documentation](../../docs/README.md) for shared concepts and complete flows.
@@ -0,0 +1,39 @@
1
+ # @atom-workflow-agent/workflow-planner
2
+
3
+ [English](README.md) | [简体中文](README.zh-CN.md)
4
+
5
+ 基于 Catalog 将目标编排为全局有效 Workflow Revision 的规划层。
6
+
7
+ ## 职责
8
+
9
+ - 在生成图前解析能力覆盖并尽早报告缺失 Atom。
10
+ - 由模型选择精确 Atom key,并把业务角色映射到精确顶层字段;权威 Atom Schema 由 Runtime 提供并校验。
11
+ - 将语义规划事务应用到不可变 Workspace Revision。
12
+ - 执行严格自动绑定、规范化、Compiler 校验、事务回滚与 checkpoint 恢复。
13
+ - 通过 `PlanningModelPort` 接受任意模型适配器;Planner 内不依赖 ACP。
14
+
15
+ 能力预检不会要求模型复写 JSON Schema。精简 Catalog Index 只提供字段名、description、必填标记和所有适用 JSON 值类型。已覆盖需求引用这些字段;真正缺少的可执行能力使用独立的 `missing` resolution。控制流终态和常量绑定不属于能力。
16
+
17
+ 控制结构与控制执行必须区分:Decision 容器不是能力,但根据运行时数据计算分支的 Atom 是能力。选择器 Atom 与其他会执行的 Atom 一样,必须通过精确 key 和精确字段覆盖校验。
18
+
19
+ ## 边界
20
+
21
+ - 不执行 Atom、不修改冻结 Revision,也不存储 Run 证据。
22
+
23
+ ## 主要入口
24
+
25
+ - `PlanningController`
26
+ - `PlanningModelPort`
27
+ - `buildPlannerCatalog`
28
+ - `PlanningWorkspaceService`
29
+ - `resolveCapabilityCoverage`
30
+ - `LocalPlanStore`
31
+
32
+ ## 开发
33
+
34
+ ```bash
35
+ pnpm --filter @atom-workflow-agent/workflow-planner typecheck
36
+ pnpm --filter @atom-workflow-agent/workflow-planner test
37
+ ```
38
+
39
+ 通用概念与完整流程见项目[中文文档](../../docs/README.zh-CN.md)。
@@ -0,0 +1,5 @@
1
+ import { type CapabilityCoverageResult } from "@atom-workflow-agent/contracts";
2
+ import type { AtomRegistry } from "@atom-workflow-agent/atom-catalog";
3
+ /** Deterministic exact-key coverage check performed before any graph transaction. */
4
+ export declare function resolveCapabilityCoverage(raw: unknown, registry: AtomRegistry): CapabilityCoverageResult;
5
+ //# sourceMappingURL=capability-coverage-resolver.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"capability-coverage-resolver.d.ts","sourceRoot":"","sources":["../../src/capabilities/capability-coverage-resolver.ts"],"names":[],"mappings":"AACA,OAAO,EAGL,KAAK,wBAAwB,EAM9B,MAAM,gCAAgC,CAAC;AACxC,OAAO,KAAK,EAAE,YAAY,EAAqB,MAAM,mCAAmC,CAAC;AA2JzF,qFAAqF;AACrF,wBAAgB,yBAAyB,CAAC,GAAG,EAAE,OAAO,EAAE,QAAQ,EAAE,YAAY,GAAG,wBAAwB,CA6ExG"}
@@ -0,0 +1,229 @@
1
+ import { createHash } from "node:crypto";
2
+ import { CapabilityCoverageResultSchema, PlannerCapabilityPlanSchema, } from "@atom-workflow-agent/contracts";
3
+ function objectOf(value) {
4
+ return value !== null && typeof value === "object" && !Array.isArray(value) ? value : undefined;
5
+ }
6
+ function typeLabel(schema) {
7
+ const value = objectOf(schema)?.type;
8
+ if (typeof value === "string")
9
+ return value;
10
+ if (Array.isArray(value))
11
+ return value.join("|");
12
+ return "unknown";
13
+ }
14
+ function schemaFields(entry, direction) {
15
+ const schema = direction === "input" ? entry.plannerDescriptor.inputSchema : entry.plannerDescriptor.outputSchema;
16
+ return objectOf(objectOf(schema)?.properties) ?? {};
17
+ }
18
+ function schemaAllowsField(entry, direction, field) {
19
+ const schema = direction === "input" ? entry.plannerDescriptor.inputSchema : entry.plannerDescriptor.outputSchema;
20
+ if (field in schemaFields(entry, direction))
21
+ return true;
22
+ const additionalProperties = objectOf(schema)?.additionalProperties;
23
+ return additionalProperties === true || objectOf(additionalProperties) !== undefined;
24
+ }
25
+ function availableFields(entry, direction) {
26
+ return Object.entries(schemaFields(entry, direction)).map(([name, schema]) => `${name}:${typeLabel(schema)}`).sort();
27
+ }
28
+ function selectedAtomFieldIssues(requirement, entries) {
29
+ if (requirement.resolution.kind !== "covered")
30
+ return [];
31
+ const issues = [];
32
+ for (const use of requirement.resolution.uses) {
33
+ const entry = entries.get(use.atom);
34
+ if (!entry)
35
+ continue;
36
+ for (const [direction, ports] of [["input", use.inputs], ["output", use.outputs]]) {
37
+ const fields = schemaFields(entry, direction);
38
+ for (const port of ports) {
39
+ if (!schemaAllowsField(entry, direction, port.field))
40
+ issues.push({
41
+ atomKey: use.atom,
42
+ direction,
43
+ field: port.field,
44
+ reason: "field-not-found",
45
+ availableFields: availableFields(entry, direction),
46
+ });
47
+ }
48
+ }
49
+ const declaredInputs = new Set(use.inputs.map(({ field }) => field));
50
+ const requiredInputs = Array.isArray(entry.plannerDescriptor.inputSchema.required)
51
+ ? entry.plannerDescriptor.inputSchema.required.filter((field) => typeof field === "string")
52
+ : [];
53
+ for (const field of requiredInputs) {
54
+ if (!declaredInputs.has(field))
55
+ issues.push({
56
+ atomKey: use.atom,
57
+ direction: "input",
58
+ field,
59
+ reason: "required-input-not-declared",
60
+ availableFields: availableFields(entry, "input"),
61
+ });
62
+ }
63
+ }
64
+ return issues;
65
+ }
66
+ function canonicalize(value) {
67
+ if (Array.isArray(value))
68
+ return value.map(canonicalize);
69
+ if (value !== null && typeof value === "object")
70
+ return Object.fromEntries(Object.entries(value)
71
+ .sort(([left], [right]) => left.localeCompare(right))
72
+ .map(([key, nested]) => [key, canonicalize(nested)]));
73
+ return value;
74
+ }
75
+ function hash(value) {
76
+ return `sha256:${createHash("sha256").update(JSON.stringify(canonicalize(value))).digest("hex")}`;
77
+ }
78
+ function grams(value) {
79
+ const normalized = value.toLowerCase().replace(/[\s\p{P}\p{S}]+/gu, "");
80
+ if (normalized.length < 2)
81
+ return new Set(normalized ? [normalized] : []);
82
+ return new Set(Array.from({ length: normalized.length - 1 }, (_, index) => normalized.slice(index, index + 2)));
83
+ }
84
+ function similarity(left, right) {
85
+ const a = grams(left);
86
+ const b = grams(right);
87
+ if (!a.size || !b.size)
88
+ return 0;
89
+ const overlap = [...a].filter((value) => b.has(value)).length;
90
+ return overlap / (a.size + b.size - overlap);
91
+ }
92
+ function requirementText(requirement) {
93
+ const resolution = requirement.resolution;
94
+ return resolution.kind === "covered"
95
+ ? [requirement.description, ...resolution.uses.flatMap((use) => [
96
+ use.atom,
97
+ ...use.inputs.flatMap(({ field, role }) => [field, role]),
98
+ ...use.outputs.flatMap(({ field, role }) => [field, role]),
99
+ ])].join(" ")
100
+ : [requirement.description, ...resolution.desiredInputs.flatMap(({ name, description }) => [name, description]),
101
+ ...resolution.desiredOutputs.flatMap(({ name, description }) => [name, description])].join(" ");
102
+ }
103
+ function schemaDescriptions(value) {
104
+ if (Array.isArray(value))
105
+ return value.flatMap(schemaDescriptions);
106
+ const object = objectOf(value);
107
+ if (!object)
108
+ return [];
109
+ return [
110
+ ...(typeof object.description === "string" ? [object.description] : []),
111
+ ...Object.values(object).flatMap(schemaDescriptions),
112
+ ];
113
+ }
114
+ const ALL_VALUE_TYPES = ["null", "boolean", "object", "array", "number", "integer", "string"];
115
+ function desiredPort(name, description) {
116
+ return { name, description, required: true, acceptedTypes: [...ALL_VALUE_TYPES] };
117
+ }
118
+ function suggestedAtomContract(requirement) {
119
+ const resolution = requirement.resolution;
120
+ const inputFields = resolution.kind === "missing"
121
+ ? resolution.desiredInputs
122
+ : resolution.uses.flatMap(({ inputs }) => inputs.map(({ field, role }) => desiredPort(field, role)));
123
+ const outputFields = resolution.kind === "missing"
124
+ ? resolution.desiredOutputs
125
+ : resolution.uses.flatMap(({ outputs }) => outputs.map(({ field, role }) => desiredPort(field, role)));
126
+ return {
127
+ suggestedId: `missing.${requirement.id}`,
128
+ description: requirement.description,
129
+ inputFields,
130
+ outputFields,
131
+ };
132
+ }
133
+ function nearMatches(requirement, entries) {
134
+ const expected = requirementText(requirement);
135
+ return entries.map((entry) => ({
136
+ atomKey: entry.plannerDescriptor.key,
137
+ title: entry.plannerDescriptor.title,
138
+ purpose: entry.plannerDescriptor.purpose,
139
+ score: Number(similarity(expected, [
140
+ entry.plannerDescriptor.title,
141
+ entry.plannerDescriptor.purpose,
142
+ ...schemaDescriptions(entry.plannerDescriptor.inputSchema),
143
+ ...schemaDescriptions(entry.plannerDescriptor.outputSchema),
144
+ ].join(" ")).toFixed(4)),
145
+ rejectedBecause: "该项仅是语义近似候选;最终是否可用以 exact key、启用状态和权威 Atom 字段校验为准。",
146
+ })).sort((left, right) => right.score - left.score || left.atomKey.localeCompare(right.atomKey)).slice(0, 5);
147
+ }
148
+ /** Deterministic exact-key coverage check performed before any graph transaction. */
149
+ export function resolveCapabilityCoverage(raw, registry) {
150
+ const plan = PlannerCapabilityPlanSchema.parse(raw);
151
+ const entries = registry.list();
152
+ const available = new Map(entries.map((entry) => [entry.plannerDescriptor.key, entry]));
153
+ const gaps = [];
154
+ for (const requirement of plan.requirements) {
155
+ if (requirement.resolution.kind === "missing") {
156
+ if (!requirement.required)
157
+ continue;
158
+ gaps.push({
159
+ requirement,
160
+ code: "PLANNING_CAPABILITY_UNAVAILABLE",
161
+ message: `No registered Atom was selected for required capability: ${requirement.description}`,
162
+ nearMatches: nearMatches(requirement, entries),
163
+ suggestedAtomContract: suggestedAtomContract(requirement),
164
+ });
165
+ continue;
166
+ }
167
+ const atomKeys = requirement.resolution.uses.map(({ atom }) => atom);
168
+ const unknown = atomKeys.filter((key) => !available.has(key));
169
+ if (unknown.length > 0) {
170
+ gaps.push({
171
+ requirement,
172
+ code: "PLANNING_CAPABILITY_ATOM_UNKNOWN",
173
+ message: `Capability references unavailable Atom keys: ${unknown.join(", ")}`,
174
+ nearMatches: nearMatches(requirement, entries),
175
+ suggestedAtomContract: suggestedAtomContract(requirement),
176
+ });
177
+ continue;
178
+ }
179
+ const fieldIssues = selectedAtomFieldIssues(requirement, available);
180
+ if (fieldIssues.length > 0)
181
+ gaps.push({
182
+ requirement,
183
+ code: "PLANNING_CAPABILITY_SCHEMA_MISMATCH",
184
+ message: `Selected Atom fields are invalid for capability ${requirement.id}: ${fieldIssues.map(({ atomKey, direction, field, reason }) => `${atomKey}.${direction}.${field}:${reason}`).join(", ")}`,
185
+ nearMatches: nearMatches(requirement, entries),
186
+ suggestedAtomContract: suggestedAtomContract(requirement),
187
+ fieldIssues,
188
+ });
189
+ }
190
+ const catalogHash = hash(entries.map(({ plannerDescriptor }) => ({
191
+ key: plannerDescriptor.key,
192
+ descriptorHash: plannerDescriptor.hash,
193
+ })));
194
+ if (gaps.length > 0)
195
+ return CapabilityCoverageResultSchema.parse({
196
+ schemaVersion: "1.1",
197
+ status: "blocked_missing_atom",
198
+ catalogHash,
199
+ plan,
200
+ searchedAtomCount: entries.length,
201
+ gaps,
202
+ });
203
+ const selectedAtomKeys = [...new Set(plan.requirements.flatMap(({ resolution }) => resolution.kind === "covered" ? resolution.uses.map(({ atom }) => atom) : []))];
204
+ if (selectedAtomKeys.length === 0) {
205
+ const requirement = plan.requirements[0];
206
+ return CapabilityCoverageResultSchema.parse({
207
+ schemaVersion: "1.1",
208
+ status: "blocked_missing_atom",
209
+ catalogHash,
210
+ plan,
211
+ searchedAtomCount: entries.length,
212
+ gaps: [{
213
+ requirement: { ...requirement, required: true },
214
+ code: "PLANNING_CAPABILITY_UNAVAILABLE",
215
+ message: "Capability plan selected no executable Atom",
216
+ nearMatches: nearMatches(requirement, entries),
217
+ suggestedAtomContract: suggestedAtomContract(requirement),
218
+ }],
219
+ });
220
+ }
221
+ return CapabilityCoverageResultSchema.parse({
222
+ schemaVersion: "1.1",
223
+ status: "covered",
224
+ catalogHash,
225
+ plan,
226
+ selectedAtomKeys,
227
+ });
228
+ }
229
+ //# sourceMappingURL=capability-coverage-resolver.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"capability-coverage-resolver.js","sourceRoot":"","sources":["../../src/capabilities/capability-coverage-resolver.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,UAAU,EAAE,MAAM,aAAa,CAAC;AACzC,OAAO,EACL,8BAA8B,EAC9B,2BAA2B,GAO5B,MAAM,gCAAgC,CAAC;AAKxC,SAAS,QAAQ,CAAC,KAAc;IAC9B,OAAO,KAAK,KAAK,IAAI,IAAI,OAAO,KAAK,KAAK,QAAQ,IAAI,CAAC,KAAK,CAAC,OAAO,CAAC,KAAK,CAAC,CAAC,CAAC,CAAC,KAAqB,CAAC,CAAC,CAAC,SAAS,CAAC;AAClH,CAAC;AAED,SAAS,SAAS,CAAC,MAAe;IAChC,MAAM,KAAK,GAAG,QAAQ,CAAC,MAAM,CAAC,EAAE,IAAI,CAAC;IACrC,IAAI,OAAO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C,CAAC,CAAC,CAAC,EAAE,CAAC,CAAC,CAAC,CAAC;IAClF,IAAI,gBAAgB,CAAC,MAAM,KAAK,CAAC,EAAE,CAAC;QAClC,MAAM,WAAW,GAAG,IAAI,CAAC,YAAY,CAAC,CAAC,CAAE,CAAC;QAC1C,OAAO,8BAA8B,CAAC,KAAK,CAAC;YAC1C,aAAa,EAAE,KAAK;YACpB,MAAM,EAAE,sBAAsB;YAC9B,WAAW;YACX,IAAI;YACJ,iBAAiB,EAAE,OAAO,CAAC,MAAM;YACjC,IAAI,EAAE,CAAC;oBACL,WAAW,EAAE,EAAE,GAAG,WAAW,EAAE,QAAQ,EAAE,IAAI,EAAE;oBAC/C,IAAI,EAAE,iCAAiC;oBACvC,OAAO,EAAE,6CAA6C;oBACtD,WAAW,EAAE,WAAW,CAAC,WAAW,EAAE,OAAO,CAAC;oBAC9C,qBAAqB,EAAE,qBAAqB,CAAC,WAAW,CAAC;iBAC1D,CAAC;SACH,CAAC,CAAC;IACL,CAAC;IACD,OAAO,8BAA8B,CAAC,KAAK,CAAC;QAC1C,aAAa,EAAE,KAAK;QACpB,MAAM,EAAE,SAAS;QACjB,WAAW;QACX,IAAI;QACJ,gBAAgB;KACjB,CAAC,CAAC;AACL,CAAC"}
@@ -0,0 +1,14 @@
1
+ import { type PlannerAtomCatalog, type PlannerAtomCatalogIndex, type PlannerAtomDescriptor, type PlannerCatalogIndexAtomDescriptor } from "@atom-workflow-agent/contracts";
2
+ export interface PlannerCatalogEntrySource {
3
+ readonly catalogIndexDescriptor: PlannerCatalogIndexAtomDescriptor;
4
+ readonly plannerDescriptor: PlannerAtomDescriptor;
5
+ readonly state: string;
6
+ readonly enabled: boolean;
7
+ }
8
+ /** Builds the exact, executor-free catalog visible to every planning frontend. */
9
+ export declare function buildPlannerCatalog(entries: readonly PlannerCatalogEntrySource[]): PlannerAtomCatalog;
10
+ /** Compact first-pass catalog. Full Schemas are expanded only after selection. */
11
+ export declare function buildPlannerCatalogIndex(catalog: PlannerAtomCatalog, sources?: readonly PlannerCatalogEntrySource[]): PlannerAtomCatalogIndex;
12
+ /** Expands exact selected keys while preserving Catalog order and hash semantics. */
13
+ export declare function selectPlannerCatalog(catalog: PlannerAtomCatalog, selectedAtomKeys: readonly string[]): PlannerAtomCatalog;
14
+ //# sourceMappingURL=planner-catalog.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"planner-catalog.d.ts","sourceRoot":"","sources":["../../src/catalog/planner-catalog.ts"],"names":[],"mappings":"AACA,OAAO,EAGL,KAAK,kBAAkB,EACvB,KAAK,uBAAuB,EAC5B,KAAK,qBAAqB,EAC1B,KAAK,iCAAiC,EACvC,MAAM,gCAAgC,CAAC;AAExC,MAAM,WAAW,yBAAyB;IACxC,QAAQ,CAAC,sBAAsB,EAAE,iCAAiC,CAAC;IACnE,QAAQ,CAAC,iBAAiB,EAAE,qBAAqB,CAAC;IAClD,QAAQ,CAAC,KAAK,EAAE,MAAM,CAAC;IACvB,QAAQ,CAAC,OAAO,EAAE,OAAO,CAAC;CAC3B;AAcD,kFAAkF;AAClF,wBAAgB,mBAAmB,CAAC,OAAO,EAAE,SAAS,yBAAyB,EAAE,GAAG,kBAAkB,CAMrG;AAED,kFAAkF;AAClF,wBAAgB,wBAAwB,CAAC,OAAO,EAAE,kBAAkB,EAAE,OAAO,CAAC,EAAE,SAAS,yBAAyB,EAAE,GAAG,uBAAuB,CAgB7I;AAED,qFAAqF;AACrF,wBAAgB,oBAAoB,CAAC,OAAO,EAAE,kBAAkB,EAAE,gBAAgB,EAAE,SAAS,MAAM,EAAE,GAAG,kBAAkB,CAIzH"}
@@ -0,0 +1,47 @@
1
+ import { createHash } from "node:crypto";
2
+ import { PlannerAtomCatalogIndexSchema, PlannerAtomCatalogSchema, } from "@atom-workflow-agent/contracts";
3
+ function canonicalize(value) {
4
+ if (Array.isArray(value))
5
+ return value.map(canonicalize);
6
+ if (value !== null && typeof value === "object") {
7
+ return Object.fromEntries(Object.entries(value).sort(([left], [right]) => left.localeCompare(right)).map(([key, nested]) => [key, canonicalize(nested)]));
8
+ }
9
+ return value;
10
+ }
11
+ function hash(value) {
12
+ return `sha256:${createHash("sha256").update(JSON.stringify(canonicalize(value))).digest("hex")}`;
13
+ }
14
+ /** Builds the exact, executor-free catalog visible to every planning frontend. */
15
+ export function buildPlannerCatalog(entries) {
16
+ const atoms = entries
17
+ .filter((entry) => entry.enabled && entry.state === "enabled")
18
+ .map((entry) => ({ key: entry.plannerDescriptor.key, descriptor: entry.plannerDescriptor }))
19
+ .sort((left, right) => left.key.localeCompare(right.key));
20
+ return PlannerAtomCatalogSchema.parse({ schemaVersion: "1.0", hash: hash(atoms), atoms });
21
+ }
22
+ /** Compact first-pass catalog. Full Schemas are expanded only after selection. */
23
+ export function buildPlannerCatalogIndex(catalog, sources) {
24
+ const byKey = new Map((sources ?? []).map((entry) => [entry.catalogIndexDescriptor.key, entry.catalogIndexDescriptor]));
25
+ const atoms = catalog.atoms.map(({ key, descriptor }) => {
26
+ const existing = byKey.get(key);
27
+ if (existing)
28
+ return existing;
29
+ const projection = {
30
+ schemaVersion: "1.0",
31
+ key,
32
+ title: descriptor.title,
33
+ purpose: descriptor.purpose,
34
+ inputFields: [],
35
+ outputFields: [],
36
+ };
37
+ return { ...projection, hash: hash(projection) };
38
+ });
39
+ return PlannerAtomCatalogIndexSchema.parse({ schemaVersion: "1.0", hash: hash(atoms), atoms });
40
+ }
41
+ /** Expands exact selected keys while preserving Catalog order and hash semantics. */
42
+ export function selectPlannerCatalog(catalog, selectedAtomKeys) {
43
+ const selected = new Set(selectedAtomKeys);
44
+ const atoms = catalog.atoms.filter((entry) => selected.has(entry.key));
45
+ return PlannerAtomCatalogSchema.parse({ schemaVersion: "1.0", hash: hash(atoms), atoms });
46
+ }
47
+ //# sourceMappingURL=planner-catalog.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"planner-catalog.js","sourceRoot":"","sources":["../../src/catalog/planner-catalog.ts"],"names":[],"mappings":"AAAA,O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C,CAAC;AACjG,CAAC;AAED,qFAAqF;AACrF,MAAM,UAAU,oBAAoB,CAAC,OAA2B,EAAE,gBAAmC;IACnG,MAAM,QAAQ,GAAG,IAAI,GAAG,CAAC,gBAAgB,CAAC,CAAC;IAC3C,MAAM,KAAK,GAAG,OAAO,CAAC,KAAK,CAAC,MAAM,CAAC,CAAC,KAAK,EAAE,EAAE,CAAC,QAAQ,CAAC,GAAG,CAAC,KAAK,CAAC,GAAG,CAAC,CAAC,CAAC;IACvE,OAAO,wBAAwB,CAAC,KAAK,CAAC,EAAE,aAAa,EAAE,KAAK,EAAE,IAAI,EAAE,IAAI,CAAC,KAAK,CAAC,EAAE,KAAK,EAAE,CAAC,CAAC;AAC5F,CAAC"}
@@ -0,0 +1,20 @@
1
+ import { type JsonValue, type PlannerDraft, type WorkflowSpec, type WorkflowValidationError } from "@atom-workflow-agent/contracts";
2
+ export interface PlannerDraftPathMapping {
3
+ readonly alias: string;
4
+ readonly draftPath: string;
5
+ readonly workflowNodeId: string;
6
+ }
7
+ export type PlannerDraftNormalizationResult = {
8
+ readonly success: true;
9
+ readonly workflow: WorkflowSpec;
10
+ readonly pathMappings: readonly PlannerDraftPathMapping[];
11
+ } | {
12
+ readonly success: false;
13
+ readonly errors: readonly WorkflowValidationError[];
14
+ readonly pathMappings: readonly PlannerDraftPathMapping[];
15
+ };
16
+ export declare function normalizePlannerDraft(draft: PlannerDraft, options: {
17
+ readonly selectedAtomKeys: ReadonlySet<string>;
18
+ readonly workflowInputs: Readonly<Record<string, JsonValue>>;
19
+ }): PlannerDraftNormalizationResult;
20
+ //# sourceMappingURL=planner-draft-normalizer.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"planner-draft-normalizer.d.ts","sourceRoot":"","sources":["../../src/draft/planner-draft-normalizer.ts"],"names":[],"mappings":"AAAA,OAAO,EAGL,KAAK,SAAS,EACd,KAAK,YAAY,EAGjB,KAAK,YAAY,EACjB,KAAK,uBAAuB,EAC7B,MAAM,gCAAgC,CAAC;AAexC,MAAM,WAAW,uBAAuB;IACtC,QAAQ,CAAC,KAAK,EAAE,MAAM,CAAC;IACvB,QAAQ,CAAC,SAAS,EAAE,MAAM,CAAC;IAC3B,QAAQ,CAAC,cAAc,EAAE,MAAM,CAAC;CACjC;AAED,MAAM,MAAM,+BAA+B,GACvC;IAAE,QAAQ,CAAC,OAAO,EAAE,IAAI,CAAC;IAAC,QAAQ,CAAC,QAAQ,EAAE,YAAY,CAAC;IAAC,QAAQ,CAAC,YAAY,EAAE,SAAS,uBAAuB,EAAE,CAAA;CAAE,GACtH;IAAE,QAAQ,CAAC,OAAO,EAAE,KAAK,CAAC;IAAC,QAAQ,CAAC,MAAM,EAAE,SAAS,uBAAuB,EAAE,CAAC;IAAC,QAAQ,CAAC,YAAY,EAAE,SAAS,uBAAuB,EAAE,CAAA;CAAE,CAAC;AAshBhJ,wBAAgB,qBAAqB,CACnC,KAAK,EAAE,YAAY,EACnB,OAAO,EAAE;IACP,QAAQ,CAAC,gBAAgB,EAAE,WAAW,CAAC,MAAM,CAAC,CAAC;IAC/C,QAAQ,CAAC,cAAc,EAAE,QAAQ,CAAC,MAAM,CAAC,MAAM,EAAE,SAAS,CAAC,CAAC,CAAC;CAC9D,GACA,+BAA+B,CAMjC"}