@farmslot/agent-runtime 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/CHANGELOG.md +13 -0
- package/LICENSE +21 -0
- package/README.md +58 -0
- package/bin/farmslot-agent.mjs +481 -0
- package/dist/index.d.ts +8 -0
- package/dist/index.d.ts.map +1 -0
- package/dist/index.js +8 -0
- package/dist/index.js.map +1 -0
- package/dist/recipe-quality.d.ts +27 -0
- package/dist/recipe-quality.d.ts.map +1 -0
- package/dist/recipe-quality.js +178 -0
- package/dist/recipe-quality.js.map +1 -0
- package/package.json +73 -0
- package/scripts/check-task-artifact-contract.mjs +400 -0
- package/scripts/mark-checklist-step.cjs +488 -0
- package/scripts/worker-terminal-contract.cjs +382 -0
package/CHANGELOG.md
ADDED
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
# Changelog
|
|
2
|
+
|
|
3
|
+
## Unreleased
|
|
4
|
+
|
|
5
|
+
- Active-development baseline; add user-facing changes here before release or package publication.
|
|
6
|
+
|
|
7
|
+
## 0.1.0 - 2026-07-06
|
|
8
|
+
|
|
9
|
+
### Added
|
|
10
|
+
|
|
11
|
+
- Add `buildRecipeQualityArtifact()` and `farmslot-agent recipe-quality build` so agents can generate validator-compliant `recipe-quality.json` artifacts from compact verdict/reason/finding inputs.
|
|
12
|
+
- Introduce `@farmslot/agent-runtime` for task-local `mark`, `SIGNAL.json`, worker terminal contract, and task artifact checks.
|
|
13
|
+
- Add `farmslot-agent` CLI with `mark`, `artifact-check`, `install-mark`, and `contract resolve` commands.
|
package/LICENSE
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2026 Arthur Breton
|
|
4
|
+
|
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
7
|
+
in the Software without restriction, including without limitation the rights
|
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
10
|
+
furnished to do so, subject to the following conditions:
|
|
11
|
+
|
|
12
|
+
The above copyright notice and this permission notice shall be included in all
|
|
13
|
+
copies or substantial portions of the Software.
|
|
14
|
+
|
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
21
|
+
SOFTWARE.
|
package/README.md
ADDED
|
@@ -0,0 +1,58 @@
|
|
|
1
|
+
# @farmslot/agent-runtime
|
|
2
|
+
|
|
3
|
+
Live agent task lifecycle tools for Farmslot-compatible runs.
|
|
4
|
+
|
|
5
|
+
Public reference: https://farmslot.io/docs/reference/agent-runtime
|
|
6
|
+
|
|
7
|
+
This package owns the reusable task-dir runtime surface:
|
|
8
|
+
|
|
9
|
+
- `mark` and checklist timing updates;
|
|
10
|
+
- worker-owned `SIGNAL.json` writes;
|
|
11
|
+
- worker terminal contract resolution and linting;
|
|
12
|
+
- closeout artifact checks;
|
|
13
|
+
- `recipe-quality.json` builder/generator for worker-authored quality artifacts.
|
|
14
|
+
|
|
15
|
+
It does not execute recipes. Recipe graph execution belongs in
|
|
16
|
+
`@farmslot/recipe-harness`, and schemas/validators belong in `@farmslot/protocol`.
|
|
17
|
+
|
|
18
|
+
## CLI
|
|
19
|
+
|
|
20
|
+
```bash
|
|
21
|
+
farmslot-agent install-mark <task-dir> --task TASK.md --signal SIGNAL.json
|
|
22
|
+
farmslot-agent mark <task-md> <signal-json> complete --mark-last
|
|
23
|
+
farmslot-agent artifact-check <task-dir> --require-recipe-quality-if-recipe
|
|
24
|
+
farmslot-agent recipe-quality build --input recipe-quality-input.json --output artifacts/recipe-quality.json
|
|
25
|
+
farmslot-agent contract resolve --flow fix-bug
|
|
26
|
+
```
|
|
27
|
+
|
|
28
|
+
## Compatibility
|
|
29
|
+
|
|
30
|
+
Legacy script paths in `@farmslot/skills` and `scripts/quality/` delegate here
|
|
31
|
+
for one migration window. New integrations should call `farmslot-agent`, install
|
|
32
|
+
a task-local `./mark` shim, or import the explicit script subpaths.
|
|
33
|
+
|
|
34
|
+
## Source layout
|
|
35
|
+
|
|
36
|
+
- `bin/`: CLI entry point for task-local helper installation, marking, artifact checks, and terminal contract resolution.
|
|
37
|
+
- `scripts/`: Runtime scripts that can be called directly by task files and compatibility shims.
|
|
38
|
+
- `src/`: Public package constants and typed runtime helpers such as `buildRecipeQualityArtifact()`.
|
|
39
|
+
- `test/`: Node TAP-style behavior tests for package exports, checklist marking, and artifact contract checks.
|
|
40
|
+
|
|
41
|
+
## Maintenance rules
|
|
42
|
+
|
|
43
|
+
- Keep runtime behavior here, not in `@farmslot/skills`; skills should teach and install, then delegate.
|
|
44
|
+
- Keep protocol schemas and pure validators in `@farmslot/protocol`; this package may consume them but should not own them.
|
|
45
|
+
- Preserve script subpath exports while task templates, remote slots, and compatibility shims depend on direct script paths.
|
|
46
|
+
- Update package readiness, CI filters, docs, and `CHANGELOG.md` when adding bins, exports, or required artifacts.
|
|
47
|
+
|
|
48
|
+
## Local quality
|
|
49
|
+
|
|
50
|
+
```bash
|
|
51
|
+
yarn workspace @farmslot/agent-runtime build
|
|
52
|
+
yarn workspace @farmslot/agent-runtime test
|
|
53
|
+
node scripts/quality/check-farmslot-package-readiness.mjs --packages @farmslot/agent-runtime
|
|
54
|
+
```
|
|
55
|
+
|
|
56
|
+
## License
|
|
57
|
+
|
|
58
|
+
MIT. See [LICENSE](LICENSE).
|
|
@@ -0,0 +1,481 @@
|
|
|
1
|
+
#!/usr/bin/env node
|
|
2
|
+
import { spawnSync } from 'node:child_process';
|
|
3
|
+
import { mkdirSync, readFileSync, writeFileSync } from 'node:fs';
|
|
4
|
+
import { createRequire } from 'node:module';
|
|
5
|
+
import path from 'node:path';
|
|
6
|
+
import { fileURLToPath, pathToFileURL } from 'node:url';
|
|
7
|
+
|
|
8
|
+
const packageRoot = path.resolve(path.dirname(fileURLToPath(import.meta.url)), '..');
|
|
9
|
+
const require = createRequire(import.meta.url);
|
|
10
|
+
|
|
11
|
+
function usage(exitCode = 0) {
|
|
12
|
+
const text = [
|
|
13
|
+
'Usage: farmslot-agent <command> [options]',
|
|
14
|
+
'',
|
|
15
|
+
'Commands:',
|
|
16
|
+
' mark <task-md> <signal-json> <args...>',
|
|
17
|
+
' artifact-check <task-dir> [args...]',
|
|
18
|
+
' install-mark <task-dir> [--task TASK.md] [--signal SIGNAL.json]',
|
|
19
|
+
' recipe-quality build [--input input.json] [--output artifacts/recipe-quality.json]',
|
|
20
|
+
' (flags override top-level input fields; training fields are merged)',
|
|
21
|
+
' contract resolve --flow <flow> [--project-config path] [--mode mode]',
|
|
22
|
+
].join('\n');
|
|
23
|
+
(exitCode === 0 ? console.log : console.error)(text);
|
|
24
|
+
process.exit(exitCode);
|
|
25
|
+
}
|
|
26
|
+
|
|
27
|
+
function runNode(script, args) {
|
|
28
|
+
const result = spawnSync(process.execPath, [script, ...args], { stdio: 'inherit' });
|
|
29
|
+
process.exit(result.status ?? 1);
|
|
30
|
+
}
|
|
31
|
+
|
|
32
|
+
function readJsonFile(filePath) {
|
|
33
|
+
return JSON.parse(readFileSync(path.resolve(filePath), 'utf8'));
|
|
34
|
+
}
|
|
35
|
+
|
|
36
|
+
function readJsonInput(inputPath) {
|
|
37
|
+
if (!inputPath || inputPath === '-') {
|
|
38
|
+
return JSON.parse(readFileSync(0, 'utf8'));
|
|
39
|
+
}
|
|
40
|
+
return readJsonFile(inputPath);
|
|
41
|
+
}
|
|
42
|
+
|
|
43
|
+
function parseBooleanFlag(name, value) {
|
|
44
|
+
if (value === true || value === 'true') return true;
|
|
45
|
+
if (value === false || value === 'false') return false;
|
|
46
|
+
throw new Error(`${name} must be true or false`);
|
|
47
|
+
}
|
|
48
|
+
|
|
49
|
+
function isNodeModuleNotFoundError(error) {
|
|
50
|
+
return Boolean(error && typeof error === 'object' && error.code === 'ERR_MODULE_NOT_FOUND');
|
|
51
|
+
}
|
|
52
|
+
|
|
53
|
+
function pushFlagValue(target, key, value) {
|
|
54
|
+
const current = target[key];
|
|
55
|
+
if (current == null) target[key] = [value];
|
|
56
|
+
else current.push(value);
|
|
57
|
+
}
|
|
58
|
+
|
|
59
|
+
const RECIPE_QUALITY_INPUT_KEYS = new Set([
|
|
60
|
+
'verdict',
|
|
61
|
+
'reasons',
|
|
62
|
+
'compact',
|
|
63
|
+
'betterVersionGuidance',
|
|
64
|
+
'better_version_guidance',
|
|
65
|
+
'dimensions',
|
|
66
|
+
'structuralFindings',
|
|
67
|
+
'structural_findings',
|
|
68
|
+
'contextualFindings',
|
|
69
|
+
'contextual_findings',
|
|
70
|
+
'suggestedRecipeDelta',
|
|
71
|
+
'suggested_recipe_delta',
|
|
72
|
+
'trainingFields',
|
|
73
|
+
'training_fields',
|
|
74
|
+
'producer',
|
|
75
|
+
'fallbackUsed',
|
|
76
|
+
'fallback_used',
|
|
77
|
+
'fallbackSource',
|
|
78
|
+
'fallback_source',
|
|
79
|
+
'legacyTask',
|
|
80
|
+
'legacy_task',
|
|
81
|
+
'artifactRequired',
|
|
82
|
+
'artifact_required',
|
|
83
|
+
'sourceSignals',
|
|
84
|
+
'source_signals',
|
|
85
|
+
'meta',
|
|
86
|
+
'extra',
|
|
87
|
+
]);
|
|
88
|
+
|
|
89
|
+
const RECIPE_QUALITY_COMPACT_KEYS = new Set(['verdict', 'reasons', 'better_version_guidance']);
|
|
90
|
+
|
|
91
|
+
const RECIPE_QUALITY_META_KEYS = new Set([
|
|
92
|
+
'producer',
|
|
93
|
+
'fallback_used',
|
|
94
|
+
'fallback_source',
|
|
95
|
+
'legacy_task',
|
|
96
|
+
'artifact_required',
|
|
97
|
+
'source_signals',
|
|
98
|
+
]);
|
|
99
|
+
|
|
100
|
+
function unknownKeys(value, allowed) {
|
|
101
|
+
if (!value || typeof value !== 'object' || Array.isArray(value)) return [];
|
|
102
|
+
return Object.keys(value).filter((key) => !allowed.has(key));
|
|
103
|
+
}
|
|
104
|
+
|
|
105
|
+
function validateRecipeQualityCompact(input) {
|
|
106
|
+
const compact = input.compact;
|
|
107
|
+
if (compact == null) return;
|
|
108
|
+
if (typeof compact !== 'object' || Array.isArray(compact)) {
|
|
109
|
+
throw new Error('recipe-quality input compact must be a JSON object when provided');
|
|
110
|
+
}
|
|
111
|
+
const unknown = unknownKeys(compact, RECIPE_QUALITY_COMPACT_KEYS);
|
|
112
|
+
if (unknown.length > 0) {
|
|
113
|
+
throw new Error(`recipe-quality input compact contains unknown key(s): ${unknown.join(', ')}`);
|
|
114
|
+
}
|
|
115
|
+
if (compact.verdict != null) {
|
|
116
|
+
throw new Error('recipe-quality input compact.verdict is output-only; use top-level verdict');
|
|
117
|
+
}
|
|
118
|
+
}
|
|
119
|
+
|
|
120
|
+
function validateRecipeQualityMeta(input) {
|
|
121
|
+
const meta = input.meta;
|
|
122
|
+
if (meta == null) return;
|
|
123
|
+
if (typeof meta !== 'object' || Array.isArray(meta)) {
|
|
124
|
+
throw new Error('recipe-quality input meta must be a JSON object when provided');
|
|
125
|
+
}
|
|
126
|
+
const unknown = unknownKeys(meta, RECIPE_QUALITY_META_KEYS);
|
|
127
|
+
if (unknown.length > 0) {
|
|
128
|
+
throw new Error(`recipe-quality input meta contains unknown key(s): ${unknown.join(', ')}`);
|
|
129
|
+
}
|
|
130
|
+
}
|
|
131
|
+
|
|
132
|
+
function validateRecipeQualityInputKeys(input) {
|
|
133
|
+
const unknown = Object.keys(input).filter((key) => !RECIPE_QUALITY_INPUT_KEYS.has(key));
|
|
134
|
+
if (unknown.length > 0) {
|
|
135
|
+
throw new Error(`recipe-quality input contains unknown key(s): ${unknown.join(', ')}`);
|
|
136
|
+
}
|
|
137
|
+
}
|
|
138
|
+
|
|
139
|
+
function valuesEqual(left, right) {
|
|
140
|
+
return JSON.stringify(left) === JSON.stringify(right);
|
|
141
|
+
}
|
|
142
|
+
|
|
143
|
+
function rejectConflict(leftLabel, left, rightLabel, right) {
|
|
144
|
+
if (left !== undefined && right !== undefined && !valuesEqual(left, right)) {
|
|
145
|
+
throw new Error(`recipe-quality input ${leftLabel} conflicts with ${rightLabel}`);
|
|
146
|
+
}
|
|
147
|
+
}
|
|
148
|
+
|
|
149
|
+
function validateRecipeQualityInputConflicts(input) {
|
|
150
|
+
rejectConflict(
|
|
151
|
+
'betterVersionGuidance',
|
|
152
|
+
input.betterVersionGuidance,
|
|
153
|
+
'better_version_guidance',
|
|
154
|
+
input.better_version_guidance,
|
|
155
|
+
);
|
|
156
|
+
rejectConflict(
|
|
157
|
+
'structuralFindings',
|
|
158
|
+
input.structuralFindings,
|
|
159
|
+
'structural_findings',
|
|
160
|
+
input.structural_findings,
|
|
161
|
+
);
|
|
162
|
+
rejectConflict(
|
|
163
|
+
'contextualFindings',
|
|
164
|
+
input.contextualFindings,
|
|
165
|
+
'contextual_findings',
|
|
166
|
+
input.contextual_findings,
|
|
167
|
+
);
|
|
168
|
+
rejectConflict(
|
|
169
|
+
'suggestedRecipeDelta',
|
|
170
|
+
input.suggestedRecipeDelta,
|
|
171
|
+
'suggested_recipe_delta',
|
|
172
|
+
input.suggested_recipe_delta,
|
|
173
|
+
);
|
|
174
|
+
rejectConflict('trainingFields', input.trainingFields, 'training_fields', input.training_fields);
|
|
175
|
+
rejectConflict('fallbackUsed', input.fallbackUsed, 'fallback_used', input.fallback_used);
|
|
176
|
+
rejectConflict('fallbackSource', input.fallbackSource, 'fallback_source', input.fallback_source);
|
|
177
|
+
rejectConflict('legacyTask', input.legacyTask, 'legacy_task', input.legacy_task);
|
|
178
|
+
rejectConflict(
|
|
179
|
+
'artifactRequired',
|
|
180
|
+
input.artifactRequired,
|
|
181
|
+
'artifact_required',
|
|
182
|
+
input.artifact_required,
|
|
183
|
+
);
|
|
184
|
+
rejectConflict('sourceSignals', input.sourceSignals, 'source_signals', input.source_signals);
|
|
185
|
+
rejectConflict('reasons', input.reasons, 'compact.reasons', input.compact?.reasons);
|
|
186
|
+
rejectConflict(
|
|
187
|
+
'betterVersionGuidance',
|
|
188
|
+
input.betterVersionGuidance ?? input.better_version_guidance,
|
|
189
|
+
'compact.better_version_guidance',
|
|
190
|
+
input.compact?.better_version_guidance,
|
|
191
|
+
);
|
|
192
|
+
rejectConflict('producer', input.producer, 'meta.producer', input.meta?.producer);
|
|
193
|
+
rejectConflict(
|
|
194
|
+
'fallbackUsed',
|
|
195
|
+
input.fallbackUsed ?? input.fallback_used,
|
|
196
|
+
'meta.fallback_used',
|
|
197
|
+
input.meta?.fallback_used,
|
|
198
|
+
);
|
|
199
|
+
rejectConflict(
|
|
200
|
+
'fallbackSource',
|
|
201
|
+
input.fallbackSource ?? input.fallback_source,
|
|
202
|
+
'meta.fallback_source',
|
|
203
|
+
input.meta?.fallback_source,
|
|
204
|
+
);
|
|
205
|
+
rejectConflict(
|
|
206
|
+
'legacyTask',
|
|
207
|
+
input.legacyTask ?? input.legacy_task,
|
|
208
|
+
'meta.legacy_task',
|
|
209
|
+
input.meta?.legacy_task,
|
|
210
|
+
);
|
|
211
|
+
rejectConflict(
|
|
212
|
+
'artifactRequired',
|
|
213
|
+
input.artifactRequired ?? input.artifact_required,
|
|
214
|
+
'meta.artifact_required',
|
|
215
|
+
input.meta?.artifact_required,
|
|
216
|
+
);
|
|
217
|
+
rejectConflict(
|
|
218
|
+
'sourceSignals',
|
|
219
|
+
input.sourceSignals ?? input.source_signals,
|
|
220
|
+
'meta.source_signals',
|
|
221
|
+
input.meta?.source_signals,
|
|
222
|
+
);
|
|
223
|
+
}
|
|
224
|
+
|
|
225
|
+
function optionalObject(name, value) {
|
|
226
|
+
if (value == null) return {};
|
|
227
|
+
if (typeof value === 'object' && !Array.isArray(value)) return value;
|
|
228
|
+
throw new Error(`${name} must be a JSON object when provided`);
|
|
229
|
+
}
|
|
230
|
+
|
|
231
|
+
function mergeRecipeQualityInputs(fileInput, flagInput) {
|
|
232
|
+
return {
|
|
233
|
+
...fileInput,
|
|
234
|
+
...flagInput,
|
|
235
|
+
trainingFields: {
|
|
236
|
+
...optionalObject('trainingFields', fileInput.trainingFields),
|
|
237
|
+
...optionalObject('trainingFields', flagInput.trainingFields),
|
|
238
|
+
},
|
|
239
|
+
};
|
|
240
|
+
}
|
|
241
|
+
|
|
242
|
+
function parseRecipeQualityBuildArgs(args) {
|
|
243
|
+
const parsed = { input: null, output: null, flags: {} };
|
|
244
|
+
for (let i = 0; i < args.length; i += 1) {
|
|
245
|
+
const arg = args[i];
|
|
246
|
+
const next = (flag) => {
|
|
247
|
+
const value = args[++i];
|
|
248
|
+
if (value === undefined) throw new Error(`${flag} requires a value`);
|
|
249
|
+
return value;
|
|
250
|
+
};
|
|
251
|
+
if (arg === '--input') parsed.input = next(arg);
|
|
252
|
+
else if (arg.startsWith('--input=')) parsed.input = arg.slice('--input='.length);
|
|
253
|
+
else if (arg === '--output') parsed.output = next(arg);
|
|
254
|
+
else if (arg.startsWith('--output=')) parsed.output = arg.slice('--output='.length);
|
|
255
|
+
else if (arg === '--verdict') parsed.flags.verdict = next(arg);
|
|
256
|
+
else if (arg.startsWith('--verdict=')) parsed.flags.verdict = arg.slice('--verdict='.length);
|
|
257
|
+
else if (arg === '--reason') pushFlagValue(parsed.flags, 'reasons', next(arg));
|
|
258
|
+
else if (arg.startsWith('--reason='))
|
|
259
|
+
pushFlagValue(parsed.flags, 'reasons', arg.slice('--reason='.length));
|
|
260
|
+
else if (arg === '--guidance') pushFlagValue(parsed.flags, 'betterVersionGuidance', next(arg));
|
|
261
|
+
else if (arg.startsWith('--guidance='))
|
|
262
|
+
pushFlagValue(parsed.flags, 'betterVersionGuidance', arg.slice('--guidance='.length));
|
|
263
|
+
else if (arg === '--delta') pushFlagValue(parsed.flags, 'suggestedRecipeDelta', next(arg));
|
|
264
|
+
else if (arg.startsWith('--delta='))
|
|
265
|
+
pushFlagValue(parsed.flags, 'suggestedRecipeDelta', arg.slice('--delta='.length));
|
|
266
|
+
else if (arg === '--proof-mode')
|
|
267
|
+
parsed.flags.trainingFields = { ...parsed.flags.trainingFields, proof_mode: next(arg) };
|
|
268
|
+
else if (arg.startsWith('--proof-mode='))
|
|
269
|
+
parsed.flags.trainingFields = {
|
|
270
|
+
...parsed.flags.trainingFields,
|
|
271
|
+
proof_mode: arg.slice('--proof-mode='.length),
|
|
272
|
+
};
|
|
273
|
+
else if (arg === '--project')
|
|
274
|
+
parsed.flags.trainingFields = { ...parsed.flags.trainingFields, project: next(arg) };
|
|
275
|
+
else if (arg.startsWith('--project='))
|
|
276
|
+
parsed.flags.trainingFields = {
|
|
277
|
+
...parsed.flags.trainingFields,
|
|
278
|
+
project: arg.slice('--project='.length),
|
|
279
|
+
};
|
|
280
|
+
else if (arg === '--flow-type')
|
|
281
|
+
parsed.flags.trainingFields = { ...parsed.flags.trainingFields, flow_type: next(arg) };
|
|
282
|
+
else if (arg.startsWith('--flow-type='))
|
|
283
|
+
parsed.flags.trainingFields = {
|
|
284
|
+
...parsed.flags.trainingFields,
|
|
285
|
+
flow_type: arg.slice('--flow-type='.length),
|
|
286
|
+
};
|
|
287
|
+
else if (arg === '--claim-is-visual')
|
|
288
|
+
parsed.flags.trainingFields = { ...parsed.flags.trainingFields, claim_is_visual: true };
|
|
289
|
+
else if (arg.startsWith('--claim-is-visual='))
|
|
290
|
+
parsed.flags.trainingFields = {
|
|
291
|
+
...parsed.flags.trainingFields,
|
|
292
|
+
claim_is_visual: parseBooleanFlag(
|
|
293
|
+
'--claim-is-visual',
|
|
294
|
+
arg.slice('--claim-is-visual='.length),
|
|
295
|
+
),
|
|
296
|
+
};
|
|
297
|
+
else if (arg === '--producer') parsed.flags.producer = next(arg);
|
|
298
|
+
else if (arg.startsWith('--producer=')) parsed.flags.producer = arg.slice('--producer='.length);
|
|
299
|
+
else if (arg === '--artifact-required')
|
|
300
|
+
parsed.flags.artifactRequired = parseBooleanFlag(arg, next(arg));
|
|
301
|
+
else if (arg.startsWith('--artifact-required='))
|
|
302
|
+
parsed.flags.artifactRequired = parseBooleanFlag(
|
|
303
|
+
'--artifact-required',
|
|
304
|
+
arg.slice('--artifact-required='.length),
|
|
305
|
+
);
|
|
306
|
+
else if (arg === '--legacy-task') parsed.flags.legacyTask = true;
|
|
307
|
+
else if (arg.startsWith('--legacy-task='))
|
|
308
|
+
parsed.flags.legacyTask = parseBooleanFlag(
|
|
309
|
+
'--legacy-task',
|
|
310
|
+
arg.slice('--legacy-task='.length),
|
|
311
|
+
);
|
|
312
|
+
else if (arg === '--source-signal') pushFlagValue(parsed.flags, 'sourceSignals', next(arg));
|
|
313
|
+
else if (arg.startsWith('--source-signal='))
|
|
314
|
+
pushFlagValue(parsed.flags, 'sourceSignals', arg.slice('--source-signal='.length));
|
|
315
|
+
else throw new Error(`unknown option ${arg}`);
|
|
316
|
+
}
|
|
317
|
+
return parsed;
|
|
318
|
+
}
|
|
319
|
+
|
|
320
|
+
function normalizeRecipeQualityInput(input) {
|
|
321
|
+
if (!input || typeof input !== 'object' || Array.isArray(input)) {
|
|
322
|
+
throw new Error('recipe-quality input must be a JSON object');
|
|
323
|
+
}
|
|
324
|
+
validateRecipeQualityInputKeys(input);
|
|
325
|
+
validateRecipeQualityCompact(input);
|
|
326
|
+
validateRecipeQualityMeta(input);
|
|
327
|
+
validateRecipeQualityInputConflicts(input);
|
|
328
|
+
return {
|
|
329
|
+
verdict: input.verdict,
|
|
330
|
+
reasons: input.reasons ?? input.compact?.reasons,
|
|
331
|
+
betterVersionGuidance:
|
|
332
|
+
input.betterVersionGuidance ??
|
|
333
|
+
input.better_version_guidance ??
|
|
334
|
+
input.compact?.better_version_guidance,
|
|
335
|
+
dimensions: input.dimensions,
|
|
336
|
+
structuralFindings: input.structuralFindings ?? input.structural_findings,
|
|
337
|
+
contextualFindings: input.contextualFindings ?? input.contextual_findings,
|
|
338
|
+
suggestedRecipeDelta: input.suggestedRecipeDelta ?? input.suggested_recipe_delta,
|
|
339
|
+
trainingFields: input.trainingFields ?? input.training_fields,
|
|
340
|
+
producer: input.producer ?? input.meta?.producer,
|
|
341
|
+
fallbackUsed: input.fallbackUsed ?? input.fallback_used ?? input.meta?.fallback_used,
|
|
342
|
+
fallbackSource: input.fallbackSource ?? input.fallback_source ?? input.meta?.fallback_source,
|
|
343
|
+
legacyTask: input.legacyTask ?? input.legacy_task ?? input.meta?.legacy_task,
|
|
344
|
+
artifactRequired:
|
|
345
|
+
input.artifactRequired ?? input.artifact_required ?? input.meta?.artifact_required,
|
|
346
|
+
sourceSignals: input.sourceSignals ?? input.source_signals ?? input.meta?.source_signals,
|
|
347
|
+
extra: input.extra,
|
|
348
|
+
};
|
|
349
|
+
}
|
|
350
|
+
|
|
351
|
+
async function buildRecipeQuality(args) {
|
|
352
|
+
const parsed = parseRecipeQualityBuildArgs(args);
|
|
353
|
+
const fileInput = parsed.input ? normalizeRecipeQualityInput(readJsonInput(parsed.input)) : {};
|
|
354
|
+
const input = mergeRecipeQualityInputs(fileInput, parsed.flags);
|
|
355
|
+
let runtime;
|
|
356
|
+
const distEntry = path.join(packageRoot, 'dist', 'index.js');
|
|
357
|
+
try {
|
|
358
|
+
runtime = await import(pathToFileURL(distEntry).href);
|
|
359
|
+
} catch (error) {
|
|
360
|
+
const message = error instanceof Error ? error.message : String(error);
|
|
361
|
+
const missingDistEntry =
|
|
362
|
+
isNodeModuleNotFoundError(error) &&
|
|
363
|
+
(message.includes(`Cannot find module '${distEntry}'`) ||
|
|
364
|
+
message.includes(`Cannot find module ${pathToFileURL(distEntry).href}`));
|
|
365
|
+
if (missingDistEntry) {
|
|
366
|
+
throw new Error(
|
|
367
|
+
`farmslot-agent recipe-quality build requires the compiled package at ${distEntry}. Run yarn workspace @farmslot/agent-runtime build in source checkouts. Original error: ${message}`,
|
|
368
|
+
);
|
|
369
|
+
}
|
|
370
|
+
throw error;
|
|
371
|
+
}
|
|
372
|
+
const artifact = runtime.buildRecipeQualityArtifact(input);
|
|
373
|
+
const text = `${JSON.stringify(artifact, null, 2)}\n`;
|
|
374
|
+
if (parsed.output) {
|
|
375
|
+
const outputPath = path.resolve(parsed.output);
|
|
376
|
+
mkdirSync(path.dirname(outputPath), { recursive: true });
|
|
377
|
+
writeFileSync(outputPath, text);
|
|
378
|
+
console.log(`wrote ${outputPath}`);
|
|
379
|
+
} else {
|
|
380
|
+
process.stdout.write(text);
|
|
381
|
+
}
|
|
382
|
+
}
|
|
383
|
+
|
|
384
|
+
function parseInstallMarkArgs(args) {
|
|
385
|
+
const parsed = { taskDir: args[0], task: 'TASK.md', signal: 'SIGNAL.json' };
|
|
386
|
+
for (let i = 1; i < args.length; i += 1) {
|
|
387
|
+
const arg = args[i];
|
|
388
|
+
if (arg === '--task') {
|
|
389
|
+
parsed.task = args[++i] || parsed.task;
|
|
390
|
+
} else if (arg.startsWith('--task=')) {
|
|
391
|
+
parsed.task = arg.slice('--task='.length);
|
|
392
|
+
} else if (arg === '--signal') {
|
|
393
|
+
parsed.signal = args[++i] || parsed.signal;
|
|
394
|
+
} else if (arg.startsWith('--signal=')) {
|
|
395
|
+
parsed.signal = arg.slice('--signal='.length);
|
|
396
|
+
} else {
|
|
397
|
+
usage(2);
|
|
398
|
+
}
|
|
399
|
+
}
|
|
400
|
+
if (!parsed.taskDir) usage(2);
|
|
401
|
+
return parsed;
|
|
402
|
+
}
|
|
403
|
+
|
|
404
|
+
function installMark(args) {
|
|
405
|
+
const parsed = parseInstallMarkArgs(args);
|
|
406
|
+
const taskDir = path.resolve(parsed.taskDir);
|
|
407
|
+
mkdirSync(taskDir, { recursive: true });
|
|
408
|
+
const markPath = path.join(taskDir, 'mark');
|
|
409
|
+
const binPath = path.join(packageRoot, 'bin', 'farmslot-agent.mjs');
|
|
410
|
+
writeFileSync(
|
|
411
|
+
markPath,
|
|
412
|
+
[
|
|
413
|
+
'#!/usr/bin/env bash',
|
|
414
|
+
'set -euo pipefail',
|
|
415
|
+
'DIR="$(CDPATH= cd -- "$(dirname -- "$0")" && pwd)"',
|
|
416
|
+
`node ${JSON.stringify(binPath)} mark "$DIR/${parsed.task}" "$DIR/${parsed.signal}" "$@"`,
|
|
417
|
+
'',
|
|
418
|
+
].join('\n'),
|
|
419
|
+
{ mode: 0o755 },
|
|
420
|
+
);
|
|
421
|
+
console.log(`installed ${markPath}`);
|
|
422
|
+
}
|
|
423
|
+
|
|
424
|
+
function parseContractResolveArgs(args) {
|
|
425
|
+
const parsed = { flow: null, mode: null, projectConfig: null };
|
|
426
|
+
for (let i = 0; i < args.length; i += 1) {
|
|
427
|
+
const arg = args[i];
|
|
428
|
+
if (arg === '--flow') parsed.flow = args[++i] || null;
|
|
429
|
+
else if (arg.startsWith('--flow=')) parsed.flow = arg.slice('--flow='.length);
|
|
430
|
+
else if (arg === '--mode') parsed.mode = args[++i] || null;
|
|
431
|
+
else if (arg.startsWith('--mode=')) parsed.mode = arg.slice('--mode='.length);
|
|
432
|
+
else if (arg === '--project-config') parsed.projectConfig = args[++i] || null;
|
|
433
|
+
else if (arg.startsWith('--project-config='))
|
|
434
|
+
parsed.projectConfig = arg.slice('--project-config='.length);
|
|
435
|
+
else usage(2);
|
|
436
|
+
}
|
|
437
|
+
if (!parsed.flow) usage(2);
|
|
438
|
+
return parsed;
|
|
439
|
+
}
|
|
440
|
+
|
|
441
|
+
function resolveContract(args) {
|
|
442
|
+
const parsed = parseContractResolveArgs(args);
|
|
443
|
+
const { resolveWorkerTerminalContract } = require('../scripts/worker-terminal-contract.cjs');
|
|
444
|
+
const projectConfig = parsed.projectConfig
|
|
445
|
+
? (JSON.parse(readFileSync(path.resolve(parsed.projectConfig), 'utf8')).worker_terminal ?? null)
|
|
446
|
+
: null;
|
|
447
|
+
const contract = resolveWorkerTerminalContract(projectConfig, parsed.flow, {
|
|
448
|
+
mode: parsed.mode,
|
|
449
|
+
});
|
|
450
|
+
console.log(JSON.stringify(contract, null, 2));
|
|
451
|
+
}
|
|
452
|
+
|
|
453
|
+
async function main() {
|
|
454
|
+
const [command, subcommand, ...rest] = process.argv.slice(2);
|
|
455
|
+
if (!command || command === '--help' || command === '-h') usage(0);
|
|
456
|
+
|
|
457
|
+
if (command === 'mark') {
|
|
458
|
+
runNode(
|
|
459
|
+
path.join(packageRoot, 'scripts', 'mark-checklist-step.cjs'),
|
|
460
|
+
[subcommand, ...rest].filter((arg) => arg !== undefined),
|
|
461
|
+
);
|
|
462
|
+
} else if (command === 'artifact-check') {
|
|
463
|
+
runNode(
|
|
464
|
+
path.join(packageRoot, 'scripts', 'check-task-artifact-contract.mjs'),
|
|
465
|
+
[subcommand, ...rest].filter((arg) => arg !== undefined),
|
|
466
|
+
);
|
|
467
|
+
} else if (command === 'install-mark') {
|
|
468
|
+
installMark([subcommand, ...rest].filter((arg) => arg !== undefined));
|
|
469
|
+
} else if (command === 'contract' && subcommand === 'resolve') {
|
|
470
|
+
resolveContract(rest);
|
|
471
|
+
} else if (command === 'recipe-quality' && subcommand === 'build') {
|
|
472
|
+
await buildRecipeQuality(rest);
|
|
473
|
+
} else {
|
|
474
|
+
usage(2);
|
|
475
|
+
}
|
|
476
|
+
}
|
|
477
|
+
|
|
478
|
+
main().catch((error) => {
|
|
479
|
+
console.error(error instanceof Error ? error.message : String(error));
|
|
480
|
+
process.exit(1);
|
|
481
|
+
});
|
package/dist/index.d.ts
ADDED
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
export declare const AGENT_RUNTIME_PACKAGE = "@farmslot/agent-runtime";
|
|
2
|
+
export declare const AGENT_RUNTIME_SCRIPT_EXPORTS: {
|
|
3
|
+
readonly markChecklistStep: "@farmslot/agent-runtime/scripts/mark-checklist-step.cjs";
|
|
4
|
+
readonly workerTerminalContract: "@farmslot/agent-runtime/scripts/worker-terminal-contract.cjs";
|
|
5
|
+
readonly checkTaskArtifactContract: "@farmslot/agent-runtime/scripts/check-task-artifact-contract.mjs";
|
|
6
|
+
};
|
|
7
|
+
export * from './recipe-quality.js';
|
|
8
|
+
//# sourceMappingURL=index.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,eAAO,MAAM,qBAAqB,4BAA4B,CAAC;AAE/D,eAAO,MAAM,4BAA4B;;;;CAI/B,CAAC;AAEX,cAAc,qBAAqB,CAAC"}
|
package/dist/index.js
ADDED
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
export const AGENT_RUNTIME_PACKAGE = '@farmslot/agent-runtime';
|
|
2
|
+
export const AGENT_RUNTIME_SCRIPT_EXPORTS = {
|
|
3
|
+
markChecklistStep: '@farmslot/agent-runtime/scripts/mark-checklist-step.cjs',
|
|
4
|
+
workerTerminalContract: '@farmslot/agent-runtime/scripts/worker-terminal-contract.cjs',
|
|
5
|
+
checkTaskArtifactContract: '@farmslot/agent-runtime/scripts/check-task-artifact-contract.mjs',
|
|
6
|
+
};
|
|
7
|
+
export * from './recipe-quality.js';
|
|
8
|
+
//# sourceMappingURL=index.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,MAAM,CAAC,MAAM,qBAAqB,GAAG,yBAAyB,CAAC;AAE/D,MAAM,CAAC,MAAM,4BAA4B,GAAG;IAC1C,iBAAiB,EAAE,yDAAyD;IAC5E,sBAAsB,EAAE,8DAA8D;IACtF,yBAAyB,EAAE,kEAAkE;CACrF,CAAC;AAEX,cAAc,qBAAqB,CAAC"}
|
|
@@ -0,0 +1,27 @@
|
|
|
1
|
+
import { type RecipeQualityArtifact, type RecipeQualityArtifactSource, type RecipeQualityVerdict } from '@farmslot/protocol';
|
|
2
|
+
type RecipeQualityFallbackSource = Exclude<RecipeQualityArtifactSource, 'worker' | 'gateway'>;
|
|
3
|
+
export interface RecipeQualityArtifactBuilderInput {
|
|
4
|
+
verdict: RecipeQualityVerdict;
|
|
5
|
+
reasons: string[];
|
|
6
|
+
betterVersionGuidance?: string[];
|
|
7
|
+
dimensions?: RecipeQualityArtifact['dimensions'];
|
|
8
|
+
structuralFindings?: RecipeQualityArtifact['structural_findings'];
|
|
9
|
+
contextualFindings?: RecipeQualityArtifact['contextual_findings'];
|
|
10
|
+
suggestedRecipeDelta?: string[];
|
|
11
|
+
trainingFields?: RecipeQualityArtifact['training_fields'];
|
|
12
|
+
producer?: RecipeQualityArtifactSource;
|
|
13
|
+
fallbackUsed?: boolean;
|
|
14
|
+
fallbackSource?: RecipeQualityFallbackSource;
|
|
15
|
+
legacyTask?: boolean;
|
|
16
|
+
artifactRequired?: boolean;
|
|
17
|
+
sourceSignals?: string[];
|
|
18
|
+
extra?: Record<string, unknown>;
|
|
19
|
+
}
|
|
20
|
+
export type BuiltRecipeQualityArtifact = RecipeQualityArtifact & Record<string, unknown>;
|
|
21
|
+
/**
|
|
22
|
+
* Builds the canonical `artifacts/recipe-quality.json` payload from the compact
|
|
23
|
+
* fields agents are expected to know after a recipe-quality pass.
|
|
24
|
+
*/
|
|
25
|
+
export declare function buildRecipeQualityArtifact(input: RecipeQualityArtifactBuilderInput): BuiltRecipeQualityArtifact;
|
|
26
|
+
export {};
|
|
27
|
+
//# sourceMappingURL=recipe-quality.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"recipe-quality.d.ts","sourceRoot":"","sources":["../src/recipe-quality.ts"],"names":[],"mappings":"AAAA,OAAO,EAQL,KAAK,qBAAqB,EAC1B,KAAK,2BAA2B,EAEhC,KAAK,oBAAoB,EAC1B,MAAM,oBAAoB,CAAC;AAE5B,KAAK,2BAA2B,GAAG,OAAO,CAAC,2BAA2B,EAAE,QAAQ,GAAG,SAAS,CAAC,CAAC;AAE9F,MAAM,WAAW,iCAAiC;IAChD,OAAO,EAAE,oBAAoB,CAAC;IAC9B,OAAO,EAAE,MAAM,EAAE,CAAC;IAClB,qBAAqB,CAAC,EAAE,MAAM,EAAE,CAAC;IACjC,UAAU,CAAC,EAAE,qBAAqB,CAAC,YAAY,CAAC,CAAC;IACjD,kBAAkB,CAAC,EAAE,qBAAqB,CAAC,qBAAqB,CAAC,CAAC;IAClE,kBAAkB,CAAC,EAAE,qBAAqB,CAAC,qBAAqB,CAAC,CAAC;IAClE,oBAAoB,CAAC,EAAE,MAAM,EAAE,CAAC;IAChC,cAAc,CAAC,EAAE,qBAAqB,CAAC,iBAAiB,CAAC,CAAC;IAC1D,QAAQ,CAAC,EAAE,2BAA2B,CAAC;IACvC,YAAY,CAAC,EAAE,OAAO,CAAC;IACvB,cAAc,CAAC,EAAE,2BAA2B,CAAC;IAC7C,UAAU,CAAC,EAAE,OAAO,CAAC;IACrB,gBAAgB,CAAC,EAAE,OAAO,CAAC;IAC3B,aAAa,CAAC,EAAE,MAAM,EAAE,CAAC;IACzB,KAAK,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,CAAC;CACjC;AAED,MAAM,MAAM,0BAA0B,GAAG,qBAAqB,GAAG,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,CAAC;AA+HzF;;;GAGG;AACH,wBAAgB,0BAA0B,CACxC,KAAK,EAAE,iCAAiC,GACvC,0BAA0B,CAuE5B"}
|