@atom-workflow-agent/select-atom 1.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.
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,63 @@
1
+ # `@atom-workflow-agent/select-atom`
2
+
3
+ [English](README.md) | [简体中文](README.zh-CN.md)
4
+
5
+ Built-in selectors for one job: choosing a statically declared branch of a Workflow `DecisionNode`.
6
+
7
+ ## Which Atom to use
8
+
9
+ | Atom | Use when | May suspend |
10
+ | --- | --- | --- |
11
+ | `select.rule@1.0.0` | structured facts can be evaluated by ordered rules, optionally falling back to a user choice | for `manual`, or ambiguous/no-match `auto_then_user` |
12
+ | `select.host-model@1.0.0` | the current Codex/Trae conversation must use project or conversational context to decide | always, as a HostTask |
13
+
14
+ Both return an auditable `branch`, `source`, `reason`, `matchedRuleIds`, and `factsHash`. They never return a target node ID. The compiler verifies that every possible branch is declared by the surrounding Decision node.
15
+
16
+ ## Rule selector
17
+
18
+ Modes:
19
+
20
+ - `automatic`: first matching rule, then `fallbackBranch`; otherwise fail;
21
+ - `manual`: always ask the user;
22
+ - `auto_then_user`: select automatically only when exactly one rule matches; otherwise ask the user.
23
+
24
+ Rules are evaluated in order. A rule uses `all` or `any` across conditions. Supported operators are `eq`, `ne`, `gt`, `gte`, `lt`, `lte`, `in`, `not_in`, `contains`, and `exists`; `path` accepts JSON Pointer or dot notation.
25
+
26
+ Example Decision Atom input:
27
+
28
+ ```json
29
+ {
30
+ "mode": "automatic",
31
+ "facts": { "metrics": { "lcpMs": 3200 } },
32
+ "rules": [
33
+ {
34
+ "id": "slow-lcp",
35
+ "branch": "optimize",
36
+ "match": "all",
37
+ "conditions": [
38
+ { "path": "/metrics/lcpMs", "operator": "gt", "value": 2500 }
39
+ ],
40
+ "reason": "LCP exceeds the 2.5 s target"
41
+ }
42
+ ],
43
+ "fallbackBranch": "finish"
44
+ }
45
+ ```
46
+
47
+ The surrounding Decision node must declare exactly the `optimize` and `finish` branch IDs used here.
48
+
49
+ ## Host selector
50
+
51
+ Provide a bounded `question`, structured `facts`, and optional `guidance`. Runtime creates a HostTask for the current conversation and validates the returned branch against the frozen Decision node. Use it for contextual judgment—not for modifying code, running tests, deploying, or performing the selected branch's work.
52
+
53
+ ## Author API
54
+
55
+ - `defineSelectorAtom` creates a rule/user selector with a custom ID and Signal expiry.
56
+ - `defineHostSelectorAtom` creates a Host-model selector with a custom ID and HostTask expiry.
57
+
58
+ ```bash
59
+ pnpm --filter @atom-workflow-agent/select-atom typecheck
60
+ pnpm --filter @atom-workflow-agent/select-atom test
61
+ ```
62
+
63
+ See [Workflow control structures](../../docs/workflow-authoring.md#control-structures).
@@ -0,0 +1,63 @@
1
+ # `@atom-workflow-agent/select-atom`
2
+
3
+ [English](README.md) | [简体中文](README.zh-CN.md)
4
+
5
+ 内置选择器只负责一件事:为 Workflow `DecisionNode` 选择一个静态声明的分支。
6
+
7
+ ## 如何选择 Atom
8
+
9
+ | Atom | 适用场景 | 是否可能暂停 |
10
+ | --- | --- | --- |
11
+ | `select.rule@1.0.0` | 可以通过有序规则判断结构化事实,并可在必要时让用户选择 | `manual`,或 `auto_then_user` 无匹配/多匹配时 |
12
+ | `select.host-model@1.0.0` | 当前 Codex/Trae 对话需要结合项目或会话上下文判断 | 始终以 HostTask 暂停 |
13
+
14
+ 两者都会返回可审计的 `branch`、`source`、`reason`、`matchedRuleIds` 和 `factsHash`,不会返回目标节点 ID。Compiler 会验证所有可能分支都已由外层 Decision 节点声明。
15
+
16
+ ## 规则选择器
17
+
18
+ 模式:
19
+
20
+ - `automatic`:选择第一条命中规则,其次使用 `fallbackBranch`,否则失败;
21
+ - `manual`:始终询问用户;
22
+ - `auto_then_user`:仅在恰好一条规则命中时自动选择,否则询问用户。
23
+
24
+ 规则按顺序求值,一条规则可以用 `all` 或 `any` 组合条件。支持 `eq`、`ne`、`gt`、`gte`、`lt`、`lte`、`in`、`not_in`、`contains`、`exists`;`path` 支持 JSON Pointer 或点路径。
25
+
26
+ Decision Atom 输入示例:
27
+
28
+ ```json
29
+ {
30
+ "mode": "automatic",
31
+ "facts": { "metrics": { "lcpMs": 3200 } },
32
+ "rules": [
33
+ {
34
+ "id": "slow-lcp",
35
+ "branch": "optimize",
36
+ "match": "all",
37
+ "conditions": [
38
+ { "path": "/metrics/lcpMs", "operator": "gt", "value": 2500 }
39
+ ],
40
+ "reason": "LCP 超过 2.5 秒目标"
41
+ }
42
+ ],
43
+ "fallbackBranch": "finish"
44
+ }
45
+ ```
46
+
47
+ 外层 Decision 节点必须准确声明这里使用的 `optimize` 和 `finish` 分支 ID。
48
+
49
+ ## Host 选择器
50
+
51
+ 传入边界清晰的 `question`、结构化 `facts` 和可选 `guidance`。Runtime 会为当前对话创建 HostTask,并根据冻结 Decision 节点校验返回分支。它适合上下文判断,不负责修改代码、运行测试、部署或执行所选分支的业务动作。
52
+
53
+ ## 作者 API
54
+
55
+ - `defineSelectorAtom`:使用自定义 ID 和 Signal 过期时间创建规则/用户选择器;
56
+ - `defineHostSelectorAtom`:使用自定义 ID 和 HostTask 过期时间创建 Host 模型选择器。
57
+
58
+ ```bash
59
+ pnpm --filter @atom-workflow-agent/select-atom typecheck
60
+ pnpm --filter @atom-workflow-agent/select-atom test
61
+ ```
62
+
63
+ 参见 [Workflow 控制结构](../../docs/workflow-authoring.zh-CN.md#控制结构)。
@@ -0,0 +1,4 @@
1
+ import { type AtomDefinition } from "@atom-workflow-agent/atom-sdk";
2
+ import type { HostSelectorAtomDefinition, HostSelectorInput, SelectorDecision } from "./types.js";
3
+ export declare function defineHostSelectorAtom(definition: HostSelectorAtomDefinition): AtomDefinition<HostSelectorInput, SelectorDecision>;
4
+ //# sourceMappingURL=host-selector-atom.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"host-selector-atom.d.ts","sourceRoot":"","sources":["../src/host-selector-atom.ts"],"names":[],"mappings":"AACA,OAAO,EAAkC,KAAK,cAAc,EAAE,MAAM,+BAA+B,CAAC;AAGpG,OAAO,KAAK,EAAE,0BAA0B,EAAE,iBAAiB,EAAE,gBAAgB,EAAE,MAAM,YAAY,CAAC;AAIlG,wBAAgB,sBAAsB,CAAC,UAAU,EAAE,0BAA0B,GAAG,cAAc,CAAC,iBAAiB,EAAE,gBAAgB,CAAC,CAuClI"}
@@ -0,0 +1,50 @@
1
+ import { AtomExecutionError, defineAtom } from "@atom-workflow-agent/atom-sdk";
2
+ import { hashSelectorFacts } from "./rule-evaluator.js";
3
+ import { HOST_SELECTOR_INPUT_SCHEMA, selectorOutputSchema } from "./schemas.js";
4
+ export function defineHostSelectorAtom(definition) {
5
+ const expiresInMs = definition.hostExpiresInMs ?? 86_400_000;
6
+ if (!Number.isInteger(expiresInMs) || expiresInMs <= 0 || expiresInMs > 31_536_000_000)
7
+ throw new TypeError("Host Selector Atom hostExpiresInMs must be a positive integer no greater than 31536000000");
8
+ return defineAtom({
9
+ id: definition.id,
10
+ ...(definition.version ? { version: definition.version } : {}),
11
+ title: definition.title ?? "DecisionNode current Host Model branch selector",
12
+ description: definition.description ?? "DecisionNode-only Atom that pauses for the current native Codex or Trae conversation to choose one statically declared branch using project and conversation context.",
13
+ input: HOST_SELECTOR_INPUT_SCHEMA,
14
+ output: selectorOutputSchema(["host"]),
15
+ reliability: { idempotent: true, timeoutMs: 5_000 },
16
+ execute(input, context) {
17
+ const branches = context.decision?.branches;
18
+ if (!branches?.length)
19
+ throw new AtomExecutionError("HOST_SELECT_DECISION_CONTEXT_REQUIRED", "select.host-model must run as a DecisionNode");
20
+ const factsHash = hashSelectorFacts(input.facts);
21
+ return context.waitForHost({
22
+ instruction: [
23
+ `需要判断:${input.question}`,
24
+ `只允许选择以下 branch 之一:${branches.join("、")}。`,
25
+ input.guidance ? `补充判断要求:${input.guidance}` : "",
26
+ "必要时可继续与用户交流或使用当前项目工具。完成后返回结构化结果:branch、source='host'、reason、matchedRuleIds=[]、factsHash。",
27
+ ].filter(Boolean).join("\n"),
28
+ context: { question: input.question, facts: input.facts, allowedBranches: [...branches], factsHash, ...(input.guidance ? { guidance: input.guidance } : {}) },
29
+ checkpoint: { factsHash },
30
+ expiresInMs,
31
+ metadata: { selector: definition.id, allowedBranches: [...branches] },
32
+ });
33
+ },
34
+ resume(input, resumed, context) {
35
+ if (resumed.type !== "host")
36
+ throw new AtomExecutionError("HOST_SELECT_RESUME_REQUIRED", "Host selector requires a HostTask result");
37
+ const checkpoint = resumed.checkpoint;
38
+ if (hashSelectorFacts(input.facts) !== checkpoint.factsHash)
39
+ throw new AtomExecutionError("HOST_SELECT_FACTS_CHANGED", "Host selector facts changed while awaiting the Host Model");
40
+ const decision = resumed.value;
41
+ const branches = context.decision?.branches;
42
+ if (!branches?.includes(decision.branch))
43
+ throw new AtomExecutionError("HOST_SELECT_BRANCH_UNDECLARED", `Host selected an undeclared branch: ${decision.branch}`);
44
+ if (decision.source !== "host" || decision.matchedRuleIds.length !== 0 || decision.factsHash !== checkpoint.factsHash)
45
+ throw new AtomExecutionError("HOST_SELECT_OUTPUT_INVALID", "Host selector returned an invalid auditable decision");
46
+ return decision;
47
+ },
48
+ });
49
+ }
50
+ //# sourceMappingURL=host-selector-atom.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"host-selector-atom.js","sourceRoot":"","sources":["../src/host-selector-atom.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,kBAAkB,EAAE,UAAU,EAAuB,MAAM,+BAA+B,CAAC;AACpG,OAAO,EAAE,iBAAiB,EAAE,MAAM,qBAAqB,CAAC;AACxD,OAAO,EAAE,0BAA0B,EAAE,oBAAoB,EAAE,MAAM,cAAc,CAAC;AAKhF,MAAM,UAAU,sBAAsB,CAAC,UAAsC;IAC3E,MAAM,WAAW,GAAG,UAAU,CAAC,eAAe,IAAI,UAAU,CAAC;IAC7D,IAAI,CAAC,MAAM,CAAC,SAAS,CAAC,WAA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E,sDAAsD,CAAC,CAAC;YAC1O,OAAO,QAAQ,CAAC;QAClB,CAAC;KACF,CAAC,CAAC;AACL,CAAC"}
@@ -0,0 +1,6 @@
1
+ export { defineHostSelectorAtom } from "./host-selector-atom.js";
2
+ export { defineSelectorAtom } from "./selector-atom.js";
3
+ export type { HostSelectorAtomDefinition, HostSelectorInput, SelectCondition, SelectionSource, SelectorAtomDefinition, SelectorDecision, SelectorInput, SelectMode, SelectOperator, SelectRule, } from "./types.js";
4
+ export declare const atomPackage: import("@atom-workflow-agent/atom-sdk").AtomPackage;
5
+ export default atomPackage;
6
+ //# sourceMappingURL=index.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAIA,OAAO,EAAE,sBAAsB,EAAE,MAAM,yBAAyB,CAAC;AACjE,OAAO,EAAE,kBAAkB,EAAE,MAAM,oBAAoB,CAAC;AACxD,YAAY,EACV,0BAA0B,EAAE,iBAAiB,EAAE,eAAe,EAAE,eAAe,EAC/E,sBAAsB,EAAE,gBAAgB,EAAE,aAAa,EAAE,UAAU,EAAE,cAAc,EAAE,UAAU,GAChG,MAAM,YAAY,CAAC;AAEpB,eAAO,MAAM,WAAW,qDAOtB,CAAC;AAEH,eAAe,WAAW,CAAC"}
package/dist/index.js ADDED
@@ -0,0 +1,15 @@
1
+ import { defineAtomPackage } from "@atom-workflow-agent/atom-sdk";
2
+ import { defineHostSelectorAtom } from "./host-selector-atom.js";
3
+ import { defineSelectorAtom } from "./selector-atom.js";
4
+ export { defineHostSelectorAtom } from "./host-selector-atom.js";
5
+ export { defineSelectorAtom } from "./selector-atom.js";
6
+ export const atomPackage = defineAtomPackage({
7
+ id: "atomworkflow.select-atoms",
8
+ version: "1.0.0",
9
+ name: "Generic Workflow Select Atoms",
10
+ description: "DecisionNode selectors for deterministic/user and current Host Model decisions.",
11
+ metadata: { generic: true, usesSignal: true, usesHostHandoff: true, dynamicTargetNodeForbidden: true },
12
+ atoms: [defineSelectorAtom({ id: "select.rule" }), defineHostSelectorAtom({ id: "select.host-model" })],
13
+ });
14
+ export default atomPackage;
15
+ //# sourceMappingURL=index.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,iBAAiB,EAAE,MAAM,+BAA+B,CAAC;AAClE,OAAO,EAAE,sBAAsB,EAAE,MAAM,yBAAyB,CAAC;AACjE,OAAO,EAAE,kBAAkB,EAAE,MAAM,oBAAoB,CAAC;AAExD,OAAO,EAAE,sBAAsB,EAAE,MAAM,yBAAyB,CAAC;AACjE,OAAO,EAAE,kBAAkB,EAAE,MAAM,oBAAoB,CAAC;AAMxD,MAAM,CAAC,MAAM,WAAW,GAAG,iBAAiB,CAAC;IAC3C,EAAE,EAAE,2BAA2B;IAC/B,OAAO,EAAE,OAAO;IAChB,IAAI,EAAE,+BAA+B;IACrC,WAAW,EAAE,iFAAiF;IAC9F,QAAQ,EAAE,EAAE,OAAO,EAAE,IAAI,EAAE,UAAU,EAAE,IAAI,EAAE,eAAe,EAAE,IAAI,EAAE,0BAA0B,EAAE,IAAI,EAAE;IACtG,KAAK,EAAE,CAAC,kBAAkB,CAAC,EAAE,EAAE,EAAE,aAAa,EAAE,CAAC,EAAE,sBAAsB,CAAC,EAAE,EAAE,EAAE,mBAAmB,EAAE,CAAC,CAAC;CACxG,CAAC,CAAC;AAEH,eAAe,WAAW,CAAC"}
@@ -0,0 +1,6 @@
1
+ import type { JsonValue } from "@atom-workflow-agent/contracts";
2
+ import type { SelectCondition, SelectRule } from "./types.js";
3
+ export declare function hashSelectorFacts(facts: JsonValue): string;
4
+ export declare function evaluateCondition(facts: JsonValue, condition: SelectCondition): boolean;
5
+ export declare function matchingRules<TBranch extends string>(facts: JsonValue, rules: readonly SelectRule<TBranch>[], branches: ReadonlySet<string>): readonly SelectRule<TBranch>[];
6
+ //# sourceMappingURL=rule-evaluator.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"rule-evaluator.d.ts","sourceRoot":"","sources":["../src/rule-evaluator.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,SAAS,EAAE,MAAM,gCAAgC,CAAC;AAEhE,OAAO,KAAK,EAAE,eAAe,EAAE,UAAU,EAAE,MAAM,YAAY,CAAC;AAuB9D,wBAAgB,iBAAiB,CAAC,KAAK,EAAE,SAAS,GAAG,MAAM,CAG1D;AA2GD,wBAAgB,iBAAiB,CAAC,KAAK,EAAE,SAAS,EAAE,SAAS,EAAE,eAAe,GAAG,OAAO,CAGvF;AAED,wBAAgB,aAAa,CAAC,OAAO,SAAS,MAAM,EAClD,KAAK,EAAE,SAAS,EAChB,KAAK,EAAE,SAAS,UAAU,CAAC,OAAO,CAAC,EAAE,EACrC,QAAQ,EAAE,WAAW,CAAC,MAAM,CAAC,GAC5B,SAAS,UAAU,CAAC,OAAO,CAAC,EAAE,CAqBhC"}
@@ -0,0 +1,131 @@
1
+ import { createHash } from "node:crypto";
2
+ import { AtomExecutionError } from "@atom-workflow-agent/atom-sdk";
3
+ function isRecord(value) {
4
+ return value !== null && typeof value === "object" && !Array.isArray(value);
5
+ }
6
+ function canonicalize(value) {
7
+ if (Array.isArray(value))
8
+ return value.map(canonicalize);
9
+ if (isRecord(value)) {
10
+ return Object.fromEntries(Object.entries(value)
11
+ .sort(([left], [right]) => left.localeCompare(right))
12
+ .map(([key, nested]) => [key, canonicalize(nested)]));
13
+ }
14
+ return value;
15
+ }
16
+ export function hashSelectorFacts(facts) {
17
+ const serialized = JSON.stringify(canonicalize(facts));
18
+ return `sha256:${createHash("sha256").update(serialized).digest("hex")}`;
19
+ }
20
+ function pointerSegments(path) {
21
+ if (path === "" || path === "$")
22
+ return [];
23
+ if (path.startsWith("/")) {
24
+ return path.slice(1).split("/").map((segment) => segment.replaceAll("~1", "/").replaceAll("~0", "~"));
25
+ }
26
+ const normalized = path.startsWith("$.") ? path.slice(2) : path;
27
+ return normalized === "" ? [] : normalized.split(".");
28
+ }
29
+ function resolveFact(facts, path) {
30
+ let current = facts;
31
+ for (const segment of pointerSegments(path)) {
32
+ if (Array.isArray(current)) {
33
+ if (!/^\d+$/.test(segment))
34
+ return { exists: false };
35
+ const index = Number(segment);
36
+ if (index >= current.length)
37
+ return { exists: false };
38
+ current = current[index];
39
+ continue;
40
+ }
41
+ if (!isRecord(current) || !Object.prototype.hasOwnProperty.call(current, segment)) {
42
+ return { exists: false };
43
+ }
44
+ current = current[segment];
45
+ }
46
+ return { exists: true, value: current };
47
+ }
48
+ function equalJson(left, right) {
49
+ return JSON.stringify(canonicalize(left)) === JSON.stringify(canonicalize(right));
50
+ }
51
+ function requiredValue(condition) {
52
+ if (condition.value === undefined) {
53
+ throw new AtomExecutionError("SELECT_CONDITION_VALUE_REQUIRED", `Selector operator '${condition.operator}' requires a value`, { details: { path: condition.path, operator: condition.operator } });
54
+ }
55
+ return condition.value;
56
+ }
57
+ function compareOrdered(actual, expected, operator) {
58
+ if (typeof actual !== "number" || typeof expected !== "number") {
59
+ throw new AtomExecutionError("SELECT_CONDITION_TYPE_INVALID", `Selector operator '${operator}' requires numeric facts and values`, { details: { operator, actual, expected } });
60
+ }
61
+ if (operator === "gt")
62
+ return actual > expected;
63
+ if (operator === "gte")
64
+ return actual >= expected;
65
+ if (operator === "lt")
66
+ return actual < expected;
67
+ return actual <= expected;
68
+ }
69
+ function evaluateRaw(condition, resolved) {
70
+ if (condition.operator === "exists") {
71
+ if (condition.value !== undefined) {
72
+ throw new AtomExecutionError("SELECT_CONDITION_VALUE_FORBIDDEN", "Selector operator 'exists' does not accept a value; use negate for a missing check", { details: { path: condition.path } });
73
+ }
74
+ return resolved.exists;
75
+ }
76
+ if (!resolved.exists)
77
+ return false;
78
+ const actual = resolved.value;
79
+ const expected = requiredValue(condition);
80
+ switch (condition.operator) {
81
+ case "eq": return equalJson(actual, expected);
82
+ case "ne": return !equalJson(actual, expected);
83
+ case "gt":
84
+ case "gte":
85
+ case "lt":
86
+ case "lte": return compareOrdered(actual, expected, condition.operator);
87
+ case "in":
88
+ case "not_in": {
89
+ if (!Array.isArray(expected)) {
90
+ throw new AtomExecutionError("SELECT_CONDITION_TYPE_INVALID", `Selector operator '${condition.operator}' requires an array value`, { details: { path: condition.path, operator: condition.operator } });
91
+ }
92
+ const included = expected.some((candidate) => equalJson(actual, candidate));
93
+ return condition.operator === "in" ? included : !included;
94
+ }
95
+ case "contains": {
96
+ if (Array.isArray(actual))
97
+ return actual.some((candidate) => equalJson(candidate, expected));
98
+ if (typeof actual === "string" && typeof expected === "string")
99
+ return actual.includes(expected);
100
+ throw new AtomExecutionError("SELECT_CONDITION_TYPE_INVALID", "Selector operator 'contains' requires an array, or string facts and value", { details: { path: condition.path } });
101
+ }
102
+ default: {
103
+ const exhaustive = condition.operator;
104
+ throw new AtomExecutionError("SELECT_OPERATOR_UNSUPPORTED", `Unsupported selector operator: ${String(exhaustive)}`);
105
+ }
106
+ }
107
+ }
108
+ export function evaluateCondition(facts, condition) {
109
+ const matched = evaluateRaw(condition, resolveFact(facts, condition.path));
110
+ return condition.negate === true ? !matched : matched;
111
+ }
112
+ export function matchingRules(facts, rules, branches) {
113
+ const ids = new Set();
114
+ for (const rule of rules) {
115
+ if (ids.has(rule.id)) {
116
+ throw new AtomExecutionError("SELECT_RULE_ID_DUPLICATE", `Selector rule id is duplicated: ${rule.id}`);
117
+ }
118
+ ids.add(rule.id);
119
+ if (!branches.has(rule.branch)) {
120
+ throw new AtomExecutionError("SELECT_BRANCH_UNDECLARED", `Selector rule '${rule.id}' uses an undeclared branch: ${rule.branch}`);
121
+ }
122
+ if (rule.conditions.length === 0) {
123
+ throw new AtomExecutionError("SELECT_RULE_EMPTY", `Selector rule '${rule.id}' must contain at least one condition`);
124
+ }
125
+ }
126
+ return rules.filter((rule) => {
127
+ const matches = rule.conditions.map((condition) => evaluateCondition(facts, condition));
128
+ return rule.match === "all" ? matches.every(Boolean) : matches.some(Boolean);
129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C,CAAC,CAAC,OAAO,CAAC,KAAK,CAAC,OAAO,CAAC,CAAC,CAAC,CAAC,OAAO,CAAC,IAAI,CAAC,OAAO,CAAC,CAAC;IAC/E,CAAC,CAAC,CAAC;AACL,CAAC"}
@@ -0,0 +1,7 @@
1
+ import type { JsonSchema } from "@atom-workflow-agent/contracts";
2
+ export declare function selectorInputSchema(): JsonSchema;
3
+ export declare const HOST_SELECTOR_INPUT_SCHEMA: JsonSchema;
4
+ export declare function selectorOutputSchema(sources: readonly ("automatic" | "user" | "host")[]): JsonSchema;
5
+ export declare function selectorCheckpointSchema(): JsonSchema;
6
+ export declare function hostSelectorCheckpointSchema(): JsonSchema;
7
+ //# sourceMappingURL=schemas.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"schemas.d.ts","sourceRoot":"","sources":["../src/schemas.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,UAAU,EAAE,MAAM,gCAAgC,CAAC;AAEjE,wBAAgB,mBAAmB,IAAI,UAAU,CAkDhD;AAED,eAAO,MAAM,0BAA0B,EAAE,UAUxC,CAAC;AAEF,wBAAgB,oBAAoB,CAClC,OAAO,EAAE,SAAS,CAAC,WAAW,GAAG,MAAM,GAAG,MAAM,CAAC,EAAE,GAClD,UAAU,CAcZ;AAED,wBAAgB,wBAAwB,IAAI,UAAU,CAWrD;AAED,wBAAgB,4BAA4B,IAAI,UAAU,CAUzD"}
@@ -0,0 +1,101 @@
1
+ export function selectorInputSchema() {
2
+ return {
3
+ type: "object",
4
+ description: "Input for select.rule. This Atom only chooses one branch declared by its DecisionNode; it does not execute the selected branch.",
5
+ properties: {
6
+ mode: {
7
+ enum: ["automatic", "manual", "auto_then_user"],
8
+ description: "automatic selects the first matching rule or fallback; manual always asks the user; auto_then_user asks the user unless exactly one rule matches.",
9
+ },
10
+ facts: { type: ["null", "boolean", "object", "array", "number", "string"], description: "用于规则判断的业务事实对象或 JSON 值,例如页面指标、预算结果或校验结论。" },
11
+ rules: {
12
+ type: "array",
13
+ description: "Ordered safe rules. Each rule may only select a branch statically declared by the DecisionNode.",
14
+ items: {
15
+ type: "object",
16
+ properties: {
17
+ id: { type: "string", minLength: 1, description: "规则的稳定审计标识,用于 matchedRuleIds 记录命中来源。" },
18
+ branch: { type: "string", minLength: 1, description: "规则命中后选择的 DecisionNode 已声明分支 ID。" },
19
+ match: { enum: ["all", "any"], description: "all 要求全部条件成立;any 只要求至少一个条件成立。" },
20
+ conditions: {
21
+ type: "array",
22
+ minItems: 1,
23
+ description: "针对 facts 的条件列表,按照 match 指定的 all 或 any 方式组合。",
24
+ items: {
25
+ type: "object",
26
+ properties: {
27
+ path: { type: "string", description: "读取 facts 的 JSON Pointer;空字符串表示整个 facts。" },
28
+ operator: {
29
+ enum: ["eq", "ne", "gt", "gte", "lt", "lte", "in", "not_in", "contains", "exists"],
30
+ description: "将 path 对应事实值与 value 比较时使用的有限运算符。",
31
+ },
32
+ value: { type: ["null", "boolean", "object", "array", "number", "string"], description: "比较目标值;exists 运算符可省略该字段。" },
33
+ negate: { type: "boolean", description: "为 true 时反转当前条件的判断结果。" },
34
+ },
35
+ required: ["path", "operator"],
36
+ additionalProperties: false,
37
+ },
38
+ },
39
+ reason: { type: "string", minLength: 1, description: "规则命中时写入选择结果的可读原因。" },
40
+ },
41
+ required: ["id", "branch", "match", "conditions"],
42
+ additionalProperties: false,
43
+ },
44
+ },
45
+ prompt: { type: "string", minLength: 1, description: "Optional user-facing question used when a Signal is required." },
46
+ fallbackBranch: { type: "string", minLength: 1, description: "Declared branch selected by automatic mode when no rule matches." },
47
+ },
48
+ required: ["mode", "facts", "rules"],
49
+ additionalProperties: false,
50
+ };
51
+ }
52
+ export const HOST_SELECTOR_INPUT_SCHEMA = {
53
+ type: "object",
54
+ description: "Input for select.host-model. The current native Codex or Trae chooses one declared DecisionNode branch; this Atom does not perform the branch action.",
55
+ properties: {
56
+ question: { type: "string", minLength: 1, description: "The concrete branch decision the current Host Model must make." },
57
+ facts: { type: ["null", "boolean", "object", "array", "number", "string"], description: "交给当前 Codex 或 Trae 判断分支时参考的结构化业务事实。" },
58
+ guidance: { type: "string", minLength: 1, description: "Optional evaluation criteria; it cannot expand the statically declared branches." },
59
+ },
60
+ required: ["question", "facts"],
61
+ additionalProperties: false,
62
+ };
63
+ export function selectorOutputSchema(sources) {
64
+ return {
65
+ type: "object",
66
+ description: "Auditable branch decision consumed by DecisionNode.select. branch is data, not a target node id.",
67
+ properties: {
68
+ branch: { type: "string", minLength: 1, description: "One branch id declared by the active DecisionNode." },
69
+ source: { enum: [...sources], description: "Whether deterministic rules, the user, or the current Host Model made the decision." },
70
+ reason: { type: "string", minLength: 1, description: "Human-readable audit reason for the choice." },
71
+ matchedRuleIds: { type: "array", description: "自动模式下实际命中的规则 ID;用户或 Host 决策时通常为空数组。", items: { type: "string", description: "一条已命中规则的稳定 ID。" } },
72
+ factsHash: { type: "string", pattern: "^sha256:[a-f0-9]{64}$", description: "参与本次决策的 facts 内容哈希,用于恢复和审计一致性。" },
73
+ },
74
+ required: ["branch", "source", "reason", "matchedRuleIds", "factsHash"],
75
+ additionalProperties: false,
76
+ };
77
+ }
78
+ export function selectorCheckpointSchema() {
79
+ return {
80
+ type: "object",
81
+ properties: {
82
+ stage: { enum: ["ready", "waiting_user"], description: "选择器当前处于可计算状态还是正在等待用户 Signal。" },
83
+ factsHash: { type: "string", pattern: "^sha256:[a-f0-9]{64}$", description: "暂停前 facts 的内容哈希,用于恢复时校验输入未漂移。" },
84
+ matchedRuleIds: { type: "array", description: "暂停或恢复前已经命中的规则 ID。", items: { type: "string", description: "一条已命中规则的稳定 ID。" } },
85
+ },
86
+ required: ["stage", "factsHash", "matchedRuleIds"],
87
+ additionalProperties: false,
88
+ };
89
+ }
90
+ export function hostSelectorCheckpointSchema() {
91
+ return {
92
+ type: "object",
93
+ properties: {
94
+ stage: { enum: ["ready", "waiting_host"], description: "Host 选择器当前处于可计算状态还是正在等待 HostTask。" },
95
+ factsHash: { type: "string", pattern: "^sha256:[a-f0-9]{64}$", description: "暂停前 facts 的内容哈希,用于恢复时校验输入未漂移。" },
96
+ },
97
+ required: ["stage", "factsHash"],
98
+ additionalProperties: false,
99
+ };
100
+ }
101
+ //# sourceMappingURL=schemas.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"schemas.js","sourceRoot":"","sources":["../src/schemas.ts"],"names":[],"mappings":"AAEA,MAAM,UAAU,mBAAmB;IACjC,OAAO;QACL,IAAI,EAAE,QAAQ;QACd,WAAW,EAAE,iIAAiI;QAC9I,UAAU,EAAE;YACV,IAAI,EAAE;gBACJ,IAAI,EAAE,CAAC,WAAW,EAAE,QAAQ,EAAE,gBAAgB,CAAC;gBAC/C,WAAW,EAAE,mJAAmJ;aACjK;YACD,KAAK,EAAE,EAAE,IAAI,EAAE,CAAC,MAAM,EAAE,SAAS,EAAE,QAAQ,EAAE,OAAO,EAAE,QAAQ,EAAE,QAAQ,CAAC,EAAE,WAAW,EAAE,yCAAyC,EAAE;YACnI,KAAK,EAAE;gBACL,IAAI,EAAE,OAAO;gBACb,WAAW,EAAE,iGAAiG;gBAC9G,KAAK,EAAE;oBACL,IAAI,EAAE,QAAQ;oBACd,UAAU,EAAE;wBACV,EAAE,EAAE,EAAE,IAAI,EAAE,QAAQ,EAAE,SAAS,EAAE,CAAC,EAAE,WAAW,EAAE,qCAAqC,EAAE;wBACxF,MAAM,EAAE,EAAE,IAAI,EAAE,QAAQ,EAAE,SAAS,EAAE,CAAC,EAAE,WAAW,EAAE,iCAAiC,EAAE;wBACxF,KAAK,EAAE,EAAE,IAAI,EAAE,CAAC,KAAK,EAAE,KAAK,CAAC,EAAE,WAAW,EAAE,+BAA+B,EAAE;wBAC7E,UAAU,EAAE;4BACV,IAAI,EAAE,OAAO;4BACb,QAAQ,EAAE,CAAC;4BACX,WAAW,EAAE,6CAA6C;4BAC1D,KAAK,EAAE;gCACL,IAAI,EAAE,QAAQ;gCACd,UAAU,EAAE;oCACV,IAAI,EAAE,EAAE,IAAI,E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5B,CAAC;AACJ,CAAC;AAED,MAAM,UAAU,wBAAwB;IACtC,OAAO;QACL,IAAI,EAAE,QAAQ;QACd,UAAU,EAAE;YACV,KAAK,EAAE,EAAE,IAAI,EAAE,CAAC,OAAO,EAAE,cAAc,CAAC,EAAE,WAAW,EAAE,8BAA8B,EAAE;YACvF,SAAS,EAAE,EAAE,IAAI,EAAE,QAAQ,EAAE,OAAO,EAAE,uBAAuB,EAAE,WAAW,EAAE,+BAA+B,EAAE;YAC7G,cAAc,EAAE,EAAE,IAAI,EAAE,OAAO,EAAE,WAAW,EAAE,mBAAmB,EAAE,KAAK,EAAE,EAAE,IAAI,EAAE,QAAQ,EAAE,WAAW,EAAE,gBAAgB,EAAE,EAAE;SAC9H;QACD,QAAQ,EAAE,CAAC,OAAO,EAAE,WAAW,EAAE,gBAAgB,CAAC;QAClD,oBAAoB,EAAE,KAAK;KAC5B,CAAC;AACJ,CAAC;AAED,MAAM,UAAU,4BAA4B;IAC1C,OAAO;QACL,IAAI,EAAE,QAAQ;QACd,UAAU,EAAE;YACV,KAAK,EAAE,EAAE,IAAI,EAAE,CAAC,OAAO,EAAE,cAAc,CAAC,EAAE,WAAW,EAAE,mCAAmC,EAAE;YAC5F,SAAS,EAAE,EAAE,IAAI,EAAE,QAAQ,EAAE,OAAO,EAAE,uBAAuB,EAAE,WAAW,EAAE,+BAA+B,EAAE;SAC9G;QACD,QAAQ,EAAE,CAAC,OAAO,EAAE,WAAW,CAAC;QAChC,oBAAoB,EAAE,KAAK;KAC5B,CAAC;AACJ,CAAC"}
@@ -0,0 +1,4 @@
1
+ import { type AtomDefinition } from "@atom-workflow-agent/atom-sdk";
2
+ import type { SelectorAtomDefinition, SelectorDecision, SelectorInput } from "./types.js";
3
+ export declare function defineSelectorAtom(definition: SelectorAtomDefinition): AtomDefinition<SelectorInput, SelectorDecision>;
4
+ //# sourceMappingURL=selector-atom.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"selector-atom.d.ts","sourceRoot":"","sources":["../src/selector-atom.ts"],"names":[],"mappings":"AACA,OAAO,EAAkC,KAAK,cAAc,EAAE,MAAM,+BAA+B,CAAC;AAGpG,OAAO,KAAK,EAAE,sBAAsB,EAAE,gBAAgB,EAAE,aAAa,EAAE,MAAM,YAAY,CAAC;AAQ1F,wBAAgB,kBAAkB,CAAC,UAAU,EAAE,sBAAsB,GAAG,cAAc,CAAC,aAAa,EAAE,gBAAgB,CAAC,CA6CtH"}
@@ -0,0 +1,58 @@
1
+ import { AtomExecutionError, defineAtom } from "@atom-workflow-agent/atom-sdk";
2
+ import { hashSelectorFacts, matchingRules } from "./rule-evaluator.js";
3
+ import { selectorInputSchema, selectorOutputSchema } from "./schemas.js";
4
+ export function defineSelectorAtom(definition) {
5
+ const expiresInMs = definition.signalExpiresInMs ?? 86_400_000;
6
+ if (!Number.isInteger(expiresInMs) || expiresInMs <= 0 || expiresInMs > 31_536_000_000)
7
+ throw new TypeError("Selector Atom signalExpiresInMs must be a positive integer no greater than 31536000000");
8
+ return defineAtom({
9
+ id: definition.id,
10
+ ...(definition.version ? { version: definition.version } : {}),
11
+ title: definition.title ?? "DecisionNode rule or user branch selector",
12
+ description: definition.description ?? "DecisionNode-only Atom that deterministically evaluates structured facts or pauses for an explicit user choice, then returns one statically declared branch id.",
13
+ input: selectorInputSchema(),
14
+ output: selectorOutputSchema(["automatic", "user"]),
15
+ reliability: { idempotent: true, timeoutMs: 5_000 },
16
+ execute(input, context) {
17
+ const branches = context.decision?.branches;
18
+ if (!branches?.length)
19
+ throw new AtomExecutionError("SELECT_DECISION_CONTEXT_REQUIRED", "select.rule must run as a DecisionNode");
20
+ const branchSet = new Set(branches);
21
+ const matched = matchingRules(input.facts, input.rules, branchSet);
22
+ const matchedRuleIds = matched.map((rule) => rule.id);
23
+ const factsHash = hashSelectorFacts(input.facts);
24
+ const automatic = (branch, reason) => ({ branch, source: "automatic", reason, matchedRuleIds, factsHash });
25
+ if (input.mode === "automatic" || (input.mode === "auto_then_user" && matched.length === 1)) {
26
+ if (matched[0])
27
+ return automatic(matched[0].branch, matched[0].reason ?? `Rule '${matched[0].id}' matched`);
28
+ if (input.fallbackBranch) {
29
+ if (!branchSet.has(input.fallbackBranch))
30
+ throw new AtomExecutionError("SELECT_BRANCH_UNDECLARED", `Selector fallback uses an undeclared branch: ${input.fallbackBranch}`);
31
+ return automatic(input.fallbackBranch, "No rule matched; selected the configured fallback branch");
32
+ }
33
+ if (input.mode === "automatic")
34
+ throw new AtomExecutionError("SELECT_NO_MATCH", "No selector rule matched and no fallbackBranch was provided", { details: { factsHash } });
35
+ }
36
+ const prompt = input.prompt ?? (input.mode === "manual" ? `请选择 Workflow 分支:${branches.join("、")}` : `自动规则${matched.length === 0 ? "没有匹配" : "存在多个匹配"},请选择 Workflow 分支:${branches.join("、")}`);
37
+ return context.waitForSignal({
38
+ key: "selector_decision", prompt, expiresInMs,
39
+ checkpoint: { factsHash, matchedRuleIds },
40
+ response: { type: "object", properties: { branch: { enum: [...branches] }, reason: { type: "string", minLength: 1 } }, required: ["branch", "reason"], additionalProperties: false },
41
+ metadata: { selector: definition.id, allowedBranches: [...branches], matchedRuleIds, requiresExplicitUserResponse: true },
42
+ });
43
+ },
44
+ resume(input, resumed, context) {
45
+ if (resumed.type !== "signal")
46
+ throw new AtomExecutionError("SELECT_SIGNAL_RESUME_REQUIRED", "Selector requires an explicit user Signal response");
47
+ const checkpoint = resumed.checkpoint;
48
+ if (hashSelectorFacts(input.facts) !== checkpoint.factsHash)
49
+ throw new AtomExecutionError("SELECT_FACTS_CHANGED", "Selector facts changed while awaiting the user response");
50
+ const response = resumed.value;
51
+ const branches = context.decision?.branches;
52
+ if (!branches?.includes(response.branch))
53
+ throw new AtomExecutionError("SELECT_BRANCH_UNDECLARED", `User selected an undeclared branch: ${response.branch}`);
54
+ return { branch: response.branch, source: "user", reason: response.reason, matchedRuleIds: checkpoint.matchedRuleIds, factsHash: checkpoint.factsHash };
55
+ },
56
+ });
57
+ }
58
+ //# source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,IAAI,iBAAiB,CAAC,KAAK,CAAC,KAAK,CAAC,KAAK,UAAU,CAAC,SAAS;gBAAE,MAAM,IAAI,kBAAkB,CAAC,sBAAsB,EAAE,yDAAyD,CAAC,CAAC;YAC7K,MAAM,QAAQ,GAAG,OAAO,CAAC,KAAsB,CAAC;YAChD,MAAM,QAAQ,GAAG,OAAO,CAAC,QAAQ,EAAE,QAAQ,CAAC;YAC5C,IAAI,CAAC,QAAQ,EAAE,QAAQ,CAAC,QAAQ,CAAC,MAAM,CAAC;gBAAE,MAAM,IAAI,kBAAkB,CAAC,0BAA0B,EAAE,uCAAuC,QAAQ,CAAC,MAAM,EAAE,CAAC,CAAC;YAC7J,OAAO,EAAE,MAAM,EAAE,QAAQ,CAAC,MAAM,EAAE,MAAM,EAAE,MAAM,EAAE,MAAM,EAAE,QAAQ,CAAC,MAAM,EAAE,cAAc,EAAE,UAAU,CAAC,cAAc,EAAE,SAAS,EAAE,UAAU,CAAC,SAAS,EAAE,CAAC;QAC1J,CAAC;KACF,CAAC,CAAC;AACL,CAAC"}
@@ -0,0 +1,52 @@
1
+ import type { JsonValue } from "@atom-workflow-agent/contracts";
2
+ export type SelectMode = "automatic" | "manual" | "auto_then_user";
3
+ export type SelectOperator = "eq" | "ne" | "gt" | "gte" | "lt" | "lte" | "in" | "not_in" | "contains" | "exists";
4
+ export interface SelectCondition extends Record<string, JsonValue> {
5
+ /** JSON Pointer (`/metrics/lcpMs`) or dot path (`metrics.lcpMs`). */
6
+ readonly path: string;
7
+ readonly operator: SelectOperator;
8
+ readonly value?: JsonValue;
9
+ readonly negate?: boolean;
10
+ }
11
+ export interface SelectRule<TBranch extends string = string> extends Record<string, JsonValue> {
12
+ readonly id: string;
13
+ readonly branch: TBranch;
14
+ readonly match: "all" | "any";
15
+ readonly conditions: SelectCondition[];
16
+ readonly reason?: string;
17
+ }
18
+ export interface SelectorInput<TBranch extends string = string> extends Record<string, JsonValue> {
19
+ readonly mode: SelectMode;
20
+ readonly facts: JsonValue;
21
+ readonly rules: SelectRule<TBranch>[];
22
+ readonly prompt?: string;
23
+ readonly fallbackBranch?: TBranch;
24
+ }
25
+ export interface HostSelectorInput extends Record<string, JsonValue> {
26
+ readonly question: string;
27
+ readonly facts: JsonValue;
28
+ readonly guidance?: string;
29
+ }
30
+ export type SelectionSource = "automatic" | "user" | "host";
31
+ export interface SelectorDecision<TBranch extends string = string> extends Record<string, JsonValue> {
32
+ readonly branch: TBranch;
33
+ readonly source: SelectionSource;
34
+ readonly reason: string;
35
+ readonly matchedRuleIds: string[];
36
+ readonly factsHash: string;
37
+ }
38
+ export interface SelectorAtomDefinition {
39
+ readonly id: string;
40
+ readonly version?: string;
41
+ readonly title?: string;
42
+ readonly description?: string;
43
+ readonly signalExpiresInMs?: number;
44
+ }
45
+ export interface HostSelectorAtomDefinition {
46
+ readonly id: string;
47
+ readonly version?: string;
48
+ readonly title?: string;
49
+ readonly description?: string;
50
+ readonly hostExpiresInMs?: number;
51
+ }
52
+ //# sourceMappingURL=types.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"types.d.ts","sourceRoot":"","sources":["../src/types.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,SAAS,EAAE,MAAM,gCAAgC,CAAC;AAEhE,MAAM,MAAM,UAAU,GAAG,WAAW,GAAG,QAAQ,GAAG,gBAAgB,CAAC;AAEnE,MAAM,MAAM,cAAc,GACtB,IAAI,GACJ,IAAI,GACJ,IAAI,GACJ,KAAK,GACL,IAAI,GACJ,KAAK,GACL,IAAI,GACJ,QAAQ,GACR,UAAU,GACV,QAAQ,CAAC;AAEb,MAAM,WAAW,eAAgB,SAAQ,MAAM,CAAC,MAAM,EAAE,SAAS,CAAC;IAChE,qEAAqE;IACrE,QAAQ,CAAC,IAAI,EAAE,MAAM,CAAC;IACtB,QAAQ,CAAC,QAAQ,EAAE,cAAc,CAAC;IAClC,QAAQ,CAAC,KAAK,CAAC,EAAE,SAAS,CAAC;IAC3B,QAAQ,CAAC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AAE,eAAe,CAAC;IACjC,QAAQ,CAAC,MAAM,EAAE,MAAM,CAAC;IACxB,QAAQ,CAAC,cAAc,EAAE,MAAM,EAAE,CAAC;IAClC,QAAQ,CAAC,SAAS,EAAE,MAAM,CAAC;CAC5B;AAED,MAAM,WAAW,sBAAsB;IACrC,QAAQ,CAAC,EAAE,EAAE,MAAM,CAAC;IACpB,QAAQ,CAAC,OAAO,CAAC,EAAE,MAAM,CAAC;IAC1B,QAAQ,CAAC,KAAK,CAAC,EAAE,MAAM,CAAC;IACxB,QAAQ,CAAC,WAAW,CAAC,EAAE,MAAM,CAAC;IAC9B,QAAQ,CAAC,iBAAiB,CAAC,EAAE,MAAM,CAAC;CACrC;AAED,MAAM,WAAW,0BAA0B;IACzC,QAAQ,CAAC,EAAE,EAAE,MAAM,CAAC;IACpB,QAAQ,CAAC,OAAO,CAAC,EAAE,MAAM,CAAC;IAC1B,QAAQ,CAAC,KAAK,CAAC,EAAE,MAAM,CAAC;IACxB,QAAQ,CAAC,WAAW,CAAC,EAAE,MAAM,CAAC;IAC9B,QAAQ,CAAC,eAAe,CAAC,EAAE,MAAM,CAAC;CACnC"}
package/dist/types.js ADDED
@@ -0,0 +1,2 @@
1
+ export {};
2
+ //# sourceMappingURL=types.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"types.js","sourceRoot":"","sources":["../src/types.ts"],"names":[],"mappings":""}
package/package.json ADDED
@@ -0,0 +1,49 @@
1
+ {
2
+ "name": "@atom-workflow-agent/select-atom",
3
+ "version": "1.0.0",
4
+ "description": "Built-in deterministic and human-in-the-loop selection atoms.",
5
+ "license": "Apache-2.0",
6
+ "repository": {
7
+ "type": "git",
8
+ "url": "git+https://github.com/joekbits/atom-workflow-agent.git",
9
+ "directory": "atoms/select-atom"
10
+ },
11
+ "homepage": "https://github.com/joekbits/atom-workflow-agent/tree/main/atoms/select-atom#readme",
12
+ "bugs": {
13
+ "url": "https://github.com/joekbits/atom-workflow-agent/issues"
14
+ },
15
+ "keywords": [
16
+ "atom",
17
+ "workflow",
18
+ "decision",
19
+ "selector"
20
+ ],
21
+ "type": "module",
22
+ "files": [
23
+ "dist",
24
+ "README.md",
25
+ "README.zh-CN.md"
26
+ ],
27
+ "exports": {
28
+ ".": {
29
+ "types": "./dist/index.d.ts",
30
+ "default": "./dist/index.js"
31
+ }
32
+ },
33
+ "publishConfig": {
34
+ "access": "public",
35
+ "provenance": true
36
+ },
37
+ "engines": {
38
+ "node": ">=22"
39
+ },
40
+ "dependencies": {
41
+ "@atom-workflow-agent/contracts": "0.1.0",
42
+ "@atom-workflow-agent/atom-sdk": "0.1.0"
43
+ },
44
+ "scripts": {
45
+ "build": "tsc -p tsconfig.json",
46
+ "typecheck": "tsc -p tsconfig.json --noEmit",
47
+ "test": "vitest run"
48
+ }
49
+ }