@auxiora/reasoning 0.1.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/LICENSE +191 -0
- package/package.json +10 -0
- package/src/improvement-store.ts +94 -0
- package/src/improvement-types.ts +15 -0
- package/src/index.ts +13 -0
- package/src/meta-improvement.ts +93 -0
- package/src/step-registry.ts +118 -0
- package/src/step-tools.ts +55 -0
- package/src/types.ts +21 -0
- package/tests/improvement-store.test.ts +86 -0
- package/tests/meta-improvement.test.ts +95 -0
- package/tests/step-registry.test.ts +85 -0
- package/tests/step-tools.test.ts +75 -0
- package/tsconfig.json +5 -0
package/LICENSE
ADDED
|
@@ -0,0 +1,191 @@
|
|
|
1
|
+
|
|
2
|
+
Apache License
|
|
3
|
+
Version 2.0, January 2004
|
|
4
|
+
http://www.apache.org/licenses/
|
|
5
|
+
|
|
6
|
+
TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION
|
|
7
|
+
|
|
8
|
+
1. Definitions.
|
|
9
|
+
|
|
10
|
+
"License" shall mean the terms and conditions for use, reproduction,
|
|
11
|
+
and distribution as defined by Sections 1 through 9 of this document.
|
|
12
|
+
|
|
13
|
+
"Licensor" shall mean the copyright owner or entity authorized by
|
|
14
|
+
the copyright owner that is granting the License.
|
|
15
|
+
|
|
16
|
+
"Legal Entity" shall mean the union of the acting entity and all
|
|
17
|
+
other entities that control, are controlled by, or are under common
|
|
18
|
+
control with that entity. For the purposes of this definition,
|
|
19
|
+
"control" means (i) the power, direct or indirect, to cause the
|
|
20
|
+
direction or management of such entity, whether by contract or
|
|
21
|
+
otherwise, or (ii) ownership of fifty percent (50%) or more of the
|
|
22
|
+
outstanding shares, or (iii) beneficial ownership of such entity.
|
|
23
|
+
|
|
24
|
+
"You" (or "Your") shall mean an individual or Legal Entity
|
|
25
|
+
exercising permissions granted by this License.
|
|
26
|
+
|
|
27
|
+
"Source" form shall mean the preferred form for making modifications,
|
|
28
|
+
including but not limited to software source code, documentation
|
|
29
|
+
source, and configuration files.
|
|
30
|
+
|
|
31
|
+
"Object" form shall mean any form resulting from mechanical
|
|
32
|
+
transformation or translation of a Source form, including but
|
|
33
|
+
not limited to compiled object code, generated documentation,
|
|
34
|
+
and conversions to other media types.
|
|
35
|
+
|
|
36
|
+
"Work" shall mean the work of authorship, whether in Source or
|
|
37
|
+
Object form, made available under the License, as indicated by a
|
|
38
|
+
copyright notice that is included in or attached to the work
|
|
39
|
+
(an example is provided in the Appendix below).
|
|
40
|
+
|
|
41
|
+
"Derivative Works" shall mean any work, whether in Source or Object
|
|
42
|
+
form, that is based on (or derived from) the Work and for which the
|
|
43
|
+
editorial revisions, annotations, elaborations, or other modifications
|
|
44
|
+
represent, as a whole, an original work of authorship. For the purposes
|
|
45
|
+
of this License, Derivative Works shall not include works that remain
|
|
46
|
+
separable from, or merely link (or bind by name) to the interfaces of,
|
|
47
|
+
the Work and Derivative Works thereof.
|
|
48
|
+
|
|
49
|
+
"Contribution" shall mean any work of authorship, including
|
|
50
|
+
the original version of the Work and any modifications or additions
|
|
51
|
+
to that Work or Derivative Works thereof, that is intentionally
|
|
52
|
+
submitted to the Licensor for inclusion in the Work by the copyright owner
|
|
53
|
+
or by an individual or Legal Entity authorized to submit on behalf of
|
|
54
|
+
the copyright owner. For the purposes of this definition, "submitted"
|
|
55
|
+
means any form of electronic, verbal, or written communication sent
|
|
56
|
+
to the Licensor or its representatives, including but not limited to
|
|
57
|
+
communication on electronic mailing lists, source code control systems,
|
|
58
|
+
and issue tracking systems that are managed by, or on behalf of, the
|
|
59
|
+
Licensor for the purpose of discussing and improving the Work, but
|
|
60
|
+
excluding communication that is conspicuously marked or otherwise
|
|
61
|
+
designated in writing by the copyright owner as "Not a Contribution."
|
|
62
|
+
|
|
63
|
+
"Contributor" shall mean Licensor and any individual or Legal Entity
|
|
64
|
+
on behalf of whom a Contribution has been received by the Licensor and
|
|
65
|
+
subsequently incorporated within the Work.
|
|
66
|
+
|
|
67
|
+
2. Grant of Copyright License. Subject to the terms and conditions of
|
|
68
|
+
this License, each Contributor hereby grants to You a perpetual,
|
|
69
|
+
worldwide, non-exclusive, no-charge, royalty-free, irrevocable
|
|
70
|
+
copyright license to reproduce, prepare Derivative Works of,
|
|
71
|
+
publicly display, publicly perform, sublicense, and distribute the
|
|
72
|
+
Work and such Derivative Works in Source or Object form.
|
|
73
|
+
|
|
74
|
+
3. Grant of Patent License. Subject to the terms and conditions of
|
|
75
|
+
this License, each Contributor hereby grants to You a perpetual,
|
|
76
|
+
worldwide, non-exclusive, no-charge, royalty-free, irrevocable
|
|
77
|
+
(except as stated in this section) patent license to make, have made,
|
|
78
|
+
use, offer to sell, sell, import, and otherwise transfer the Work,
|
|
79
|
+
where such license applies only to those patent claims licensable
|
|
80
|
+
by such Contributor that are necessarily infringed by their
|
|
81
|
+
Contribution(s) alone or by combination of their Contribution(s)
|
|
82
|
+
with the Work to which such Contribution(s) was submitted. If You
|
|
83
|
+
institute patent litigation against any entity (including a
|
|
84
|
+
cross-claim or counterclaim in a lawsuit) alleging that the Work
|
|
85
|
+
or a Contribution incorporated within the Work constitutes direct
|
|
86
|
+
or contributory patent infringement, then any patent licenses
|
|
87
|
+
granted to You under this License for that Work shall terminate
|
|
88
|
+
as of the date such litigation is filed.
|
|
89
|
+
|
|
90
|
+
4. Redistribution. You may reproduce and distribute copies of the
|
|
91
|
+
Work or Derivative Works thereof in any medium, with or without
|
|
92
|
+
modifications, and in Source or Object form, provided that You
|
|
93
|
+
meet the following conditions:
|
|
94
|
+
|
|
95
|
+
(a) You must give any other recipients of the Work or
|
|
96
|
+
Derivative Works a copy of this License; and
|
|
97
|
+
|
|
98
|
+
(b) You must cause any modified files to carry prominent notices
|
|
99
|
+
stating that You changed the files; and
|
|
100
|
+
|
|
101
|
+
(c) You must retain, in the Source form of any Derivative Works
|
|
102
|
+
that You distribute, all copyright, patent, trademark, and
|
|
103
|
+
attribution notices from the Source form of the Work,
|
|
104
|
+
excluding those notices that do not pertain to any part of
|
|
105
|
+
the Derivative Works; and
|
|
106
|
+
|
|
107
|
+
(d) If the Work includes a "NOTICE" text file as part of its
|
|
108
|
+
distribution, then any Derivative Works that You distribute must
|
|
109
|
+
include a readable copy of the attribution notices contained
|
|
110
|
+
within such NOTICE file, excluding any notices that do not
|
|
111
|
+
pertain to any part of the Derivative Works, in at least one
|
|
112
|
+
of the following places: within a NOTICE text file distributed
|
|
113
|
+
as part of the Derivative Works; within the Source form or
|
|
114
|
+
documentation, if provided along with the Derivative Works; or,
|
|
115
|
+
within a display generated by the Derivative Works, if and
|
|
116
|
+
wherever such third-party notices normally appear. The contents
|
|
117
|
+
of the NOTICE file are for informational purposes only and
|
|
118
|
+
do not modify the License. You may add Your own attribution
|
|
119
|
+
notices within Derivative Works that You distribute, alongside
|
|
120
|
+
or as an addendum to the NOTICE text from the Work, provided
|
|
121
|
+
that such additional attribution notices cannot be construed
|
|
122
|
+
as modifying the License.
|
|
123
|
+
|
|
124
|
+
You may add Your own copyright statement to Your modifications and
|
|
125
|
+
may provide additional or different license terms and conditions
|
|
126
|
+
for use, reproduction, or distribution of Your modifications, or
|
|
127
|
+
for any such Derivative Works as a whole, provided Your use,
|
|
128
|
+
reproduction, and distribution of the Work otherwise complies with
|
|
129
|
+
the conditions stated in this License.
|
|
130
|
+
|
|
131
|
+
5. Submission of Contributions. Unless You explicitly state otherwise,
|
|
132
|
+
any Contribution intentionally submitted for inclusion in the Work
|
|
133
|
+
by You to the Licensor shall be under the terms and conditions of
|
|
134
|
+
this License, without any additional terms or conditions.
|
|
135
|
+
Notwithstanding the above, nothing herein shall supersede or modify
|
|
136
|
+
the terms of any separate license agreement you may have executed
|
|
137
|
+
with Licensor regarding such Contributions.
|
|
138
|
+
|
|
139
|
+
6. Trademarks. This License does not grant permission to use the trade
|
|
140
|
+
names, trademarks, service marks, or product names of the Licensor,
|
|
141
|
+
except as required for reasonable and customary use in describing the
|
|
142
|
+
origin of the Work and reproducing the content of the NOTICE file.
|
|
143
|
+
|
|
144
|
+
7. Disclaimer of Warranty. Unless required by applicable law or
|
|
145
|
+
agreed to in writing, Licensor provides the Work (and each
|
|
146
|
+
Contributor provides its Contributions) on an "AS IS" BASIS,
|
|
147
|
+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
|
|
148
|
+
implied, including, without limitation, any warranties or conditions
|
|
149
|
+
of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A
|
|
150
|
+
PARTICULAR PURPOSE. You are solely responsible for determining the
|
|
151
|
+
appropriateness of using or redistributing the Work and assume any
|
|
152
|
+
risks associated with Your exercise of permissions under this License.
|
|
153
|
+
|
|
154
|
+
8. Limitation of Liability. In no event and under no legal theory,
|
|
155
|
+
whether in tort (including negligence), contract, or otherwise,
|
|
156
|
+
unless required by applicable law (such as deliberate and grossly
|
|
157
|
+
negligent acts) or agreed to in writing, shall any Contributor be
|
|
158
|
+
liable to You for damages, including any direct, indirect, special,
|
|
159
|
+
incidental, or consequential damages of any character arising as a
|
|
160
|
+
result of this License or out of the use or inability to use the
|
|
161
|
+
Work (including but not limited to damages for loss of goodwill,
|
|
162
|
+
work stoppage, computer failure or malfunction, or any and all
|
|
163
|
+
other commercial damages or losses), even if such Contributor
|
|
164
|
+
has been advised of the possibility of such damages.
|
|
165
|
+
|
|
166
|
+
9. Accepting Warranty or Additional Liability. While redistributing
|
|
167
|
+
the Work or Derivative Works thereof, You may choose to offer,
|
|
168
|
+
and charge a fee for, acceptance of support, warranty, indemnity,
|
|
169
|
+
or other liability obligations and/or rights consistent with this
|
|
170
|
+
License. However, in accepting such obligations, You may act only
|
|
171
|
+
on Your own behalf and on Your sole responsibility, not on behalf
|
|
172
|
+
of any other Contributor, and only if You agree to indemnify,
|
|
173
|
+
defend, and hold each Contributor harmless for any liability
|
|
174
|
+
incurred by, or claims asserted against, such Contributor by reason
|
|
175
|
+
of your accepting any such warranty or additional liability.
|
|
176
|
+
|
|
177
|
+
END OF TERMS AND CONDITIONS
|
|
178
|
+
|
|
179
|
+
Copyright 2026 Auxiora Contributors
|
|
180
|
+
|
|
181
|
+
Licensed under the Apache License, Version 2.0 (the "License");
|
|
182
|
+
you may not use this file except in compliance with the License.
|
|
183
|
+
You may obtain a copy of the License at
|
|
184
|
+
|
|
185
|
+
http://www.apache.org/licenses/LICENSE-2.0
|
|
186
|
+
|
|
187
|
+
Unless required by applicable law or agreed to in writing, software
|
|
188
|
+
distributed under the License is distributed on an "AS IS" BASIS,
|
|
189
|
+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
190
|
+
See the License for the specific language governing permissions and
|
|
191
|
+
limitations under the License.
|
package/package.json
ADDED
|
@@ -0,0 +1,94 @@
|
|
|
1
|
+
import { DatabaseSync } from 'node:sqlite';
|
|
2
|
+
import type { ImprovementProposal } from './improvement-types.js';
|
|
3
|
+
|
|
4
|
+
export interface StoredProposal extends ImprovementProposal {
|
|
5
|
+
id: number;
|
|
6
|
+
}
|
|
7
|
+
|
|
8
|
+
export class ImprovementStore {
|
|
9
|
+
private readonly db: DatabaseSync;
|
|
10
|
+
private closed = false;
|
|
11
|
+
|
|
12
|
+
constructor(dbPath: string) {
|
|
13
|
+
this.db = new DatabaseSync(dbPath);
|
|
14
|
+
this.db.exec('PRAGMA journal_mode=WAL');
|
|
15
|
+
this.db.exec('PRAGMA busy_timeout=5000');
|
|
16
|
+
this.db.exec(`
|
|
17
|
+
CREATE TABLE IF NOT EXISTS improvement_proposals (
|
|
18
|
+
id INTEGER PRIMARY KEY AUTOINCREMENT,
|
|
19
|
+
observationsJson TEXT NOT NULL,
|
|
20
|
+
reflectionsJson TEXT NOT NULL,
|
|
21
|
+
hypothesesJson TEXT NOT NULL,
|
|
22
|
+
validationsJson TEXT NOT NULL,
|
|
23
|
+
status TEXT NOT NULL,
|
|
24
|
+
createdAt INTEGER NOT NULL
|
|
25
|
+
)
|
|
26
|
+
`);
|
|
27
|
+
this.db.exec('CREATE INDEX IF NOT EXISTS idx_proposals_status ON improvement_proposals (status)');
|
|
28
|
+
}
|
|
29
|
+
|
|
30
|
+
record(proposal: ImprovementProposal): number {
|
|
31
|
+
if (this.closed) return -1;
|
|
32
|
+
const stmt = this.db.prepare(
|
|
33
|
+
'INSERT INTO improvement_proposals (observationsJson, reflectionsJson, hypothesesJson, validationsJson, status, createdAt) VALUES (?, ?, ?, ?, ?, ?)',
|
|
34
|
+
);
|
|
35
|
+
stmt.run(
|
|
36
|
+
JSON.stringify(proposal.observations),
|
|
37
|
+
JSON.stringify(proposal.reflections),
|
|
38
|
+
JSON.stringify(proposal.hypotheses),
|
|
39
|
+
JSON.stringify(proposal.validations),
|
|
40
|
+
proposal.status,
|
|
41
|
+
proposal.createdAt,
|
|
42
|
+
);
|
|
43
|
+
const row = this.db.prepare('SELECT last_insert_rowid() as id').get() as Record<string, unknown>;
|
|
44
|
+
return row.id as number;
|
|
45
|
+
}
|
|
46
|
+
|
|
47
|
+
getById(id: number): StoredProposal | undefined {
|
|
48
|
+
if (this.closed) return undefined;
|
|
49
|
+
const stmt = this.db.prepare('SELECT * FROM improvement_proposals WHERE id = ?');
|
|
50
|
+
const row = stmt.get(id) as Record<string, unknown> | undefined;
|
|
51
|
+
if (!row) return undefined;
|
|
52
|
+
return this.mapRow(row);
|
|
53
|
+
}
|
|
54
|
+
|
|
55
|
+
updateStatus(id: number, status: ImprovementProposal['status']): void {
|
|
56
|
+
if (this.closed) return;
|
|
57
|
+
const stmt = this.db.prepare('UPDATE improvement_proposals SET status = ? WHERE id = ?');
|
|
58
|
+
stmt.run(status, id);
|
|
59
|
+
}
|
|
60
|
+
|
|
61
|
+
getByStatus(status: ImprovementProposal['status']): StoredProposal[] {
|
|
62
|
+
if (this.closed) return [];
|
|
63
|
+
const stmt = this.db.prepare('SELECT * FROM improvement_proposals WHERE status = ? ORDER BY createdAt DESC');
|
|
64
|
+
return this.mapRows(stmt.all(status) as Record<string, unknown>[]);
|
|
65
|
+
}
|
|
66
|
+
|
|
67
|
+
getRecent(limit = 50): StoredProposal[] {
|
|
68
|
+
if (this.closed) return [];
|
|
69
|
+
const stmt = this.db.prepare('SELECT * FROM improvement_proposals ORDER BY createdAt DESC LIMIT ?');
|
|
70
|
+
return this.mapRows(stmt.all(limit) as Record<string, unknown>[]);
|
|
71
|
+
}
|
|
72
|
+
|
|
73
|
+
close(): void {
|
|
74
|
+
if (this.closed) return;
|
|
75
|
+
this.closed = true;
|
|
76
|
+
this.db.close();
|
|
77
|
+
}
|
|
78
|
+
|
|
79
|
+
private mapRows(rows: Record<string, unknown>[]): StoredProposal[] {
|
|
80
|
+
return rows.map((r) => this.mapRow(r));
|
|
81
|
+
}
|
|
82
|
+
|
|
83
|
+
private mapRow(r: Record<string, unknown>): StoredProposal {
|
|
84
|
+
return {
|
|
85
|
+
id: r.id as number,
|
|
86
|
+
observations: JSON.parse(r.observationsJson as string) as Record<string, unknown>,
|
|
87
|
+
reflections: JSON.parse(r.reflectionsJson as string) as Record<string, unknown>,
|
|
88
|
+
hypotheses: JSON.parse(r.hypothesesJson as string) as Record<string, unknown>,
|
|
89
|
+
validations: JSON.parse(r.validationsJson as string) as Record<string, unknown>,
|
|
90
|
+
status: r.status as ImprovementProposal['status'],
|
|
91
|
+
createdAt: r.createdAt as number,
|
|
92
|
+
};
|
|
93
|
+
}
|
|
94
|
+
}
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
export interface ImprovementProposal {
|
|
2
|
+
observations: Record<string, unknown>;
|
|
3
|
+
reflections: Record<string, unknown>;
|
|
4
|
+
hypotheses: Record<string, unknown>;
|
|
5
|
+
validations: Record<string, unknown>;
|
|
6
|
+
status: 'pending_review' | 'approved' | 'rejected' | 'applied';
|
|
7
|
+
createdAt: number;
|
|
8
|
+
}
|
|
9
|
+
|
|
10
|
+
export interface StepDescription {
|
|
11
|
+
name: string;
|
|
12
|
+
description: string;
|
|
13
|
+
order: number;
|
|
14
|
+
required: boolean;
|
|
15
|
+
}
|
package/src/index.ts
ADDED
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
export { StepRegistry } from './step-registry.js';
|
|
2
|
+
export { StepToolGenerator } from './step-tools.js';
|
|
3
|
+
export { MetaImprovementStructure } from './meta-improvement.js';
|
|
4
|
+
export { ImprovementStore } from './improvement-store.js';
|
|
5
|
+
export type { StoredProposal } from './improvement-store.js';
|
|
6
|
+
export type { ToolLike } from './step-tools.js';
|
|
7
|
+
export type { ImprovementProposal, StepDescription } from './improvement-types.js';
|
|
8
|
+
export type {
|
|
9
|
+
ReasoningStep,
|
|
10
|
+
StepStatus,
|
|
11
|
+
StepState,
|
|
12
|
+
StepProgress,
|
|
13
|
+
} from './types.js';
|
|
@@ -0,0 +1,93 @@
|
|
|
1
|
+
import { StepRegistry } from './step-registry.js';
|
|
2
|
+
import { StepToolGenerator } from './step-tools.js';
|
|
3
|
+
import type { ReasoningStep } from './types.js';
|
|
4
|
+
import type { ImprovementProposal, StepDescription } from './improvement-types.js';
|
|
5
|
+
|
|
6
|
+
const META_STEPS: ReasoningStep[] = [
|
|
7
|
+
{
|
|
8
|
+
name: 'observe',
|
|
9
|
+
description: 'Collect performance metrics, error rates, and anomalies from recent operations. Output should include numeric metrics and notable anomalies.',
|
|
10
|
+
order: 1,
|
|
11
|
+
required: true,
|
|
12
|
+
},
|
|
13
|
+
{
|
|
14
|
+
name: 'reflect',
|
|
15
|
+
description: 'Analyze observations to identify patterns, correlations, and root causes. Output should include identified patterns and hypothesized root causes.',
|
|
16
|
+
order: 2,
|
|
17
|
+
required: true,
|
|
18
|
+
},
|
|
19
|
+
{
|
|
20
|
+
name: 'hypothesize',
|
|
21
|
+
description: 'Propose concrete changes based on reflections. Each proposal should include the change description and confidence level (0-1).',
|
|
22
|
+
order: 3,
|
|
23
|
+
required: true,
|
|
24
|
+
},
|
|
25
|
+
{
|
|
26
|
+
name: 'validate',
|
|
27
|
+
description: 'Test proposed changes against benchmarks or simulations. Output should include test results with pass/fail and measured improvement.',
|
|
28
|
+
order: 4,
|
|
29
|
+
required: true,
|
|
30
|
+
},
|
|
31
|
+
];
|
|
32
|
+
|
|
33
|
+
export class MetaImprovementStructure {
|
|
34
|
+
private readonly registry: StepRegistry;
|
|
35
|
+
private readonly toolGenerator: StepToolGenerator;
|
|
36
|
+
|
|
37
|
+
constructor() {
|
|
38
|
+
this.registry = new StepRegistry([...META_STEPS]);
|
|
39
|
+
this.toolGenerator = new StepToolGenerator(this.registry);
|
|
40
|
+
}
|
|
41
|
+
|
|
42
|
+
getCurrentStepName(): string | undefined {
|
|
43
|
+
return this.registry.currentStep()?.name;
|
|
44
|
+
}
|
|
45
|
+
|
|
46
|
+
completeStep(name: string, output: Record<string, unknown>): void {
|
|
47
|
+
if (!this.registry.isAvailable(name)) {
|
|
48
|
+
throw new Error(`Step "${name}" is not available. Current step: ${this.getCurrentStepName()}`);
|
|
49
|
+
}
|
|
50
|
+
this.registry.complete(name, output);
|
|
51
|
+
}
|
|
52
|
+
|
|
53
|
+
getProgress(): { completed: number; total: number; percentage: number } {
|
|
54
|
+
return this.registry.progress();
|
|
55
|
+
}
|
|
56
|
+
|
|
57
|
+
isComplete(): boolean {
|
|
58
|
+
return this.registry.isComplete();
|
|
59
|
+
}
|
|
60
|
+
|
|
61
|
+
getCurrentTools(): Array<{
|
|
62
|
+
name: string;
|
|
63
|
+
description: string;
|
|
64
|
+
parameters: Record<string, unknown>;
|
|
65
|
+
run(args: Record<string, unknown>): Promise<{ success: boolean; data: Record<string, unknown> }>;
|
|
66
|
+
getPermission(): string;
|
|
67
|
+
}> {
|
|
68
|
+
return this.toolGenerator.getCurrentTools();
|
|
69
|
+
}
|
|
70
|
+
|
|
71
|
+
buildProposal(): ImprovementProposal | undefined {
|
|
72
|
+
if (!this.isComplete()) return undefined;
|
|
73
|
+
const outputs = this.registry.getOutputs();
|
|
74
|
+
|
|
75
|
+
return {
|
|
76
|
+
observations: outputs.get('observe') ?? {},
|
|
77
|
+
reflections: outputs.get('reflect') ?? {},
|
|
78
|
+
hypotheses: outputs.get('hypothesize') ?? {},
|
|
79
|
+
validations: outputs.get('validate') ?? {},
|
|
80
|
+
status: 'pending_review',
|
|
81
|
+
createdAt: Date.now(),
|
|
82
|
+
};
|
|
83
|
+
}
|
|
84
|
+
|
|
85
|
+
getStepDescriptions(): StepDescription[] {
|
|
86
|
+
return META_STEPS.map((s) => ({
|
|
87
|
+
name: s.name,
|
|
88
|
+
description: s.description,
|
|
89
|
+
order: s.order,
|
|
90
|
+
required: s.required,
|
|
91
|
+
}));
|
|
92
|
+
}
|
|
93
|
+
}
|
|
@@ -0,0 +1,118 @@
|
|
|
1
|
+
import type { ReasoningStep, StepState, StepProgress } from './types.js';
|
|
2
|
+
|
|
3
|
+
export class StepRegistry {
|
|
4
|
+
private readonly states: Map<string, StepState>;
|
|
5
|
+
private readonly ordered: ReasoningStep[];
|
|
6
|
+
|
|
7
|
+
constructor(steps: ReasoningStep[]) {
|
|
8
|
+
this.ordered = [...steps].sort((a, b) => a.order - b.order);
|
|
9
|
+
this.states = new Map();
|
|
10
|
+
|
|
11
|
+
for (const step of this.ordered) {
|
|
12
|
+
this.states.set(step.name, { step, status: 'pending' });
|
|
13
|
+
}
|
|
14
|
+
|
|
15
|
+
if (this.ordered.length > 0) {
|
|
16
|
+
this.states.get(this.ordered[0].name)!.status = 'available';
|
|
17
|
+
}
|
|
18
|
+
}
|
|
19
|
+
|
|
20
|
+
currentStep(): ReasoningStep | undefined {
|
|
21
|
+
for (const step of this.ordered) {
|
|
22
|
+
const state = this.states.get(step.name)!;
|
|
23
|
+
if (state.status === 'available') {
|
|
24
|
+
return step;
|
|
25
|
+
}
|
|
26
|
+
}
|
|
27
|
+
return undefined;
|
|
28
|
+
}
|
|
29
|
+
|
|
30
|
+
isAvailable(name: string): boolean {
|
|
31
|
+
const state = this.states.get(name);
|
|
32
|
+
if (!state) return false;
|
|
33
|
+
return state.status === 'available';
|
|
34
|
+
}
|
|
35
|
+
|
|
36
|
+
canSkip(name: string): boolean {
|
|
37
|
+
const state = this.states.get(name);
|
|
38
|
+
if (!state) return false;
|
|
39
|
+
return !state.step.required && state.status === 'available';
|
|
40
|
+
}
|
|
41
|
+
|
|
42
|
+
complete(name: string, output?: Record<string, unknown>): void {
|
|
43
|
+
const state = this.states.get(name);
|
|
44
|
+
if (!state) {
|
|
45
|
+
throw new Error(`Step "${name}" not found`);
|
|
46
|
+
}
|
|
47
|
+
if (state.status !== 'available') {
|
|
48
|
+
throw new Error(`Step "${name}" is not available`);
|
|
49
|
+
}
|
|
50
|
+
state.status = 'completed';
|
|
51
|
+
state.output = output;
|
|
52
|
+
state.completedAt = Date.now();
|
|
53
|
+
this.advanceNext(name);
|
|
54
|
+
}
|
|
55
|
+
|
|
56
|
+
skip(name: string): void {
|
|
57
|
+
const state = this.states.get(name);
|
|
58
|
+
if (!state) {
|
|
59
|
+
throw new Error(`Step "${name}" not found`);
|
|
60
|
+
}
|
|
61
|
+
if (state.step.required) {
|
|
62
|
+
throw new Error(`Step "${name}" is required and cannot be skipped`);
|
|
63
|
+
}
|
|
64
|
+
if (state.status !== 'available') {
|
|
65
|
+
throw new Error(`Step "${name}" is not available`);
|
|
66
|
+
}
|
|
67
|
+
state.status = 'skipped';
|
|
68
|
+
this.advanceNext(name);
|
|
69
|
+
}
|
|
70
|
+
|
|
71
|
+
progress(): StepProgress {
|
|
72
|
+
let completed = 0;
|
|
73
|
+
const total = this.ordered.length;
|
|
74
|
+
for (const state of this.states.values()) {
|
|
75
|
+
if (state.status === 'completed' || state.status === 'skipped') {
|
|
76
|
+
completed++;
|
|
77
|
+
}
|
|
78
|
+
}
|
|
79
|
+
return {
|
|
80
|
+
completed,
|
|
81
|
+
total,
|
|
82
|
+
percentage: total === 0 ? 100 : Math.round((completed / total) * 100),
|
|
83
|
+
};
|
|
84
|
+
}
|
|
85
|
+
|
|
86
|
+
isComplete(): boolean {
|
|
87
|
+
for (const state of this.states.values()) {
|
|
88
|
+
if (state.step.required && state.status !== 'completed') {
|
|
89
|
+
return false;
|
|
90
|
+
}
|
|
91
|
+
if (!state.step.required && state.status !== 'completed' && state.status !== 'skipped') {
|
|
92
|
+
return false;
|
|
93
|
+
}
|
|
94
|
+
}
|
|
95
|
+
return true;
|
|
96
|
+
}
|
|
97
|
+
|
|
98
|
+
getOutputs(): Map<string, Record<string, unknown>> {
|
|
99
|
+
const outputs = new Map<string, Record<string, unknown>>();
|
|
100
|
+
for (const [name, state] of this.states) {
|
|
101
|
+
if (state.output) {
|
|
102
|
+
outputs.set(name, state.output);
|
|
103
|
+
}
|
|
104
|
+
}
|
|
105
|
+
return outputs;
|
|
106
|
+
}
|
|
107
|
+
|
|
108
|
+
private advanceNext(completedName: string): void {
|
|
109
|
+
const idx = this.ordered.findIndex((s) => s.name === completedName);
|
|
110
|
+
if (idx < this.ordered.length - 1) {
|
|
111
|
+
const next = this.ordered[idx + 1];
|
|
112
|
+
const nextState = this.states.get(next.name)!;
|
|
113
|
+
if (nextState.status === 'pending') {
|
|
114
|
+
nextState.status = 'available';
|
|
115
|
+
}
|
|
116
|
+
}
|
|
117
|
+
}
|
|
118
|
+
}
|
|
@@ -0,0 +1,55 @@
|
|
|
1
|
+
import type { StepRegistry } from './step-registry.js';
|
|
2
|
+
|
|
3
|
+
export interface ToolLike {
|
|
4
|
+
name: string;
|
|
5
|
+
description: string;
|
|
6
|
+
parameters: Record<string, unknown>;
|
|
7
|
+
run(args: Record<string, unknown>): Promise<{ success: boolean; data: Record<string, unknown> }>;
|
|
8
|
+
getPermission(): string;
|
|
9
|
+
}
|
|
10
|
+
|
|
11
|
+
export class StepToolGenerator {
|
|
12
|
+
private readonly registry: StepRegistry;
|
|
13
|
+
|
|
14
|
+
constructor(registry: StepRegistry) {
|
|
15
|
+
this.registry = registry;
|
|
16
|
+
}
|
|
17
|
+
|
|
18
|
+
getCurrentTools(): ToolLike[] {
|
|
19
|
+
const step = this.registry.currentStep();
|
|
20
|
+
if (!step) {
|
|
21
|
+
return [];
|
|
22
|
+
}
|
|
23
|
+
|
|
24
|
+
const registry = this.registry;
|
|
25
|
+
|
|
26
|
+
return [
|
|
27
|
+
{
|
|
28
|
+
name: `reasoning_${step.name}`,
|
|
29
|
+
description: `[Reasoning Step ${step.order}] ${step.description}`,
|
|
30
|
+
parameters: {
|
|
31
|
+
type: 'object',
|
|
32
|
+
properties: {
|
|
33
|
+
result: { type: 'object' },
|
|
34
|
+
},
|
|
35
|
+
},
|
|
36
|
+
async run(args: Record<string, unknown>): Promise<{ success: boolean; data: Record<string, unknown> }> {
|
|
37
|
+
registry.complete(step.name, args);
|
|
38
|
+
const progress = registry.progress();
|
|
39
|
+
const nextStep = registry.currentStep();
|
|
40
|
+
return {
|
|
41
|
+
success: true,
|
|
42
|
+
data: {
|
|
43
|
+
step: step.name,
|
|
44
|
+
progress,
|
|
45
|
+
nextStep: nextStep?.name ?? null,
|
|
46
|
+
},
|
|
47
|
+
};
|
|
48
|
+
},
|
|
49
|
+
getPermission(): string {
|
|
50
|
+
return 'AUTO_APPROVE';
|
|
51
|
+
},
|
|
52
|
+
},
|
|
53
|
+
];
|
|
54
|
+
}
|
|
55
|
+
}
|
package/src/types.ts
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
export interface ReasoningStep {
|
|
2
|
+
name: string;
|
|
3
|
+
description: string;
|
|
4
|
+
order: number;
|
|
5
|
+
required: boolean;
|
|
6
|
+
}
|
|
7
|
+
|
|
8
|
+
export type StepStatus = 'pending' | 'available' | 'completed' | 'skipped';
|
|
9
|
+
|
|
10
|
+
export interface StepState {
|
|
11
|
+
step: ReasoningStep;
|
|
12
|
+
status: StepStatus;
|
|
13
|
+
output?: Record<string, unknown>;
|
|
14
|
+
completedAt?: number;
|
|
15
|
+
}
|
|
16
|
+
|
|
17
|
+
export interface StepProgress {
|
|
18
|
+
completed: number;
|
|
19
|
+
total: number;
|
|
20
|
+
percentage: number;
|
|
21
|
+
}
|
|
@@ -0,0 +1,86 @@
|
|
|
1
|
+
import { describe, it, expect, afterEach } from 'vitest';
|
|
2
|
+
import { ImprovementStore } from '../src/improvement-store.js';
|
|
3
|
+
import { mkdtempSync, rmSync } from 'node:fs';
|
|
4
|
+
import { join } from 'node:path';
|
|
5
|
+
import { tmpdir } from 'node:os';
|
|
6
|
+
import type { ImprovementProposal } from '../src/improvement-types.js';
|
|
7
|
+
|
|
8
|
+
describe('ImprovementStore', () => {
|
|
9
|
+
let store: ImprovementStore;
|
|
10
|
+
let tmpDir: string;
|
|
11
|
+
|
|
12
|
+
afterEach(() => {
|
|
13
|
+
store?.close();
|
|
14
|
+
if (tmpDir) rmSync(tmpDir, { recursive: true, force: true });
|
|
15
|
+
});
|
|
16
|
+
|
|
17
|
+
it('stores and retrieves proposals', () => {
|
|
18
|
+
tmpDir = mkdtempSync(join(tmpdir(), 'imp-'));
|
|
19
|
+
store = new ImprovementStore(join(tmpDir, 'improvements.db'));
|
|
20
|
+
|
|
21
|
+
const proposal: ImprovementProposal = {
|
|
22
|
+
observations: { accuracy: 0.85 },
|
|
23
|
+
reflections: { patterns: ['error on long inputs'] },
|
|
24
|
+
hypotheses: { proposals: [{ change: 'chunk inputs' }] },
|
|
25
|
+
validations: { testResults: [{ passed: true }] },
|
|
26
|
+
status: 'pending_review',
|
|
27
|
+
createdAt: Date.now(),
|
|
28
|
+
};
|
|
29
|
+
|
|
30
|
+
const id = store.record(proposal);
|
|
31
|
+
expect(id).toBeGreaterThan(0);
|
|
32
|
+
|
|
33
|
+
const retrieved = store.getById(id);
|
|
34
|
+
expect(retrieved).toBeDefined();
|
|
35
|
+
expect(retrieved!.status).toBe('pending_review');
|
|
36
|
+
expect(retrieved!.observations).toEqual({ accuracy: 0.85 });
|
|
37
|
+
});
|
|
38
|
+
|
|
39
|
+
it('updates proposal status', () => {
|
|
40
|
+
tmpDir = mkdtempSync(join(tmpdir(), 'imp-'));
|
|
41
|
+
store = new ImprovementStore(join(tmpDir, 'improvements.db'));
|
|
42
|
+
|
|
43
|
+
const id = store.record({
|
|
44
|
+
observations: {},
|
|
45
|
+
reflections: {},
|
|
46
|
+
hypotheses: {},
|
|
47
|
+
validations: {},
|
|
48
|
+
status: 'pending_review',
|
|
49
|
+
createdAt: Date.now(),
|
|
50
|
+
});
|
|
51
|
+
|
|
52
|
+
store.updateStatus(id, 'approved');
|
|
53
|
+
expect(store.getById(id)!.status).toBe('approved');
|
|
54
|
+
|
|
55
|
+
store.updateStatus(id, 'applied');
|
|
56
|
+
expect(store.getById(id)!.status).toBe('applied');
|
|
57
|
+
});
|
|
58
|
+
|
|
59
|
+
it('lists proposals by status', () => {
|
|
60
|
+
tmpDir = mkdtempSync(join(tmpdir(), 'imp-'));
|
|
61
|
+
store = new ImprovementStore(join(tmpDir, 'improvements.db'));
|
|
62
|
+
|
|
63
|
+
store.record({ observations: {}, reflections: {}, hypotheses: {}, validations: {}, status: 'pending_review', createdAt: 1000 });
|
|
64
|
+
store.record({ observations: {}, reflections: {}, hypotheses: {}, validations: {}, status: 'approved', createdAt: 2000 });
|
|
65
|
+
store.record({ observations: {}, reflections: {}, hypotheses: {}, validations: {}, status: 'pending_review', createdAt: 3000 });
|
|
66
|
+
|
|
67
|
+
const pending = store.getByStatus('pending_review');
|
|
68
|
+
expect(pending).toHaveLength(2);
|
|
69
|
+
|
|
70
|
+
const approved = store.getByStatus('approved');
|
|
71
|
+
expect(approved).toHaveLength(1);
|
|
72
|
+
});
|
|
73
|
+
|
|
74
|
+
it('returns recent proposals', () => {
|
|
75
|
+
tmpDir = mkdtempSync(join(tmpdir(), 'imp-'));
|
|
76
|
+
store = new ImprovementStore(join(tmpDir, 'improvements.db'));
|
|
77
|
+
|
|
78
|
+
for (let i = 0; i < 5; i++) {
|
|
79
|
+
store.record({ observations: { i }, reflections: {}, hypotheses: {}, validations: {}, status: 'pending_review', createdAt: i * 1000 });
|
|
80
|
+
}
|
|
81
|
+
|
|
82
|
+
const recent = store.getRecent(2);
|
|
83
|
+
expect(recent).toHaveLength(2);
|
|
84
|
+
expect((recent[0].observations as Record<string, number>).i).toBe(4);
|
|
85
|
+
});
|
|
86
|
+
});
|
|
@@ -0,0 +1,95 @@
|
|
|
1
|
+
import { describe, it, expect } from 'vitest';
|
|
2
|
+
import { MetaImprovementStructure } from '../src/meta-improvement.js';
|
|
3
|
+
import type { ImprovementProposal } from '../src/improvement-types.js';
|
|
4
|
+
|
|
5
|
+
describe('MetaImprovementStructure', () => {
|
|
6
|
+
it('creates a 4-step reasoning structure', () => {
|
|
7
|
+
const meta = new MetaImprovementStructure();
|
|
8
|
+
const progress = meta.getProgress();
|
|
9
|
+
|
|
10
|
+
expect(progress.total).toBe(4);
|
|
11
|
+
expect(progress.completed).toBe(0);
|
|
12
|
+
expect(meta.getCurrentStepName()).toBe('observe');
|
|
13
|
+
});
|
|
14
|
+
|
|
15
|
+
it('progresses through steps in order', () => {
|
|
16
|
+
const meta = new MetaImprovementStructure();
|
|
17
|
+
|
|
18
|
+
meta.completeStep('observe', {
|
|
19
|
+
metrics: { accuracy: 0.85, latency_p50: 200 },
|
|
20
|
+
anomalies: ['High error rate on code reviews'],
|
|
21
|
+
});
|
|
22
|
+
expect(meta.getCurrentStepName()).toBe('reflect');
|
|
23
|
+
|
|
24
|
+
meta.completeStep('reflect', {
|
|
25
|
+
patterns: ['Code review errors correlate with long inputs'],
|
|
26
|
+
rootCauses: ['Context window truncation on large diffs'],
|
|
27
|
+
});
|
|
28
|
+
expect(meta.getCurrentStepName()).toBe('hypothesize');
|
|
29
|
+
|
|
30
|
+
meta.completeStep('hypothesize', {
|
|
31
|
+
proposals: [
|
|
32
|
+
{ change: 'Chunk large diffs before review', confidence: 0.8 },
|
|
33
|
+
{ change: 'Increase context window budget', confidence: 0.6 },
|
|
34
|
+
],
|
|
35
|
+
});
|
|
36
|
+
expect(meta.getCurrentStepName()).toBe('validate');
|
|
37
|
+
});
|
|
38
|
+
|
|
39
|
+
it('builds improvement proposal from step outputs', () => {
|
|
40
|
+
const meta = new MetaImprovementStructure();
|
|
41
|
+
|
|
42
|
+
meta.completeStep('observe', { metrics: { accuracy: 0.85 } });
|
|
43
|
+
meta.completeStep('reflect', { patterns: ['Error on long inputs'] });
|
|
44
|
+
meta.completeStep('hypothesize', {
|
|
45
|
+
proposals: [{ change: 'Chunk inputs', confidence: 0.8 }],
|
|
46
|
+
});
|
|
47
|
+
meta.completeStep('validate', {
|
|
48
|
+
testResults: [{ proposal: 'Chunk inputs', passed: true, improvement: 0.12 }],
|
|
49
|
+
});
|
|
50
|
+
|
|
51
|
+
expect(meta.isComplete()).toBe(true);
|
|
52
|
+
const proposal = meta.buildProposal();
|
|
53
|
+
expect(proposal).toBeDefined();
|
|
54
|
+
expect(proposal!.observations).toBeDefined();
|
|
55
|
+
expect(proposal!.reflections).toBeDefined();
|
|
56
|
+
expect(proposal!.hypotheses).toBeDefined();
|
|
57
|
+
expect(proposal!.validations).toBeDefined();
|
|
58
|
+
expect(proposal!.status).toBe('pending_review');
|
|
59
|
+
});
|
|
60
|
+
|
|
61
|
+
it('generates tools for the current step', () => {
|
|
62
|
+
const meta = new MetaImprovementStructure();
|
|
63
|
+
const tools = meta.getCurrentTools();
|
|
64
|
+
|
|
65
|
+
expect(tools).toHaveLength(1);
|
|
66
|
+
expect(tools[0].name).toContain('observe');
|
|
67
|
+
});
|
|
68
|
+
|
|
69
|
+
it('returns empty tools when all steps are complete', () => {
|
|
70
|
+
const meta = new MetaImprovementStructure();
|
|
71
|
+
|
|
72
|
+
meta.completeStep('observe', { metrics: {} });
|
|
73
|
+
meta.completeStep('reflect', { patterns: [] });
|
|
74
|
+
meta.completeStep('hypothesize', { proposals: [] });
|
|
75
|
+
meta.completeStep('validate', { testResults: [] });
|
|
76
|
+
|
|
77
|
+
const tools = meta.getCurrentTools();
|
|
78
|
+
expect(tools).toHaveLength(0);
|
|
79
|
+
});
|
|
80
|
+
|
|
81
|
+
it('rejects completing steps out of order', () => {
|
|
82
|
+
const meta = new MetaImprovementStructure();
|
|
83
|
+
|
|
84
|
+
expect(() => meta.completeStep('reflect', { patterns: [] })).toThrow();
|
|
85
|
+
});
|
|
86
|
+
|
|
87
|
+
it('provides step descriptions for LLM context', () => {
|
|
88
|
+
const meta = new MetaImprovementStructure();
|
|
89
|
+
const descriptions = meta.getStepDescriptions();
|
|
90
|
+
|
|
91
|
+
expect(descriptions).toHaveLength(4);
|
|
92
|
+
expect(descriptions[0].name).toBe('observe');
|
|
93
|
+
expect(descriptions[0].description).toBeTruthy();
|
|
94
|
+
});
|
|
95
|
+
});
|
|
@@ -0,0 +1,85 @@
|
|
|
1
|
+
import { describe, it, expect } from 'vitest';
|
|
2
|
+
import type { ReasoningStep } from '../src/types.js';
|
|
3
|
+
import { StepRegistry } from '../src/step-registry.js';
|
|
4
|
+
|
|
5
|
+
function makeSteps(): ReasoningStep[] {
|
|
6
|
+
return [
|
|
7
|
+
{ name: 'analyze', description: 'Analyze the problem', order: 1, required: true },
|
|
8
|
+
{ name: 'plan', description: 'Plan a solution', order: 2, required: true },
|
|
9
|
+
{ name: 'validate', description: 'Validate the plan', order: 3, required: false },
|
|
10
|
+
{ name: 'apply', description: 'Apply the solution', order: 4, required: true },
|
|
11
|
+
];
|
|
12
|
+
}
|
|
13
|
+
|
|
14
|
+
describe('StepRegistry', () => {
|
|
15
|
+
it('tracks step completion in order', () => {
|
|
16
|
+
const registry = new StepRegistry(makeSteps());
|
|
17
|
+
|
|
18
|
+
expect(registry.currentStep()?.name).toBe('analyze');
|
|
19
|
+
registry.complete('analyze', { result: 'ok' });
|
|
20
|
+
|
|
21
|
+
expect(registry.currentStep()?.name).toBe('plan');
|
|
22
|
+
registry.complete('plan', { strategy: 'incremental' });
|
|
23
|
+
|
|
24
|
+
expect(registry.currentStep()?.name).toBe('validate');
|
|
25
|
+
});
|
|
26
|
+
|
|
27
|
+
it('allows skipping optional steps', () => {
|
|
28
|
+
const registry = new StepRegistry(makeSteps());
|
|
29
|
+
|
|
30
|
+
registry.complete('analyze');
|
|
31
|
+
registry.complete('plan');
|
|
32
|
+
expect(registry.canSkip('validate')).toBe(true);
|
|
33
|
+
registry.skip('validate');
|
|
34
|
+
|
|
35
|
+
expect(registry.currentStep()?.name).toBe('apply');
|
|
36
|
+
});
|
|
37
|
+
|
|
38
|
+
it('rejects out-of-order completion', () => {
|
|
39
|
+
const registry = new StepRegistry(makeSteps());
|
|
40
|
+
|
|
41
|
+
expect(() => registry.complete('plan')).toThrow(/not available/);
|
|
42
|
+
});
|
|
43
|
+
|
|
44
|
+
it('rejects skipping required steps', () => {
|
|
45
|
+
const registry = new StepRegistry(makeSteps());
|
|
46
|
+
|
|
47
|
+
expect(() => registry.skip('analyze')).toThrow(/required/);
|
|
48
|
+
});
|
|
49
|
+
|
|
50
|
+
it('reports overall progress', () => {
|
|
51
|
+
const registry = new StepRegistry(makeSteps());
|
|
52
|
+
|
|
53
|
+
registry.complete('analyze');
|
|
54
|
+
const progress = registry.progress();
|
|
55
|
+
expect(progress.completed).toBe(1);
|
|
56
|
+
expect(progress.total).toBe(4);
|
|
57
|
+
expect(progress.percentage).toBe(25);
|
|
58
|
+
});
|
|
59
|
+
|
|
60
|
+
it('reports completion when all required steps done', () => {
|
|
61
|
+
const registry = new StepRegistry(makeSteps());
|
|
62
|
+
|
|
63
|
+
expect(registry.isComplete()).toBe(false);
|
|
64
|
+
registry.complete('analyze');
|
|
65
|
+
registry.complete('plan');
|
|
66
|
+
registry.skip('validate');
|
|
67
|
+
registry.complete('apply');
|
|
68
|
+
expect(registry.isComplete()).toBe(true);
|
|
69
|
+
});
|
|
70
|
+
|
|
71
|
+
it('collects outputs from all completed steps', () => {
|
|
72
|
+
const registry = new StepRegistry(makeSteps());
|
|
73
|
+
|
|
74
|
+
registry.complete('analyze', { findings: ['a', 'b'] });
|
|
75
|
+
registry.complete('plan', { strategy: 'fast' });
|
|
76
|
+
registry.skip('validate');
|
|
77
|
+
registry.complete('apply', { applied: true });
|
|
78
|
+
|
|
79
|
+
const outputs = registry.getOutputs();
|
|
80
|
+
expect(outputs.size).toBe(3);
|
|
81
|
+
expect(outputs.get('analyze')).toEqual({ findings: ['a', 'b'] });
|
|
82
|
+
expect(outputs.get('plan')).toEqual({ strategy: 'fast' });
|
|
83
|
+
expect(outputs.get('apply')).toEqual({ applied: true });
|
|
84
|
+
});
|
|
85
|
+
});
|
|
@@ -0,0 +1,75 @@
|
|
|
1
|
+
import { describe, it, expect } from 'vitest';
|
|
2
|
+
import { StepRegistry } from '../src/step-registry.js';
|
|
3
|
+
import { StepToolGenerator } from '../src/step-tools.js';
|
|
4
|
+
import type { ReasoningStep } from '../src/types.js';
|
|
5
|
+
|
|
6
|
+
function makeSteps(): ReasoningStep[] {
|
|
7
|
+
return [
|
|
8
|
+
{ name: 'gather', description: 'Gather information', order: 1, required: true },
|
|
9
|
+
{ name: 'analyze', description: 'Analyze data', order: 2, required: true },
|
|
10
|
+
{ name: 'conclude', description: 'Draw conclusions', order: 3, required: true },
|
|
11
|
+
];
|
|
12
|
+
}
|
|
13
|
+
|
|
14
|
+
describe('StepToolGenerator', () => {
|
|
15
|
+
it('generates tool for current step only', () => {
|
|
16
|
+
const registry = new StepRegistry(makeSteps());
|
|
17
|
+
const generator = new StepToolGenerator(registry);
|
|
18
|
+
const tools = generator.getCurrentTools();
|
|
19
|
+
|
|
20
|
+
expect(tools).toHaveLength(1);
|
|
21
|
+
expect(tools[0].name).toBe('reasoning_gather');
|
|
22
|
+
expect(tools[0].description).toBe('[Reasoning Step 1] Gather information');
|
|
23
|
+
});
|
|
24
|
+
|
|
25
|
+
it('tool invocation completes step and advances', async () => {
|
|
26
|
+
const registry = new StepRegistry(makeSteps());
|
|
27
|
+
const generator = new StepToolGenerator(registry);
|
|
28
|
+
|
|
29
|
+
const tools = generator.getCurrentTools();
|
|
30
|
+
await tools[0].run({ result: 'done' });
|
|
31
|
+
|
|
32
|
+
const nextTools = generator.getCurrentTools();
|
|
33
|
+
expect(nextTools).toHaveLength(1);
|
|
34
|
+
expect(nextTools[0].name).toBe('reasoning_analyze');
|
|
35
|
+
});
|
|
36
|
+
|
|
37
|
+
it('returns empty tools when all steps complete', async () => {
|
|
38
|
+
const registry = new StepRegistry(makeSteps());
|
|
39
|
+
const generator = new StepToolGenerator(registry);
|
|
40
|
+
|
|
41
|
+
// Complete all three steps sequentially
|
|
42
|
+
let tools = generator.getCurrentTools();
|
|
43
|
+
await tools[0].run({ result: 'gathered' });
|
|
44
|
+
|
|
45
|
+
tools = generator.getCurrentTools();
|
|
46
|
+
await tools[0].run({ result: 'analyzed' });
|
|
47
|
+
|
|
48
|
+
tools = generator.getCurrentTools();
|
|
49
|
+
await tools[0].run({ result: 'concluded' });
|
|
50
|
+
|
|
51
|
+
const finalTools = generator.getCurrentTools();
|
|
52
|
+
expect(finalTools).toHaveLength(0);
|
|
53
|
+
});
|
|
54
|
+
|
|
55
|
+
it('tool has AUTO_APPROVE permission', () => {
|
|
56
|
+
const registry = new StepRegistry(makeSteps());
|
|
57
|
+
const generator = new StepToolGenerator(registry);
|
|
58
|
+
const tools = generator.getCurrentTools();
|
|
59
|
+
|
|
60
|
+
expect(tools[0].getPermission()).toBe('AUTO_APPROVE');
|
|
61
|
+
});
|
|
62
|
+
|
|
63
|
+
it('includes progress in tool result', async () => {
|
|
64
|
+
const registry = new StepRegistry(makeSteps());
|
|
65
|
+
const generator = new StepToolGenerator(registry);
|
|
66
|
+
|
|
67
|
+
const tools = generator.getCurrentTools();
|
|
68
|
+
const result = await tools[0].run({ result: 'gathered' });
|
|
69
|
+
|
|
70
|
+
expect(result.success).toBe(true);
|
|
71
|
+
expect(result.data.progress).toEqual({ completed: 1, total: 3, percentage: 33 });
|
|
72
|
+
expect(result.data.step).toBe('gather');
|
|
73
|
+
expect(result.data.nextStep).toBe('analyze');
|
|
74
|
+
});
|
|
75
|
+
});
|