@cotal-ai/lang 0.0.0 → 0.15.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 +202 -0
- package/dist/dryrun.d.ts +106 -0
- package/dist/dryrun.d.ts.map +1 -0
- package/dist/dryrun.js +172 -0
- package/dist/dryrun.js.map +1 -0
- package/dist/duration.d.ts +12 -0
- package/dist/duration.d.ts.map +1 -0
- package/dist/duration.js +34 -0
- package/dist/duration.js.map +1 -0
- package/dist/effects.d.ts +231 -0
- package/dist/effects.d.ts.map +1 -0
- package/dist/effects.js +64 -0
- package/dist/effects.js.map +1 -0
- package/dist/errors.d.ts +141 -0
- package/dist/errors.d.ts.map +1 -0
- package/dist/errors.js +163 -0
- package/dist/errors.js.map +1 -0
- package/dist/grammar.d.ts +28 -0
- package/dist/grammar.d.ts.map +1 -0
- package/dist/grammar.js +793 -0
- package/dist/grammar.js.map +1 -0
- package/dist/index.d.ts +23 -0
- package/dist/index.d.ts.map +1 -0
- package/dist/index.js +23 -0
- package/dist/index.js.map +1 -0
- package/dist/interpret.d.ts +89 -0
- package/dist/interpret.d.ts.map +1 -0
- package/dist/interpret.js +1117 -0
- package/dist/interpret.js.map +1 -0
- package/dist/journal.d.ts +177 -0
- package/dist/journal.d.ts.map +1 -0
- package/dist/journal.js +198 -0
- package/dist/journal.js.map +1 -0
- package/dist/keys.d.ts +87 -0
- package/dist/keys.d.ts.map +1 -0
- package/dist/keys.js +105 -0
- package/dist/keys.js.map +1 -0
- package/dist/primitives.d.ts +84 -0
- package/dist/primitives.d.ts.map +1 -0
- package/dist/primitives.js +265 -0
- package/dist/primitives.js.map +1 -0
- package/dist/sim.d.ts +101 -0
- package/dist/sim.d.ts.map +1 -0
- package/dist/sim.js +192 -0
- package/dist/sim.js.map +1 -0
- package/dist/values.d.ts +35 -0
- package/dist/values.d.ts.map +1 -0
- package/dist/values.js +0 -0
- package/dist/values.js.map +1 -0
- package/package.json +27 -7
- package/README.md +0 -10
package/LICENSE
ADDED
|
@@ -0,0 +1,202 @@
|
|
|
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 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 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 those 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
|
+
APPENDIX: How to apply the Apache License to your work.
|
|
180
|
+
|
|
181
|
+
To apply the Apache License to your work, attach the following
|
|
182
|
+
boilerplate notice, with the fields enclosed by brackets "[]"
|
|
183
|
+
replaced with your own identifying information. (Don't include
|
|
184
|
+
the brackets!) The text should be enclosed in the appropriate
|
|
185
|
+
comment syntax for the file format. We also recommend that a
|
|
186
|
+
file or class name and description of purpose be included on the
|
|
187
|
+
same "printed page" as the copyright notice for easier
|
|
188
|
+
identification within third-party archives.
|
|
189
|
+
|
|
190
|
+
Copyright [yyyy] [name of copyright owner]
|
|
191
|
+
|
|
192
|
+
Licensed under the Apache License, Version 2.0 (the "License");
|
|
193
|
+
you may not use this file except in compliance with the License.
|
|
194
|
+
You may obtain a copy of the License at
|
|
195
|
+
|
|
196
|
+
http://www.apache.org/licenses/LICENSE-2.0
|
|
197
|
+
|
|
198
|
+
Unless required by applicable law or agreed to in writing, software
|
|
199
|
+
distributed under the License is distributed on an "AS IS" BASIS,
|
|
200
|
+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
201
|
+
See the License for the specific language governing permissions and
|
|
202
|
+
limitations under the License.
|
package/dist/dryrun.d.ts
ADDED
|
@@ -0,0 +1,106 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Dry run: simulate a program and report what it WOULD do, before it does it. `plan` before
|
|
3
|
+
* `apply`.
|
|
4
|
+
*
|
|
5
|
+
* The report is built by wrapping any {@link EffectHandler} in a recorder rather than by teaching
|
|
6
|
+
* the simulator to describe itself. That matters for a reason beyond tidiness: the recorder sees
|
|
7
|
+
* exactly what the interpreter hands a handler, so a dry run cannot describe a program differently
|
|
8
|
+
* from the way it would be executed. A reporter that reads the source separately can drift from the
|
|
9
|
+
* runtime; this one is downstream of the same call.
|
|
10
|
+
*
|
|
11
|
+
* It also means the recorder works over the production handler, which is what makes "the run I
|
|
12
|
+
* dry-ran is the run I got" checkable later rather than promised now.
|
|
13
|
+
*
|
|
14
|
+
* What a dry run answers: which effects run and in what order, which agents get spawned and on what
|
|
15
|
+
* permits, and which checkpoints a human will be asked to sit in front of. That last one is the
|
|
16
|
+
* point of the feature. A program that quietly stops on a checkpoint at 3am is a fact worth having
|
|
17
|
+
* before the run starts, not after.
|
|
18
|
+
*/
|
|
19
|
+
import { type SimScript } from "./sim.js";
|
|
20
|
+
import type { Journal } from "./journal.js";
|
|
21
|
+
import type { AgentHandleValue, AskRequest, ChannelHandleValue, CheckpointRequest, CheckpointRaw, ConclaveRequest, EffectContext, EffectHandler, MonitorRequest, NotifyRequest, SleepRequest, SpawnRequest, TurnRequest, TurnResultValue, WaitRequest } from "./effects.js";
|
|
22
|
+
/** One effect, in the order the run reached it. */
|
|
23
|
+
export interface PlannedEffect {
|
|
24
|
+
readonly step: string;
|
|
25
|
+
readonly kind: string;
|
|
26
|
+
readonly name: string;
|
|
27
|
+
/** `ok`, `failed`, or `cancelled`. A cancelled branch is part of the plan and says so. */
|
|
28
|
+
readonly status: string;
|
|
29
|
+
}
|
|
30
|
+
/** An agent the program would spawn, with the permits it would hold. */
|
|
31
|
+
export interface PlannedAgent {
|
|
32
|
+
readonly persona: string;
|
|
33
|
+
readonly worktree?: string;
|
|
34
|
+
readonly role?: string;
|
|
35
|
+
readonly permits?: Readonly<Record<string, unknown>>;
|
|
36
|
+
readonly joins: readonly string[];
|
|
37
|
+
}
|
|
38
|
+
/** A point where the run stops and waits for a person. */
|
|
39
|
+
export interface PlannedCheckpoint {
|
|
40
|
+
readonly step: string;
|
|
41
|
+
readonly name: string;
|
|
42
|
+
readonly prompt: string;
|
|
43
|
+
readonly timeout?: string;
|
|
44
|
+
readonly onExpiry?: string;
|
|
45
|
+
readonly to?: string;
|
|
46
|
+
}
|
|
47
|
+
export interface DryRunReport {
|
|
48
|
+
readonly effects: readonly PlannedEffect[];
|
|
49
|
+
readonly agents: readonly PlannedAgent[];
|
|
50
|
+
readonly checkpoints: readonly PlannedCheckpoint[];
|
|
51
|
+
/** Total virtual time the simulated run consumed, in ms. */
|
|
52
|
+
readonly elapsedMs: number;
|
|
53
|
+
readonly steps: number;
|
|
54
|
+
/**
|
|
55
|
+
* Script entries the run never reached, usually a renamed step. Surfaced in the report rather
|
|
56
|
+
* than left for someone to ask about: a script that silently stops matching is a test that
|
|
57
|
+
* silently stops testing.
|
|
58
|
+
*/
|
|
59
|
+
readonly unusedScript: readonly string[];
|
|
60
|
+
readonly journal: Journal;
|
|
61
|
+
}
|
|
62
|
+
/**
|
|
63
|
+
* Wrap a handler so every request through it is recorded, and delegate everything unchanged.
|
|
64
|
+
*
|
|
65
|
+
* Deliberately NOT a `SimHandler` subclass. A dry run over the production handler is the thing
|
|
66
|
+
* that makes the report worth trusting, and inheritance would tie it to simulation forever.
|
|
67
|
+
*/
|
|
68
|
+
export declare class RecordingHandler implements EffectHandler {
|
|
69
|
+
private readonly inner;
|
|
70
|
+
readonly spawns: SpawnRequest[];
|
|
71
|
+
readonly checkpointsAsked: {
|
|
72
|
+
req: CheckpointRequest;
|
|
73
|
+
step: string;
|
|
74
|
+
}[];
|
|
75
|
+
constructor(inner: EffectHandler);
|
|
76
|
+
now(): number;
|
|
77
|
+
spawn(req: SpawnRequest, ctx: EffectContext): Promise<AgentHandleValue>;
|
|
78
|
+
checkpoint(req: CheckpointRequest, ctx: EffectContext): Promise<CheckpointRaw>;
|
|
79
|
+
turn(req: TurnRequest, ctx: EffectContext): Promise<TurnResultValue>;
|
|
80
|
+
ask(req: AskRequest, ctx: EffectContext): Promise<unknown>;
|
|
81
|
+
sleep(req: SleepRequest, ctx: EffectContext): Promise<null>;
|
|
82
|
+
wait(req: WaitRequest, ctx: EffectContext): Promise<unknown | null>;
|
|
83
|
+
notify(req: NotifyRequest, ctx: EffectContext): Promise<null>;
|
|
84
|
+
monitor(req: MonitorRequest, ctx: EffectContext): Promise<null>;
|
|
85
|
+
openConclave(req: ConclaveRequest, ctx: EffectContext): Promise<ChannelHandleValue>;
|
|
86
|
+
closeConclave(req: ConclaveRequest, ctx: EffectContext): Promise<null>;
|
|
87
|
+
}
|
|
88
|
+
export interface DryRunOptions {
|
|
89
|
+
readonly runId?: string;
|
|
90
|
+
readonly seed?: string;
|
|
91
|
+
readonly file?: string;
|
|
92
|
+
readonly stepBudget?: number;
|
|
93
|
+
readonly yieldEvery?: number;
|
|
94
|
+
}
|
|
95
|
+
/**
|
|
96
|
+
* Simulate `source` under `script` and report what it would do.
|
|
97
|
+
*
|
|
98
|
+
* The simulator refuses any unscripted effect (L6001), so a dry run of a program whose script does
|
|
99
|
+
* not cover it FAILS rather than reporting a shorter plan. That is the intended behaviour and it is
|
|
100
|
+
* the whole reason to trust the output: a report that stopped early and said so is useful, and one
|
|
101
|
+
* that quietly described half a program would be worse than no report.
|
|
102
|
+
*/
|
|
103
|
+
export declare function dryRun(source: string, script?: SimScript, options?: DryRunOptions): Promise<DryRunReport>;
|
|
104
|
+
/** Render a report for a human. The order is the order the run would take. */
|
|
105
|
+
export declare function renderReport(report: DryRunReport): string;
|
|
106
|
+
//# sourceMappingURL=dryrun.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"dryrun.d.ts","sourceRoot":"","sources":["../src/dryrun.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;GAiBG;AAGH,OAAO,EAAc,KAAK,SAAS,EAAE,MAAM,UAAU,CAAC;AAEtD,OAAO,KAAK,EAAE,OAAO,EAAE,MAAM,cAAc,CAAC;AAC5C,OAAO,KAAK,EACV,gBAAgB,EAChB,UAAU,EACV,kBAAkB,EAClB,iBAAiB,EACjB,aAAa,EACb,eAAe,EACf,aAAa,EACb,aAAa,EACb,cAAc,EACd,aAAa,EACb,YAAY,EACZ,YAAY,EACZ,WAAW,EACX,eAAe,EACf,WAAW,EACZ,MAAM,cAAc,CAAC;AAEtB,mDAAmD;AACnD,MAAM,WAAW,aAAa;IAC5B,QAAQ,CAAC,IAAI,EAAE,MAAM,CAAC;IACtB,QAAQ,CAAC,IAAI,EAAE,MAAM,CAAC;IACtB,QAAQ,CAAC,IAAI,EAAE,MAAM,CAAC;IACtB,0FAA0F;IAC1F,QAAQ,CAAC,MAAM,EAAE,MAAM,CAAC;CACzB;AAED,wEAAwE;AACxE,MAAM,WAAW,YAAY;IAC3B,QAAQ,CAAC,OAAO,EAAE,MAAM,CAAC;IACzB,QAAQ,CAAC,QAAQ,CAAC,EAAE,MAAM,CAAC;IAC3B,QAAQ,CAAC,IAAI,CAAC,EAAE,MAAM,CAAC;IACvB,QAAQ,CAAC,OAAO,CAAC,EAAE,QAAQ,CAAC,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,CA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AAC,YAAY,CAAC,CAkDvB;AAED,8EAA8E;AAC9E,wBAAgB,YAAY,CAAC,MAAM,EAAE,YAAY,GAAG,MAAM,CA8CzD"}
|
package/dist/dryrun.js
ADDED
|
@@ -0,0 +1,172 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Dry run: simulate a program and report what it WOULD do, before it does it. `plan` before
|
|
3
|
+
* `apply`.
|
|
4
|
+
*
|
|
5
|
+
* The report is built by wrapping any {@link EffectHandler} in a recorder rather than by teaching
|
|
6
|
+
* the simulator to describe itself. That matters for a reason beyond tidiness: the recorder sees
|
|
7
|
+
* exactly what the interpreter hands a handler, so a dry run cannot describe a program differently
|
|
8
|
+
* from the way it would be executed. A reporter that reads the source separately can drift from the
|
|
9
|
+
* runtime; this one is downstream of the same call.
|
|
10
|
+
*
|
|
11
|
+
* It also means the recorder works over the production handler, which is what makes "the run I
|
|
12
|
+
* dry-ran is the run I got" checkable later rather than promised now.
|
|
13
|
+
*
|
|
14
|
+
* What a dry run answers: which effects run and in what order, which agents get spawned and on what
|
|
15
|
+
* permits, and which checkpoints a human will be asked to sit in front of. That last one is the
|
|
16
|
+
* point of the feature. A program that quietly stops on a checkpoint at 3am is a fact worth having
|
|
17
|
+
* before the run starts, not after.
|
|
18
|
+
*/
|
|
19
|
+
import { run } from "./interpret.js";
|
|
20
|
+
import { SimHandler } from "./sim.js";
|
|
21
|
+
import { stepKeyString } from "./keys.js";
|
|
22
|
+
/**
|
|
23
|
+
* Wrap a handler so every request through it is recorded, and delegate everything unchanged.
|
|
24
|
+
*
|
|
25
|
+
* Deliberately NOT a `SimHandler` subclass. A dry run over the production handler is the thing
|
|
26
|
+
* that makes the report worth trusting, and inheritance would tie it to simulation forever.
|
|
27
|
+
*/
|
|
28
|
+
export class RecordingHandler {
|
|
29
|
+
inner;
|
|
30
|
+
spawns = [];
|
|
31
|
+
checkpointsAsked = [];
|
|
32
|
+
constructor(inner) {
|
|
33
|
+
this.inner = inner;
|
|
34
|
+
}
|
|
35
|
+
now() {
|
|
36
|
+
return this.inner.now();
|
|
37
|
+
}
|
|
38
|
+
async spawn(req, ctx) {
|
|
39
|
+
this.spawns.push(req);
|
|
40
|
+
return await this.inner.spawn(req, ctx);
|
|
41
|
+
}
|
|
42
|
+
async checkpoint(req, ctx) {
|
|
43
|
+
this.checkpointsAsked.push({ req, step: stepKeyString(ctx.key) });
|
|
44
|
+
return await this.inner.checkpoint(req, ctx);
|
|
45
|
+
}
|
|
46
|
+
async turn(req, ctx) {
|
|
47
|
+
return await this.inner.turn(req, ctx);
|
|
48
|
+
}
|
|
49
|
+
async ask(req, ctx) {
|
|
50
|
+
return await this.inner.ask(req, ctx);
|
|
51
|
+
}
|
|
52
|
+
async sleep(req, ctx) {
|
|
53
|
+
return await this.inner.sleep(req, ctx);
|
|
54
|
+
}
|
|
55
|
+
async wait(req, ctx) {
|
|
56
|
+
return await this.inner.wait(req, ctx);
|
|
57
|
+
}
|
|
58
|
+
async notify(req, ctx) {
|
|
59
|
+
return await this.inner.notify(req, ctx);
|
|
60
|
+
}
|
|
61
|
+
async monitor(req, ctx) {
|
|
62
|
+
return await this.inner.monitor(req, ctx);
|
|
63
|
+
}
|
|
64
|
+
async openConclave(req, ctx) {
|
|
65
|
+
return await this.inner.openConclave(req, ctx);
|
|
66
|
+
}
|
|
67
|
+
async closeConclave(req, ctx) {
|
|
68
|
+
return await this.inner.closeConclave(req, ctx);
|
|
69
|
+
}
|
|
70
|
+
}
|
|
71
|
+
/**
|
|
72
|
+
* Simulate `source` under `script` and report what it would do.
|
|
73
|
+
*
|
|
74
|
+
* The simulator refuses any unscripted effect (L6001), so a dry run of a program whose script does
|
|
75
|
+
* not cover it FAILS rather than reporting a shorter plan. That is the intended behaviour and it is
|
|
76
|
+
* the whole reason to trust the output: a report that stopped early and said so is useful, and one
|
|
77
|
+
* that quietly described half a program would be worse than no report.
|
|
78
|
+
*/
|
|
79
|
+
export async function dryRun(source, script = {}, options = {}) {
|
|
80
|
+
const sim = new SimHandler(script);
|
|
81
|
+
const startedAt = sim.now();
|
|
82
|
+
const recorder = new RecordingHandler(sim);
|
|
83
|
+
const result = await run(source, {
|
|
84
|
+
runId: options.runId ?? "dry-run",
|
|
85
|
+
handler: recorder,
|
|
86
|
+
...(options.seed !== undefined ? { seed: options.seed } : {}),
|
|
87
|
+
...(options.file !== undefined ? { file: options.file } : {}),
|
|
88
|
+
...(options.stepBudget !== undefined ? { stepBudget: options.stepBudget } : {}),
|
|
89
|
+
...(options.yieldEvery !== undefined ? { yieldEvery: options.yieldEvery } : {}),
|
|
90
|
+
});
|
|
91
|
+
const effects = result.journal.entries().map((e) => ({
|
|
92
|
+
step: `${e.scope}/${e.kind}${e.name === "" ? "" : `:${e.name}`}#${e.occurrence}`,
|
|
93
|
+
kind: e.kind,
|
|
94
|
+
name: e.name,
|
|
95
|
+
status: e.status ?? e.state,
|
|
96
|
+
}));
|
|
97
|
+
const agents = recorder.spawns.map((s) => ({
|
|
98
|
+
persona: s.persona,
|
|
99
|
+
...(s.worktree !== undefined ? { worktree: s.worktree } : {}),
|
|
100
|
+
...(s.role !== undefined ? { role: s.role } : {}),
|
|
101
|
+
...(s.permits !== undefined ? { permits: s.permits } : {}),
|
|
102
|
+
joins: (s.join ?? []).map((c) => c.channel),
|
|
103
|
+
}));
|
|
104
|
+
const checkpoints = recorder.checkpointsAsked.map(({ req, step }) => {
|
|
105
|
+
const name = step.slice(step.lastIndexOf(":") + 1, step.lastIndexOf("#"));
|
|
106
|
+
return {
|
|
107
|
+
step,
|
|
108
|
+
name,
|
|
109
|
+
prompt: req.prompt,
|
|
110
|
+
...(req.timeout !== undefined ? { timeout: req.timeout } : {}),
|
|
111
|
+
...(req.onExpiry !== undefined ? { onExpiry: req.onExpiry } : {}),
|
|
112
|
+
...(req.to !== undefined ? { to: req.to } : {}),
|
|
113
|
+
};
|
|
114
|
+
});
|
|
115
|
+
return {
|
|
116
|
+
effects,
|
|
117
|
+
agents,
|
|
118
|
+
checkpoints,
|
|
119
|
+
elapsedMs: sim.now() - startedAt,
|
|
120
|
+
steps: result.steps,
|
|
121
|
+
unusedScript: sim.unusedScript(),
|
|
122
|
+
journal: result.journal,
|
|
123
|
+
};
|
|
124
|
+
}
|
|
125
|
+
/** Render a report for a human. The order is the order the run would take. */
|
|
126
|
+
export function renderReport(report) {
|
|
127
|
+
const out = [];
|
|
128
|
+
const dur = (ms) => {
|
|
129
|
+
if (ms < 1_000)
|
|
130
|
+
return `${ms}ms`;
|
|
131
|
+
if (ms < 60_000)
|
|
132
|
+
return `${Math.round(ms / 1_000)}s`;
|
|
133
|
+
if (ms < 3_600_000)
|
|
134
|
+
return `${Math.round(ms / 60_000)}m`;
|
|
135
|
+
return `${(ms / 3_600_000).toFixed(1)}h`;
|
|
136
|
+
};
|
|
137
|
+
out.push(`Dry run: ${report.effects.length} effects, ${report.agents.length} agents, ${dur(report.elapsedMs)} of simulated time.`);
|
|
138
|
+
if (report.checkpoints.length > 0) {
|
|
139
|
+
// First, and named as a person's problem rather than a step type. This is the part of the
|
|
140
|
+
// report someone acts on before starting the run.
|
|
141
|
+
out.push("", `A person is asked ${report.checkpoints.length} time(s):`);
|
|
142
|
+
for (const c of report.checkpoints) {
|
|
143
|
+
const on = c.onExpiry === undefined ? "" : `, then ${c.onExpiry}`;
|
|
144
|
+
const t = c.timeout === undefined ? "waits indefinitely" : `waits ${c.timeout}${on}`;
|
|
145
|
+
out.push(` ${c.name} "${c.prompt}" (${t})`);
|
|
146
|
+
}
|
|
147
|
+
}
|
|
148
|
+
else {
|
|
149
|
+
out.push("", "No checkpoints: this run never stops for a person.");
|
|
150
|
+
}
|
|
151
|
+
if (report.agents.length > 0) {
|
|
152
|
+
out.push("", "Agents:");
|
|
153
|
+
for (const a of report.agents) {
|
|
154
|
+
const bits = [
|
|
155
|
+
a.worktree === undefined ? null : `worktree ${a.worktree}`,
|
|
156
|
+
a.role === undefined ? null : `role ${a.role}`,
|
|
157
|
+
a.permits === undefined ? null : `permits ${JSON.stringify(a.permits)}`,
|
|
158
|
+
a.joins.length === 0 ? null : `joins ${a.joins.join(", ")}`,
|
|
159
|
+
].filter((x) => x !== null);
|
|
160
|
+
out.push(` ${a.persona}${bits.length === 0 ? "" : ` ${bits.join(" ")}`}`);
|
|
161
|
+
}
|
|
162
|
+
}
|
|
163
|
+
out.push("", "Effects, in order:");
|
|
164
|
+
for (const e of report.effects) {
|
|
165
|
+
out.push(` ${e.status === "ok" ? " " : "!"} ${e.step}${e.status === "ok" ? "" : ` ${e.status}`}`);
|
|
166
|
+
}
|
|
167
|
+
if (report.unusedScript.length > 0) {
|
|
168
|
+
out.push("", `Script entries never reached: ${report.unusedScript.join(", ")}`);
|
|
169
|
+
}
|
|
170
|
+
return out.join("\n");
|
|
171
|
+
}
|
|
172
|
+
//# sourceMappingURL=dryrun.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"dryrun.js","sourceRoot":"","sources":["../src/dryrun.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;GAiBG;AAEH,OAAO,EAAE,GAAG,EAAE,MAAM,gBAAgB,CAAC;AACrC,OAAO,EAAE,UAAU,EAAkB,MAAM,UAAU,CAAC;AACtD,OAAO,EAAE,aAAa,EAAE,MAAM,WAAW,CAAC;AAgE1C;;;;;GAKG;AACH,MAAM,OAAO,gBAAgB;IAIE;IAHpB,MAAM,GAAmB,EAAE,CAAC;IAC5B,gBAAgB,GAA+C,EAAE,CAAC;IAE3E,YAA6B,KAAoB;QAApB,UAAK,GAAL,KAAK,CAAe;IAAG,CAAC;IAErD,GAAG;QACD,OAAO,IAAI,CAAC,KAAK,CAAC,GAAG,EAAE,CAAC;IAC1B,CAAC;IAED,KAAK,CAAC,KAAK,CAAC,GAAiB,EAAE,GAAkB;QAC/C,IAAI,CAAC,MAAM,CAAC,IAAI,CAAC,GAAG,CAAC,CAAC;QACtB,OAAO,MAAM,IAAI,CAAC,KAAK,CAAC,KAAK,CAAC,GAAG,EAAE,GAAG,CAAC,C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CAAC,GAAG,IAAI,CAAC,CAAC,IAAI,GAAG,CAAC,CAAC,MAAM,KAAK,IAAI,CAAC,CAAC,CAAC,EAAE,CAAC,CAAC,CAAC,MAAM,CAAC,CAAC,MAAM,EAAE,EAAE,CAAC,CAAC;IACvG,CAAC;IAED,IAAI,MAAM,CAAC,YAAY,CAAC,MAAM,GAAG,CAAC,EAAE,CAAC;QACnC,GAAG,CAAC,IAAI,CAAC,EAAE,EAAE,iCAAiC,MAAM,CAAC,YAAY,CAAC,IAAI,CAAC,IAAI,CAAC,EAAE,CAAC,CAAC;IAClF,CAAC;IACD,OAAO,GAAG,CAAC,IAAI,CAAC,IAAI,CAAC,CAAC;AACxB,CAAC"}
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Durations are strings: "30s", "10m", "4h", "2d". One spelling, no ambient time units, and no
|
|
3
|
+
* bare numbers, so a program never leaves it to the reader to guess whether 30 meant seconds or
|
|
4
|
+
* minutes.
|
|
5
|
+
*/
|
|
6
|
+
export declare class DurationError extends Error {
|
|
7
|
+
constructor(value: string);
|
|
8
|
+
}
|
|
9
|
+
/** Parse a duration to milliseconds. Throws rather than guessing: there is no fallback unit. */
|
|
10
|
+
export declare function parseDuration(value: string): number;
|
|
11
|
+
export declare function isDuration(value: unknown): value is string;
|
|
12
|
+
//# sourceMappingURL=duration.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"duration.d.ts","sourceRoot":"","sources":["../src/duration.ts"],"names":[],"mappings":"AAAA;;;;GAIG;AAYH,qBAAa,aAAc,SAAQ,KAAK;gBAC1B,KAAK,EAAE,MAAM;CAM1B;AAED,gGAAgG;AAChG,wBAAgB,aAAa,CAAC,KAAK,EAAE,MAAM,GAAG,MAAM,CAOnD;AAED,wBAAgB,UAAU,CAAC,KAAK,EAAE,OAAO,GAAG,KAAK,IAAI,MAAM,CAE1D"}
|
package/dist/duration.js
ADDED
|
@@ -0,0 +1,34 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Durations are strings: "30s", "10m", "4h", "2d". One spelling, no ambient time units, and no
|
|
3
|
+
* bare numbers, so a program never leaves it to the reader to guess whether 30 meant seconds or
|
|
4
|
+
* minutes.
|
|
5
|
+
*/
|
|
6
|
+
const DURATION_RE = /^(\d+)(ms|s|m|h|d)$/;
|
|
7
|
+
const UNIT_MS = Object.freeze({
|
|
8
|
+
ms: 1,
|
|
9
|
+
s: 1000,
|
|
10
|
+
m: 60_000,
|
|
11
|
+
h: 3_600_000,
|
|
12
|
+
d: 86_400_000,
|
|
13
|
+
});
|
|
14
|
+
export class DurationError extends Error {
|
|
15
|
+
constructor(value) {
|
|
16
|
+
super(`"${value}" is not a duration. Durations are a whole number and a unit, one of ms, s, m, h, or d: "30s", "10m", "4h", "2d".`);
|
|
17
|
+
this.name = "DurationError";
|
|
18
|
+
}
|
|
19
|
+
}
|
|
20
|
+
/** Parse a duration to milliseconds. Throws rather than guessing: there is no fallback unit. */
|
|
21
|
+
export function parseDuration(value) {
|
|
22
|
+
const m = DURATION_RE.exec(value);
|
|
23
|
+
if (m === null)
|
|
24
|
+
throw new DurationError(value);
|
|
25
|
+
const n = Number(m[1]);
|
|
26
|
+
const unit = UNIT_MS[m[2]];
|
|
27
|
+
if (!Number.isSafeInteger(n) || unit === undefined)
|
|
28
|
+
throw new DurationError(value);
|
|
29
|
+
return n * unit;
|
|
30
|
+
}
|
|
31
|
+
export function isDuration(value) {
|
|
32
|
+
return typeof value === "string" && DURATION_RE.test(value);
|
|
33
|
+
}
|
|
34
|
+
//# sourceMappingURL=duration.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"duration.js","sourceRoot":"","sources":["../src/duration.ts"],"names":[],"mappings":"AAAA;;;;GAIG;AAEH,MAAM,WAAW,GAAG,qBAAqB,CAAC;AAE1C,MAAM,OAAO,GAAqC,MAAM,CAAC,MAAM,CAAC;IAC9D,EAAE,EAAE,CAAC;IACL,CAAC,EAAE,IAAI;IACP,CAAC,EAAE,MAAM;IACT,CAAC,EAAE,SAAS;IACZ,CAAC,EAAE,UAAU;CACd,CAAC,CAAC;AAEH,MAAM,OAAO,aAAc,SAAQ,KAAK;IACtC,YAAY,KAAa;QACvB,KAAK,CACH,IAAI,KAAK,mHAAmH,CAC7H,CAAC;QACF,IAAI,CAAC,IAAI,GAAG,eAAe,CAAC;IAC9B,CAAC;CACF;AAED,gGAAgG;AAChG,MAAM,UAAU,aAAa,CAAC,KAAa;IACzC,MAAM,CAAC,GAAG,WAAW,CAAC,IAAI,CAAC,KAAK,CAAC,CAAC;IAClC,IAAI,CAAC,KAAK,IAAI;QAAE,MAAM,IAAI,aAAa,CAAC,KAAK,CAAC,CAAC;IAC/C,MAAM,CAAC,GAAG,MAAM,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC;IACvB,MAAM,IAAI,GAAG,OAAO,CAAC,CAAC,CAAC,CAAC,CAAW,CAAC,CAAC;IACrC,IAAI,CAAC,MAAM,CAAC,aAAa,CAAC,CAAC,CAAC,IAAI,IAAI,KAAK,SAAS;QAAE,MAAM,IAAI,aAAa,CAAC,KAAK,CAAC,CAAC;IACnF,OAAO,CAAC,GAAG,IAAI,CAAC;AAClB,CAAC;AAED,MAAM,UAAU,UAAU,CAAC,KAAc;IACvC,OAAO,OAAO,KAAK,KAAK,QAAQ,IAAI,WAAW,CAAC,IAAI,CAAC,KAAK,CAAC,CAAC;AAC9D,CAAC"}
|