@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,628 @@
|
|
|
1
|
+
import { execFile } from 'node:child_process';
|
|
2
|
+
import { readdir, readFile, realpath } from 'node:fs/promises';
|
|
3
|
+
import { basename, dirname, join, posix, relative, sep } from 'node:path';
|
|
4
|
+
import { promisify } from 'node:util';
|
|
5
|
+
import { mountSkill, mountSkillDirectory, } from '@tangle-network/agent-interface';
|
|
6
|
+
import { isMaterializerHarness, skillDirForHarness, } from '@tangle-network/agent-profile-materialize';
|
|
7
|
+
import { draftProfileFromFeedback } from '../profile-learning.js';
|
|
8
|
+
import { carriedInstructionBlocks, composable, instructionBlockId, loadedInstructionBlocks, onDisk, rankInstructionBlocks, withInstructionBlock, withoutInstructionBlock, } from './instruction-blocks.js';
|
|
9
|
+
import { CANDIDATE_KINDS, DEFAULT_LEARNER_SETTINGS } from './learner-profile.js';
|
|
10
|
+
import { carriedSkillNames, inlineSkills, loadedTokens, profileDigest, sha256Hex, withoutSkill, withSkills, withSubagent, } from './learning-profile.js';
|
|
11
|
+
import { countChanges, harnessName, orderedSkillPairs, sessionIndex, sessionsInvoking, subagentStarts, } from './learning-sources.js';
|
|
12
|
+
const run = promisify(execFile);
|
|
13
|
+
async function git(cwd, args) {
|
|
14
|
+
const { stdout } = await run('git', ['-C', cwd, ...args], {
|
|
15
|
+
timeout: 10_000,
|
|
16
|
+
maxBuffer: 8 * 1024 * 1024,
|
|
17
|
+
});
|
|
18
|
+
return stdout;
|
|
19
|
+
}
|
|
20
|
+
async function gitBytes(cwd, args) {
|
|
21
|
+
const { stdout } = await run('git', ['-C', cwd, ...args], {
|
|
22
|
+
timeout: 10_000,
|
|
23
|
+
maxBuffer: 8 * 1024 * 1024,
|
|
24
|
+
encoding: 'buffer',
|
|
25
|
+
});
|
|
26
|
+
return stdout;
|
|
27
|
+
}
|
|
28
|
+
const MAX_SIBLINGS = 64;
|
|
29
|
+
const MAX_SIBLING_BYTES = 1024 * 1024;
|
|
30
|
+
/**
|
|
31
|
+
* The committed files beside a skill's `SKILL.md` at one commit. Only text
|
|
32
|
+
* files mount inline, so a binary file, a link or a submodule is omitted with
|
|
33
|
+
* its reason, as is everything past the size limits.
|
|
34
|
+
*/
|
|
35
|
+
async function skillSiblings(root, commit, skillPath) {
|
|
36
|
+
const directory = posix.dirname(skillPath);
|
|
37
|
+
if (directory === '.')
|
|
38
|
+
return { files: [], omitted: ['the skill is the repository root, so no sibling is mounted'] };
|
|
39
|
+
const listing = (await gitBytes(root, ['ls-tree', '-r', '-z', commit, '--', `${directory}/`]))
|
|
40
|
+
.toString('utf8')
|
|
41
|
+
.split('\0')
|
|
42
|
+
.filter((entry) => entry !== '');
|
|
43
|
+
const files = [];
|
|
44
|
+
const omitted = [];
|
|
45
|
+
let bytes = 0;
|
|
46
|
+
for (const entry of listing) {
|
|
47
|
+
const tab = entry.indexOf('\t');
|
|
48
|
+
const [mode, type] = entry.slice(0, tab).split(' ');
|
|
49
|
+
const path = entry.slice(tab + 1);
|
|
50
|
+
const inside = path.slice(directory.length + 1);
|
|
51
|
+
if (inside === 'SKILL.md')
|
|
52
|
+
continue;
|
|
53
|
+
if (type !== 'blob' || (mode !== '100644' && mode !== '100755')) {
|
|
54
|
+
omitted.push(`${inside}: a ${mode === '120000' ? 'symbolic link' : type} has no inline form`);
|
|
55
|
+
continue;
|
|
56
|
+
}
|
|
57
|
+
if (files.length >= MAX_SIBLINGS) {
|
|
58
|
+
omitted.push(`${inside}: past the ${MAX_SIBLINGS}-file limit`);
|
|
59
|
+
continue;
|
|
60
|
+
}
|
|
61
|
+
const content = await gitBytes(root, ['show', `${commit}:${path}`]);
|
|
62
|
+
const text = content.toString('utf8');
|
|
63
|
+
if (content.includes(0) || !Buffer.from(text, 'utf8').equals(content)) {
|
|
64
|
+
omitted.push(`${inside}: binary, so it has no inline form`);
|
|
65
|
+
continue;
|
|
66
|
+
}
|
|
67
|
+
if (bytes + content.length > MAX_SIBLING_BYTES) {
|
|
68
|
+
omitted.push(`${inside}: past the ${MAX_SIBLING_BYTES}-byte limit`);
|
|
69
|
+
continue;
|
|
70
|
+
}
|
|
71
|
+
bytes += content.length;
|
|
72
|
+
files.push({ path: inside, content: text, ...(mode === '100755' ? { executable: true } : {}) });
|
|
73
|
+
}
|
|
74
|
+
return { files, omitted };
|
|
75
|
+
}
|
|
76
|
+
/** `owner/repo` from a GitHub remote URL, or undefined for any other remote. */
|
|
77
|
+
export function githubRepository(remote) {
|
|
78
|
+
const match = /^(?:https:\/\/github\.com\/|git@github\.com:|ssh:\/\/git@github\.com\/)([A-Za-z0-9_.-]+)\/([A-Za-z0-9_.-]+?)(?:\.git)?\/?$/u.exec(remote.trim());
|
|
79
|
+
return match === null ? undefined : `${match[1]}/${match[2]}`;
|
|
80
|
+
}
|
|
81
|
+
async function pinCommittedFile(source, what) {
|
|
82
|
+
let file;
|
|
83
|
+
try {
|
|
84
|
+
file = await realpath(source);
|
|
85
|
+
}
|
|
86
|
+
catch {
|
|
87
|
+
return { pinned: false, reason: `the ${what} no longer exists` };
|
|
88
|
+
}
|
|
89
|
+
try {
|
|
90
|
+
const root = (await git(dirname(file), ['rev-parse', '--show-toplevel'])).trim();
|
|
91
|
+
const path = relative(await realpath(root), file)
|
|
92
|
+
.split(sep)
|
|
93
|
+
.join('/');
|
|
94
|
+
const commit = (await git(root, ['rev-parse', 'HEAD'])).trim();
|
|
95
|
+
const repository = githubRepository(await git(root, ['remote', 'get-url', 'origin']));
|
|
96
|
+
if (repository === undefined)
|
|
97
|
+
return { pinned: false, reason: 'its checkout has no GitHub origin to pin to' };
|
|
98
|
+
if ((await git(root, ['status', '--porcelain', '--', path])).trim() !== '')
|
|
99
|
+
return { pinned: false, reason: `the ${what} has uncommitted changes` };
|
|
100
|
+
const content = await git(root, ['show', `${commit}:${path}`]);
|
|
101
|
+
return { pinned: true, file, root, repository, commit, path, content };
|
|
102
|
+
}
|
|
103
|
+
catch {
|
|
104
|
+
return { pinned: false, reason: `the ${what} is not in a git checkout` };
|
|
105
|
+
}
|
|
106
|
+
}
|
|
107
|
+
export async function pinSkillFile(name, skillFile) {
|
|
108
|
+
const pinned = await pinCommittedFile(skillFile, 'skill file');
|
|
109
|
+
if (!pinned.pinned)
|
|
110
|
+
return pinned;
|
|
111
|
+
const { file, root, repository, commit, path, content } = pinned;
|
|
112
|
+
try {
|
|
113
|
+
const directory = posix.dirname(path);
|
|
114
|
+
if (directory !== '.' &&
|
|
115
|
+
(await git(root, ['status', '--porcelain', '--untracked-files=no', '--', `${directory}/`])).trim() !== '')
|
|
116
|
+
return { pinned: false, reason: 'a file beside the skill has uncommitted changes' };
|
|
117
|
+
const { files: siblings, omitted } = await skillSiblings(root, commit, path);
|
|
118
|
+
const { readSkillFile } = await import('@tangle-network/agent-eval/analyst');
|
|
119
|
+
const read = readSkillFile(file);
|
|
120
|
+
if (!read.succeeded)
|
|
121
|
+
return { pinned: false, reason: `the skill file is unreadable: ${read.error}` };
|
|
122
|
+
return {
|
|
123
|
+
pinned: true,
|
|
124
|
+
skill: {
|
|
125
|
+
name,
|
|
126
|
+
repository,
|
|
127
|
+
commit,
|
|
128
|
+
path,
|
|
129
|
+
content,
|
|
130
|
+
siblings,
|
|
131
|
+
omitted,
|
|
132
|
+
bodySha256: read.bodySha256,
|
|
133
|
+
},
|
|
134
|
+
};
|
|
135
|
+
}
|
|
136
|
+
catch {
|
|
137
|
+
return { pinned: false, reason: 'the skill directory could not be read at its commit' };
|
|
138
|
+
}
|
|
139
|
+
}
|
|
140
|
+
/** Pin a subagent definition file, committed and unchanged, to its commit. */
|
|
141
|
+
export async function pinAgentFile(name, agentFile) {
|
|
142
|
+
const pinned = await pinCommittedFile(agentFile, 'definition file');
|
|
143
|
+
if (!pinned.pinned)
|
|
144
|
+
return pinned;
|
|
145
|
+
const { repository, commit, path, content } = pinned;
|
|
146
|
+
return { pinned: true, agent: { name, repository, commit, path, content } };
|
|
147
|
+
}
|
|
148
|
+
/**
|
|
149
|
+
* Where siblings mount: the profile's harness's skill directory. A runner that
|
|
150
|
+
* reads skills elsewhere gets them beside its own copy of the skill from the
|
|
151
|
+
* materializer, which keeps a skill's files with it.
|
|
152
|
+
*/
|
|
153
|
+
const FRONTMATTER = /^---\r?\n([\s\S]*?)\r?\n---[ \t]*(?:\r?\n|$)([\s\S]*)$/;
|
|
154
|
+
/** The subagent names every runner's materializer accepts. */
|
|
155
|
+
const SUBAGENT_NAME = /^[a-z0-9][a-z0-9_-]*$/;
|
|
156
|
+
function scalar(raw) {
|
|
157
|
+
const value = raw.trim();
|
|
158
|
+
if (value.startsWith('"')) {
|
|
159
|
+
try {
|
|
160
|
+
const parsed = JSON.parse(value);
|
|
161
|
+
return typeof parsed === 'string' ? parsed : undefined;
|
|
162
|
+
}
|
|
163
|
+
catch {
|
|
164
|
+
return undefined;
|
|
165
|
+
}
|
|
166
|
+
}
|
|
167
|
+
if (value.startsWith("'"))
|
|
168
|
+
return value.length >= 2 && value.endsWith("'")
|
|
169
|
+
? value.slice(1, -1).replaceAll("''", "'")
|
|
170
|
+
: undefined;
|
|
171
|
+
// A block scalar or a nested value is not flat.
|
|
172
|
+
return value.startsWith('|') || value.startsWith('>') ? undefined : value;
|
|
173
|
+
}
|
|
174
|
+
/**
|
|
175
|
+
* Read a subagent definition. Only flat `key: value` frontmatter is read; a
|
|
176
|
+
* definition with nested or block values is refused rather than half read.
|
|
177
|
+
*/
|
|
178
|
+
export function readAgentDefinition(content) {
|
|
179
|
+
const match = FRONTMATTER.exec(content);
|
|
180
|
+
if (match === null)
|
|
181
|
+
return { read: false, reason: 'it has no frontmatter block' };
|
|
182
|
+
const fields = {};
|
|
183
|
+
for (const line of match[1].split(/\r?\n/)) {
|
|
184
|
+
if (line.trim() === '' || line.trimStart().startsWith('#'))
|
|
185
|
+
continue;
|
|
186
|
+
const pair = /^([A-Za-z][\w-]*):(.*)$/.exec(line);
|
|
187
|
+
const value = pair === null ? undefined : scalar(pair[2]);
|
|
188
|
+
if (pair === null || value === undefined)
|
|
189
|
+
return { read: false, reason: 'its frontmatter is not flat `key: value` lines' };
|
|
190
|
+
fields[pair[1]] = value;
|
|
191
|
+
}
|
|
192
|
+
const description = fields.description ?? '';
|
|
193
|
+
const prompt = match[2].trim();
|
|
194
|
+
if (description === '')
|
|
195
|
+
return { read: false, reason: 'it has no description' };
|
|
196
|
+
if (prompt === '')
|
|
197
|
+
return { read: false, reason: 'it has no prompt' };
|
|
198
|
+
return { read: true, description, prompt, fields };
|
|
199
|
+
}
|
|
200
|
+
/**
|
|
201
|
+
* Definition files by the subagent name their frontmatter gives, from the
|
|
202
|
+
* first directory that defines each name: the order Claude Code gives a
|
|
203
|
+
* project's agents over the user's. A directory that cannot be read defines none.
|
|
204
|
+
*/
|
|
205
|
+
async function agentDefinitionFiles(directories) {
|
|
206
|
+
const files = new Map();
|
|
207
|
+
for (const directory of directories) {
|
|
208
|
+
let entries;
|
|
209
|
+
try {
|
|
210
|
+
entries = (await readdir(directory)).filter((entry) => entry.endsWith('.md')).sort();
|
|
211
|
+
}
|
|
212
|
+
catch {
|
|
213
|
+
continue;
|
|
214
|
+
}
|
|
215
|
+
for (const entry of entries) {
|
|
216
|
+
const file = join(directory, entry);
|
|
217
|
+
let content;
|
|
218
|
+
try {
|
|
219
|
+
content = await readFile(file, 'utf8');
|
|
220
|
+
}
|
|
221
|
+
catch {
|
|
222
|
+
continue;
|
|
223
|
+
}
|
|
224
|
+
const definition = readAgentDefinition(content);
|
|
225
|
+
const name = definition.read ? definition.fields.name : undefined;
|
|
226
|
+
if (name !== undefined && !files.has(name))
|
|
227
|
+
files.set(name, file);
|
|
228
|
+
}
|
|
229
|
+
}
|
|
230
|
+
return files;
|
|
231
|
+
}
|
|
232
|
+
export function skillsDirectoryFor(profile) {
|
|
233
|
+
const harness = profile.harness;
|
|
234
|
+
return ((harness !== undefined && isMaterializerHarness(harness)
|
|
235
|
+
? skillDirForHarness(harness)
|
|
236
|
+
: null) ?? '.claude/skills');
|
|
237
|
+
}
|
|
238
|
+
function mounted(skill, skillsDirectory) {
|
|
239
|
+
if (skill.siblings.length === 0) {
|
|
240
|
+
const { skill: resource, provenance } = mountSkill({ repository: skill.repository, ref: skill.commit, path: skill.path, name: skill.name }, skill.content);
|
|
241
|
+
return { skill: resource, provenance: [{ ...provenance }] };
|
|
242
|
+
}
|
|
243
|
+
const directory = posix.dirname(skill.path);
|
|
244
|
+
const mount = mountSkillDirectory({
|
|
245
|
+
repository: skill.repository,
|
|
246
|
+
ref: skill.commit,
|
|
247
|
+
directory: directory === '.' ? '' : directory,
|
|
248
|
+
name: skill.name,
|
|
249
|
+
}, [{ path: 'SKILL.md', content: skill.content }, ...skill.siblings], { skillsDirectory });
|
|
250
|
+
return {
|
|
251
|
+
skill: mount.skill,
|
|
252
|
+
files: mount.files,
|
|
253
|
+
provenance: mount.provenance.map((record) => ({ ...record })),
|
|
254
|
+
};
|
|
255
|
+
}
|
|
256
|
+
/** The evidence line for a skill's directory: what mounted beside `SKILL.md`, and what did not. */
|
|
257
|
+
function siblingEvidence(skill) {
|
|
258
|
+
return [
|
|
259
|
+
...(skill.siblings.length === 0
|
|
260
|
+
? []
|
|
261
|
+
: [
|
|
262
|
+
`mounted with ${skill.siblings.length} files beside SKILL.md, each pinned to the same commit`,
|
|
263
|
+
]),
|
|
264
|
+
...skill.omitted.map((reason) => `not mounted: ${reason}`),
|
|
265
|
+
];
|
|
266
|
+
}
|
|
267
|
+
async function candidate(kind, input) {
|
|
268
|
+
const digest = profileDigest(input.profile);
|
|
269
|
+
return {
|
|
270
|
+
id: `${kind}-${digest.slice('sha256:'.length, 'sha256:'.length + 10)}`,
|
|
271
|
+
kind,
|
|
272
|
+
...input,
|
|
273
|
+
profileDigest: digest,
|
|
274
|
+
loadedTokens: await loadedTokens(input.profile),
|
|
275
|
+
};
|
|
276
|
+
}
|
|
277
|
+
function workflowSkill(first, second, sessions) {
|
|
278
|
+
const name = `${first}-then-${second}`;
|
|
279
|
+
return [
|
|
280
|
+
'---',
|
|
281
|
+
`name: ${name}`,
|
|
282
|
+
`description: Run the ${first} skill, then the ${second} skill on its result.`,
|
|
283
|
+
'---',
|
|
284
|
+
'',
|
|
285
|
+
`# ${first}, then ${second}`,
|
|
286
|
+
'',
|
|
287
|
+
`Learned from ${sessions} recorded sessions that ran \`${first}\` before \`${second}\`.`,
|
|
288
|
+
'',
|
|
289
|
+
`1. Run the \`${first}\` skill for the task.`,
|
|
290
|
+
`2. When it finishes, run the \`${second}\` skill on what it produced.`,
|
|
291
|
+
'3. Report the result of both steps together.',
|
|
292
|
+
'',
|
|
293
|
+
].join('\n');
|
|
294
|
+
}
|
|
295
|
+
/** The evidence line for what a candidate's sessions came to; unknown is its own count, never folded into none. */
|
|
296
|
+
/** Sessions per harness: `2 Claude Code, 1 Codex`. */
|
|
297
|
+
function sessionsByHarness(records) {
|
|
298
|
+
return [...new Set(records.map((session) => session.harness))]
|
|
299
|
+
.map((name) => `${records.filter((session) => session.harness === name).length} ${harnessName(name)}`)
|
|
300
|
+
.join(', ');
|
|
301
|
+
}
|
|
302
|
+
function changeEvidence(counts, sessions) {
|
|
303
|
+
const total = counts.changed + counts.none + counts.unknown;
|
|
304
|
+
return `Changes of the ${total} sessions that ${sessions}: ${counts.changed} made a change, ${counts.none} made none, ${counts.unknown} unknown`;
|
|
305
|
+
}
|
|
306
|
+
/** Invocations of one skill version per harness: `3 in 3 Claude Code sessions, 2 in 2 Codex sessions`. */
|
|
307
|
+
function invocationsByHarness(harness, row) {
|
|
308
|
+
return harness.harnesses
|
|
309
|
+
.flatMap((read) => {
|
|
310
|
+
const own = read.usage.rows.find((item) => item.skill === row.skill && item.version?.bodySha256 === row.version?.bodySha256);
|
|
311
|
+
return own === undefined
|
|
312
|
+
? []
|
|
313
|
+
: [`${own.invocations.total} in ${own.sessions} ${harnessName(read.harness)} sessions`];
|
|
314
|
+
})
|
|
315
|
+
.join(', ');
|
|
316
|
+
}
|
|
317
|
+
/**
|
|
318
|
+
* Propose profile changes from recorded sessions and feedback. Every candidate
|
|
319
|
+
* is the base profile plus or minus one unit:
|
|
320
|
+
*
|
|
321
|
+
* | Kind | Unit | From |
|
|
322
|
+
* |---|---|---|
|
|
323
|
+
* | `skill` | one skill the sessions invoked most, pinned by commit | Claude Code and Codex sessions |
|
|
324
|
+
* | `workflow` | a composed skill that runs two skills in the order sessions ran them | Claude Code and Codex sessions |
|
|
325
|
+
* | `instructions` | lessons from task feedback reasons | Braid feedback |
|
|
326
|
+
* | `removal` | one skill or instruction block the profile carries | the profile itself |
|
|
327
|
+
* | `subagent` | a child profile from the definition of a subagent type the sessions started, pinned by commit | Claude Code sessions |
|
|
328
|
+
* | `instruction-block` | one rule block of an instruction file the sessions loaded, ranked against the tasks the profile fails | the instruction files Claude Code sessions loaded |
|
|
329
|
+
*
|
|
330
|
+
* A skill or workflow candidate also records what its sessions came to (see
|
|
331
|
+
* `changeState`). That is evidence for the reader; the measurement decides.
|
|
332
|
+
*/
|
|
333
|
+
export async function proposeCandidates(input) {
|
|
334
|
+
const pin = input.pin ?? pinSkillFile;
|
|
335
|
+
const settings = input.settings ?? DEFAULT_LEARNER_SETTINGS.candidates;
|
|
336
|
+
const skillsDirectory = skillsDirectoryFor(input.base);
|
|
337
|
+
const proposes = (kind) => settings.kinds.includes(kind);
|
|
338
|
+
const candidates = [];
|
|
339
|
+
const skipped = [];
|
|
340
|
+
for (const kind of CANDIDATE_KINDS)
|
|
341
|
+
if (!proposes(kind))
|
|
342
|
+
skipped.push(`${kind}: the learner does not propose this kind`);
|
|
343
|
+
// A skill the profile already carries, inline or by reference, is not proposed again.
|
|
344
|
+
const present = carriedSkillNames(input.base);
|
|
345
|
+
const usage = input.harness.usage?.rows ?? [];
|
|
346
|
+
for (const row of usage)
|
|
347
|
+
if (present.has(row.skill))
|
|
348
|
+
skipped.push(`skill ${row.skill}: the profile carries it`);
|
|
349
|
+
const rows = usage
|
|
350
|
+
.filter((row) => !present.has(row.skill))
|
|
351
|
+
.sort((left, right) => right.invocations.total - left.invocations.total)
|
|
352
|
+
.slice(0, proposes('skill') || proposes('workflow') ? settings.rowsTried : 0);
|
|
353
|
+
const index = sessionIndex(input.harness.sessions);
|
|
354
|
+
const pinned = new Map();
|
|
355
|
+
const rowOf = new Map();
|
|
356
|
+
for (const row of rows) {
|
|
357
|
+
rowOf.set(row.skill, row);
|
|
358
|
+
if (row.skillFile === null) {
|
|
359
|
+
skipped.push(`skill ${row.skill}: the sessions name no skill file`);
|
|
360
|
+
continue;
|
|
361
|
+
}
|
|
362
|
+
const result = await pin(row.skill, row.skillFile.path);
|
|
363
|
+
if (result.pinned)
|
|
364
|
+
pinned.set(row.skill, result.skill);
|
|
365
|
+
else
|
|
366
|
+
skipped.push(`skill ${row.skill}: ${result.reason}`);
|
|
367
|
+
}
|
|
368
|
+
for (const skill of [...pinned.values()].slice(0, proposes('skill') ? settings.maxSkills : 0)) {
|
|
369
|
+
const row = rowOf.get(skill.name);
|
|
370
|
+
const changes = countChanges(sessionsInvoking(input.harness.sessions, skill.name, input.harness.sinceMs), index);
|
|
371
|
+
candidates.push(await candidate('skill', {
|
|
372
|
+
name: skill.name,
|
|
373
|
+
summary: `Mount ${skill.name} from ${skill.repository}@${skill.commit.slice(0, 12)}`,
|
|
374
|
+
evidence: [
|
|
375
|
+
`${row.invocations.total} invocations in ${row.sessions} sessions: ${invocationsByHarness(input.harness, row)}`,
|
|
376
|
+
changeEvidence(changes, `invoked ${skill.name}`),
|
|
377
|
+
`pinned to ${skill.repository}@${skill.commit.slice(0, 12)}:${skill.path}`,
|
|
378
|
+
...siblingEvidence(skill),
|
|
379
|
+
],
|
|
380
|
+
unitText: skill.content,
|
|
381
|
+
unitDigest: `sha256:${skill.bodySha256}`,
|
|
382
|
+
profile: withSkills(input.base, [mounted(skill, skillsDirectory)]),
|
|
383
|
+
changes,
|
|
384
|
+
}));
|
|
385
|
+
}
|
|
386
|
+
const pair = orderedSkillPairs(input.harness.sessions).find((entry) => entry.sessions >= settings.workflowMinSessions &&
|
|
387
|
+
(present.has(entry.first) || pinned.has(entry.first)) &&
|
|
388
|
+
(present.has(entry.second) || pinned.has(entry.second)));
|
|
389
|
+
if (proposes('workflow') && pair === undefined) {
|
|
390
|
+
skipped.push(`workflow: no two pinnable skills ran in the same order in ${settings.workflowMinSessions} or more sessions`);
|
|
391
|
+
}
|
|
392
|
+
else if (proposes('workflow') && pair !== undefined) {
|
|
393
|
+
const text = workflowSkill(pair.first, pair.second, pair.sessions);
|
|
394
|
+
const changes = countChanges(pair.records, index);
|
|
395
|
+
const components = [pair.first, pair.second].flatMap((name) => {
|
|
396
|
+
const skill = pinned.get(name);
|
|
397
|
+
return skill === undefined ? [] : [mounted(skill, skillsDirectory)];
|
|
398
|
+
});
|
|
399
|
+
candidates.push(await candidate('workflow', {
|
|
400
|
+
name: `${pair.first}-then-${pair.second}`,
|
|
401
|
+
summary: `Compose ${pair.first} then ${pair.second} into one workflow skill`,
|
|
402
|
+
evidence: [
|
|
403
|
+
`${pair.sessions} sessions ran ${pair.first} before ${pair.second}: ${sessionsByHarness(pair.records)}`,
|
|
404
|
+
changeEvidence(changes, `ran ${pair.first} before ${pair.second}`),
|
|
405
|
+
],
|
|
406
|
+
unitText: text,
|
|
407
|
+
unitDigest: `sha256:${sha256Hex(text)}`,
|
|
408
|
+
profile: withSkills(input.base, [
|
|
409
|
+
...components,
|
|
410
|
+
{ skill: { kind: 'inline', name: `${pair.first}-then-${pair.second}`, content: text } },
|
|
411
|
+
]),
|
|
412
|
+
changes,
|
|
413
|
+
}));
|
|
414
|
+
}
|
|
415
|
+
const reasoned = input.feedback.some((item) => item.labels.some((label) => (label.reason ?? '') !== ''));
|
|
416
|
+
if (proposes('instructions') && reasoned) {
|
|
417
|
+
const draft = await draftProfileFromFeedback(input.base, input.feedback);
|
|
418
|
+
const text = draft.lessons.map((lesson) => lesson.instruction).join('\n');
|
|
419
|
+
candidates.push(await candidate('instructions', {
|
|
420
|
+
name: 'feedback-lessons',
|
|
421
|
+
summary: `Add ${draft.lessons.length} lessons from task feedback`,
|
|
422
|
+
evidence: [`${draft.feedbackIds.length} feedback decisions with a reason`],
|
|
423
|
+
unitText: text,
|
|
424
|
+
unitDigest: `sha256:${sha256Hex(text)}`,
|
|
425
|
+
profile: draft.profile,
|
|
426
|
+
changes: null,
|
|
427
|
+
}));
|
|
428
|
+
}
|
|
429
|
+
else if (proposes('instructions')) {
|
|
430
|
+
skipped.push('instructions: no task feedback with a reason');
|
|
431
|
+
}
|
|
432
|
+
// Removals: each inline skill, then each learned instruction block, up to the limit.
|
|
433
|
+
const removals = [
|
|
434
|
+
...inlineSkills(input.base).map((skill) => ({
|
|
435
|
+
name: skill.name,
|
|
436
|
+
summary: `Remove ${skill.name}`,
|
|
437
|
+
text: skill.content,
|
|
438
|
+
profile: () => withoutSkill(input.base, skill.name),
|
|
439
|
+
})),
|
|
440
|
+
...carriedInstructionBlocks(input.base).map((block) => {
|
|
441
|
+
const name = block.source === undefined
|
|
442
|
+
? `instruction block ${block.id}`
|
|
443
|
+
: `${basename(block.source.path)}:${block.source.startLine}`;
|
|
444
|
+
return {
|
|
445
|
+
name,
|
|
446
|
+
summary: `Remove the instruction block ${name}`,
|
|
447
|
+
text: block.text,
|
|
448
|
+
profile: () => withoutInstructionBlock(input.base, block.id),
|
|
449
|
+
};
|
|
450
|
+
}),
|
|
451
|
+
];
|
|
452
|
+
for (const removal of removals.slice(0, proposes('removal') ? settings.maxRemovals : 0)) {
|
|
453
|
+
candidates.push(await candidate('removal', {
|
|
454
|
+
name: removal.name,
|
|
455
|
+
summary: removal.summary,
|
|
456
|
+
evidence: ['the profile carries it; removal is kept only if success holds'],
|
|
457
|
+
unitText: removal.text,
|
|
458
|
+
unitDigest: `sha256:${sha256Hex(removal.text)}`,
|
|
459
|
+
profile: removal.profile(),
|
|
460
|
+
changes: null,
|
|
461
|
+
}));
|
|
462
|
+
}
|
|
463
|
+
candidates.push(...(await childProfileCandidates(input, settings, skipped)));
|
|
464
|
+
candidates.push(...(await instructionBlockCandidates(input, settings, skipped)));
|
|
465
|
+
return { candidates, skipped };
|
|
466
|
+
}
|
|
467
|
+
/**
|
|
468
|
+
* What instruction blocks are ranked against: the tasks the active profile
|
|
469
|
+
* failed in its latest measurement, with what their checks printed; or every
|
|
470
|
+
* task when no measurement of this profile recorded its results; or the reason
|
|
471
|
+
* there is nothing to rank against.
|
|
472
|
+
*/
|
|
473
|
+
function blockTargets(input) {
|
|
474
|
+
const tasks = input.tasks ?? [];
|
|
475
|
+
if (tasks.length === 0)
|
|
476
|
+
return { reason: 'no held-out task to rank blocks against: /learn task -- <check command>' };
|
|
477
|
+
const results = new Map((input.baseResults ?? []).map((result) => [result.taskId, result]));
|
|
478
|
+
if (results.size === 0)
|
|
479
|
+
return {
|
|
480
|
+
targets: tasks.map((task) => task.prompt),
|
|
481
|
+
against: `all ${tasks.length} held-out tasks: no measurement of the active profile records which it failed`,
|
|
482
|
+
};
|
|
483
|
+
const failed = tasks.flatMap((task) => {
|
|
484
|
+
const result = results.get(task.id);
|
|
485
|
+
return result?.pass === false ? [{ task, output: result.checkOutput }] : [];
|
|
486
|
+
});
|
|
487
|
+
if (failed.length === 0)
|
|
488
|
+
return {
|
|
489
|
+
reason: 'the active profile failed no held-out task in its latest measurement, so no block is proposed to fix one',
|
|
490
|
+
};
|
|
491
|
+
return {
|
|
492
|
+
targets: failed.map(({ task, output }) => output === '' ? task.prompt : `${task.prompt}\n${output}`),
|
|
493
|
+
against: `the ${failed.length} held-out tasks the active profile failed and what their checks printed`,
|
|
494
|
+
};
|
|
495
|
+
}
|
|
496
|
+
/**
|
|
497
|
+
* Instruction-block candidates: the blocks of the instruction files the
|
|
498
|
+
* sessions loaded that best match what the active profile fails, each added
|
|
499
|
+
* to the profile's instructions with a record of its file and lines. A block
|
|
500
|
+
* the profile already carries is not proposed again.
|
|
501
|
+
*/
|
|
502
|
+
async function instructionBlockCandidates(input, settings, skipped) {
|
|
503
|
+
if (!settings.kinds.includes('instruction-block') || settings.maxInstructionBlocks === 0)
|
|
504
|
+
return [];
|
|
505
|
+
const loaded = loadedInstructionBlocks(input.harness.sessions);
|
|
506
|
+
if (loaded.withoutPath > 0)
|
|
507
|
+
skipped.push(`instruction-block: ${loaded.withoutPath} sessions loaded instruction text that names no file (Codex joins the AGENTS.md files it finds), so none of it has a file and line to propose`);
|
|
508
|
+
if (loaded.blocks.length === 0) {
|
|
509
|
+
skipped.push('instruction-block: the sessions loaded no instruction file that names its path');
|
|
510
|
+
return [];
|
|
511
|
+
}
|
|
512
|
+
const ranking = blockTargets(input);
|
|
513
|
+
if ('reason' in ranking) {
|
|
514
|
+
skipped.push(`instruction-block: ${ranking.reason}`);
|
|
515
|
+
return [];
|
|
516
|
+
}
|
|
517
|
+
const carried = new Set(carriedInstructionBlocks(input.base).map((block) => block.id));
|
|
518
|
+
const eligible = loaded.blocks.filter((block) => !carried.has(instructionBlockId(block.sha256)) && composable(block));
|
|
519
|
+
const ranked = rankInstructionBlocks(eligible, ranking.targets, settings.maxInstructionBlocks);
|
|
520
|
+
if (ranked.length === 0) {
|
|
521
|
+
skipped.push(`instruction-block: no block of the ${loaded.files} loaded files shares a term with ${ranking.against}`);
|
|
522
|
+
return [];
|
|
523
|
+
}
|
|
524
|
+
const index = sessionIndex(input.harness.sessions);
|
|
525
|
+
const candidates = [];
|
|
526
|
+
for (const { block, matched } of ranked) {
|
|
527
|
+
const name = `${basename(block.path)}:${block.startLine}`;
|
|
528
|
+
const lines = block.startLine === block.endLine
|
|
529
|
+
? `line ${block.startLine}`
|
|
530
|
+
: `lines ${block.startLine}-${block.endLine}`;
|
|
531
|
+
const changes = countChanges(block.sessions, index);
|
|
532
|
+
const firstLine = block.text.split('\n')[0]?.trim() ?? '';
|
|
533
|
+
candidates.push(await candidate('instruction-block', {
|
|
534
|
+
name,
|
|
535
|
+
summary: `Add ${basename(block.path)} ${lines}: ${firstLine.length > 72 ? `${firstLine.slice(0, 71)}…` : firstLine}`,
|
|
536
|
+
evidence: [
|
|
537
|
+
`loaded in ${block.sessions.length} sessions: ${sessionsByHarness(block.sessions)}`,
|
|
538
|
+
`from ${block.path} ${lines}, in the newest text the sessions loaded (sha256 ${block.fileSha256.slice(0, 12)}${block.scope === null ? '' : `, ${block.scope} file`})`,
|
|
539
|
+
await onDisk(block),
|
|
540
|
+
...(block.otherPaths === 0
|
|
541
|
+
? []
|
|
542
|
+
: [`${block.otherPaths} other loaded files hold the same block`]),
|
|
543
|
+
`ranked against ${ranking.against}; it matches on ${matched.join(', ')}`,
|
|
544
|
+
changeEvidence(changes, 'loaded it'),
|
|
545
|
+
],
|
|
546
|
+
unitText: block.text,
|
|
547
|
+
unitDigest: `sha256:${block.sha256}`,
|
|
548
|
+
profile: withInstructionBlock(input.base, block),
|
|
549
|
+
changes,
|
|
550
|
+
}));
|
|
551
|
+
}
|
|
552
|
+
return candidates;
|
|
553
|
+
}
|
|
554
|
+
/**
|
|
555
|
+
* Child-profile candidates: each subagent type the sessions started that the
|
|
556
|
+
* profile lacks, whose definition is committed in a GitHub checkout, becomes a
|
|
557
|
+
* subagent of the profile. The child carries the definition's description and
|
|
558
|
+
* prompt; its other settings are Claude Code's own names, so they are listed
|
|
559
|
+
* as not carried and the child runs with the parent's tools, permissions and model.
|
|
560
|
+
*/
|
|
561
|
+
async function childProfileCandidates(input, settings, skipped) {
|
|
562
|
+
if (!settings.kinds.includes('subagent'))
|
|
563
|
+
return [];
|
|
564
|
+
const starts = subagentStarts(input.harness.sessions, input.harness.sinceMs)
|
|
565
|
+
.filter((start) => input.base.subagents?.[start.type] === undefined)
|
|
566
|
+
.slice(0, settings.rowsTried);
|
|
567
|
+
if (starts.length === 0) {
|
|
568
|
+
skipped.push('subagent: the sessions started no subagent type the profile lacks');
|
|
569
|
+
return [];
|
|
570
|
+
}
|
|
571
|
+
const directories = input.agentDirectories ?? [];
|
|
572
|
+
const definitions = await agentDefinitionFiles(directories);
|
|
573
|
+
const index = sessionIndex(input.harness.sessions);
|
|
574
|
+
const candidates = [];
|
|
575
|
+
for (const start of starts) {
|
|
576
|
+
if (candidates.length >= settings.maxSubagents)
|
|
577
|
+
break;
|
|
578
|
+
const where = `subagent ${start.type}`;
|
|
579
|
+
if (!SUBAGENT_NAME.test(start.type)) {
|
|
580
|
+
skipped.push(`${where}: not a name a profile can carry, so no definition of it is mounted`);
|
|
581
|
+
continue;
|
|
582
|
+
}
|
|
583
|
+
const file = definitions.get(start.type);
|
|
584
|
+
if (file === undefined) {
|
|
585
|
+
skipped.push(`${where}: no definition names it in ${directories.length === 0 ? 'any agents directory' : directories.join(' or ')}; a built-in type has none`);
|
|
586
|
+
continue;
|
|
587
|
+
}
|
|
588
|
+
const pinned = await pinAgentFile(start.type, file);
|
|
589
|
+
if (!pinned.pinned) {
|
|
590
|
+
skipped.push(`${where}: ${pinned.reason}`);
|
|
591
|
+
continue;
|
|
592
|
+
}
|
|
593
|
+
const { agent } = pinned;
|
|
594
|
+
const definition = readAgentDefinition(agent.content);
|
|
595
|
+
if (!definition.read || definition.fields.name !== start.type) {
|
|
596
|
+
skipped.push(`${where}: ${definition.read ? 'the committed definition names another subagent' : definition.reason}`);
|
|
597
|
+
continue;
|
|
598
|
+
}
|
|
599
|
+
const sha256 = sha256Hex(agent.content);
|
|
600
|
+
const pin = `${agent.repository}@${agent.commit.slice(0, 12)}`;
|
|
601
|
+
const notCarried = Object.entries(definition.fields).filter(([key]) => key !== 'name' && key !== 'description');
|
|
602
|
+
const changes = countChanges(start.records, index);
|
|
603
|
+
candidates.push(await candidate('subagent', {
|
|
604
|
+
name: start.type,
|
|
605
|
+
summary: `Add the ${start.type} child profile from ${pin}`,
|
|
606
|
+
evidence: [
|
|
607
|
+
`${start.calls} starts in ${start.records.length} sessions: ${sessionsByHarness(start.records)}`,
|
|
608
|
+
changeEvidence(changes, `started ${start.type}`),
|
|
609
|
+
`pinned to ${pin}:${agent.path}`,
|
|
610
|
+
notCarried.length === 0
|
|
611
|
+
? "carries the definition's description and prompt"
|
|
612
|
+
: `not carried: ${notCarried.map(([key, value]) => `${key} (${value})`).join(', ')}; the child runs with the parent's tools, permissions and model`,
|
|
613
|
+
],
|
|
614
|
+
unitText: agent.content,
|
|
615
|
+
unitDigest: `sha256:${sha256}`,
|
|
616
|
+
profile: withSubagent(input.base, { description: definition.description, prompt: definition.prompt }, {
|
|
617
|
+
name: start.type,
|
|
618
|
+
repository: agent.repository,
|
|
619
|
+
ref: agent.commit,
|
|
620
|
+
path: agent.path,
|
|
621
|
+
sha256,
|
|
622
|
+
}),
|
|
623
|
+
changes,
|
|
624
|
+
}));
|
|
625
|
+
}
|
|
626
|
+
return candidates;
|
|
627
|
+
}
|
|
628
|
+
//# sourceMappingURL=learning-candidates.js.map
|