@mobrienv/autoloop 0.1.2
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/README.md +145 -0
- package/bin/autoloop +2 -0
- package/dist/backend/index.d.ts +10 -0
- package/dist/backend/index.js +59 -0
- package/dist/backend/index.js.map +1 -0
- package/dist/backend/run-command.d.ts +7 -0
- package/dist/backend/run-command.js +50 -0
- package/dist/backend/run-command.js.map +1 -0
- package/dist/backend/run-mock.d.ts +1 -0
- package/dist/backend/run-mock.js +6 -0
- package/dist/backend/run-mock.js.map +1 -0
- package/dist/backend/run-pi.d.ts +5 -0
- package/dist/backend/run-pi.js +5 -0
- package/dist/backend/run-pi.js.map +1 -0
- package/dist/backend/types.d.ts +21 -0
- package/dist/backend/types.js +2 -0
- package/dist/backend/types.js.map +1 -0
- package/dist/chains/budget.d.ts +7 -0
- package/dist/chains/budget.js +42 -0
- package/dist/chains/budget.js.map +1 -0
- package/dist/chains/load.d.ts +12 -0
- package/dist/chains/load.js +80 -0
- package/dist/chains/load.js.map +1 -0
- package/dist/chains/render.d.ts +2 -0
- package/dist/chains/render.js +46 -0
- package/dist/chains/render.js.map +1 -0
- package/dist/chains/run.d.ts +17 -0
- package/dist/chains/run.js +175 -0
- package/dist/chains/run.js.map +1 -0
- package/dist/chains/types.d.ts +37 -0
- package/dist/chains/types.js +2 -0
- package/dist/chains/types.js.map +1 -0
- package/dist/chains.d.ts +5 -0
- package/dist/chains.js +5 -0
- package/dist/chains.js.map +1 -0
- package/dist/commands/chain.d.ts +1 -0
- package/dist/commands/chain.js +51 -0
- package/dist/commands/chain.js.map +1 -0
- package/dist/commands/inspect.d.ts +1 -0
- package/dist/commands/inspect.js +95 -0
- package/dist/commands/inspect.js.map +1 -0
- package/dist/commands/list.d.ts +1 -0
- package/dist/commands/list.js +12 -0
- package/dist/commands/list.js.map +1 -0
- package/dist/commands/loops.d.ts +1 -0
- package/dist/commands/loops.js +72 -0
- package/dist/commands/loops.js.map +1 -0
- package/dist/commands/memory.d.ts +1 -0
- package/dist/commands/memory.js +65 -0
- package/dist/commands/memory.js.map +1 -0
- package/dist/commands/pi-adapter.d.ts +1 -0
- package/dist/commands/pi-adapter.js +6 -0
- package/dist/commands/pi-adapter.js.map +1 -0
- package/dist/commands/run.d.ts +1 -0
- package/dist/commands/run.js +185 -0
- package/dist/commands/run.js.map +1 -0
- package/dist/config.d.ts +16 -0
- package/dist/config.js +169 -0
- package/dist/config.js.map +1 -0
- package/dist/events/decode.d.ts +2 -0
- package/dist/events/decode.js +45 -0
- package/dist/events/decode.js.map +1 -0
- package/dist/events/encode.d.ts +2 -0
- package/dist/events/encode.js +33 -0
- package/dist/events/encode.js.map +1 -0
- package/dist/events/guards.d.ts +5 -0
- package/dist/events/guards.js +42 -0
- package/dist/events/guards.js.map +1 -0
- package/dist/events/types.d.ts +25 -0
- package/dist/events/types.js +2 -0
- package/dist/events/types.js.map +1 -0
- package/dist/harness/config-helpers.d.ts +24 -0
- package/dist/harness/config-helpers.js +231 -0
- package/dist/harness/config-helpers.js.map +1 -0
- package/dist/harness/coordination.d.ts +1 -0
- package/dist/harness/coordination.js +127 -0
- package/dist/harness/coordination.js.map +1 -0
- package/dist/harness/display.d.ts +20 -0
- package/dist/harness/display.js +130 -0
- package/dist/harness/display.js.map +1 -0
- package/dist/harness/emit.d.ts +15 -0
- package/dist/harness/emit.js +220 -0
- package/dist/harness/emit.js.map +1 -0
- package/dist/harness/index.d.ts +13 -0
- package/dist/harness/index.js +124 -0
- package/dist/harness/index.js.map +1 -0
- package/dist/harness/iteration.d.ts +4 -0
- package/dist/harness/iteration.js +129 -0
- package/dist/harness/iteration.js.map +1 -0
- package/dist/harness/journal.d.ts +13 -0
- package/dist/harness/journal.js +106 -0
- package/dist/harness/journal.js.map +1 -0
- package/dist/harness/metareview.d.ts +4 -0
- package/dist/harness/metareview.js +33 -0
- package/dist/harness/metareview.js.map +1 -0
- package/dist/harness/metrics.d.ts +12 -0
- package/dist/harness/metrics.js +180 -0
- package/dist/harness/metrics.js.map +1 -0
- package/dist/harness/parallel.d.ts +37 -0
- package/dist/harness/parallel.js +158 -0
- package/dist/harness/parallel.js.map +1 -0
- package/dist/harness/prompt.d.ts +35 -0
- package/dist/harness/prompt.js +328 -0
- package/dist/harness/prompt.js.map +1 -0
- package/dist/harness/scratchpad.d.ts +2 -0
- package/dist/harness/scratchpad.js +65 -0
- package/dist/harness/scratchpad.js.map +1 -0
- package/dist/harness/stop.d.ts +5 -0
- package/dist/harness/stop.js +63 -0
- package/dist/harness/stop.js.map +1 -0
- package/dist/harness/tools.d.ts +3 -0
- package/dist/harness/tools.js +39 -0
- package/dist/harness/tools.js.map +1 -0
- package/dist/harness/types.d.ts +81 -0
- package/dist/harness/types.js +2 -0
- package/dist/harness/types.js.map +1 -0
- package/dist/harness/wave/finalize-wave.d.ts +9 -0
- package/dist/harness/wave/finalize-wave.js +60 -0
- package/dist/harness/wave/finalize-wave.js.map +1 -0
- package/dist/harness/wave/launch-branches.d.ts +6 -0
- package/dist/harness/wave/launch-branches.js +218 -0
- package/dist/harness/wave/launch-branches.js.map +1 -0
- package/dist/harness/wave/parse-objectives.d.ts +3 -0
- package/dist/harness/wave/parse-objectives.js +29 -0
- package/dist/harness/wave/parse-objectives.js.map +1 -0
- package/dist/harness/wave/types.d.ts +43 -0
- package/dist/harness/wave/types.js +2 -0
- package/dist/harness/wave/types.js.map +1 -0
- package/dist/harness/wave.d.ts +6 -0
- package/dist/harness/wave.js +98 -0
- package/dist/harness/wave.js.map +1 -0
- package/dist/json.d.ts +8 -0
- package/dist/json.js +80 -0
- package/dist/json.js.map +1 -0
- package/dist/loops/health.d.ts +14 -0
- package/dist/loops/health.js +104 -0
- package/dist/loops/health.js.map +1 -0
- package/dist/loops/list.d.ts +6 -0
- package/dist/loops/list.js +21 -0
- package/dist/loops/list.js.map +1 -0
- package/dist/loops/render.d.ts +18 -0
- package/dist/loops/render.js +87 -0
- package/dist/loops/render.js.map +1 -0
- package/dist/loops/show.d.ts +8 -0
- package/dist/loops/show.js +31 -0
- package/dist/loops/show.js.map +1 -0
- package/dist/loops/watch.d.ts +8 -0
- package/dist/loops/watch.js +77 -0
- package/dist/loops/watch.js.map +1 -0
- package/dist/main.d.ts +1 -0
- package/dist/main.js +101 -0
- package/dist/main.js.map +1 -0
- package/dist/markdown.d.ts +10 -0
- package/dist/markdown.js +66 -0
- package/dist/markdown.js.map +1 -0
- package/dist/memory-render.d.ts +6 -0
- package/dist/memory-render.js +81 -0
- package/dist/memory-render.js.map +1 -0
- package/dist/memory.d.ts +23 -0
- package/dist/memory.js +314 -0
- package/dist/memory.js.map +1 -0
- package/dist/pi-adapter.d.ts +1 -0
- package/dist/pi-adapter.js +220 -0
- package/dist/pi-adapter.js.map +1 -0
- package/dist/registry/derive.d.ts +8 -0
- package/dist/registry/derive.js +81 -0
- package/dist/registry/derive.js.map +1 -0
- package/dist/registry/harness.d.ts +7 -0
- package/dist/registry/harness.js +57 -0
- package/dist/registry/harness.js.map +1 -0
- package/dist/registry/index.d.ts +5 -0
- package/dist/registry/index.js +5 -0
- package/dist/registry/index.js.map +1 -0
- package/dist/registry/read.d.ts +11 -0
- package/dist/registry/read.js +50 -0
- package/dist/registry/read.js.map +1 -0
- package/dist/registry/rebuild.d.ts +5 -0
- package/dist/registry/rebuild.js +19 -0
- package/dist/registry/rebuild.js.map +1 -0
- package/dist/registry/types.d.ts +19 -0
- package/dist/registry/types.js +2 -0
- package/dist/registry/types.js.map +1 -0
- package/dist/registry/update.d.ts +2 -0
- package/dist/registry/update.js +7 -0
- package/dist/registry/update.js.map +1 -0
- package/dist/testing/mock-backend.d.ts +11 -0
- package/dist/testing/mock-backend.js +76 -0
- package/dist/testing/mock-backend.js.map +1 -0
- package/dist/topology.d.ts +25 -0
- package/dist/topology.js +188 -0
- package/dist/topology.js.map +1 -0
- package/dist/usage.d.ts +8 -0
- package/dist/usage.js +114 -0
- package/dist/usage.js.map +1 -0
- package/dist/utils.d.ts +15 -0
- package/dist/utils.js +79 -0
- package/dist/utils.js.map +1 -0
- package/package.json +52 -0
- package/presets/autocode/README.md +81 -0
- package/presets/autocode/autoloops.toml +22 -0
- package/presets/autocode/harness.md +19 -0
- package/presets/autocode/miniloops.toml +22 -0
- package/presets/autocode/roles/build.md +33 -0
- package/presets/autocode/roles/critic.md +40 -0
- package/presets/autocode/roles/finalizer.md +43 -0
- package/presets/autocode/roles/planner.md +40 -0
- package/presets/autocode/topology.toml +32 -0
- package/presets/autodoc/README.md +42 -0
- package/presets/autodoc/autoloops.toml +21 -0
- package/presets/autodoc/harness.md +19 -0
- package/presets/autodoc/miniloops.toml +21 -0
- package/presets/autodoc/roles/auditor.md +39 -0
- package/presets/autodoc/roles/checker.md +43 -0
- package/presets/autodoc/roles/publisher.md +51 -0
- package/presets/autodoc/roles/writer.md +37 -0
- package/presets/autodoc/topology.toml +31 -0
- package/presets/autofix/README.md +56 -0
- package/presets/autofix/autoloops.toml +21 -0
- package/presets/autofix/harness.md +24 -0
- package/presets/autofix/miniloops.toml +21 -0
- package/presets/autofix/roles/closer.md +48 -0
- package/presets/autofix/roles/diagnoser.md +42 -0
- package/presets/autofix/roles/fixer.md +28 -0
- package/presets/autofix/roles/verifier.md +31 -0
- package/presets/autofix/topology.toml +33 -0
- package/presets/autoideas/README.md +73 -0
- package/presets/autoideas/autoloops.toml +18 -0
- package/presets/autoideas/harness.md +31 -0
- package/presets/autoideas/miniloops.toml +18 -0
- package/presets/autoideas/roles/analyst.md +32 -0
- package/presets/autoideas/roles/reviewer.md +36 -0
- package/presets/autoideas/roles/scanner.md +26 -0
- package/presets/autoideas/roles/synthesizer.md +48 -0
- package/presets/autoideas/topology.toml +32 -0
- package/presets/autoperf/README.md +56 -0
- package/presets/autoperf/autoloops.toml +21 -0
- package/presets/autoperf/harness.md +21 -0
- package/presets/autoperf/miniloops.toml +21 -0
- package/presets/autoperf/roles/judge.md +38 -0
- package/presets/autoperf/roles/measurer.md +36 -0
- package/presets/autoperf/roles/optimizer.md +35 -0
- package/presets/autoperf/roles/profiler.md +38 -0
- package/presets/autoperf/topology.toml +32 -0
- package/presets/autoqa/README.md +76 -0
- package/presets/autoqa/autoloops.toml +21 -0
- package/presets/autoqa/harness.md +30 -0
- package/presets/autoqa/miniloops.toml +21 -0
- package/presets/autoqa/roles/executor.md +43 -0
- package/presets/autoqa/roles/inspector.md +45 -0
- package/presets/autoqa/roles/planner.md +55 -0
- package/presets/autoqa/roles/reporter.md +74 -0
- package/presets/autoqa/topology.toml +31 -0
- package/presets/autoresearch/README.md +63 -0
- package/presets/autoresearch/autoloops.toml +18 -0
- package/presets/autoresearch/harness.md +28 -0
- package/presets/autoresearch/miniloops.toml +18 -0
- package/presets/autoresearch/roles/benchmarker.md +34 -0
- package/presets/autoresearch/roles/evaluator.md +33 -0
- package/presets/autoresearch/roles/implementer.md +26 -0
- package/presets/autoresearch/roles/strategist.md +43 -0
- package/presets/autoresearch/topology.toml +31 -0
- package/presets/autoreview/README.md +51 -0
- package/presets/autoreview/autoloops.toml +21 -0
- package/presets/autoreview/harness.md +20 -0
- package/presets/autoreview/miniloops.toml +21 -0
- package/presets/autoreview/roles/checker.md +36 -0
- package/presets/autoreview/roles/reader.md +33 -0
- package/presets/autoreview/roles/suggester.md +26 -0
- package/presets/autoreview/roles/summarizer.md +57 -0
- package/presets/autoreview/topology.toml +31 -0
- package/presets/autosec/README.md +51 -0
- package/presets/autosec/autoloops.toml +21 -0
- package/presets/autosec/harness.md +20 -0
- package/presets/autosec/miniloops.toml +21 -0
- package/presets/autosec/roles/analyst.md +38 -0
- package/presets/autosec/roles/hardener.md +36 -0
- package/presets/autosec/roles/reporter.md +63 -0
- package/presets/autosec/roles/scanner.md +38 -0
- package/presets/autosec/topology.toml +31 -0
- package/presets/autosimplify/README.md +83 -0
- package/presets/autosimplify/autoloops.toml +22 -0
- package/presets/autosimplify/harness.md +25 -0
- package/presets/autosimplify/miniloops.toml +22 -0
- package/presets/autosimplify/roles/reviewer.md +38 -0
- package/presets/autosimplify/roles/scoper.md +42 -0
- package/presets/autosimplify/roles/simplifier.md +51 -0
- package/presets/autosimplify/roles/verifier.md +40 -0
- package/presets/autosimplify/topology.toml +32 -0
- package/presets/autospec/README.md +84 -0
- package/presets/autospec/autoloops.toml +21 -0
- package/presets/autospec/harness.md +23 -0
- package/presets/autospec/miniloops.toml +21 -0
- package/presets/autospec/roles/clarifier.md +38 -0
- package/presets/autospec/roles/critic.md +41 -0
- package/presets/autospec/roles/designer.md +37 -0
- package/presets/autospec/roles/planner.md +38 -0
- package/presets/autospec/roles/researcher.md +33 -0
- package/presets/autospec/topology.toml +38 -0
- package/presets/autotest/README.md +55 -0
- package/presets/autotest/autoloops.toml +21 -0
- package/presets/autotest/harness.md +21 -0
- package/presets/autotest/miniloops.toml +21 -0
- package/presets/autotest/roles/assessor.md +57 -0
- package/presets/autotest/roles/runner.md +31 -0
- package/presets/autotest/roles/surveyor.md +39 -0
- package/presets/autotest/roles/writer.md +37 -0
- package/presets/autotest/topology.toml +32 -0
|
@@ -0,0 +1,81 @@
|
|
|
1
|
+
import { lineSep, joinCsv } from "./utils.js";
|
|
2
|
+
export function truncateText(text, budgetChars, memory) {
|
|
3
|
+
if (budgetChars <= 0)
|
|
4
|
+
return text;
|
|
5
|
+
if (text.length <= budgetChars)
|
|
6
|
+
return text;
|
|
7
|
+
return truncateOnLineBoundary(text, budgetChars, memory);
|
|
8
|
+
}
|
|
9
|
+
function truncateOnLineBoundary(text, budgetChars, memory) {
|
|
10
|
+
const lines = text.split(lineSep());
|
|
11
|
+
const kept = [];
|
|
12
|
+
let used = 0;
|
|
13
|
+
for (const line of lines) {
|
|
14
|
+
const lineLen = line.length + 1;
|
|
15
|
+
if (used + lineLen > budgetChars)
|
|
16
|
+
break;
|
|
17
|
+
kept.push(line);
|
|
18
|
+
used += lineLen;
|
|
19
|
+
}
|
|
20
|
+
const keptText = kept.join(lineSep());
|
|
21
|
+
const keptCount = countBulletEntries(kept);
|
|
22
|
+
const totalCount = countBulletEntries(lines);
|
|
23
|
+
const dropped = totalCount - keptCount;
|
|
24
|
+
const droppedDetail = truncationDroppedDetail(keptText, memory);
|
|
25
|
+
return (keptText +
|
|
26
|
+
"\n...\n" +
|
|
27
|
+
truncationFooter(dropped, droppedDetail, text.length, budgetChars));
|
|
28
|
+
}
|
|
29
|
+
function countBulletEntries(lines) {
|
|
30
|
+
return lines.filter((l) => l.startsWith("- ")).length;
|
|
31
|
+
}
|
|
32
|
+
function truncationDroppedDetail(keptText, memory) {
|
|
33
|
+
const totalPrefs = memory.preferences.length;
|
|
34
|
+
const totalLearnings = memory.learnings.length;
|
|
35
|
+
const totalMeta = memory.meta.length;
|
|
36
|
+
const keptPrefs = countCategoryInText(keptText, "Preferences:");
|
|
37
|
+
const keptLearnings = countCategoryInText(keptText, "Learnings:");
|
|
38
|
+
const keptMeta = countCategoryInText(keptText, "Meta:");
|
|
39
|
+
return formatDroppedCounts(totalPrefs - keptPrefs, totalLearnings - keptLearnings, totalMeta - keptMeta);
|
|
40
|
+
}
|
|
41
|
+
function countCategoryInText(text, header) {
|
|
42
|
+
if (!text.includes(header))
|
|
43
|
+
return 0;
|
|
44
|
+
const parts = text.split(header);
|
|
45
|
+
if (parts.length < 2)
|
|
46
|
+
return 0;
|
|
47
|
+
const afterHeader = parts[1];
|
|
48
|
+
const sectionLines = afterHeader.split(lineSep());
|
|
49
|
+
let count = 0;
|
|
50
|
+
for (const line of sectionLines) {
|
|
51
|
+
if (line.startsWith("- "))
|
|
52
|
+
count++;
|
|
53
|
+
else if (line.trim() !== "")
|
|
54
|
+
break;
|
|
55
|
+
}
|
|
56
|
+
return count;
|
|
57
|
+
}
|
|
58
|
+
function formatDroppedCounts(prefs, learnings, meta) {
|
|
59
|
+
if (prefs === 0 && learnings === 0 && meta === 0)
|
|
60
|
+
return "";
|
|
61
|
+
const parts = [];
|
|
62
|
+
if (prefs > 0)
|
|
63
|
+
parts.push(prefs + " preferences");
|
|
64
|
+
if (learnings > 0)
|
|
65
|
+
parts.push(learnings + " learnings");
|
|
66
|
+
if (meta > 0)
|
|
67
|
+
parts.push(meta + " meta");
|
|
68
|
+
return " (" + joinCsv(parts) + " truncated)";
|
|
69
|
+
}
|
|
70
|
+
function truncationFooter(droppedEntries, droppedDetail, renderedChars, budgetChars) {
|
|
71
|
+
return ("(memory truncated: " +
|
|
72
|
+
droppedEntries +
|
|
73
|
+
" entries dropped" +
|
|
74
|
+
droppedDetail +
|
|
75
|
+
" — " +
|
|
76
|
+
renderedChars +
|
|
77
|
+
"/" +
|
|
78
|
+
budgetChars +
|
|
79
|
+
" chars)");
|
|
80
|
+
}
|
|
81
|
+
//# sourceMappingURL=memory-render.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"memory-render.js","sourceRoot":"","sources":["../src/memory-render.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,OAAO,EAAE,OAAO,EAAE,MAAM,YAAY,CAAC;AAQ9C,MAAM,UAAU,YAAY,CAC1B,IAAY,EACZ,WAAmB,EACnB,MAA0B;IAE1B,IAAI,WAAW,IAAI,CAAC;QAAE,OAAO,IAAI,CAAC;IAClC,IAAI,IAAI,CAAC,MAAM,IAAI,WAAW;QAAE,OAAO,IAAI,CAAC;IAC5C,OAAO,sBAAsB,CAAC,IAAI,EAAE,WAAW,EAAE,MAAM,CAAC,CAAC;AAC3D,CAAC;AAED,SAAS,sBAAsB,CAC7B,IAAY,EACZ,WAAmB,EACnB,MAA0B;IAE1B,MAAM,KAAK,GAAG,IAAI,CAAC,KAAK,CAAC,OAAO,EAAE,CAAC,CAAC;IACpC,MAAM,IAAI,GAAa,EAAE,CAAC;IAC1B,IAAI,IAAI,GAAG,CAAC,CAAC;IACb,KAAK,MAAM,IAAI,IAAI,KAAK,EAAE,CAAC;QACzB,MAAM,OAAO,GAAG,IAAI,CAAC,MAAM,GAAG,CAAC,CAAC;QAChC,IAAI,IAAI,GAAG,OAAO,GAAG,WAAW;YAAE,MAAM;QACxC,I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BAAgB,CACvB,cAAsB,EACtB,aAAqB,EACrB,aAAqB,EACrB,WAAmB;IAEnB,OAAO,CACL,qBAAqB;QACrB,cAAc;QACd,kBAAkB;QAClB,aAAa;QACb,KAAK;QACL,aAAa;QACb,GAAG;QACH,WAAW;QACX,SAAS,CACV,CAAC;AACJ,CAAC"}
|
package/dist/memory.d.ts
ADDED
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
interface MemoryStats {
|
|
2
|
+
preferences: number;
|
|
3
|
+
learnings: number;
|
|
4
|
+
meta: number;
|
|
5
|
+
totalEntries: number;
|
|
6
|
+
renderedChars: number;
|
|
7
|
+
budgetChars: number;
|
|
8
|
+
truncated: boolean;
|
|
9
|
+
}
|
|
10
|
+
export declare function resolveFile(projectDir: string): string;
|
|
11
|
+
export declare function renderProject(projectDir: string, budgetChars: number): string;
|
|
12
|
+
export declare function renderFile(path: string, budgetChars: number): string;
|
|
13
|
+
export declare function statsProject(projectDir: string, budgetChars: number): MemoryStats;
|
|
14
|
+
export declare function statsFile(path: string, budgetChars: number): MemoryStats;
|
|
15
|
+
export declare function listProject(projectDir: string): string;
|
|
16
|
+
export declare function rawProject(projectDir: string): string;
|
|
17
|
+
export declare function statusProject(projectDir: string): string;
|
|
18
|
+
export declare function findProject(projectDir: string, pattern: string): string;
|
|
19
|
+
export declare function addLearning(projectDir: string, text: string, source: string): void;
|
|
20
|
+
export declare function addPreference(projectDir: string, category: string, text: string): void;
|
|
21
|
+
export declare function addMeta(projectDir: string, key: string, value: string): void;
|
|
22
|
+
export declare function remove(projectDir: string, id: string, reason: string): void;
|
|
23
|
+
export {};
|
package/dist/memory.js
ADDED
|
@@ -0,0 +1,314 @@
|
|
|
1
|
+
import { appendFileSync, mkdirSync } from "node:fs";
|
|
2
|
+
import { dirname, join } from "node:path";
|
|
3
|
+
import * as config from "./config.js";
|
|
4
|
+
import { jsonField, extractField } from "./json.js";
|
|
5
|
+
import { bulletList } from "./markdown.js";
|
|
6
|
+
import { readIfExists, readLines } from "./harness/journal.js";
|
|
7
|
+
import { truncateText } from "./memory-render.js";
|
|
8
|
+
export function resolveFile(projectDir) {
|
|
9
|
+
const envPath = process.env["MINILOOPS_MEMORY_FILE"];
|
|
10
|
+
if (envPath)
|
|
11
|
+
return envPath;
|
|
12
|
+
const cfg = config.loadProject(projectDir);
|
|
13
|
+
return join(projectDir, config.get(cfg, "core.memory_file", ".autoloop/memory.jsonl"));
|
|
14
|
+
}
|
|
15
|
+
export function renderProject(projectDir, budgetChars) {
|
|
16
|
+
return renderFile(resolveFile(projectDir), budgetChars);
|
|
17
|
+
}
|
|
18
|
+
export function renderFile(path, budgetChars) {
|
|
19
|
+
const memory = materialize(readLines(path));
|
|
20
|
+
const text = renderMaterialized(memory);
|
|
21
|
+
return truncateText(text, budgetChars, memory);
|
|
22
|
+
}
|
|
23
|
+
export function statsProject(projectDir, budgetChars) {
|
|
24
|
+
return statsFile(resolveFile(projectDir), budgetChars);
|
|
25
|
+
}
|
|
26
|
+
export function statsFile(path, budgetChars) {
|
|
27
|
+
const memory = materialize(readLines(path));
|
|
28
|
+
return memoryStats(memory, budgetChars);
|
|
29
|
+
}
|
|
30
|
+
export function listProject(projectDir) {
|
|
31
|
+
return renderMaterialized(materialize(readLines(resolveFile(projectDir))));
|
|
32
|
+
}
|
|
33
|
+
export function rawProject(projectDir) {
|
|
34
|
+
return readIfExists(resolveFile(projectDir));
|
|
35
|
+
}
|
|
36
|
+
export function statusProject(projectDir) {
|
|
37
|
+
const stats = statsProject(projectDir, projectBudgetChars(projectDir));
|
|
38
|
+
return formatStatus(stats);
|
|
39
|
+
}
|
|
40
|
+
export function findProject(projectDir, pattern) {
|
|
41
|
+
const memory = materialize(readLines(resolveFile(projectDir)));
|
|
42
|
+
return renderMatches(findEntries(memory, pattern), pattern);
|
|
43
|
+
}
|
|
44
|
+
export function addLearning(projectDir, text, source) {
|
|
45
|
+
const path = resolveFile(projectDir);
|
|
46
|
+
appendMemoryEntry(path, memoryLine(nextId(path, "mem"), "learning", jsonField("text", text) +
|
|
47
|
+
", " +
|
|
48
|
+
jsonField("source", source) +
|
|
49
|
+
", " +
|
|
50
|
+
jsonField("created", currentTime())));
|
|
51
|
+
console.log("stored learning");
|
|
52
|
+
printBudgetWarning(projectDir);
|
|
53
|
+
}
|
|
54
|
+
export function addPreference(projectDir, category, text) {
|
|
55
|
+
const path = resolveFile(projectDir);
|
|
56
|
+
appendMemoryEntry(path, memoryLine(nextId(path, "mem"), "preference", jsonField("category", category) +
|
|
57
|
+
", " +
|
|
58
|
+
jsonField("text", text) +
|
|
59
|
+
", " +
|
|
60
|
+
jsonField("created", currentTime())));
|
|
61
|
+
console.log("stored preference");
|
|
62
|
+
printBudgetWarning(projectDir);
|
|
63
|
+
}
|
|
64
|
+
export function addMeta(projectDir, key, value) {
|
|
65
|
+
const path = resolveFile(projectDir);
|
|
66
|
+
appendMemoryEntry(path, memoryLine(nextId(path, "meta"), "meta", jsonField("key", key) +
|
|
67
|
+
", " +
|
|
68
|
+
jsonField("value", value) +
|
|
69
|
+
", " +
|
|
70
|
+
jsonField("created", currentTime())));
|
|
71
|
+
console.log("stored meta");
|
|
72
|
+
printBudgetWarning(projectDir);
|
|
73
|
+
}
|
|
74
|
+
export function remove(projectDir, id, reason) {
|
|
75
|
+
const path = resolveFile(projectDir);
|
|
76
|
+
const memory = materialize(readLines(path));
|
|
77
|
+
if (activeEntryExists(memory, id)) {
|
|
78
|
+
removeExistingEntry(path, id, reason);
|
|
79
|
+
}
|
|
80
|
+
else {
|
|
81
|
+
console.log("warning: no active entry with ID " + id + " found");
|
|
82
|
+
}
|
|
83
|
+
}
|
|
84
|
+
function renderMaterialized(memory) {
|
|
85
|
+
if (memory.preferences.length === 0 &&
|
|
86
|
+
memory.learnings.length === 0 &&
|
|
87
|
+
memory.meta.length === 0) {
|
|
88
|
+
return "";
|
|
89
|
+
}
|
|
90
|
+
return ("Loop memory:\n" +
|
|
91
|
+
renderPreferences(memory.preferences) +
|
|
92
|
+
renderLearnings(memory.learnings) +
|
|
93
|
+
renderMeta(memory.meta));
|
|
94
|
+
}
|
|
95
|
+
function renderPreferences(entries) {
|
|
96
|
+
if (entries.length === 0)
|
|
97
|
+
return "";
|
|
98
|
+
const items = entries.map((e) => "[" +
|
|
99
|
+
extractField(e, "id") +
|
|
100
|
+
"] [" +
|
|
101
|
+
extractField(e, "category") +
|
|
102
|
+
"] " +
|
|
103
|
+
extractField(e, "text"));
|
|
104
|
+
return "Preferences:\n" + bulletList(items) + "\n";
|
|
105
|
+
}
|
|
106
|
+
function renderLearnings(entries) {
|
|
107
|
+
if (entries.length === 0)
|
|
108
|
+
return "";
|
|
109
|
+
const items = entries.map((e) => {
|
|
110
|
+
const source = extractField(e, "source");
|
|
111
|
+
const prefix = source ? "(" + source + ") " : "";
|
|
112
|
+
return "[" + extractField(e, "id") + "] " + prefix + extractField(e, "text");
|
|
113
|
+
});
|
|
114
|
+
return "Learnings:\n" + bulletList(items) + "\n";
|
|
115
|
+
}
|
|
116
|
+
function renderMeta(entries) {
|
|
117
|
+
if (entries.length === 0)
|
|
118
|
+
return "";
|
|
119
|
+
const items = entries.map((e) => "[" +
|
|
120
|
+
extractField(e, "id") +
|
|
121
|
+
"] " +
|
|
122
|
+
extractField(e, "key") +
|
|
123
|
+
": " +
|
|
124
|
+
extractField(e, "value"));
|
|
125
|
+
return "Meta:\n" + bulletList(items) + "\n";
|
|
126
|
+
}
|
|
127
|
+
function memoryStats(memory, budgetChars) {
|
|
128
|
+
const renderedChars = renderMaterialized(memory).length;
|
|
129
|
+
return {
|
|
130
|
+
preferences: memory.preferences.length,
|
|
131
|
+
learnings: memory.learnings.length,
|
|
132
|
+
meta: memory.meta.length,
|
|
133
|
+
totalEntries: memory.preferences.length +
|
|
134
|
+
memory.learnings.length +
|
|
135
|
+
memory.meta.length,
|
|
136
|
+
renderedChars,
|
|
137
|
+
budgetChars,
|
|
138
|
+
truncated: budgetChars > 0 && renderedChars > budgetChars,
|
|
139
|
+
};
|
|
140
|
+
}
|
|
141
|
+
function formatStatus(stats) {
|
|
142
|
+
const budgetStr = stats.budgetChars <= 0
|
|
143
|
+
? "budget disabled"
|
|
144
|
+
: stats.renderedChars > stats.budgetChars
|
|
145
|
+
? stats.budgetChars +
|
|
146
|
+
" char budget (" +
|
|
147
|
+
Math.floor(((stats.renderedChars - stats.budgetChars) * 100) /
|
|
148
|
+
stats.budgetChars) +
|
|
149
|
+
"% over)"
|
|
150
|
+
: stats.budgetChars +
|
|
151
|
+
" char budget (" +
|
|
152
|
+
Math.floor((stats.renderedChars * 100) / stats.budgetChars) +
|
|
153
|
+
"% used)";
|
|
154
|
+
return ("Memory: " +
|
|
155
|
+
stats.renderedChars +
|
|
156
|
+
" chars rendered, " +
|
|
157
|
+
budgetStr +
|
|
158
|
+
". " +
|
|
159
|
+
stats.learnings +
|
|
160
|
+
" learnings, " +
|
|
161
|
+
stats.preferences +
|
|
162
|
+
" preferences, " +
|
|
163
|
+
stats.meta +
|
|
164
|
+
" meta active.");
|
|
165
|
+
}
|
|
166
|
+
function printBudgetWarning(projectDir) {
|
|
167
|
+
const stats = statsProject(projectDir, projectBudgetChars(projectDir));
|
|
168
|
+
if (stats.truncated) {
|
|
169
|
+
console.log("warning: memory is " +
|
|
170
|
+
stats.renderedChars +
|
|
171
|
+
"/" +
|
|
172
|
+
stats.budgetChars +
|
|
173
|
+
" chars rendered. This entry will be truncated from the agent prompt.");
|
|
174
|
+
console.log("consider increasing memory.prompt_budget_chars or removing stale entries.");
|
|
175
|
+
}
|
|
176
|
+
}
|
|
177
|
+
function projectBudgetChars(projectDir) {
|
|
178
|
+
const cfg = config.loadProject(projectDir);
|
|
179
|
+
return config.getInt(cfg, "memory.prompt_budget_chars", 8000);
|
|
180
|
+
}
|
|
181
|
+
function findEntries(memory, pattern) {
|
|
182
|
+
const all = [
|
|
183
|
+
...memory.preferences,
|
|
184
|
+
...memory.learnings,
|
|
185
|
+
...memory.meta,
|
|
186
|
+
];
|
|
187
|
+
return all.filter((entry) => entryMatches(entry, pattern));
|
|
188
|
+
}
|
|
189
|
+
function entryMatches(entry, pattern) {
|
|
190
|
+
const haystack = searchText(entry);
|
|
191
|
+
return haystack.includes(pattern);
|
|
192
|
+
}
|
|
193
|
+
function searchText(entry) {
|
|
194
|
+
return [
|
|
195
|
+
extractField(entry, "id"),
|
|
196
|
+
extractField(entry, "category"),
|
|
197
|
+
extractField(entry, "text"),
|
|
198
|
+
extractField(entry, "source"),
|
|
199
|
+
extractField(entry, "key"),
|
|
200
|
+
extractField(entry, "value"),
|
|
201
|
+
].join(" ");
|
|
202
|
+
}
|
|
203
|
+
function renderMatches(entries, pattern) {
|
|
204
|
+
if (entries.length === 0) {
|
|
205
|
+
return "No active memory entries matching `" + pattern + "`.";
|
|
206
|
+
}
|
|
207
|
+
return entries.map(renderMatch).join("\n");
|
|
208
|
+
}
|
|
209
|
+
function renderMatch(entry) {
|
|
210
|
+
const id = extractField(entry, "id");
|
|
211
|
+
const type = extractField(entry, "type");
|
|
212
|
+
if (type === "preference") {
|
|
213
|
+
return (id +
|
|
214
|
+
": preference [" +
|
|
215
|
+
extractField(entry, "category") +
|
|
216
|
+
"] " +
|
|
217
|
+
extractField(entry, "text"));
|
|
218
|
+
}
|
|
219
|
+
if (type === "learning") {
|
|
220
|
+
const source = extractField(entry, "source");
|
|
221
|
+
const prefix = source ? "(" + source + ") " : "";
|
|
222
|
+
return id + ": learning " + prefix + extractField(entry, "text");
|
|
223
|
+
}
|
|
224
|
+
if (type === "meta") {
|
|
225
|
+
return (id +
|
|
226
|
+
": meta " +
|
|
227
|
+
extractField(entry, "key") +
|
|
228
|
+
": " +
|
|
229
|
+
extractField(entry, "value"));
|
|
230
|
+
}
|
|
231
|
+
return id + ": " + extractField(entry, "text");
|
|
232
|
+
}
|
|
233
|
+
function activeEntryExists(memory, id) {
|
|
234
|
+
const all = [
|
|
235
|
+
...memory.preferences,
|
|
236
|
+
...memory.learnings,
|
|
237
|
+
...memory.meta,
|
|
238
|
+
];
|
|
239
|
+
return all.some((entry) => extractField(entry, "id") === id);
|
|
240
|
+
}
|
|
241
|
+
function materialize(lines) {
|
|
242
|
+
const reversed = [...lines].reverse();
|
|
243
|
+
const seen = [];
|
|
244
|
+
const tombstoned = [];
|
|
245
|
+
const preferences = [];
|
|
246
|
+
const learnings = [];
|
|
247
|
+
const meta = [];
|
|
248
|
+
const metaKeysSeen = [];
|
|
249
|
+
for (const line of reversed) {
|
|
250
|
+
const type = extractField(line, "type");
|
|
251
|
+
const id = extractField(line, "id");
|
|
252
|
+
if (type === "tombstone") {
|
|
253
|
+
const targetId = extractField(line, "target_id");
|
|
254
|
+
tombstoned.push(targetId);
|
|
255
|
+
continue;
|
|
256
|
+
}
|
|
257
|
+
if (!id)
|
|
258
|
+
continue;
|
|
259
|
+
if (tombstoned.includes(id) || seen.includes(id))
|
|
260
|
+
continue;
|
|
261
|
+
seen.push(id);
|
|
262
|
+
if (type === "preference") {
|
|
263
|
+
preferences.push(line);
|
|
264
|
+
}
|
|
265
|
+
else if (type === "learning") {
|
|
266
|
+
learnings.push(line);
|
|
267
|
+
}
|
|
268
|
+
else if (type === "meta") {
|
|
269
|
+
const key = extractField(line, "key");
|
|
270
|
+
if (!metaKeysSeen.includes(key)) {
|
|
271
|
+
metaKeysSeen.push(key);
|
|
272
|
+
meta.push(line);
|
|
273
|
+
}
|
|
274
|
+
}
|
|
275
|
+
}
|
|
276
|
+
return {
|
|
277
|
+
preferences: preferences.reverse(),
|
|
278
|
+
learnings: learnings.reverse(),
|
|
279
|
+
meta: meta.reverse(),
|
|
280
|
+
};
|
|
281
|
+
}
|
|
282
|
+
function appendMemoryEntry(path, content) {
|
|
283
|
+
const dir = dirname(path);
|
|
284
|
+
mkdirSync(dir, { recursive: true });
|
|
285
|
+
appendFileSync(path, content, "utf-8");
|
|
286
|
+
}
|
|
287
|
+
function nextId(path, prefix) {
|
|
288
|
+
const count = readLines(path).length;
|
|
289
|
+
return prefix + "-" + (count + 1);
|
|
290
|
+
}
|
|
291
|
+
function removeExistingEntry(path, id, reason) {
|
|
292
|
+
appendMemoryEntry(path, memoryLine(nextId(path, "ts"), "tombstone", tombstoneFields(id, reason)));
|
|
293
|
+
console.log("removed " + id);
|
|
294
|
+
}
|
|
295
|
+
function currentTime() {
|
|
296
|
+
return new Date().toISOString().replace(/\.\d{3}Z$/, "Z");
|
|
297
|
+
}
|
|
298
|
+
function memoryLine(id, type, fieldsJson) {
|
|
299
|
+
return ("{" +
|
|
300
|
+
jsonField("id", id) +
|
|
301
|
+
", " +
|
|
302
|
+
jsonField("type", type) +
|
|
303
|
+
", " +
|
|
304
|
+
fieldsJson +
|
|
305
|
+
"}\n");
|
|
306
|
+
}
|
|
307
|
+
function tombstoneFields(id, reason) {
|
|
308
|
+
return (jsonField("target_id", id) +
|
|
309
|
+
", " +
|
|
310
|
+
jsonField("reason", reason) +
|
|
311
|
+
", " +
|
|
312
|
+
jsonField("created", currentTime()));
|
|
313
|
+
}
|
|
314
|
+
//# sourceMappingURL=memory.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"memory.js","sourceRoot":"","sources":["../src/memory.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,cAAc,EAAE,SAAS,EAAE,MAAM,SAAS,CAAC;AACpD,OAAO,EAAE,OAAO,EAAE,IAAI,EAAE,MAAM,WAAW,CAAC;AAC1C,OAAO,KAAK,MAAM,MAAM,aAAa,CAAC;AACtC,OAAO,EAAE,SAAS,EAAE,YAAY,EAAE,MAAM,WAAW,CAAC;AACpD,OAAO,EAAE,UAAU,EAAE,MAAM,eAAe,CAAC;AAC3C,OAAO,EAAE,YAAY,EAAE,SAAS,EAAE,MAAM,sBAAsB,CAAC;AAC/D,OAAO,EAAE,YAAY,EAAE,MAAM,oBAAoB,CAAC;AAalD,MAAM,UAAU,WAAW,CAAC,UAAkB;IAC5C,MAAM,OAAO,GAAG,OAAO,CAAC,GAAG,CAAC,uBAAuB,CAAC,CAAC;IACrD,IAAI,OAAO;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AACJ,CAAC"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export declare function run(args: string[]): void;
|
|
@@ -0,0 +1,220 @@
|
|
|
1
|
+
import { existsSync, readFileSync, writeFileSync } from "node:fs";
|
|
2
|
+
import { execSync } from "node:child_process";
|
|
3
|
+
import { shellWords } from "./utils.js";
|
|
4
|
+
const BRIDGE_SCRIPT = `
|
|
5
|
+
import json
|
|
6
|
+
import os
|
|
7
|
+
import pathlib
|
|
8
|
+
import subprocess
|
|
9
|
+
import sys
|
|
10
|
+
|
|
11
|
+
|
|
12
|
+
def extract_text_from_message(message):
|
|
13
|
+
text_parts = []
|
|
14
|
+
for item in message.get("content") or []:
|
|
15
|
+
if item.get("type") == "text":
|
|
16
|
+
text_parts.append(item.get("text", ""))
|
|
17
|
+
return "".join(text_parts)
|
|
18
|
+
|
|
19
|
+
|
|
20
|
+
def extract_text_from_messages(messages):
|
|
21
|
+
if not messages:
|
|
22
|
+
return ""
|
|
23
|
+
return extract_text_from_message(messages[-1] or {})
|
|
24
|
+
|
|
25
|
+
|
|
26
|
+
def extract_tool_error(response):
|
|
27
|
+
for item in response.get("output") or []:
|
|
28
|
+
if item.get("type") == "text":
|
|
29
|
+
text = item.get("text", "")
|
|
30
|
+
if text:
|
|
31
|
+
return text
|
|
32
|
+
return ""
|
|
33
|
+
|
|
34
|
+
|
|
35
|
+
def stream_log_path():
|
|
36
|
+
state_dir = os.environ.get("MINILOOPS_STATE_DIR", "")
|
|
37
|
+
if not state_dir:
|
|
38
|
+
return None
|
|
39
|
+
prefix = "pi-review" if os.environ.get("MINILOOPS_REVIEW_MODE", "") == "hyperagent" else "pi-stream"
|
|
40
|
+
iteration = os.environ.get("MINILOOPS_ITERATION", "")
|
|
41
|
+
name = prefix + (("." + iteration) if iteration else "") + ".jsonl"
|
|
42
|
+
return pathlib.Path(state_dir) / name
|
|
43
|
+
|
|
44
|
+
|
|
45
|
+
cmd = sys.argv[1:-1]
|
|
46
|
+
prompt_path = sys.argv[-1]
|
|
47
|
+
raw_output = ""
|
|
48
|
+
exit_code = 1
|
|
49
|
+
|
|
50
|
+
try:
|
|
51
|
+
with open(prompt_path, "r", encoding="utf-8") as prompt_file:
|
|
52
|
+
completed = subprocess.run(cmd, stdin=prompt_file, stdout=subprocess.PIPE, stderr=subprocess.STDOUT, text=True, encoding="utf-8", errors="replace")
|
|
53
|
+
raw_output = completed.stdout or ""
|
|
54
|
+
exit_code = completed.returncode
|
|
55
|
+
except FileNotFoundError as exc:
|
|
56
|
+
raw_output = str(exc)
|
|
57
|
+
exit_code = 127
|
|
58
|
+
|
|
59
|
+
log_path = stream_log_path()
|
|
60
|
+
if log_path is not None:
|
|
61
|
+
log_path.parent.mkdir(parents=True, exist_ok=True)
|
|
62
|
+
log_path.write_text(raw_output)
|
|
63
|
+
|
|
64
|
+
text_parts = []
|
|
65
|
+
fallback_text = ""
|
|
66
|
+
saw_turn_end = False
|
|
67
|
+
saw_agent_end = False
|
|
68
|
+
error = ""
|
|
69
|
+
|
|
70
|
+
for raw_line in raw_output.splitlines():
|
|
71
|
+
line = raw_line.strip()
|
|
72
|
+
if not line:
|
|
73
|
+
continue
|
|
74
|
+
|
|
75
|
+
try:
|
|
76
|
+
event = json.loads(line)
|
|
77
|
+
except Exception:
|
|
78
|
+
continue
|
|
79
|
+
|
|
80
|
+
event_type = event.get("type")
|
|
81
|
+
|
|
82
|
+
if event_type == "message_update":
|
|
83
|
+
assistant_event = event.get("assistantMessageEvent") or {}
|
|
84
|
+
assistant_type = assistant_event.get("type")
|
|
85
|
+
if assistant_type == "text_delta":
|
|
86
|
+
text_parts.append(assistant_event.get("delta", ""))
|
|
87
|
+
elif assistant_type == "error" and assistant_event.get("reason"):
|
|
88
|
+
error = assistant_event.get("reason")
|
|
89
|
+
elif event_type == "tool_execution_end":
|
|
90
|
+
response = event.get("toolExecutionResponseEvent") or {}
|
|
91
|
+
if response.get("isError"):
|
|
92
|
+
detail = extract_tool_error(response)
|
|
93
|
+
if detail:
|
|
94
|
+
error = detail
|
|
95
|
+
elif event_type == "turn_end":
|
|
96
|
+
saw_turn_end = True
|
|
97
|
+
if not fallback_text:
|
|
98
|
+
fallback_text = extract_text_from_message(event.get("message") or {})
|
|
99
|
+
elif event_type == "agent_end":
|
|
100
|
+
saw_agent_end = True
|
|
101
|
+
if not fallback_text:
|
|
102
|
+
fallback_text = extract_text_from_messages(event.get("messages") or [])
|
|
103
|
+
|
|
104
|
+
text = "".join(text_parts)
|
|
105
|
+
if not text:
|
|
106
|
+
text = fallback_text
|
|
107
|
+
|
|
108
|
+
failed = exit_code != 0 or (not saw_turn_end and not saw_agent_end) or bool(error)
|
|
109
|
+
verbose = os.environ.get("MINILOOPS_LOG_LEVEL", "") == "debug"
|
|
110
|
+
output = ""
|
|
111
|
+
|
|
112
|
+
if failed:
|
|
113
|
+
if verbose:
|
|
114
|
+
if text and error:
|
|
115
|
+
output = text + "\\n\\npi error: " + error
|
|
116
|
+
elif text:
|
|
117
|
+
output = text
|
|
118
|
+
else:
|
|
119
|
+
output = raw_output or error
|
|
120
|
+
else:
|
|
121
|
+
if text:
|
|
122
|
+
output = text
|
|
123
|
+
elif error:
|
|
124
|
+
output = "pi failed (run with -v for details)"
|
|
125
|
+
else:
|
|
126
|
+
output = raw_output or "pi failed"
|
|
127
|
+
else:
|
|
128
|
+
output = text
|
|
129
|
+
|
|
130
|
+
if output:
|
|
131
|
+
sys.stdout.write(output)
|
|
132
|
+
|
|
133
|
+
sys.exit(1 if failed else 0)
|
|
134
|
+
`;
|
|
135
|
+
export function run(args) {
|
|
136
|
+
const prompt = resolvePrompt();
|
|
137
|
+
if (!prompt) {
|
|
138
|
+
finishFailure("missing projected prompt");
|
|
139
|
+
return;
|
|
140
|
+
}
|
|
141
|
+
const promptPath = materializePromptPath(prompt);
|
|
142
|
+
const piCommand = args[0] || "pi";
|
|
143
|
+
const piArgs = args.slice(1);
|
|
144
|
+
const command = buildPiBridgeCommand(piCommand, piArgs, promptPath);
|
|
145
|
+
try {
|
|
146
|
+
const output = execSync(command, {
|
|
147
|
+
encoding: "utf-8",
|
|
148
|
+
stdio: ["pipe", "pipe", "pipe"],
|
|
149
|
+
shell: "/bin/sh",
|
|
150
|
+
maxBuffer: 100 * 1024 * 1024,
|
|
151
|
+
});
|
|
152
|
+
finishSuccess(output || "");
|
|
153
|
+
}
|
|
154
|
+
catch (err) {
|
|
155
|
+
const e = err;
|
|
156
|
+
finishFailure(e.stdout || e.stderr || "");
|
|
157
|
+
}
|
|
158
|
+
}
|
|
159
|
+
function resolvePrompt() {
|
|
160
|
+
const envPrompt = process.env["MINILOOPS_PROMPT"];
|
|
161
|
+
if (envPrompt)
|
|
162
|
+
return envPrompt;
|
|
163
|
+
const pathPrompt = promptFromPath();
|
|
164
|
+
if (pathPrompt)
|
|
165
|
+
return pathPrompt;
|
|
166
|
+
return projectedPrompt();
|
|
167
|
+
}
|
|
168
|
+
function projectedPrompt() {
|
|
169
|
+
const bin = process.env["MINILOOPS_BIN"] || "";
|
|
170
|
+
const iteration = process.env["MINILOOPS_ITERATION"] || "";
|
|
171
|
+
if (!bin || !iteration)
|
|
172
|
+
return "";
|
|
173
|
+
try {
|
|
174
|
+
const output = execSync(shellWords([bin, "inspect", "prompt", iteration, "--format", "md"]), { encoding: "utf-8", shell: "/bin/sh", timeout: 30000 });
|
|
175
|
+
return output || "";
|
|
176
|
+
}
|
|
177
|
+
catch {
|
|
178
|
+
return "";
|
|
179
|
+
}
|
|
180
|
+
}
|
|
181
|
+
function promptFromPath() {
|
|
182
|
+
const path = process.env["MINILOOPS_PROMPT_PATH"] || "";
|
|
183
|
+
if (!path || !existsSync(path))
|
|
184
|
+
return "";
|
|
185
|
+
return readFileSync(path, "utf-8");
|
|
186
|
+
}
|
|
187
|
+
function buildPiBridgeCommand(command, extraArgs, promptPath) {
|
|
188
|
+
return shellWords([
|
|
189
|
+
"python3",
|
|
190
|
+
"-c",
|
|
191
|
+
BRIDGE_SCRIPT,
|
|
192
|
+
command,
|
|
193
|
+
...defaultPiArgs(),
|
|
194
|
+
...extraArgs,
|
|
195
|
+
promptPath,
|
|
196
|
+
]);
|
|
197
|
+
}
|
|
198
|
+
function materializePromptPath(prompt) {
|
|
199
|
+
const path = promptStoragePath();
|
|
200
|
+
writeFileSync(path, prompt, "utf-8");
|
|
201
|
+
return path;
|
|
202
|
+
}
|
|
203
|
+
function promptStoragePath() {
|
|
204
|
+
const configured = process.env["MINILOOPS_PROMPT_PATH"] || "";
|
|
205
|
+
return configured || "/tmp/miniloops-pi-adapter-prompt.md";
|
|
206
|
+
}
|
|
207
|
+
function defaultPiArgs() {
|
|
208
|
+
return ["-p", "--mode", "json", "--no-session"];
|
|
209
|
+
}
|
|
210
|
+
function finishSuccess(output) {
|
|
211
|
+
if (output)
|
|
212
|
+
process.stdout.write(output);
|
|
213
|
+
process.exitCode = 0;
|
|
214
|
+
}
|
|
215
|
+
function finishFailure(output) {
|
|
216
|
+
if (output)
|
|
217
|
+
process.stdout.write(output);
|
|
218
|
+
process.exitCode = 1;
|
|
219
|
+
}
|
|
220
|
+
//# sourceMappingURL=pi-adapter.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"pi-adapter.js","sourceRoot":"","sources":["../src/pi-adapter.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,UAAU,EAAE,YAAY,EAAE,aAAa,EAAE,MAAM,SAAS,CAAC;AAClE,OAAO,EAAE,QAAQ,EAAE,MAAM,oBAAoB,CAAC;AAC9C,OAAO,EAAE,UAAU,EAAE,MAAM,YAAY,CAAC;AAExC,MAAM,aAAa,GAAG;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;CAkIrB,CAAC;AAEF,MAAM,UAAU,GAAG,CAAC,IAAc;IAChC,MAAM,MAAM,GAAG,aAAa,EAAE,CAAC;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