@tangle-network/braid 0.3.6 → 0.3.9
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 +2 -0
- package/THIRD_PARTY_LICENSES.json +512 -777
- package/THIRD_PARTY_NOTICES.md +8 -6
- package/dist/adapters/analysis/managed-analysis-runtime.js +1 -1
- package/dist/adapters/analysis/runtime-retained-model-call.d.ts.map +1 -1
- package/dist/adapters/analysis/runtime-retained-model-call.js +4 -0
- package/dist/adapters/analysis/runtime-retained-model-call.js.map +1 -1
- package/dist/adapters/connections/production-connection-health.js +2 -2
- package/dist/adapters/connections/production-connection-health.js.map +1 -1
- package/dist/adapters/connections/production-connection-providers.d.ts +1 -1
- package/dist/adapters/connections/production-connection-providers.d.ts.map +1 -1
- package/dist/adapters/connections/production-connection-providers.js +2 -2
- package/dist/adapters/connections/production-connection-providers.js.map +1 -1
- package/dist/adapters/connections/production-connections.d.ts +1 -1
- package/dist/adapters/connections/production-connections.d.ts.map +1 -1
- package/dist/adapters/connections/production-connections.js +1 -1
- package/dist/adapters/connections/production-connections.js.map +1 -1
- package/dist/adapters/connections/stored-model-grant.d.ts +6 -0
- package/dist/adapters/connections/stored-model-grant.d.ts.map +1 -0
- package/dist/adapters/connections/stored-model-grant.js +63 -0
- package/dist/adapters/connections/stored-model-grant.js.map +1 -0
- package/dist/adapters/connections/tangle-model-credentials.d.ts.map +1 -1
- package/dist/adapters/connections/tangle-model-credentials.js +8 -0
- package/dist/adapters/connections/tangle-model-credentials.js.map +1 -1
- package/dist/adapters/connections/tangle-router-client.d.ts +1 -1
- package/dist/adapters/connections/tangle-router-client.js +1 -1
- package/dist/adapters/runtime/production-cli-bridge-backend.d.ts.map +1 -1
- package/dist/adapters/runtime/production-cli-bridge-backend.js +2 -0
- package/dist/adapters/runtime/production-cli-bridge-backend.js.map +1 -1
- package/dist/adapters/runtime/production-tangle-sandbox-backend.js +4 -4
- package/dist/adapters/runtime/production-tangle-sandbox-backend.js.map +1 -1
- package/dist/adapters/runtime/sandbox-instance-observation.js.map +1 -1
- package/dist/adapters/runtime/sandbox-observation-types.d.ts +1 -2
- package/dist/adapters/runtime/sandbox-observation-types.d.ts.map +1 -1
- package/dist/adapters/runtime/sandbox-observation-types.js.map +1 -1
- package/dist/adapters/tui/application-ui-controller.d.ts.map +1 -1
- package/dist/adapters/tui/application-ui-controller.js +15 -0
- package/dist/adapters/tui/application-ui-controller.js.map +1 -1
- package/dist/adapters/tui/learning-dispatch.d.ts +21 -0
- package/dist/adapters/tui/learning-dispatch.d.ts.map +1 -0
- package/dist/adapters/tui/learning-dispatch.js +474 -0
- package/dist/adapters/tui/learning-dispatch.js.map +1 -0
- package/dist/adapters/tui/native-terminal-transport.js +14 -2
- package/dist/adapters/tui/native-terminal-transport.js.map +1 -1
- package/dist/adapters/tui/profile-connection-dispatch.d.ts +4 -0
- package/dist/adapters/tui/profile-connection-dispatch.d.ts.map +1 -1
- package/dist/adapters/tui/profile-connection-dispatch.js +1 -0
- package/dist/adapters/tui/profile-connection-dispatch.js.map +1 -1
- package/dist/adapters/tui/ui-command-dispatch.d.ts.map +1 -1
- package/dist/adapters/tui/ui-command-dispatch.js +8 -0
- package/dist/adapters/tui/ui-command-dispatch.js.map +1 -1
- package/dist/adapters/tui/ui-fixtures.d.ts +1 -1
- package/dist/adapters/tui/ui-fixtures.d.ts.map +1 -1
- package/dist/adapters/tui/ui-fixtures.js.map +1 -1
- package/dist/adapters/tui/ui-headless-dispatch.d.ts.map +1 -1
- package/dist/adapters/tui/ui-headless-dispatch.js +8 -0
- package/dist/adapters/tui/ui-headless-dispatch.js.map +1 -1
- package/dist/app/active-reconnects.d.ts +10 -0
- package/dist/app/active-reconnects.d.ts.map +1 -0
- package/dist/app/active-reconnects.js +60 -0
- package/dist/app/active-reconnects.js.map +1 -0
- package/dist/app/application-guards.d.ts +5 -0
- package/dist/app/application-guards.d.ts.map +1 -1
- package/dist/app/application-guards.js +19 -0
- package/dist/app/application-guards.js.map +1 -1
- package/dist/app/application-options.d.ts +5 -0
- package/dist/app/application-options.d.ts.map +1 -1
- package/dist/app/application-runtime-wiring.d.ts +1 -0
- package/dist/app/application-runtime-wiring.d.ts.map +1 -1
- package/dist/app/application-runtime-wiring.js +1 -0
- package/dist/app/application-runtime-wiring.js.map +1 -1
- package/dist/app/application-support.d.ts +2 -1
- package/dist/app/application-support.d.ts.map +1 -1
- package/dist/app/application-support.js +5 -0
- package/dist/app/application-support.js.map +1 -1
- package/dist/app/application-transition.d.ts +2 -0
- package/dist/app/application-transition.d.ts.map +1 -1
- package/dist/app/application-transition.js +5 -1
- package/dist/app/application-transition.js.map +1 -1
- package/dist/app/application.d.ts +11 -1
- package/dist/app/application.d.ts.map +1 -1
- package/dist/app/application.js +84 -54
- package/dist/app/application.js.map +1 -1
- package/dist/app/canary/canary-ledger.d.ts +72 -0
- package/dist/app/canary/canary-ledger.d.ts.map +1 -0
- package/dist/app/canary/canary-ledger.js +161 -0
- package/dist/app/canary/canary-ledger.js.map +1 -0
- package/dist/app/canary/canary-observe.d.ts +58 -0
- package/dist/app/canary/canary-observe.d.ts.map +1 -0
- package/dist/app/canary/canary-observe.js +115 -0
- package/dist/app/canary/canary-observe.js.map +1 -0
- package/dist/app/canary/canary-pack.d.ts +53 -0
- package/dist/app/canary/canary-pack.d.ts.map +1 -0
- package/dist/app/canary/canary-pack.js +100 -0
- package/dist/app/canary/canary-pack.js.map +1 -0
- package/dist/app/canary/canary-protocol.d.ts +111 -0
- package/dist/app/canary/canary-protocol.d.ts.map +1 -0
- package/dist/app/canary/canary-protocol.js +260 -0
- package/dist/app/canary/canary-protocol.js.map +1 -0
- package/dist/app/connections.js +2 -0
- package/dist/app/connections.js.map +1 -1
- package/dist/app/journal-follower.d.ts +20 -0
- package/dist/app/journal-follower.d.ts.map +1 -0
- package/dist/app/journal-follower.js +61 -0
- package/dist/app/journal-follower.js.map +1 -0
- package/dist/app/learning/instruction-blocks.d.ts +100 -0
- package/dist/app/learning/instruction-blocks.d.ts.map +1 -0
- package/dist/app/learning/instruction-blocks.js +373 -0
- package/dist/app/learning/instruction-blocks.js.map +1 -0
- package/dist/app/learning/learner-measure.d.ts +44 -0
- package/dist/app/learning/learner-measure.d.ts.map +1 -0
- package/dist/app/learning/learner-measure.js +134 -0
- package/dist/app/learning/learner-measure.js.map +1 -0
- package/dist/app/learning/learner-profile.d.ts +35 -0
- package/dist/app/learning/learner-profile.d.ts.map +1 -0
- package/dist/app/learning/learner-profile.js +145 -0
- package/dist/app/learning/learner-profile.js.map +1 -0
- package/dist/app/learning/learning-actions.d.ts +44 -0
- package/dist/app/learning/learning-actions.d.ts.map +1 -0
- package/dist/app/learning/learning-actions.js +458 -0
- package/dist/app/learning/learning-actions.js.map +1 -0
- package/dist/app/learning/learning-candidates.d.ts +102 -0
- package/dist/app/learning/learning-candidates.d.ts.map +1 -0
- package/dist/app/learning/learning-candidates.js +628 -0
- package/dist/app/learning/learning-candidates.js.map +1 -0
- package/dist/app/learning/learning-ledger.d.ts +52 -0
- package/dist/app/learning/learning-ledger.d.ts.map +1 -0
- package/dist/app/learning/learning-ledger.js +353 -0
- package/dist/app/learning/learning-ledger.js.map +1 -0
- package/dist/app/learning/learning-measure.d.ts +44 -0
- package/dist/app/learning/learning-measure.d.ts.map +1 -0
- package/dist/app/learning/learning-measure.js +189 -0
- package/dist/app/learning/learning-measure.js.map +1 -0
- package/dist/app/learning/learning-profile.d.ts +53 -0
- package/dist/app/learning/learning-profile.d.ts.map +1 -0
- package/dist/app/learning/learning-profile.js +137 -0
- package/dist/app/learning/learning-profile.js.map +1 -0
- package/dist/app/learning/learning-replay.d.ts +45 -0
- package/dist/app/learning/learning-replay.d.ts.map +1 -0
- package/dist/app/learning/learning-replay.js +170 -0
- package/dist/app/learning/learning-replay.js.map +1 -0
- package/dist/app/learning/learning-sources.d.ts +81 -0
- package/dist/app/learning/learning-sources.d.ts.map +1 -0
- package/dist/app/learning/learning-sources.js +212 -0
- package/dist/app/learning/learning-sources.js.map +1 -0
- package/dist/app/learning/learning-store.d.ts +41 -0
- package/dist/app/learning/learning-store.d.ts.map +1 -0
- package/dist/app/learning/learning-store.js +107 -0
- package/dist/app/learning/learning-store.js.map +1 -0
- package/dist/app/learning/learning-types.d.ts +287 -0
- package/dist/app/learning/learning-types.d.ts.map +1 -0
- package/dist/app/learning/learning-types.js +2 -0
- package/dist/app/learning/learning-types.js.map +1 -0
- package/dist/app/provider-values.d.ts +2 -0
- package/dist/app/provider-values.d.ts.map +1 -1
- package/dist/app/provider-values.js +27 -0
- package/dist/app/provider-values.js.map +1 -1
- package/dist/app/run-continuation.d.ts +2 -1
- package/dist/app/run-continuation.d.ts.map +1 -1
- package/dist/app/run-continuation.js +11 -4
- package/dist/app/run-continuation.js.map +1 -1
- package/dist/app/run-event-mapper.d.ts.map +1 -1
- package/dist/app/run-event-mapper.js +6 -0
- package/dist/app/run-event-mapper.js.map +1 -1
- package/dist/app/run-execution.d.ts.map +1 -1
- package/dist/app/run-execution.js +4 -2
- package/dist/app/run-execution.js.map +1 -1
- package/dist/app/run-handoff-context.d.ts +21 -16
- package/dist/app/run-handoff-context.d.ts.map +1 -1
- package/dist/app/run-ingestion.d.ts.map +1 -1
- package/dist/app/run-ingestion.js +27 -3
- package/dist/app/run-ingestion.js.map +1 -1
- package/dist/app/run-replay.d.ts.map +1 -1
- package/dist/app/run-replay.js +120 -27
- package/dist/app/run-replay.js.map +1 -1
- package/dist/app/run-stream-coalescing.d.ts +16 -0
- package/dist/app/run-stream-coalescing.d.ts.map +1 -0
- package/dist/app/run-stream-coalescing.js +185 -0
- package/dist/app/run-stream-coalescing.js.map +1 -0
- package/dist/bin/args.d.ts +3 -2
- package/dist/bin/args.d.ts.map +1 -1
- package/dist/bin/args.js +13 -0
- package/dist/bin/args.js.map +1 -1
- package/dist/bin/braid-runtime.js +7 -3
- package/dist/bin/braid-runtime.js.map +1 -1
- package/dist/bin/braid.js +5 -0
- package/dist/bin/braid.js.map +1 -1
- package/dist/bin/canary-command.d.ts +16 -0
- package/dist/bin/canary-command.d.ts.map +1 -0
- package/dist/bin/canary-command.js +192 -0
- package/dist/bin/canary-command.js.map +1 -0
- package/dist/bin/fixture-application.d.ts +9 -0
- package/dist/bin/fixture-application.d.ts.map +1 -1
- package/dist/bin/fixture-application.js +22 -1
- package/dist/bin/fixture-application.js.map +1 -1
- package/dist/bin/interface-runner.d.ts.map +1 -1
- package/dist/bin/interface-runner.js +7 -2
- package/dist/bin/interface-runner.js.map +1 -1
- package/dist/bin/native-interactive-actions.d.ts +3 -2
- package/dist/bin/native-interactive-actions.d.ts.map +1 -1
- package/dist/bin/native-interactive-actions.js +12 -2
- package/dist/bin/native-interactive-actions.js.map +1 -1
- package/dist/bin/production-application.d.ts.map +1 -1
- package/dist/bin/production-application.js +1 -0
- package/dist/bin/production-application.js.map +1 -1
- package/dist/bin/production-config-mutation-lock.d.ts.map +1 -1
- package/dist/bin/production-config-mutation-lock.js +10 -2
- package/dist/bin/production-config-mutation-lock.js.map +1 -1
- package/dist/bin/production-setup-application.d.ts +6 -0
- package/dist/bin/production-setup-application.d.ts.map +1 -1
- package/dist/bin/production-setup-application.js +4 -0
- package/dist/bin/production-setup-application.js.map +1 -1
- package/dist/bin/production-setup-persistence.d.ts.map +1 -1
- package/dist/bin/production-setup-persistence.js +2 -8
- package/dist/bin/production-setup-persistence.js.map +1 -1
- package/dist/bin/production-setup-types.d.ts +2 -0
- package/dist/bin/production-setup-types.d.ts.map +1 -1
- package/dist/bin/runtime-startup-options.d.ts.map +1 -1
- package/dist/bin/runtime-startup-options.js +1 -0
- package/dist/bin/runtime-startup-options.js.map +1 -1
- package/dist/bin/state-path.d.ts +25 -0
- package/dist/bin/state-path.d.ts.map +1 -1
- package/dist/bin/state-path.js +36 -0
- package/dist/bin/state-path.js.map +1 -1
- package/dist/domain/bounded-structured.d.ts +12 -0
- package/dist/domain/bounded-structured.d.ts.map +1 -1
- package/dist/domain/bounded-structured.js +32 -4
- package/dist/domain/bounded-structured.js.map +1 -1
- package/dist/domain/connection-credential-references.d.ts +4 -1
- package/dist/domain/connection-credential-references.d.ts.map +1 -1
- package/dist/domain/connection-credential-references.js +43 -1
- package/dist/domain/connection-credential-references.js.map +1 -1
- package/dist/domain/entities-core.d.ts +7 -1
- package/dist/domain/entities-core.d.ts.map +1 -1
- package/dist/domain/events-legacy.d.ts +2 -0
- package/dist/domain/events-legacy.d.ts.map +1 -1
- package/dist/domain/invariants-base.d.ts +5 -5
- package/dist/domain/invariants-base.d.ts.map +1 -1
- package/dist/domain/invariants-base.js.map +1 -1
- package/dist/domain/redaction.d.ts +6 -0
- package/dist/domain/redaction.d.ts.map +1 -1
- package/dist/domain/redaction.js +25 -2
- package/dist/domain/redaction.js.map +1 -1
- package/dist/domain/reducer-conversation-events.d.ts +2 -0
- package/dist/domain/reducer-conversation-events.d.ts.map +1 -1
- package/dist/domain/reducer-conversation-events.js +13 -0
- package/dist/domain/reducer-conversation-events.js.map +1 -1
- package/dist/domain/reducer-support.d.ts.map +1 -1
- package/dist/domain/reducer-support.js +5 -3
- package/dist/domain/reducer-support.js.map +1 -1
- package/dist/domain/runtime-events.d.ts +5 -0
- package/dist/domain/runtime-events.d.ts.map +1 -1
- package/dist/domain/runtime-events.js.map +1 -1
- package/dist/ports/native-terminal-transport.d.ts +6 -0
- package/dist/ports/native-terminal-transport.d.ts.map +1 -1
- package/dist/profiles/discovery-operator.d.ts +2 -2
- package/dist/profiles/discovery-operator.js +21 -21
- package/dist/profiles/discovery-operator.js.map +1 -1
- package/dist/startup/durable-runtime.d.ts +2 -0
- package/dist/startup/durable-runtime.d.ts.map +1 -1
- package/dist/startup/durable-runtime.js +1 -0
- package/dist/startup/durable-runtime.js.map +1 -1
- package/dist/testing/deterministic-backend.d.ts +3 -0
- package/dist/testing/deterministic-backend.d.ts.map +1 -1
- package/dist/testing/deterministic-backend.js +1 -1
- package/dist/testing/deterministic-backend.js.map +1 -1
- package/dist/testing/learning-fixture.d.ts +20 -0
- package/dist/testing/learning-fixture.d.ts.map +1 -0
- package/dist/testing/learning-fixture.js +35 -0
- package/dist/testing/learning-fixture.js.map +1 -0
- package/dist/views/headless/protocol.d.ts +1 -1
- package/dist/views/headless/protocol.d.ts.map +1 -1
- package/dist/views/headless/rpc-parser.d.ts.map +1 -1
- package/dist/views/headless/rpc-parser.js +13 -0
- package/dist/views/headless/rpc-parser.js.map +1 -1
- package/dist/views/shared/command-registry.d.ts +1 -1
- package/dist/views/shared/command-registry.d.ts.map +1 -1
- package/dist/views/shared/command-registry.js +9 -0
- package/dist/views/shared/command-registry.js.map +1 -1
- package/dist/views/shared/command-table.d.ts +5 -0
- package/dist/views/shared/command-table.d.ts.map +1 -1
- package/dist/views/shared/command-table.js +6 -0
- package/dist/views/shared/command-table.js.map +1 -1
- package/dist/views/shared/headless-commands.d.ts +1 -1
- package/dist/views/shared/headless-commands.d.ts.map +1 -1
- package/dist/views/shared/headless-commands.js +2 -0
- package/dist/views/shared/headless-commands.js.map +1 -1
- package/dist/views/tui/terminal-app.d.ts +6 -2
- package/dist/views/tui/terminal-app.d.ts.map +1 -1
- package/dist/views/tui/terminal-app.js +8 -2
- package/dist/views/tui/terminal-app.js.map +1 -1
- package/dist/views/tui/terminal-command-controller.d.ts.map +1 -1
- package/dist/views/tui/terminal-command-controller.js +2 -0
- package/dist/views/tui/terminal-command-controller.js.map +1 -1
- package/dist/views/tui/terminal-overlays.d.ts +1 -0
- package/dist/views/tui/terminal-overlays.d.ts.map +1 -1
- package/dist/views/tui/terminal-overlays.js +3 -0
- package/dist/views/tui/terminal-overlays.js.map +1 -1
- package/dist/views/tui/terminal-surface-overlays.d.ts +2 -0
- package/dist/views/tui/terminal-surface-overlays.d.ts.map +1 -1
- package/dist/views/tui/terminal-surface-overlays.js +5 -1
- package/dist/views/tui/terminal-surface-overlays.js.map +1 -1
- package/dist/views/tui/transcript.d.ts.map +1 -1
- package/dist/views/tui/transcript.js +15 -3
- package/dist/views/tui/transcript.js.map +1 -1
- package/package.json +9 -10
|
@@ -0,0 +1,189 @@
|
|
|
1
|
+
import { replayTask } from './learning-replay.js';
|
|
2
|
+
export const ADDITION_RULE = 'Addition: promote only when the skill eval keeps the unit and worst-family success does not fall.';
|
|
3
|
+
export const COMPRESSION_RULE = 'Compression: promote only when worst-family success holds or rises at equal or fewer loaded tokens, and the skill eval does not keep what was removed.';
|
|
4
|
+
const VERDICT = /^check (passed|failed)\n/u;
|
|
5
|
+
function familiesOf(tasks, results) {
|
|
6
|
+
const names = [...new Set(tasks.map((task) => task.family))].sort();
|
|
7
|
+
return names.map((family) => {
|
|
8
|
+
const known = results.filter((result) => result.family === family && result.pass !== null);
|
|
9
|
+
const passed = known.filter((result) => result.pass === true).length;
|
|
10
|
+
return {
|
|
11
|
+
family,
|
|
12
|
+
passed,
|
|
13
|
+
known: known.length,
|
|
14
|
+
rate: known.length === 0 ? null : passed / known.length,
|
|
15
|
+
};
|
|
16
|
+
});
|
|
17
|
+
}
|
|
18
|
+
export function armSummary(profileDigest, loadedTokens, tasks, replays) {
|
|
19
|
+
const results = tasks.flatMap((task) => {
|
|
20
|
+
const result = replays.get(`${profileDigest}:${task.id}`);
|
|
21
|
+
return result === undefined ? [] : [result];
|
|
22
|
+
});
|
|
23
|
+
const families = familiesOf(tasks, results);
|
|
24
|
+
const measured = families.filter((family) => family.rate !== null);
|
|
25
|
+
const worstFamily = measured.length === 0
|
|
26
|
+
? null
|
|
27
|
+
: measured.reduce((worst, family) => family.rate < worst.rate ? family : worst);
|
|
28
|
+
let costUsd = results.length === 0 ? null : 0;
|
|
29
|
+
for (const result of results)
|
|
30
|
+
costUsd =
|
|
31
|
+
costUsd === null || result.trace.costUsd === null ? null : costUsd + result.trace.costUsd;
|
|
32
|
+
return {
|
|
33
|
+
profileDigest,
|
|
34
|
+
loadedTokens,
|
|
35
|
+
passed: results.filter((result) => result.pass === true).length,
|
|
36
|
+
known: results.filter((result) => result.pass !== null).length,
|
|
37
|
+
errored: results.filter((result) => result.pass === null).length,
|
|
38
|
+
worstFamily,
|
|
39
|
+
families,
|
|
40
|
+
costUsd,
|
|
41
|
+
};
|
|
42
|
+
}
|
|
43
|
+
/** The promotion gate: the skill eval's decision, then worst-family success at the candidate's cost. */
|
|
44
|
+
export function promotionGate(candidate, report, base, measured, tasks) {
|
|
45
|
+
const compression = candidate.kind === 'removal' || measured.loadedTokens <= base.loadedTokens;
|
|
46
|
+
const rule = compression ? COMPRESSION_RULE : ADDITION_RULE;
|
|
47
|
+
const refuse = (reason) => ({ promotable: false, rule, reason });
|
|
48
|
+
if (measured.known < tasks)
|
|
49
|
+
return refuse(`${tasks - measured.known} of ${tasks} candidate replays have no check result`);
|
|
50
|
+
if (base.worstFamily === null || measured.worstFamily === null)
|
|
51
|
+
return refuse('worst-family success is unknown');
|
|
52
|
+
const baseRate = base.worstFamily.rate;
|
|
53
|
+
const rate = measured.worstFamily.rate;
|
|
54
|
+
const worst = `worst family ${measured.worstFamily.family} ${measured.worstFamily.passed}/${measured.worstFamily.known} against ${base.worstFamily.family} ${base.worstFamily.passed}/${base.worstFamily.known}`;
|
|
55
|
+
if (compression) {
|
|
56
|
+
if (candidate.kind === 'removal' && report.decision === 'keep')
|
|
57
|
+
return refuse(`the skill eval keeps ${candidate.name}: removing it loses answers`);
|
|
58
|
+
if (candidate.kind !== 'removal' && report.decision === 'cut')
|
|
59
|
+
return refuse('the skill eval cuts the unit');
|
|
60
|
+
if (rate < baseRate)
|
|
61
|
+
return refuse(`success falls: ${worst}`);
|
|
62
|
+
return {
|
|
63
|
+
promotable: true,
|
|
64
|
+
rule,
|
|
65
|
+
reason: `success holds (${worst}) at ${measured.loadedTokens} loaded tokens against ${base.loadedTokens}`,
|
|
66
|
+
};
|
|
67
|
+
}
|
|
68
|
+
if (report.decision !== 'keep')
|
|
69
|
+
return refuse(`the skill eval is ${report.decision}`);
|
|
70
|
+
if (rate < baseRate)
|
|
71
|
+
return refuse(`success falls: ${worst}`);
|
|
72
|
+
return {
|
|
73
|
+
promotable: true,
|
|
74
|
+
rule,
|
|
75
|
+
reason: `kept by the skill eval; ${worst}; ${measured.loadedTokens - base.loadedTokens} more loaded tokens`,
|
|
76
|
+
};
|
|
77
|
+
}
|
|
78
|
+
export async function mapLimit(items, limit, each) {
|
|
79
|
+
let next = 0;
|
|
80
|
+
await Promise.all(Array.from({ length: Math.min(limit, items.length) }, async () => {
|
|
81
|
+
while (next < items.length) {
|
|
82
|
+
const item = items[next++];
|
|
83
|
+
await each(item);
|
|
84
|
+
}
|
|
85
|
+
}));
|
|
86
|
+
}
|
|
87
|
+
/** Replays each profile on each task at most once, however many measurements ask for it. */
|
|
88
|
+
export function createReplayer(input) {
|
|
89
|
+
const replays = new Map();
|
|
90
|
+
const pending = new Map();
|
|
91
|
+
return {
|
|
92
|
+
replays,
|
|
93
|
+
replay(profile, digest, task) {
|
|
94
|
+
const key = `${digest}:${task.id}`;
|
|
95
|
+
let result = pending.get(key);
|
|
96
|
+
if (result === undefined) {
|
|
97
|
+
result = replayTask({
|
|
98
|
+
host: input.host,
|
|
99
|
+
profile,
|
|
100
|
+
task,
|
|
101
|
+
replayRoot: input.replayRoot,
|
|
102
|
+
timeoutMs: input.timeoutMs,
|
|
103
|
+
}).then((value) => {
|
|
104
|
+
replays.set(key, value);
|
|
105
|
+
input.onProgress?.(`Replayed ${task.id} under ${digest.slice(7, 19)}: ${value.pass === null ? `no result (${value.error})` : value.pass ? 'passed' : 'failed'}`);
|
|
106
|
+
return value;
|
|
107
|
+
});
|
|
108
|
+
pending.set(key, result);
|
|
109
|
+
}
|
|
110
|
+
return result;
|
|
111
|
+
},
|
|
112
|
+
};
|
|
113
|
+
}
|
|
114
|
+
/**
|
|
115
|
+
* Measure every candidate against the base profile on the held-out tasks with
|
|
116
|
+
* agent-eval's skill eval. The base replays once per task and is shared by every
|
|
117
|
+
* candidate. Each replay's check decides pass or fail; the blind judge prefers a
|
|
118
|
+
* passing answer to a failing one and otherwise calls a tie.
|
|
119
|
+
*/
|
|
120
|
+
export async function measureCandidates(input) {
|
|
121
|
+
const { runSkillEval } = await import('@tangle-network/agent-eval');
|
|
122
|
+
const replayer = input.replayer ?? createReplayer(input);
|
|
123
|
+
const { replays } = replayer;
|
|
124
|
+
const replay = replayer.replay;
|
|
125
|
+
input.onProgress?.(`Replaying ${input.tasks.length} tasks under the active profile`);
|
|
126
|
+
await mapLimit(input.tasks, input.concurrency, async (task) => {
|
|
127
|
+
await replay(input.base, input.baseDigest, task);
|
|
128
|
+
});
|
|
129
|
+
const base = armSummary(input.baseDigest, input.baseLoadedTokens, input.tasks, replays);
|
|
130
|
+
const results = [];
|
|
131
|
+
for (const candidate of input.candidates) {
|
|
132
|
+
input.onProgress?.(`Measuring ${candidate.kind} ${candidate.name}`);
|
|
133
|
+
const removal = candidate.kind === 'removal';
|
|
134
|
+
const withArm = removal
|
|
135
|
+
? { profile: input.base, digest: input.baseDigest }
|
|
136
|
+
: { profile: candidate.profile, digest: candidate.profileDigest };
|
|
137
|
+
const withoutArm = removal
|
|
138
|
+
? { profile: candidate.profile, digest: candidate.profileDigest }
|
|
139
|
+
: { profile: input.base, digest: input.baseDigest };
|
|
140
|
+
const report = await runSkillEval({
|
|
141
|
+
unit: { name: candidate.name, text: candidate.unitText },
|
|
142
|
+
cases: input.tasks,
|
|
143
|
+
seed: input.seed,
|
|
144
|
+
concurrency: input.concurrency,
|
|
145
|
+
run: async (task, arm) => {
|
|
146
|
+
const chosen = arm.arm === 'with' ? withArm : withoutArm;
|
|
147
|
+
const result = await replay(chosen.profile, chosen.digest, task);
|
|
148
|
+
if (result.pass === null)
|
|
149
|
+
throw new Error(result.error ?? 'the replay has no result');
|
|
150
|
+
return {
|
|
151
|
+
answer: `check ${result.pass ? 'passed' : 'failed'}\n${result.answer}`,
|
|
152
|
+
pass: result.pass,
|
|
153
|
+
trace: result.trace,
|
|
154
|
+
};
|
|
155
|
+
},
|
|
156
|
+
judge: async ({ first, second }) => {
|
|
157
|
+
const left = VERDICT.exec(first)?.[1];
|
|
158
|
+
const right = VERDICT.exec(second)?.[1];
|
|
159
|
+
if (left === right)
|
|
160
|
+
return 'tie';
|
|
161
|
+
return left === 'passed' ? 'first' : 'second';
|
|
162
|
+
},
|
|
163
|
+
});
|
|
164
|
+
const measured = armSummary(candidate.profileDigest, candidate.loadedTokens, input.tasks, replays);
|
|
165
|
+
const comparison = report.comparisons.find((item) => item.against === 'without');
|
|
166
|
+
results.push({
|
|
167
|
+
candidateId: candidate.id,
|
|
168
|
+
kind: candidate.kind,
|
|
169
|
+
name: candidate.name,
|
|
170
|
+
decision: report.decision,
|
|
171
|
+
reason: report.reason,
|
|
172
|
+
headroom: `${report.headroom.verdict}: the arm without the unit passes ${report.headroom.passed} of ${report.headroom.passed + report.headroom.failed} known`,
|
|
173
|
+
wins: comparison?.preference.wins ?? 0,
|
|
174
|
+
losses: comparison?.preference.losses ?? 0,
|
|
175
|
+
ties: comparison?.preference.ties ?? 0,
|
|
176
|
+
notJudged: comparison?.preference.notJudged ?? 0,
|
|
177
|
+
base,
|
|
178
|
+
candidate: measured,
|
|
179
|
+
gate: promotionGate(candidate, report, base, measured, input.tasks.length),
|
|
180
|
+
failures: report.failures.map((failure) => `${failure.caseId} ${'run' in failure.step ? `run ${failure.step.run}` : `judge ${failure.step.judge}`}: ${failure.error}`),
|
|
181
|
+
});
|
|
182
|
+
}
|
|
183
|
+
const promotable = results
|
|
184
|
+
.filter((result) => result.gate.promotable)
|
|
185
|
+
.sort((left, right) => (right.candidate.worstFamily?.rate ?? 0) - (left.candidate.worstFamily?.rate ?? 0) ||
|
|
186
|
+
left.candidate.loadedTokens - right.candidate.loadedTokens);
|
|
187
|
+
return { results, selected: promotable[0]?.candidateId ?? null, replays };
|
|
188
|
+
}
|
|
189
|
+
//# sourceMappingURL=learning-measure.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"learning-measure.js","sourceRoot":"","sources":["../../../src/app/learning/learning-measure.ts"],"names":[],"mappings":"AAEA,OAAO,EAAoC,UAAU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,CAAC;YACtC,SAAS,EAAE,UAAU,EAAE,UAAU,CAAC,SAAS,IAAI,CAAC;YAChD,IAAI;YACJ,SAAS,EAAE,QAAQ;YACnB,IAAI,EAAE,aAAa,CAAC,SAAS,EAAE,MAAM,EAAE,IAAI,EAAE,QAAQ,EAAE,KAAK,CAAC,KAAK,CAAC,MAAM,CAAC;YAC1E,QAAQ,EAAE,MAAM,CAAC,QAAQ,CAAC,GAAG,CAC3B,CAAC,OAAO,EAAE,EAAE,CACV,GAAG,OAAO,CAAC,MAAM,IAAI,KAAK,IAAI,OAAO,CAAC,IAAI,CAAC,CAAC,CAAC,OAAO,OAAO,CAAC,IAAI,CAAC,GAAG,EAAE,CAAC,CAAC,CAAC,SAAS,OAAO,CAAC,IAAI,CAAC,KAAK,EAAE,KAAK,OAAO,CAAC,KAAK,EAAE,CAC7H;SACF,CAAC,CAAA;IACJ,CAAC;IACD,MAAM,UAAU,GAAG,OAAO;SACvB,MAAM,CAAC,CAAC,MAAM,EAAE,EAAE,CAAC,MAAM,CAAC,IAAI,CAAC,UAAU,CAAC;SAC1C,IAAI,CACH,CAAC,IAAI,EAAE,KAAK,EAAE,EAAE,CACd,CAAC,KAAK,CAAC,SAAS,CAAC,WAAW,EAAE,IAAI,IAAI,CAAC,CAAC,GAAG,CAAC,IAAI,CAAC,SAAS,CAAC,WAAW,EAAE,IAAI,IAAI,CAAC,CAAC;QAClF,IAAI,CAAC,SAAS,CAAC,YAAY,GAAG,KAAK,CAAC,SAAS,CAAC,YAAY,CAC7D,CAAA;IACH,OAAO,EAAE,OAAO,EAAE,QAAQ,EAAE,UAAU,CAAC,CAAC,CAAC,EAAE,WAAW,IAAI,IAAI,EAAE,OAAO,EAAE,CAAA;AAC3E,CAAC"}
|
|
@@ -0,0 +1,53 @@
|
|
|
1
|
+
import type { AgentProfile, AgentProfileFileMount, AgentProfileResourceRef, AgentSubagentProfile } from '@tangle-network/agent-interface';
|
|
2
|
+
export declare function sha256Hex(text: string): string;
|
|
3
|
+
export declare function profileDigest(profile: AgentProfile): string;
|
|
4
|
+
/**
|
|
5
|
+
* Every text a harness may load from the profile into the model's context:
|
|
6
|
+
* system prompt additions, instructions, inline skills, tools, agents,
|
|
7
|
+
* commands and subagent prompts. A skill counts in full, so this is an upper
|
|
8
|
+
* bound for harnesses that load a skill's body only when it is invoked.
|
|
9
|
+
*/
|
|
10
|
+
export declare function loadedText(profile: AgentProfile): string;
|
|
11
|
+
/** Estimated loaded tokens: agent-eval's chars / 4 estimate over {@link loadedText}. */
|
|
12
|
+
export declare function loadedTokens(profile: AgentProfile): Promise<number>;
|
|
13
|
+
/** Where `mountSkill` provenance, and Braid's other source records, live for this profile. */
|
|
14
|
+
export declare function provenanceNamespace(profile: AgentProfile): string;
|
|
15
|
+
export interface MountedSkill {
|
|
16
|
+
readonly skill: Extract<AgentProfileResourceRef, {
|
|
17
|
+
kind: 'inline';
|
|
18
|
+
}>;
|
|
19
|
+
/** The skill's sibling files, each mounted beside its `SKILL.md`. */
|
|
20
|
+
readonly files?: readonly AgentProfileFileMount[];
|
|
21
|
+
/** The skill's provenance record first, then one per sibling. */
|
|
22
|
+
readonly provenance?: readonly Readonly<Record<string, unknown>>[];
|
|
23
|
+
}
|
|
24
|
+
/** Add skills, their sibling files and their provenance records to a copy of the profile. */
|
|
25
|
+
export declare function withSkills(profile: AgentProfile, mounts: readonly MountedSkill[]): AgentProfile;
|
|
26
|
+
/** Remove one inline skill, its sibling files and their provenance records from a copy of the profile. */
|
|
27
|
+
export declare function withoutSkill(profile: AgentProfile, name: string): AgentProfile;
|
|
28
|
+
/**
|
|
29
|
+
* Where a child profile came from: the definition file at one commit, and the
|
|
30
|
+
* sha256 of that file's bytes. The child carries a translation of the file,
|
|
31
|
+
* not the file, so Interface's `resourceProvenance`, which hashes inline
|
|
32
|
+
* resources, cannot hold it; the record sits beside it as `subagentSources`.
|
|
33
|
+
*/
|
|
34
|
+
export interface SubagentSource {
|
|
35
|
+
/** The subagent's name in `profile.subagents`. */
|
|
36
|
+
readonly name: string;
|
|
37
|
+
readonly repository: string;
|
|
38
|
+
readonly ref: string;
|
|
39
|
+
readonly path: string;
|
|
40
|
+
readonly sha256: string;
|
|
41
|
+
}
|
|
42
|
+
/** Add one child profile and its source record to a copy of the profile, replacing any of that name. */
|
|
43
|
+
export declare function withSubagent(profile: AgentProfile, child: AgentSubagentProfile, source: SubagentSource): AgentProfile;
|
|
44
|
+
export declare function inlineSkills(profile: AgentProfile): Array<Extract<AgentProfileResourceRef, {
|
|
45
|
+
kind: 'inline';
|
|
46
|
+
}>>;
|
|
47
|
+
/**
|
|
48
|
+
* The name of every skill the profile carries, inline or by a GitHub reference.
|
|
49
|
+
* A GitHub reference without a name counts by the directory of its `SKILL.md`,
|
|
50
|
+
* since that directory is the skill the sessions invoke.
|
|
51
|
+
*/
|
|
52
|
+
export declare function carriedSkillNames(profile: AgentProfile): Set<string>;
|
|
53
|
+
//# sourceMappingURL=learning-profile.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"learning-profile.d.ts","sourceRoot":"","sources":["../../../src/app/learning/learning-profile.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EACV,YAAY,EACZ,qBAAqB,EACrB,uBAAuB,EACvB,oBAAoB,EACrB,MAAM,iCAAiC,CAAA;AAGxC,wBAAgB,SAAS,CAAC,IAAI,EAAE,MAAM,GAAG,MAAM,CAE9C;AAED,wBAAgB,aAAa,CAAC,OAAO,EAAE,YAAY,GAAG,MAAM,CAE3D;AAQD;;;;;GAKG;AACH,wBAAgB,UAAU,CAAC,OAAO,EAAE,YAAY,GAAG,MAAM,CAexD;AAED,wFAAwF;AACxF,wBAAsB,YAAY,CAAC,OAAO,EAAE,YAAY,GAAG,OAAO,CAAC,MAAM,CAAC,CAGzE;AAED,8FAA8F;AAC9F,wBAAgB,mBAAmB,CAAC,OAAO,EAAE,YAAY,GAAG,MAAM,CAEjE;AAED,MAAM,WAAW,YAAY;IAC3B,QAAQ,CAAC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
|
+
import { canonicalAgentProfileDigestHex } from '../../adapters/agent-interface/profile-runtime.js';
|
|
3
|
+
export function sha256Hex(text) {
|
|
4
|
+
return createHash('sha256').update(text, 'utf8').digest('hex');
|
|
5
|
+
}
|
|
6
|
+
export function profileDigest(profile) {
|
|
7
|
+
return `sha256:${canonicalAgentProfileDigestHex(profile)}`;
|
|
8
|
+
}
|
|
9
|
+
function inlineText(resources) {
|
|
10
|
+
return (resources ?? []).flatMap((resource) => resource.kind === 'inline' ? [resource.content] : []);
|
|
11
|
+
}
|
|
12
|
+
/**
|
|
13
|
+
* Every text a harness may load from the profile into the model's context:
|
|
14
|
+
* system prompt additions, instructions, inline skills, tools, agents,
|
|
15
|
+
* commands and subagent prompts. A skill counts in full, so this is an upper
|
|
16
|
+
* bound for harnesses that load a skill's body only when it is invoked.
|
|
17
|
+
*/
|
|
18
|
+
export function loadedText(profile) {
|
|
19
|
+
const parts = [
|
|
20
|
+
profile.prompt?.systemPrompt ?? '',
|
|
21
|
+
profile.prompt?.appendSystemPrompt ?? '',
|
|
22
|
+
...(profile.prompt?.instructions ?? []),
|
|
23
|
+
...inlineText(profile.resources?.skills),
|
|
24
|
+
...inlineText(profile.resources?.tools),
|
|
25
|
+
...inlineText(profile.resources?.agents),
|
|
26
|
+
...inlineText(profile.resources?.commands),
|
|
27
|
+
...Object.values(profile.subagents ?? {}).flatMap((agent) => [
|
|
28
|
+
agent.description ?? '',
|
|
29
|
+
agent.prompt ?? '',
|
|
30
|
+
]),
|
|
31
|
+
];
|
|
32
|
+
return parts.filter((part) => part !== '').join('\n');
|
|
33
|
+
}
|
|
34
|
+
/** Estimated loaded tokens: agent-eval's chars / 4 estimate over {@link loadedText}. */
|
|
35
|
+
export async function loadedTokens(profile) {
|
|
36
|
+
const { estimateTokens } = await import('@tangle-network/agent-eval');
|
|
37
|
+
return estimateTokens(loadedText(profile));
|
|
38
|
+
}
|
|
39
|
+
/** Where `mountSkill` provenance, and Braid's other source records, live for this profile. */
|
|
40
|
+
export function provenanceNamespace(profile) {
|
|
41
|
+
return profile.name ?? 'braid';
|
|
42
|
+
}
|
|
43
|
+
/**
|
|
44
|
+
* A file mount belongs to skill `name` when its inline resource is named
|
|
45
|
+
* `name/<rel>` and it is mounted at `.../name/<rel>`: the shape Interface's
|
|
46
|
+
* `mountSkillDirectory` writes for a skill's sibling files.
|
|
47
|
+
*/
|
|
48
|
+
function isSiblingOf(mount, names) {
|
|
49
|
+
const resource = mount.resource;
|
|
50
|
+
if (resource.kind !== 'inline')
|
|
51
|
+
return false;
|
|
52
|
+
const slash = resource.name.indexOf('/');
|
|
53
|
+
if (slash <= 0)
|
|
54
|
+
return false;
|
|
55
|
+
return (names.has(resource.name.slice(0, slash)) &&
|
|
56
|
+
(mount.path === resource.name || mount.path.endsWith(`/${resource.name}`)));
|
|
57
|
+
}
|
|
58
|
+
/** A provenance record for skill `name` itself or for one of its sibling files. */
|
|
59
|
+
function isRecordOf(record, names) {
|
|
60
|
+
return names.has(String(record.name)) || names.has(String(record.skill));
|
|
61
|
+
}
|
|
62
|
+
/** Replace skills by name in a copy of the profile: their files and provenance records go with them. */
|
|
63
|
+
function replaceSkills(profile, names, mounts) {
|
|
64
|
+
const skills = (profile.resources?.skills ?? []).filter((resource) => resource.kind !== 'inline' || !names.has(resource.name));
|
|
65
|
+
const files = (profile.resources?.files ?? []).filter((mount) => !isSiblingOf(mount, names));
|
|
66
|
+
const addedFiles = mounts.flatMap((mount) => mount.files ?? []);
|
|
67
|
+
const namespace = provenanceNamespace(profile);
|
|
68
|
+
const extension = profile.extensions?.[namespace];
|
|
69
|
+
const existing = Array.isArray(extension?.resourceProvenance)
|
|
70
|
+
? extension.resourceProvenance
|
|
71
|
+
: undefined;
|
|
72
|
+
const records = (existing ?? []).filter((record) => !isRecordOf(record, names));
|
|
73
|
+
const added = mounts.flatMap((mount) => mount.provenance ?? []);
|
|
74
|
+
const nextFiles = [...files, ...addedFiles];
|
|
75
|
+
return {
|
|
76
|
+
...profile,
|
|
77
|
+
resources: {
|
|
78
|
+
...profile.resources,
|
|
79
|
+
skills: [...skills, ...mounts.map((mount) => mount.skill)],
|
|
80
|
+
// A profile that mounted no files keeps no files key, so its digest is unchanged.
|
|
81
|
+
...(nextFiles.length === 0 && profile.resources?.files === undefined
|
|
82
|
+
? {}
|
|
83
|
+
: { files: nextFiles }),
|
|
84
|
+
},
|
|
85
|
+
...(existing === undefined && added.length === 0
|
|
86
|
+
? {}
|
|
87
|
+
: {
|
|
88
|
+
extensions: {
|
|
89
|
+
...profile.extensions,
|
|
90
|
+
[namespace]: { ...extension, resourceProvenance: [...records, ...added] },
|
|
91
|
+
},
|
|
92
|
+
}),
|
|
93
|
+
};
|
|
94
|
+
}
|
|
95
|
+
/** Add skills, their sibling files and their provenance records to a copy of the profile. */
|
|
96
|
+
export function withSkills(profile, mounts) {
|
|
97
|
+
return replaceSkills(profile, new Set(mounts.map((mount) => mount.skill.name)), mounts);
|
|
98
|
+
}
|
|
99
|
+
/** Remove one inline skill, its sibling files and their provenance records from a copy of the profile. */
|
|
100
|
+
export function withoutSkill(profile, name) {
|
|
101
|
+
return replaceSkills(profile, new Set([name]), []);
|
|
102
|
+
}
|
|
103
|
+
/** Add one child profile and its source record to a copy of the profile, replacing any of that name. */
|
|
104
|
+
export function withSubagent(profile, child, source) {
|
|
105
|
+
const namespace = provenanceNamespace(profile);
|
|
106
|
+
const extension = profile.extensions?.[namespace];
|
|
107
|
+
const sources = Array.isArray(extension?.subagentSources)
|
|
108
|
+
? extension.subagentSources.filter((item) => item.name !== source.name)
|
|
109
|
+
: [];
|
|
110
|
+
return {
|
|
111
|
+
...profile,
|
|
112
|
+
subagents: { ...profile.subagents, [source.name]: child },
|
|
113
|
+
extensions: {
|
|
114
|
+
...profile.extensions,
|
|
115
|
+
[namespace]: { ...extension, subagentSources: [...sources, source] },
|
|
116
|
+
},
|
|
117
|
+
};
|
|
118
|
+
}
|
|
119
|
+
export function inlineSkills(profile) {
|
|
120
|
+
return (profile.resources?.skills ?? []).flatMap((resource) => resource.kind === 'inline' ? [resource] : []);
|
|
121
|
+
}
|
|
122
|
+
/**
|
|
123
|
+
* The name of every skill the profile carries, inline or by a GitHub reference.
|
|
124
|
+
* A GitHub reference without a name counts by the directory of its `SKILL.md`,
|
|
125
|
+
* since that directory is the skill the sessions invoke.
|
|
126
|
+
*/
|
|
127
|
+
export function carriedSkillNames(profile) {
|
|
128
|
+
return new Set((profile.resources?.skills ?? []).flatMap((resource) => {
|
|
129
|
+
if (resource.name !== undefined && resource.name !== '')
|
|
130
|
+
return [resource.name];
|
|
131
|
+
if (resource.kind !== 'github')
|
|
132
|
+
return [];
|
|
133
|
+
const parts = resource.path.split('/');
|
|
134
|
+
return parts.at(-1) === 'SKILL.md' && parts.length > 1 ? [parts.at(-2)] : [];
|
|
135
|
+
}));
|
|
136
|
+
}
|
|
137
|
+
//# sourceMappingURL=learning-profile.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"learning-profile.js","sourceRoot":"","sources":["../../../src/app/learning/learning-profile.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,UAAU,EAAE,MAAM,aAAa,CAAA;AAOxC,OAAO,EAAE,8BAA8B,EAAE,MAAM,mDAAmD,CAAA;AAElG,MAAM,UAAU,SAAS,CAAC,IAAY;IACpC,OAAO,UAAU,CAAC,QAAQ,CAAC,CAAC,MAAM,CAAC,IAAI,EAAE,MAAM,CAAC,CAAC,MAAM,CAAC,KAAK,CAAC,CAAA;AAChE,CAAC;AAED,MAAM,UAAU,aAAa,CAAC,OAAqB;IACjD,OAAO,UAAU,8BAA8B,CAAC,OAAO,CAAC,EAAE,CAAA;AAC5D,CAAC;AAED,SAAS,UAAU,CAAC,SAAyD;IAC3E,OAAO,CAAC,SAAS,IAAI,EAAE,CAAC,CAAC,OAAO,CAAC,CAAC,QAAQ,EAAE,EAAE,CAC5C,QAAQ,CAAC,IAAI,KAAK,QAAQ,CAAC,CAAC,CAAC,CAAC,QAAQ,CAA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,CAAA;AACH,CAAC"}
|
|
@@ -0,0 +1,45 @@
|
|
|
1
|
+
import type { AgentProfile } from '@tangle-network/agent-interface';
|
|
2
|
+
import type { BraidState } from '../../domain/state.js';
|
|
3
|
+
import type { BraidApplication } from '../application.js';
|
|
4
|
+
import type { LearningTask } from './learning-types.js';
|
|
5
|
+
/** What a replay needs from the application that owns the user's connection. */
|
|
6
|
+
export interface ReplayHost {
|
|
7
|
+
state(): BraidState;
|
|
8
|
+
replayApplication(profile: Readonly<AgentProfile>): BraidApplication;
|
|
9
|
+
}
|
|
10
|
+
export interface TaskReplay {
|
|
11
|
+
readonly taskId: string;
|
|
12
|
+
readonly family: string;
|
|
13
|
+
/** null when the run or the check could not finish: not the candidate's failure. */
|
|
14
|
+
readonly pass: boolean | null;
|
|
15
|
+
readonly error: string | null;
|
|
16
|
+
readonly answer: string;
|
|
17
|
+
readonly runId: string | null;
|
|
18
|
+
readonly runner: string | null;
|
|
19
|
+
readonly model: string | null;
|
|
20
|
+
readonly trace: {
|
|
21
|
+
readonly toolCalls: number | null;
|
|
22
|
+
readonly toolErrors: number | null;
|
|
23
|
+
readonly wallMs: number | null;
|
|
24
|
+
readonly costUsd: number | null;
|
|
25
|
+
};
|
|
26
|
+
readonly tokens: {
|
|
27
|
+
readonly input: number;
|
|
28
|
+
readonly output: number;
|
|
29
|
+
readonly known: boolean;
|
|
30
|
+
};
|
|
31
|
+
readonly checkOutput: string;
|
|
32
|
+
}
|
|
33
|
+
/**
|
|
34
|
+
* Replay one held-out task under one profile: a fresh workspace at the task's
|
|
35
|
+
* commit, a fresh in-memory Braid application over the user's own execution
|
|
36
|
+
* and connection, then the task's check. The candidate never sees the check.
|
|
37
|
+
*/
|
|
38
|
+
export declare function replayTask(input: {
|
|
39
|
+
readonly host: ReplayHost;
|
|
40
|
+
readonly profile: Readonly<AgentProfile>;
|
|
41
|
+
readonly task: LearningTask;
|
|
42
|
+
readonly replayRoot: string;
|
|
43
|
+
readonly timeoutMs: number;
|
|
44
|
+
}): Promise<TaskReplay>;
|
|
45
|
+
//# sourceMappingURL=learning-replay.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"learning-replay.d.ts","sourceRoot":"","sources":["../../../src/app/learning/learning-replay.ts"],"names":[],"mappings":"AAKA,OAAO,KAAK,EAAE,YAAY,EAAE,MAAM,iCAAiC,CAAA;AACnE,OAAO,KAAK,EAAE,UAAU,EAAE,MAAM,uBAAuB,CAAA;AACvD,OAAO,KAAK,EAAE,gBAAgB,EAAE,MAAM,mBAAmB,CAAA;AAEzD,OAAO,KAAK,EAAE,YAAY,EAAE,MAAM,qBAAqB,CAAA;AAKvD,gFAAgF;AAChF,MAAM,WAAW,UAAU;IACzB,KAAK,IAAI,UAAU,CAAA;IACnB,iBAAiB,CAAC,OAAO,EAAE,QAAQ,CAAC,YAAY,CAAC,GAAG,gBAAgB,CAAA;CACrE;AAED,MAAM,WAAW,UAAU;IACzB,QAAQ,CAAC,MAAM,EAAE,MAAM,CAAA;IACvB,QAAQ,CAAC,MAAM,EAAE,MAAM,CAAA;IACvB,oFAAoF;IACpF,QAAQ,CAAC,IAAI,EAAE,OAAO,GAAG,IAAI,CAAA;IAC7B,QAAQ,CAAC,KAAK,EAAE,MAAM,GAAG,IAAI,CAAA;IAC7B,QAAQ,CAAC,MAAM,EAAE,MAAM,CAAA;IACvB,QAAQ,CAAC,KAAK,EAAE,MAAM,GAAG,IAAI,CAAA;IAC7B,QAAQ,CAAC,MAAM,EAAE,MAAM,GAAG,IAAI,CAAA;IAC9B,QAAQ,CAAC,KAAK,EAAE,MAAM,GAAG,IAAI,CAAA;IAC7B,QAAQ,CAAC,KAAK,EAAE;QACd,QAAQ,CAAC,SAAS,EAAE,MAAM,GAAG,IAAI,CAAA;QACjC,QAAQ,CAAC,UAAU,EAAE,MAAM,GAAG,IAAI,CAAA;QAClC,QAAQ,CAAC,MAAM,EAAE,MAAM,GAAG,IAAI,CAAA;QAC9B,QAAQ,CAAC,OAAO,EAAE,MAAM,GAAG,IAAI,CAAA;KAChC,CAAA;IACD,QAAQ,CAAC,MAAM,EAAE;QAAE,QAAQ,CAAC,KAAK,EAAE,MAAM,CAAC;QAAC,QAAQ,CAAC,MAAM,EAAE,MAAM,CAAC;QAAC,QAAQ,CAAC,KAAK,EAAE,OAAO,CAAA;KAAE,CAAA;IAC7F,QAAQ,CAAC,WAAW,EAAE,MAAM,CAAA;CAC7B;AA4GD;;;;GAIG;AACH,wBAAsB,UAAU,CAAC,KAAK,EAAE;IACtC,QAAQ,CAAC,IAAI,EAAE,UAAU,CAAA;IACzB,QAAQ,CAAC,OAAO,EAAE,QAAQ,CAAC,YAAY,CAAC,CAAA;IACxC,QAAQ,CAAC,IAAI,EAAE,YAAY,CAAA;IAC3B,QAAQ,CAAC,UAAU,EAAE,MAAM,CAAA;IAC3B,QAAQ,CAAC,SAAS,EAAE,MAAM,CAAA;CAC3B,GAAG,OAAO,CAAC,UAAU,CAAC,CA2EtB"}
|
|
@@ -0,0 +1,170 @@
|
|
|
1
|
+
import { execFile } from 'node:child_process';
|
|
2
|
+
import { randomUUID } from 'node:crypto';
|
|
3
|
+
import { mkdir, mkdtemp, rm, writeFile } from 'node:fs/promises';
|
|
4
|
+
import { join } from 'node:path';
|
|
5
|
+
import { promisify } from 'node:util';
|
|
6
|
+
import { ConnectionActionService } from '../connection-actions.js';
|
|
7
|
+
const run = promisify(execFile);
|
|
8
|
+
const CHECK_OUTPUT_TAIL = 2_000;
|
|
9
|
+
async function prepareWorkspace(task, directory) {
|
|
10
|
+
const work = join(directory, 'work');
|
|
11
|
+
if (task.workspace.kind === 'git') {
|
|
12
|
+
await run('git', ['-C', task.workspace.root, 'worktree', 'add', '--detach', work, task.workspace.commit], { timeout: 120_000 });
|
|
13
|
+
}
|
|
14
|
+
else {
|
|
15
|
+
await mkdir(work, { recursive: true, mode: 0o700 });
|
|
16
|
+
}
|
|
17
|
+
return work;
|
|
18
|
+
}
|
|
19
|
+
async function removeWorkspace(task, directory) {
|
|
20
|
+
if (task.workspace.kind === 'git') {
|
|
21
|
+
await run('git', ['-C', task.workspace.root, 'worktree', 'remove', '--force', join(directory, 'work')], { timeout: 120_000 }).catch(() => undefined);
|
|
22
|
+
}
|
|
23
|
+
await rm(directory, { recursive: true, force: true });
|
|
24
|
+
}
|
|
25
|
+
async function selectParentConnection(host, child) {
|
|
26
|
+
const parent = host.state();
|
|
27
|
+
const connectionId = parent.selectedConnectionId;
|
|
28
|
+
if (connectionId === null)
|
|
29
|
+
return;
|
|
30
|
+
await new ConnectionActionService({
|
|
31
|
+
host: {
|
|
32
|
+
state: () => child.state(),
|
|
33
|
+
configuration: child.configuration,
|
|
34
|
+
runtime: child.runtimeSelection,
|
|
35
|
+
},
|
|
36
|
+
connections: parent.connections,
|
|
37
|
+
}).select({ operationId: `op-learn-connection-${randomUUID()}`, connectionId });
|
|
38
|
+
}
|
|
39
|
+
function runEvidence(state, runId) {
|
|
40
|
+
const record = state.runs.find((item) => item.id === runId);
|
|
41
|
+
const messages = state.messages.filter((message) => message.runId === runId && message.role === 'assistant');
|
|
42
|
+
const messageIds = new Set(messages.map((message) => message.id));
|
|
43
|
+
const parts = state.messageParts.filter((part) => messageIds.has(part.messageId));
|
|
44
|
+
const calls = parts.filter((part) => part.kind === 'tool-call');
|
|
45
|
+
const failures = parts.filter((part) => (part.kind === 'tool-call' || part.kind === 'tool-result') && part.status === 'failed');
|
|
46
|
+
const started = record === undefined ? Number.NaN : Date.parse(record.startedAt);
|
|
47
|
+
const ended = record?.terminalAt === undefined ? Number.NaN : Date.parse(record.terminalAt);
|
|
48
|
+
return {
|
|
49
|
+
record,
|
|
50
|
+
answer: messages.map((message) => message.text).join('\n'),
|
|
51
|
+
runner: record?.receipt.requested.runner ?? record?.receipt.requested.profile.harness ?? null,
|
|
52
|
+
trace: {
|
|
53
|
+
toolCalls: calls.length,
|
|
54
|
+
toolErrors: failures.length,
|
|
55
|
+
wallMs: Number.isFinite(started) && Number.isFinite(ended) ? ended - started : null,
|
|
56
|
+
costUsd: record === undefined || record.usdKnown === false ? null : (record.costUsd ?? null),
|
|
57
|
+
},
|
|
58
|
+
tokens: {
|
|
59
|
+
input: record?.inputTokens ?? 0,
|
|
60
|
+
output: record?.outputTokens ?? 0,
|
|
61
|
+
known: record !== undefined && record.tokensKnown !== false,
|
|
62
|
+
},
|
|
63
|
+
};
|
|
64
|
+
}
|
|
65
|
+
/** Run the task's check in the replay directory. Exit 0 passes; a check that cannot start errors. */
|
|
66
|
+
async function runCheck(task, work, answerPath) {
|
|
67
|
+
const [command, ...args] = task.check.argv;
|
|
68
|
+
if (command === undefined)
|
|
69
|
+
return { pass: null, error: 'the task has no check', output: '' };
|
|
70
|
+
try {
|
|
71
|
+
const { stdout, stderr } = await run(command, args, {
|
|
72
|
+
cwd: work,
|
|
73
|
+
timeout: task.check.timeoutMs,
|
|
74
|
+
maxBuffer: 16 * 1024 * 1024,
|
|
75
|
+
env: { ...process.env, BRAID_REPLAY_ANSWER: answerPath, BRAID_REPLAY_DIR: work },
|
|
76
|
+
});
|
|
77
|
+
return { pass: true, error: null, output: `${stdout}${stderr}`.slice(-CHECK_OUTPUT_TAIL) };
|
|
78
|
+
}
|
|
79
|
+
catch (error) {
|
|
80
|
+
const failure = error;
|
|
81
|
+
const output = `${failure.stdout ?? ''}${failure.stderr ?? ''}`.slice(-CHECK_OUTPUT_TAIL);
|
|
82
|
+
if (failure.killed === true)
|
|
83
|
+
return { pass: null, error: `the check ran past ${task.check.timeoutMs} ms`, output };
|
|
84
|
+
if (typeof failure.code === 'number')
|
|
85
|
+
return { pass: false, error: null, output };
|
|
86
|
+
return { pass: null, error: `the check could not start: ${String(failure.code)}`, output };
|
|
87
|
+
}
|
|
88
|
+
}
|
|
89
|
+
/**
|
|
90
|
+
* Replay one held-out task under one profile: a fresh workspace at the task's
|
|
91
|
+
* commit, a fresh in-memory Braid application over the user's own execution
|
|
92
|
+
* and connection, then the task's check. The candidate never sees the check.
|
|
93
|
+
*/
|
|
94
|
+
export async function replayTask(input) {
|
|
95
|
+
const { task } = input;
|
|
96
|
+
const directory = await mkdtemp(join(input.replayRoot, 'replay-'));
|
|
97
|
+
const failed = (error, partial = {}) => ({
|
|
98
|
+
taskId: task.id,
|
|
99
|
+
family: task.family,
|
|
100
|
+
pass: null,
|
|
101
|
+
error,
|
|
102
|
+
answer: '',
|
|
103
|
+
runId: null,
|
|
104
|
+
runner: input.profile.harness ?? null,
|
|
105
|
+
model: input.profile.model?.default ?? null,
|
|
106
|
+
trace: { toolCalls: null, toolErrors: null, wallMs: null, costUsd: null },
|
|
107
|
+
tokens: { input: 0, output: 0, known: false },
|
|
108
|
+
checkOutput: '',
|
|
109
|
+
...partial,
|
|
110
|
+
});
|
|
111
|
+
let child;
|
|
112
|
+
try {
|
|
113
|
+
const work = await prepareWorkspace(task, directory).catch((error) => {
|
|
114
|
+
throw new Error(`the workspace could not be prepared: ${error instanceof Error ? error.message : String(error)}`);
|
|
115
|
+
});
|
|
116
|
+
child = input.host.replayApplication(input.profile);
|
|
117
|
+
child.initialize(work);
|
|
118
|
+
await selectParentConnection(input.host, child);
|
|
119
|
+
const operationId = `op-learn-replay-${randomUUID()}`;
|
|
120
|
+
const receipt = child.send({ operationId, text: task.prompt });
|
|
121
|
+
let timer;
|
|
122
|
+
const finished = await Promise.race([
|
|
123
|
+
receipt.completion.then(() => true),
|
|
124
|
+
new Promise((resolve) => {
|
|
125
|
+
timer = setTimeout(() => resolve(false), input.timeoutMs);
|
|
126
|
+
}),
|
|
127
|
+
]).finally(() => clearTimeout(timer));
|
|
128
|
+
if (!finished) {
|
|
129
|
+
child.cancel({ operationId: `${operationId}-cancel`, runId: receipt.runId });
|
|
130
|
+
return failed(`the run did not finish within ${input.timeoutMs} ms`, {
|
|
131
|
+
runId: receipt.runId,
|
|
132
|
+
});
|
|
133
|
+
}
|
|
134
|
+
const evidence = runEvidence(child.state(), receipt.runId);
|
|
135
|
+
const runner = evidence.runner ?? input.profile.harness ?? null;
|
|
136
|
+
const model = evidence.record?.model ?? input.profile.model?.default ?? null;
|
|
137
|
+
if (evidence.record?.status !== 'completed')
|
|
138
|
+
return failed(`the run ended ${evidence.record?.status ?? 'unknown'}`, {
|
|
139
|
+
runId: receipt.runId,
|
|
140
|
+
runner,
|
|
141
|
+
model,
|
|
142
|
+
trace: evidence.trace,
|
|
143
|
+
tokens: evidence.tokens,
|
|
144
|
+
});
|
|
145
|
+
const answerPath = join(directory, 'answer.txt');
|
|
146
|
+
await writeFile(answerPath, evidence.answer, { mode: 0o600 });
|
|
147
|
+
const check = await runCheck(task, work, answerPath);
|
|
148
|
+
return {
|
|
149
|
+
taskId: task.id,
|
|
150
|
+
family: task.family,
|
|
151
|
+
pass: check.pass,
|
|
152
|
+
error: check.error,
|
|
153
|
+
answer: evidence.answer,
|
|
154
|
+
runId: receipt.runId,
|
|
155
|
+
runner,
|
|
156
|
+
model,
|
|
157
|
+
trace: evidence.trace,
|
|
158
|
+
tokens: evidence.tokens,
|
|
159
|
+
checkOutput: check.output,
|
|
160
|
+
};
|
|
161
|
+
}
|
|
162
|
+
catch (error) {
|
|
163
|
+
return failed(error instanceof Error ? error.message : String(error));
|
|
164
|
+
}
|
|
165
|
+
finally {
|
|
166
|
+
await child?.close().catch(() => undefined);
|
|
167
|
+
await removeWorkspace(task, directory);
|
|
168
|
+
}
|
|
169
|
+
}
|
|
170
|
+
//# sourceMappingURL=learning-replay.js.map
|