@mmerterden/multi-agent-pipeline 23.3.0 → 23.5.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +73 -0
- package/README.md +27 -8
- package/README.tr.md +28 -9
- package/SECURITY.md +16 -0
- package/docs/adr/0008-installer-modularization-and-secret-leak-defense.md +1 -1
- package/docs/adr/0010-own-code-graph.md +299 -8
- package/docs/architecture.md +3 -3
- package/docs/ecosystem.md +10 -10
- package/docs/engineering.md +4 -4
- package/docs/facts.json +8 -8
- package/docs/features.md +5 -5
- package/docs/performance.md +17 -17
- package/install/_dev-only-files.mjs +9 -0
- package/install/_platform-filter.mjs +2 -55
- package/install/claude.mjs +28 -2
- package/install/codex.mjs +1 -3
- package/install/copilot.mjs +4 -8
- package/install/templates/claude-hooks.json +32 -1
- package/manifest.json +236 -167
- package/package.json +11 -3
- package/pipeline/commands/multi-agent/SKILL.md +1 -1
- package/pipeline/commands/multi-agent/design-check/SKILL.md +3 -2
- package/pipeline/commands/multi-agent/diff-explain/SKILL.md +3 -3
- package/pipeline/commands/multi-agent/graph/SKILL.md +57 -24
- package/pipeline/commands/multi-agent/pair/SKILL.md +92 -0
- package/pipeline/commands/multi-agent/prune-prompts/SKILL.md +1 -1
- package/pipeline/commands/multi-agent/search/SKILL.md +7 -1
- package/pipeline/commands/multi-agent/status/SKILL.md +4 -0
- package/pipeline/commands/multi-agent/sync/SKILL.md +3 -3
- package/pipeline/contract/CHANGELOG.md +63 -0
- package/pipeline/contract/README.md +1 -0
- package/pipeline/contract/build.mjs +13 -1
- package/pipeline/contract/fixtures/error-invalid-request.json +1 -1
- package/pipeline/contract/fixtures/error-unauthorized.json +1 -1
- package/pipeline/contract/fixtures/runs-awaiting-question.json +4 -1
- package/pipeline/contract/fixtures/runs-empty.json +1 -1
- package/pipeline/contract/fixtures/runs-failed.json +4 -1
- package/pipeline/contract/fixtures/runs-old-schema.json +3 -0
- package/pipeline/contract/fixtures/runs-pr-opened-redacted.json +4 -1
- package/pipeline/contract/fixtures/runs-pr-opened.json +4 -1
- package/pipeline/contract/fixtures/runs-running.json +4 -1
- package/pipeline/contract/manifest.json +41 -15
- package/pipeline/contract/types/index.d.ts +81 -3
- package/pipeline/lib/detach-self.mjs +95 -0
- package/pipeline/lib/public-mcp-servers.mjs +33 -0
- package/pipeline/lib/rotated-log.mjs +93 -0
- package/pipeline/lib/stack-detect.sh +1 -1
- package/pipeline/lib/tls-trust.mjs +29 -0
- package/pipeline/lib/usage-lifecycle.mjs +9 -11
- package/pipeline/lib/usage-names.generated.mjs +613 -0
- package/pipeline/lib/usage-run-key.mjs +235 -0
- package/pipeline/lib/usage-vocab.mjs +210 -0
- package/pipeline/multi-agent-refs/analysis/intake.md +2 -2
- package/pipeline/multi-agent-refs/analysis/render.md +1 -1
- package/pipeline/multi-agent-refs/channels/generator.md +4 -5
- package/pipeline/multi-agent-refs/cross-cli-contract.md +3 -3
- package/pipeline/multi-agent-refs/design-check/init-inventory.md +11 -1
- package/pipeline/multi-agent-refs/design-check/scope-and-ledger.md +1 -1
- package/pipeline/multi-agent-refs/features/code-graph.md +146 -11
- package/pipeline/multi-agent-refs/features/code-intelligence.md +16 -14
- package/pipeline/multi-agent-refs/features/dev-critic.md +7 -7
- package/pipeline/multi-agent-refs/features/model-fallback.md +6 -4
- package/pipeline/multi-agent-refs/features/remote-control.md +253 -0
- package/pipeline/multi-agent-refs/features/review-delta.md +1 -1
- package/pipeline/multi-agent-refs/features/review-file-set.md +3 -3
- package/pipeline/multi-agent-refs/features/review-multi-repo.md +1 -1
- package/pipeline/multi-agent-refs/features/session-brief.md +42 -0
- package/pipeline/multi-agent-refs/features/skill-conformance.md +3 -3
- package/pipeline/multi-agent-refs/features/usage-reporting.md +255 -27
- package/pipeline/multi-agent-refs/help/en.md +3 -2
- package/pipeline/multi-agent-refs/help/tr.md +3 -2
- package/pipeline/multi-agent-refs/knowledge.md +1 -1
- package/pipeline/multi-agent-refs/orchestrator/dispatcher.md +2 -2
- package/pipeline/multi-agent-refs/phases/operations.md +2 -2
- package/pipeline/multi-agent-refs/phases/phase-0-init.md +13 -12
- package/pipeline/multi-agent-refs/phases/phase-1-plan.md +4 -4
- package/pipeline/multi-agent-refs/phases/phase-3-review.md +2 -0
- package/pipeline/multi-agent-refs/phases/phase-5-report.md +1 -1
- package/pipeline/multi-agent-refs/platform-parity.md +2 -2
- package/pipeline/multi-agent-refs/wiki-capture.md +3 -17
- package/pipeline/office/index.html +1309 -236
- package/pipeline/office/toolkit.json +1 -1
- package/pipeline/rules/outside-the-pipeline.md +1 -1
- package/pipeline/schemas/activity.schema.json +23 -0
- package/pipeline/schemas/agent-state.schema.json +6 -1
- package/pipeline/schemas/code-graph-calls.schema.json +254 -0
- package/pipeline/schemas/code-graph-docs.schema.json +223 -0
- package/pipeline/schemas/code-graph-infra.schema.json +227 -0
- package/pipeline/schemas/code-graph.schema.json +2 -2
- package/pipeline/schemas/examples/design-check-config.json +27 -0
- package/pipeline/schemas/learning-curve.schema.json +67 -0
- package/pipeline/schemas/mcp-health.schema.json +96 -0
- package/pipeline/schemas/office-jobs.json +69 -2
- package/pipeline/schemas/office-jobs.schema.json +8 -1
- package/pipeline/schemas/phases.json +5 -0
- package/pipeline/schemas/phases.schema.json +8 -0
- package/pipeline/schemas/prefs.schema.json +46 -12
- package/pipeline/schemas/runs-index.schema.json +17 -0
- package/pipeline/schemas/toolkit-path-params.json +78 -8
- package/pipeline/scripts/README.md +1 -0
- package/pipeline/scripts/_code-graph.mjs +184 -103
- package/pipeline/scripts/_contract-core.mjs +1 -1
- package/pipeline/scripts/_contract-routes-office.mjs +33 -0
- package/pipeline/scripts/_diff-impact.mjs +21 -2
- package/pipeline/scripts/_graph-sidecars.mjs +372 -0
- package/pipeline/scripts/_http-post.mjs +103 -115
- package/pipeline/scripts/_safe-read.mjs +57 -0
- package/pipeline/scripts/_skill-practices.mjs +26 -0
- package/pipeline/scripts/_strip-code.mjs +380 -0
- package/pipeline/scripts/activity-snapshot.mjs +13 -1
- package/pipeline/scripts/aggregate-metrics.mjs +3 -5
- package/pipeline/scripts/build-stack-plugins.mjs +1 -47
- package/pipeline/scripts/call-graph/index.mjs +78 -0
- package/pipeline/scripts/call-graph/lang/cpp.mjs +308 -0
- package/pipeline/scripts/call-graph/lang/csharp.mjs +130 -0
- package/pipeline/scripts/call-graph/lang/go.mjs +303 -0
- package/pipeline/scripts/call-graph/lang/java.mjs +370 -0
- package/pipeline/scripts/call-graph/lang/kotlin.mjs +397 -0
- package/pipeline/scripts/call-graph/lang/python.mjs +399 -0
- package/pipeline/scripts/call-graph/lang/rust.mjs +345 -0
- package/pipeline/scripts/call-graph/lang/shared.mjs +230 -0
- package/pipeline/scripts/call-graph/lang/swift.mjs +432 -0
- package/pipeline/scripts/call-graph/lang/typescript.mjs +692 -0
- package/pipeline/scripts/call-graph/lex.mjs +396 -0
- package/pipeline/scripts/call-graph/platform.mjs +86 -0
- package/pipeline/scripts/call-graph/profiles.mjs +89 -0
- package/pipeline/scripts/call-graph/resolve.mjs +1125 -0
- package/pipeline/scripts/call-graph/scan.mjs +267 -0
- package/pipeline/scripts/code-graph-rules/android.json +7 -2
- package/pipeline/scripts/code-graph-rules/cpp.json +99 -0
- package/pipeline/scripts/code-graph-rules/csharp.json +102 -0
- package/pipeline/scripts/code-graph-rules/go.json +2 -1
- package/pipeline/scripts/code-graph-rules/ios.json +3 -1
- package/pipeline/scripts/code-graph-rules/java.json +76 -0
- package/pipeline/scripts/code-graph-rules/node.json +7 -2
- package/pipeline/scripts/code-graph-rules/python.json +6 -2
- package/pipeline/scripts/code-graph-rules/rust.json +105 -0
- package/pipeline/scripts/contract-server.mjs +3 -0
- package/pipeline/scripts/design-check-config.mjs +205 -0
- package/pipeline/scripts/feedback-send.mjs +26 -26
- package/pipeline/scripts/gate-ledger.mjs +2 -1
- package/pipeline/scripts/gen-facts.mjs +1 -2
- package/pipeline/scripts/gen-usage-names.mjs +124 -0
- package/pipeline/scripts/graph-affected.mjs +109 -20
- package/pipeline/scripts/graph-build.mjs +95 -15
- package/pipeline/scripts/graph-export.mjs +272 -0
- package/pipeline/scripts/graph-hint.mjs +15 -2
- package/pipeline/scripts/graph-query.mjs +305 -26
- package/pipeline/scripts/graph-report.mjs +187 -1
- package/pipeline/scripts/health-report.mjs +3 -4
- package/pipeline/scripts/infra/docs.mjs +317 -0
- package/pipeline/scripts/infra/extract.mjs +998 -0
- package/pipeline/scripts/infra/graph.mjs +245 -0
- package/pipeline/scripts/infra/yaml-lite.mjs +311 -0
- package/pipeline/scripts/job-launch.mjs +67 -2
- package/pipeline/scripts/learning-curve.mjs +288 -178
- package/pipeline/scripts/log-metric.sh +10 -1
- package/pipeline/scripts/mcp-health.mjs +309 -0
- package/pipeline/scripts/note-agent-event.mjs +3 -4
- package/pipeline/scripts/note-command-use.mjs +333 -0
- package/pipeline/scripts/note-command-use.sh +126 -0
- package/pipeline/scripts/note-mcp-call.sh +89 -0
- package/pipeline/scripts/note-mcp-failure.mjs +272 -1
- package/pipeline/scripts/note-session.sh +62 -3
- package/pipeline/scripts/note-skill-use.mjs +58 -2
- package/pipeline/scripts/office-build.mjs +115 -1
- package/pipeline/scripts/office-memory.mjs +14 -5
- package/pipeline/scripts/pair.mjs +333 -0
- package/pipeline/scripts/pre-push-check.sh +1 -1
- package/pipeline/scripts/remote/cbor.mjs +128 -0
- package/pipeline/scripts/remote/contract.mjs +98 -0
- package/pipeline/scripts/remote/handler.mjs +330 -0
- package/pipeline/scripts/remote/handles.mjs +57 -0
- package/pipeline/scripts/remote/lifecycle.mjs +186 -0
- package/pipeline/scripts/remote/listener.mjs +204 -0
- package/pipeline/scripts/remote/lockout.mjs +103 -0
- package/pipeline/scripts/remote/nonces.mjs +61 -0
- package/pipeline/scripts/remote/pairing.mjs +519 -0
- package/pipeline/scripts/remote/qr-encode.mjs +459 -0
- package/pipeline/scripts/remote/store.mjs +191 -0
- package/pipeline/scripts/remote/transport.mjs +211 -0
- package/pipeline/scripts/remote/verbs.json +70 -0
- package/pipeline/scripts/remote/verbs.mjs +217 -0
- package/pipeline/scripts/remote/webauthn.mjs +169 -0
- package/pipeline/scripts/remote/wire.mjs +364 -0
- package/pipeline/scripts/remote-listener.mjs +83 -0
- package/pipeline/scripts/route-learn.mjs +4 -4
- package/pipeline/scripts/run-kill.mjs +1 -1
- package/pipeline/scripts/run-write.mjs +13 -2
- package/pipeline/scripts/runs-index.mjs +30 -3
- package/pipeline/scripts/search-logs.sh +9 -0
- package/pipeline/scripts/session-brief.mjs +458 -0
- package/pipeline/scripts/session-brief.sh +130 -0
- package/pipeline/scripts/skill-usage.mjs +16 -5
- package/pipeline/scripts/test-gap-rules/cpp.json +25 -0
- package/pipeline/scripts/test-gap-rules/csharp.json +20 -0
- package/pipeline/scripts/test-gap-rules/java.json +20 -0
- package/pipeline/scripts/test-gap-rules/rust.json +14 -0
- package/pipeline/scripts/token-budget-report.mjs +3 -2
- package/pipeline/scripts/uninstall.mjs +29 -0
- package/pipeline/scripts/usage-access.mjs +16 -31
- package/pipeline/scripts/usage-health.mjs +31 -62
- package/pipeline/scripts/usage-register-beacon.mjs +11 -22
- package/pipeline/scripts/usage-register.mjs +39 -29
- package/pipeline/scripts/usage-report.mjs +579 -178
- package/pipeline/scripts/validate-code-graph.mjs +361 -111
- package/pipeline/scripts/write-state.mjs +39 -0
- package/pipeline/skills/.skill-manifest.json +21 -17
- package/pipeline/skills/.skills-index.json +13 -2
- package/pipeline/skills/shared/README.md +5 -4
- package/pipeline/skills/shared/core/multi-agent-design-check/SKILL.md +1 -1
- package/pipeline/skills/shared/core/multi-agent-diff-explain/SKILL.md +3 -3
- package/pipeline/skills/shared/core/multi-agent-graph/SKILL.md +55 -21
- package/pipeline/skills/shared/core/multi-agent-pair/SKILL.md +41 -0
- package/pipeline/skills/shared/core/multi-agent-prune-prompts/SKILL.md +1 -1
- package/pipeline/skills/shared/core/multi-agent-sync/SKILL.md +3 -3
- package/pipeline/skills/shared/external/app-store-optimization/SKILL.md +2 -3
- package/pipeline/skills/shared/external/app-store-optimization/references/keyword-research-methodology.md +2 -2
- package/pipeline/skills/shared/external/app-store-optimization/references/product-page-variants.md +2 -2
- package/pipeline/skills/shared/external/app-store-review/SKILL.md +11 -4
- package/pipeline/skills/shared/external/build-settings-audit/SKILL.md +1 -1
- package/pipeline/skills/shared/external/build-time-benchmark/SKILL.md +5 -5
- package/pipeline/skills/shared/external/build-time-fixes/SKILL.md +5 -5
- package/pipeline/skills/shared/external/build-time-optimizer/SKILL.md +6 -6
- package/pipeline/skills/shared/external/free-llm-apis/references/providers.md +1 -0
- package/pipeline/skills/shared/external/ios-coding-standard/references/STANDARD.md +2 -2
- package/pipeline/skills/shared/external/ios-haptics/references/core-haptics.md +1 -1
- package/pipeline/skills/shared/external/localization-reuse-map/references/publish-and-snapshot.md +1 -1
- package/pipeline/skills/shared/external/package-build-audit/SKILL.md +3 -3
- package/pipeline/skills/shared/external/reverse-engineer-own-app/SKILL.md +2 -3
- package/pipeline/skills/shared/external/swift-compile-hotspots/SKILL.md +2 -2
- package/pipeline/skills/shared/external/weatherkit/SKILL.md +5 -6
- package/pipeline/skills/skills-index.md +3 -2
- package/docs/FIGMA_PIPELINE.md +0 -137
- package/pipeline/lib/identifier-scan.mjs +0 -156
- package/pipeline/scripts/_renamed-skills.mjs +0 -164
- package/pipeline/scripts/publish-staged.mjs +0 -324
- package/pipeline/skills/renamed.json +0 -30
- package/pipeline/skills/shared/external/ios-coding-standard/scripts/check_structure.py +0 -765
|
@@ -0,0 +1,458 @@
|
|
|
1
|
+
#!/usr/bin/env node
|
|
2
|
+
/**
|
|
3
|
+
* @file session-brief.mjs - an opt-in block a plain session can open with:
|
|
4
|
+
* an index of the repository's learnings ledger, one line about its code graph,
|
|
5
|
+
* and, as separate settings, the skill indexes and a few working notes.
|
|
6
|
+
*
|
|
7
|
+
* It is off until prefs.global.sessionBrief.enabled is true. A run loads the
|
|
8
|
+
* ledger in Phase 0; an ordinary session would otherwise start knowing none of
|
|
9
|
+
* it. The block is an index, not the memory: each ledger line carries its
|
|
10
|
+
* pointer, and the detail is one call away (`learnings_get`, or
|
|
11
|
+
* `learnings-ledger.mjs show --id <id>`).
|
|
12
|
+
*
|
|
13
|
+
* What it injects, by setting:
|
|
14
|
+
*
|
|
15
|
+
* ledger always, when enabled: the counts and up to `maxEntries`
|
|
16
|
+
* standing entries, as many as fit, best first
|
|
17
|
+
* graph one line when a code graph exists (unless codeGraph is off)
|
|
18
|
+
* routing with ledger or graph: the `index` skill of each enabled toolkit
|
|
19
|
+
* discipline only with `discipline: true`: a few working notes
|
|
20
|
+
*
|
|
21
|
+
* A repository with no ledger entries and no code graph gets nothing at all.
|
|
22
|
+
* The block is also withheld for a repository in memory.excludeProjects.
|
|
23
|
+
*
|
|
24
|
+
* The block is built here, in a detached process, and cached; the SessionStart
|
|
25
|
+
* hook (session-brief.sh) only prints the cache, because starting node on every
|
|
26
|
+
* session start costs more than the hook may take. The cache sits under
|
|
27
|
+
* ~/.claude/memory/multi-agent/_session-brief/ (directory 0700, file 0600) and
|
|
28
|
+
* starts with a header naming the repository's git common directory and HEAD;
|
|
29
|
+
* the hook prints it only when both match. It depends on exactly these files:
|
|
30
|
+
* the repo's ledger and feedback, the cross-repo ledger, the repo's code graph,
|
|
31
|
+
* the preferences file, ~/.claude/settings.json and settings.local.json, the
|
|
32
|
+
* repo's .claude/settings.json and settings.local.json, and
|
|
33
|
+
* ~/.claude/plugins/installed_plugins.json.
|
|
34
|
+
*
|
|
35
|
+
* Everything printed is text a model or a person wrote, so each line is
|
|
36
|
+
* cleaned (control, bidi and zero-width characters removed, home paths and
|
|
37
|
+
* ticket-key-shaped tokens masked, markup tags and tool-call words defused),
|
|
38
|
+
* clipped by code point, secret-scanned in the exact form that is printed, and
|
|
39
|
+
* the entries sit inside an <untrusted-data> block.
|
|
40
|
+
*
|
|
41
|
+
* Every file is read only when it is a regular file reached without a final
|
|
42
|
+
* symlink and under a size cap; a FIFO, directory or link is skipped. The
|
|
43
|
+
* builder gives up after BUILD_LIMIT_MS.
|
|
44
|
+
*
|
|
45
|
+
* Settings, each under prefs.global:
|
|
46
|
+
* sessionBrief.enabled true turns the brief on (default off)
|
|
47
|
+
* sessionBrief.maxEntries ledger lines shown, 0 to 10 (default 5)
|
|
48
|
+
* sessionBrief.maxChars size of the whole block, 400 to 4000 (default 2400)
|
|
49
|
+
* sessionBrief.kinds ledger kinds shown (default all)
|
|
50
|
+
* sessionBrief.discipline true adds the working notes (default off)
|
|
51
|
+
*
|
|
52
|
+
* Usage:
|
|
53
|
+
* session-brief.mjs build [--cwd <dir>] rebuild the cache for the repo at cwd
|
|
54
|
+
* session-brief.mjs print [--cwd <dir>] print the hook output without writing
|
|
55
|
+
*
|
|
56
|
+
* Exit is 0 on every path.
|
|
57
|
+
*
|
|
58
|
+
* @module pipeline/scripts/session-brief
|
|
59
|
+
*/
|
|
60
|
+
|
|
61
|
+
import { spawnSync } from "node:child_process";
|
|
62
|
+
import { chmodSync, mkdirSync, renameSync, rmSync, statSync, writeFileSync } from "node:fs";
|
|
63
|
+
import { homedir } from "node:os";
|
|
64
|
+
import { join } from "node:path";
|
|
65
|
+
|
|
66
|
+
import { fitToBudget } from "../lib/context-budget.mjs";
|
|
67
|
+
import { invokedDirectly } from "../lib/invoked-directly.mjs";
|
|
68
|
+
import { prefsPath } from "../lib/prefs-value.mjs";
|
|
69
|
+
import { readRegularFile } from "../lib/regular-file.mjs";
|
|
70
|
+
import { repoName } from "../lib/slug.mjs";
|
|
71
|
+
import { wrapUntrusted } from "../lib/untrusted.mjs";
|
|
72
|
+
import { messages, outputLanguage } from "../lib/user-facing.mjs";
|
|
73
|
+
import { exitOnHelp } from "../lib/cli-help.mjs";
|
|
74
|
+
import { ledgerRowId, memoryExcluded, standing, supersededBy } from "./_memory-policy.mjs";
|
|
75
|
+
import { openScanner } from "./_secret-scan.mjs";
|
|
76
|
+
|
|
77
|
+
exitOnHelp(import.meta.url);
|
|
78
|
+
|
|
79
|
+
export const CACHE_DIR = "_session-brief";
|
|
80
|
+
export const CACHE_MAGIC = "#sb1";
|
|
81
|
+
export const BUILD_LIMIT_MS = 10_000;
|
|
82
|
+
export const DEFAULTS = Object.freeze({ maxEntries: 5, maxChars: 2400 });
|
|
83
|
+
const STORE_MAX_BYTES = 4 * 1024 * 1024;
|
|
84
|
+
const PREFS_MAX_BYTES = 1024 * 1024;
|
|
85
|
+
const GRAPH_MAX_BYTES = 128 * 1024 * 1024;
|
|
86
|
+
const LINE_CHARS = 130;
|
|
87
|
+
const KINDS = ["security-note", "decision", "convention", "fact", "rejected-preference"];
|
|
88
|
+
const CONFIDENCE = { high: 0, medium: 1, low: 2 };
|
|
89
|
+
const MAX_TOOLKITS = 4;
|
|
90
|
+
const SCAN_LIMIT = 40;
|
|
91
|
+
|
|
92
|
+
/** The cache file name for a repository folder name and its git common directory. */
|
|
93
|
+
export function cacheName(slug, common = "") {
|
|
94
|
+
const safe = String(slug).replace(/[^A-Za-z0-9._-]/g, "_");
|
|
95
|
+
return common ? `${safe}-${pathHash(common)}` : safe;
|
|
96
|
+
}
|
|
97
|
+
|
|
98
|
+
/**
|
|
99
|
+
* 32-bit djb2 of the path's UTF-8 bytes, 8 hex digits. The hook computes the
|
|
100
|
+
* same value in bash, so the two agree on a file name without a hashing tool.
|
|
101
|
+
*/
|
|
102
|
+
export function pathHash(path) {
|
|
103
|
+
let h = 5381;
|
|
104
|
+
for (const b of Buffer.from(String(path), "utf8")) h = (h * 33 + b) % 4294967296;
|
|
105
|
+
return h.toString(16).padStart(8, "0");
|
|
106
|
+
}
|
|
107
|
+
|
|
108
|
+
const home = (env) => env.HOME || homedir();
|
|
109
|
+
export const cacheDir = (env = process.env) =>
|
|
110
|
+
join(home(env), ".claude", "memory", "multi-agent", CACHE_DIR);
|
|
111
|
+
|
|
112
|
+
/** The text of a regular file under a size cap, or null for anything else. */
|
|
113
|
+
function readText(path, maxBytes) {
|
|
114
|
+
try {
|
|
115
|
+
return readRegularFile(path, { maxBytes, noFollow: true });
|
|
116
|
+
} catch {
|
|
117
|
+
return null;
|
|
118
|
+
}
|
|
119
|
+
}
|
|
120
|
+
|
|
121
|
+
function readJson(path, maxBytes) {
|
|
122
|
+
const text = readText(path, maxBytes);
|
|
123
|
+
if (text === null) return null;
|
|
124
|
+
try {
|
|
125
|
+
return JSON.parse(text);
|
|
126
|
+
} catch {
|
|
127
|
+
return null;
|
|
128
|
+
}
|
|
129
|
+
}
|
|
130
|
+
|
|
131
|
+
/** The `sessionBrief` settings with their bounds applied. */
|
|
132
|
+
export function settingsOf(prefs) {
|
|
133
|
+
const raw =
|
|
134
|
+
prefs?.sessionBrief && typeof prefs.sessionBrief === "object" ? prefs.sessionBrief : {};
|
|
135
|
+
const clamp = (v, lo, hi, d) => (Number.isInteger(v) ? Math.min(hi, Math.max(lo, v)) : d);
|
|
136
|
+
const kinds = Array.isArray(raw.kinds) ? raw.kinds.filter((k) => KINDS.includes(k)) : KINDS;
|
|
137
|
+
return {
|
|
138
|
+
enabled: raw.enabled === true,
|
|
139
|
+
maxEntries: clamp(raw.maxEntries, 0, 10, DEFAULTS.maxEntries),
|
|
140
|
+
maxChars: clamp(raw.maxChars, 400, 4000, DEFAULTS.maxChars),
|
|
141
|
+
kinds: kinds.length ? kinds : KINDS,
|
|
142
|
+
discipline: raw.discipline === true,
|
|
143
|
+
graph: prefs?.codeGraph?.enabled !== false,
|
|
144
|
+
};
|
|
145
|
+
}
|
|
146
|
+
|
|
147
|
+
const MARKS = /[\p{Cc}\p{Cf}]/gu;
|
|
148
|
+
|
|
149
|
+
/**
|
|
150
|
+
* One piece of ledger text made safe to print on a single line: invisible and
|
|
151
|
+
* directional characters removed, home paths and ticket-key-shaped tokens
|
|
152
|
+
* masked, markup tags and tool-call words defused, whitespace folded, then
|
|
153
|
+
* clipped by code point so no half of a surrogate pair is left.
|
|
154
|
+
*/
|
|
155
|
+
export function clean(text, limit = LINE_CHARS) {
|
|
156
|
+
const one = String(text ?? "")
|
|
157
|
+
.replace(MARKS, " ")
|
|
158
|
+
.replace(/(?:[A-Za-z]:\\Users\\|\/(?:Users|home)\/)[^\s/\\]+/g, "~")
|
|
159
|
+
.replace(/\b[A-Z][A-Z0-9]{1,9}-\d{1,7}\b/g, "[key]")
|
|
160
|
+
.replace(/<\/?[A-Za-z][^>]{0,80}>/g, "[tag]")
|
|
161
|
+
.replace(/\b(?:tool_use|tool_result|tool_call|function_call|antml)\w*/gi, "[x]")
|
|
162
|
+
.replace(/\s+/g, " ")
|
|
163
|
+
.trim();
|
|
164
|
+
const points = Array.from(one);
|
|
165
|
+
return points.length > limit ? `${points.slice(0, limit - 3).join("")}...` : one;
|
|
166
|
+
}
|
|
167
|
+
|
|
168
|
+
function rows(path) {
|
|
169
|
+
const text = readText(path, STORE_MAX_BYTES);
|
|
170
|
+
if (text === null) return [];
|
|
171
|
+
return text
|
|
172
|
+
.split("\n")
|
|
173
|
+
.filter((l) => l.trim())
|
|
174
|
+
.flatMap((l) => {
|
|
175
|
+
try {
|
|
176
|
+
const r = JSON.parse(l);
|
|
177
|
+
return r && typeof r === "object" && !Array.isArray(r) ? [r] : [];
|
|
178
|
+
} catch {
|
|
179
|
+
return [];
|
|
180
|
+
}
|
|
181
|
+
});
|
|
182
|
+
}
|
|
183
|
+
|
|
184
|
+
/**
|
|
185
|
+
* The repository's standing ledger entries: not superseded, not suppressed by
|
|
186
|
+
* feedback. Each carries its pointer id and its place in the file.
|
|
187
|
+
*/
|
|
188
|
+
export function standingEntries(storeDir) {
|
|
189
|
+
const ledger = rows(join(storeDir, "learnings-ledger.jsonl"));
|
|
190
|
+
const retired = supersededBy(ledger);
|
|
191
|
+
const feedback = new Map();
|
|
192
|
+
for (const f of rows(join(storeDir, "learnings-feedback.jsonl"))) {
|
|
193
|
+
if (!feedback.has(f.id)) feedback.set(f.id, []);
|
|
194
|
+
feedback.get(f.id).push(f);
|
|
195
|
+
}
|
|
196
|
+
const out = [];
|
|
197
|
+
for (const [i, r] of ledger.entries()) {
|
|
198
|
+
if (retired[i] !== null || typeof r.statement !== "string" || !r.statement.trim()) continue;
|
|
199
|
+
const id = ledgerRowId(r);
|
|
200
|
+
if (standing(feedback.get(id) ?? []).suppressed) continue;
|
|
201
|
+
out.push({ id, order: i, row: r });
|
|
202
|
+
}
|
|
203
|
+
return out;
|
|
204
|
+
}
|
|
205
|
+
|
|
206
|
+
/** Best first: confidence, repository-wide before path-scoped, kind, newest. */
|
|
207
|
+
export function rankEntries(entries) {
|
|
208
|
+
const rank = (e) => CONFIDENCE[e.row.confidence] ?? CONFIDENCE.medium;
|
|
209
|
+
const wide = (e) => (!e.row.scope || e.row.scope === "global" ? 0 : 1);
|
|
210
|
+
const kind = (e) => {
|
|
211
|
+
const k = KINDS.indexOf(e.row.kind);
|
|
212
|
+
return k === -1 ? KINDS.length : k;
|
|
213
|
+
};
|
|
214
|
+
return [...entries].sort(
|
|
215
|
+
(a, b) => rank(a) - rank(b) || wide(a) - wide(b) || kind(a) - kind(b) || b.order - a.order,
|
|
216
|
+
);
|
|
217
|
+
}
|
|
218
|
+
|
|
219
|
+
/** The line printed for one entry: every printed field is in this string. */
|
|
220
|
+
export function entryLine(e) {
|
|
221
|
+
const scope = e.row.scope && e.row.scope !== "global" ? ` (scope ${clean(e.row.scope, 40)})` : "";
|
|
222
|
+
return `- [${e.id}] ${clean(e.row.kind, 24)}: ${clean(e.row.statement)}${scope}`;
|
|
223
|
+
}
|
|
224
|
+
|
|
225
|
+
/**
|
|
226
|
+
* The ledger layer: the count by kind and the best entries whose printed line
|
|
227
|
+
* passes the secret scan. The count excludes entries the scan refused.
|
|
228
|
+
*/
|
|
229
|
+
export function ledgerLayer(storeDir, cfg, globalRows = 0) {
|
|
230
|
+
const all = standingEntries(storeDir).filter((e) => cfg.kinds.includes(e.row.kind));
|
|
231
|
+
if (!all.length || cfg.maxEntries === 0) return null;
|
|
232
|
+
const scan = openScanner();
|
|
233
|
+
const shown = [];
|
|
234
|
+
const refused = new Set();
|
|
235
|
+
try {
|
|
236
|
+
for (const e of rankEntries(all).slice(0, SCAN_LIMIT)) {
|
|
237
|
+
const line = entryLine(e);
|
|
238
|
+
const whole = `${e.row.kind} ${e.row.statement} ${e.row.scope ?? ""}`;
|
|
239
|
+
if (scan.isClean(line) && scan.isClean(whole)) {
|
|
240
|
+
if (shown.length < cfg.maxEntries) shown.push({ e, line });
|
|
241
|
+
} else {
|
|
242
|
+
refused.add(e.id);
|
|
243
|
+
}
|
|
244
|
+
}
|
|
245
|
+
} finally {
|
|
246
|
+
scan.close();
|
|
247
|
+
}
|
|
248
|
+
if (!shown.length) return null;
|
|
249
|
+
const kept = all.filter((e) => !refused.has(e.id));
|
|
250
|
+
const total = kept.length;
|
|
251
|
+
const kinds = KINDS.map((k) => [k, kept.filter((e) => e.row.kind === k).length])
|
|
252
|
+
.filter(([, n]) => n > 0)
|
|
253
|
+
.map(([k, n]) => `${n} ${k}`)
|
|
254
|
+
.join(", ");
|
|
255
|
+
const extra = globalRows > 0 ? `; the ledger profile adds ${globalRows} cross-repo entries` : "";
|
|
256
|
+
const head = `Learnings ledger: ${total} standing entries (${kinds})${extra}. Fetch one with learnings_get or learnings-ledger.mjs show --id <id>; search with learnings_search.`;
|
|
257
|
+
return { head, lines: shown.map((s) => s.line), total, shown: shown.length };
|
|
258
|
+
}
|
|
259
|
+
|
|
260
|
+
/** One line about the repository's code graph, or null when there is none. */
|
|
261
|
+
export function graphLine(slug, env = process.env) {
|
|
262
|
+
const g = readJson(
|
|
263
|
+
join(home(env), ".claude", "knowledge", slug, "code-graph.json"),
|
|
264
|
+
GRAPH_MAX_BYTES,
|
|
265
|
+
);
|
|
266
|
+
const nodes = Number(g?.stats?.nodes);
|
|
267
|
+
if (!Number.isFinite(nodes) || nodes <= 0) return null;
|
|
268
|
+
const files = Number(g.stats.files);
|
|
269
|
+
const at =
|
|
270
|
+
typeof g.baseCommit === "string" && /^[0-9a-f]{7,64}$/.test(g.baseCommit)
|
|
271
|
+
? ` at ${g.baseCommit.slice(0, 7)}`
|
|
272
|
+
: "";
|
|
273
|
+
const size =
|
|
274
|
+
Number.isFinite(files) && files > 0 ? `${files} files, ${nodes} symbols` : `${nodes} symbols`;
|
|
275
|
+
return `Code graph: ${size} indexed${at}. For a symbol or concept question try graph_query or /multi-agent:graph ask before grepping the whole repo; grep stays right for exact text.`;
|
|
276
|
+
}
|
|
277
|
+
|
|
278
|
+
/** The enabled toolkits that ship an index skill, from the effective settings. */
|
|
279
|
+
export async function indexSkills(top, env = process.env) {
|
|
280
|
+
try {
|
|
281
|
+
const { resolveSkillCandidates } = await import("./skill-candidates.mjs");
|
|
282
|
+
const r = resolveSkillCandidates(top, { home: home(env) });
|
|
283
|
+
return (r.toolkits ?? [])
|
|
284
|
+
.filter((t) => Array.isArray(t.skills) && t.skills.includes("index"))
|
|
285
|
+
.map((t) => `${t.name}:index`)
|
|
286
|
+
.slice(0, MAX_TOOLKITS);
|
|
287
|
+
} catch {
|
|
288
|
+
return [];
|
|
289
|
+
}
|
|
290
|
+
}
|
|
291
|
+
|
|
292
|
+
export const DISCIPLINE =
|
|
293
|
+
"Working notes: lead with the answer. Only when the goal behind a request is genuinely unclear, ask one question about why before how; otherwise state the assumption and go. For an open choice, name 2-3 options and recommend one. Give each step a check (step -> verify: how). Say so when a simpler route exists. Give time in minutes or hours.";
|
|
294
|
+
|
|
295
|
+
function routingLine(index) {
|
|
296
|
+
const open = index.length ? ` When unsure which applies, open ${index.join(", ")} first.` : "";
|
|
297
|
+
return `Skills: before replying, check whether an available skill fits the request.${open}`;
|
|
298
|
+
}
|
|
299
|
+
|
|
300
|
+
/** Git's view of the repository at cwd: common dir, top level and HEAD, or null. */
|
|
301
|
+
export function gitFacts(cwd) {
|
|
302
|
+
const r = spawnSync(
|
|
303
|
+
"git",
|
|
304
|
+
[
|
|
305
|
+
"-C",
|
|
306
|
+
cwd,
|
|
307
|
+
"rev-parse",
|
|
308
|
+
"--path-format=absolute",
|
|
309
|
+
"--git-common-dir",
|
|
310
|
+
"--show-toplevel",
|
|
311
|
+
"HEAD",
|
|
312
|
+
],
|
|
313
|
+
{ encoding: "utf8", timeout: 3000 },
|
|
314
|
+
);
|
|
315
|
+
if (r.status !== 0) return null;
|
|
316
|
+
const [common, top, head] = String(r.stdout).split("\n");
|
|
317
|
+
return common && top ? { common, top, head: head || "" } : null;
|
|
318
|
+
}
|
|
319
|
+
|
|
320
|
+
/** The preferences when the file is a regular file and parses; null otherwise. */
|
|
321
|
+
function loadPrefs(env) {
|
|
322
|
+
const file = prefsPath(env);
|
|
323
|
+
try {
|
|
324
|
+
if (!statSync(file).isFile()) return null;
|
|
325
|
+
} catch {
|
|
326
|
+
return null;
|
|
327
|
+
}
|
|
328
|
+
const doc = readJson(file, PREFS_MAX_BYTES);
|
|
329
|
+
return doc && typeof doc === "object" && doc.global && typeof doc.global === "object"
|
|
330
|
+
? { file, global: doc.global }
|
|
331
|
+
: null;
|
|
332
|
+
}
|
|
333
|
+
|
|
334
|
+
/**
|
|
335
|
+
* The hook output for one repository, or null when there is nothing to say.
|
|
336
|
+
*
|
|
337
|
+
* @returns {Promise<null | {output: object, bytes: number, entries: number}>}
|
|
338
|
+
*/
|
|
339
|
+
export async function composeBrief({ cwd = process.cwd(), env = process.env } = {}) {
|
|
340
|
+
const prefs = loadPrefs(env);
|
|
341
|
+
if (!prefs) return null;
|
|
342
|
+
const cfg = settingsOf(prefs.global);
|
|
343
|
+
if (!cfg.enabled) return null;
|
|
344
|
+
const git = gitFacts(cwd);
|
|
345
|
+
if (!git) return null;
|
|
346
|
+
const slug = repoName({ cwd, env });
|
|
347
|
+
if (memoryExcluded(slug, env)) return null;
|
|
348
|
+
|
|
349
|
+
const root = join(home(env), ".claude", "memory", "multi-agent");
|
|
350
|
+
const globalRows = rows(join(root, "_global", "learnings-ledger.jsonl")).length;
|
|
351
|
+
const ledger = ledgerLayer(join(root, slug), cfg, globalRows);
|
|
352
|
+
const graph = cfg.graph ? graphLine(slug, env) : null;
|
|
353
|
+
if (!ledger && !graph) return null;
|
|
354
|
+
const index = await indexSkills(git.top, env);
|
|
355
|
+
|
|
356
|
+
const items = [];
|
|
357
|
+
if (ledger) {
|
|
358
|
+
items.push({ id: "ledger-head", priority: 100, block: ledger.head });
|
|
359
|
+
ledger.lines.forEach((line, i) =>
|
|
360
|
+
items.push({ id: `ledger-${i}`, priority: 60 - i, block: line }),
|
|
361
|
+
);
|
|
362
|
+
}
|
|
363
|
+
if (graph) items.push({ id: "graph", priority: 30, block: graph });
|
|
364
|
+
items.push({ id: "routing", priority: 20, block: routingLine(index) });
|
|
365
|
+
if (cfg.discipline) items.push({ id: "discipline", priority: 10, block: DISCIPLINE });
|
|
366
|
+
|
|
367
|
+
const render = (kept) => {
|
|
368
|
+
const ledgerBlocks = kept.filter((k) => k.id.startsWith("ledger")).map((k) => k.block);
|
|
369
|
+
const rest = kept.filter((k) => !k.id.startsWith("ledger")).map((k) => k.block);
|
|
370
|
+
const fenced = ledgerBlocks.length
|
|
371
|
+
? [wrapUntrusted(`memory:${slug}`, ledgerBlocks.join("\n")).trimEnd()]
|
|
372
|
+
: [];
|
|
373
|
+
return [...fenced, ...rest].join("\n");
|
|
374
|
+
};
|
|
375
|
+
const { text } = fitToBudget(items, { maxChars: cfg.maxChars, render });
|
|
376
|
+
if (!text) return null;
|
|
377
|
+
const bytes = Buffer.byteLength(text, "utf8");
|
|
378
|
+
const tokens = Math.ceil(bytes / 4);
|
|
379
|
+
const shown = text.split("\n").filter((l) => l.startsWith("- [L:")).length;
|
|
380
|
+
const say = messages(
|
|
381
|
+
{
|
|
382
|
+
en: (n, t) =>
|
|
383
|
+
n > 0
|
|
384
|
+
? `multi-agent: session brief loaded, ${n} ledger entries indexed (~${t} tokens).`
|
|
385
|
+
: `multi-agent: session brief loaded (~${t} tokens).`,
|
|
386
|
+
tr: (n, t) =>
|
|
387
|
+
n > 0
|
|
388
|
+
? `multi-agent: oturum özeti yüklendi, ${n} ledger kaydı dizinlendi (~${t} token).`
|
|
389
|
+
: `multi-agent: oturum özeti yüklendi (~${t} token).`,
|
|
390
|
+
},
|
|
391
|
+
outputLanguage(prefs.file),
|
|
392
|
+
);
|
|
393
|
+
return {
|
|
394
|
+
output: {
|
|
395
|
+
hookSpecificOutput: { hookEventName: "SessionStart", additionalContext: text },
|
|
396
|
+
systemMessage: say(shown, tokens),
|
|
397
|
+
},
|
|
398
|
+
bytes,
|
|
399
|
+
entries: shown,
|
|
400
|
+
};
|
|
401
|
+
}
|
|
402
|
+
|
|
403
|
+
function writePrivate(path, data) {
|
|
404
|
+
const tmp = `${path}.${process.pid}.tmp`;
|
|
405
|
+
writeFileSync(tmp, data, { mode: 0o600, flag: "w" });
|
|
406
|
+
chmodSync(tmp, 0o600);
|
|
407
|
+
renameSync(tmp, path);
|
|
408
|
+
}
|
|
409
|
+
|
|
410
|
+
/**
|
|
411
|
+
* Rebuild the cache for the repository at `cwd`. The file is the header line
|
|
412
|
+
* `#sb1|<git common dir>|<HEAD>` and then the hook output as one JSON line; an
|
|
413
|
+
* empty brief is cached as the header alone, so the hook can tell "nothing to
|
|
414
|
+
* say" from "never built".
|
|
415
|
+
*/
|
|
416
|
+
export async function buildCache({ cwd = process.cwd(), env = process.env } = {}) {
|
|
417
|
+
const git = gitFacts(cwd);
|
|
418
|
+
if (!git) return null;
|
|
419
|
+
const dir = cacheDir(env);
|
|
420
|
+
const name = cacheName(repoName({ cwd, env }), git.common);
|
|
421
|
+
const lock = join(dir, `${name}.lock`);
|
|
422
|
+
try {
|
|
423
|
+
if (!loadPrefs(env) || !settingsOf(loadPrefs(env).global).enabled) return null;
|
|
424
|
+
mkdirSync(dir, { recursive: true, mode: 0o700 });
|
|
425
|
+
chmodSync(dir, 0o700);
|
|
426
|
+
const brief = await composeBrief({ cwd, env });
|
|
427
|
+
const header = `${CACHE_MAGIC}|${git.common}|${git.head}\n`;
|
|
428
|
+
writePrivate(
|
|
429
|
+
join(dir, `${name}.json`),
|
|
430
|
+
header + (brief ? `${JSON.stringify(brief.output)}\n` : ""),
|
|
431
|
+
);
|
|
432
|
+
return brief;
|
|
433
|
+
} finally {
|
|
434
|
+
rmSync(lock, { recursive: true, force: true });
|
|
435
|
+
}
|
|
436
|
+
}
|
|
437
|
+
|
|
438
|
+
async function main(argv) {
|
|
439
|
+
const timer = setTimeout(() => process.exit(0), BUILD_LIMIT_MS);
|
|
440
|
+
timer.unref();
|
|
441
|
+
const sub = argv[0];
|
|
442
|
+
const at = argv.indexOf("--cwd");
|
|
443
|
+
const cwd = at > 0 && argv[at + 1] ? argv[at + 1] : process.cwd();
|
|
444
|
+
try {
|
|
445
|
+
if (sub === "build") {
|
|
446
|
+
await buildCache({ cwd });
|
|
447
|
+
} else if (sub === "print") {
|
|
448
|
+
const brief = await composeBrief({ cwd });
|
|
449
|
+
if (brief) process.stdout.write(`${JSON.stringify(brief.output)}\n`);
|
|
450
|
+
} else {
|
|
451
|
+
process.stderr.write("usage: session-brief.mjs build|print [--cwd <dir>]\n");
|
|
452
|
+
}
|
|
453
|
+
} catch {
|
|
454
|
+
/* a session start is never failed over a brief */
|
|
455
|
+
}
|
|
456
|
+
}
|
|
457
|
+
|
|
458
|
+
if (invokedDirectly(import.meta.url)) await main(process.argv.slice(2));
|
|
@@ -0,0 +1,130 @@
|
|
|
1
|
+
#!/usr/bin/env bash
|
|
2
|
+
# session-brief.sh - opt-in SessionStart hook for the pipeline.
|
|
3
|
+
#
|
|
4
|
+
# Prints the cached session brief for the repository the session opens in (what
|
|
5
|
+
# it holds is described in session-brief.mjs). It only reads a file. Starting
|
|
6
|
+
# node on every session start costs more than this hook may take, so a detached
|
|
7
|
+
# node process builds the cache whenever HEAD or the repository differs from the
|
|
8
|
+
# cache header, or a file the cache was built from is newer than it. The cache
|
|
9
|
+
# is printed only when its header names this repository's git common directory
|
|
10
|
+
# and this HEAD; otherwise nothing is printed this session and a rebuild starts.
|
|
11
|
+
#
|
|
12
|
+
# Silent and instant unless prefs.global.sessionBrief.enabled is true. Also
|
|
13
|
+
# silent in a pipeline or unattended context (MULTI_AGENT_UNATTENDED,
|
|
14
|
+
# MULTI_AGENT_TASK_ID, MULTI_AGENT_PHASE), when the host says the session is not
|
|
15
|
+
# attended (CLAUDE_CODE_SESSION_ATTENDED set to anything but 1), for an SDK
|
|
16
|
+
# entrypoint (CLAUDE_CODE_ENTRYPOINT starting with sdk), outside a git
|
|
17
|
+
# repository, with HOME unset, and with MULTI_AGENT_SESSION_BRIEF=0.
|
|
18
|
+
# Exits 0 on every path.
|
|
19
|
+
|
|
20
|
+
case "${1:-}" in
|
|
21
|
+
--help | -h)
|
|
22
|
+
cat <<'USAGE'
|
|
23
|
+
session-brief.sh - SessionStart hook: prints the cached, opt-in session brief.
|
|
24
|
+
Turn it on with prefs.global.sessionBrief.enabled true; see
|
|
25
|
+
multi-agent-refs/features/session-brief.md. Reads the hook payload on stdin
|
|
26
|
+
only to ignore it. Exits 0 on every path.
|
|
27
|
+
USAGE
|
|
28
|
+
exit 0
|
|
29
|
+
;;
|
|
30
|
+
esac
|
|
31
|
+
|
|
32
|
+
[ -n "${HOME:-}" ] || exit 0
|
|
33
|
+
[ "${MULTI_AGENT_SESSION_BRIEF:-}" = "0" ] && exit 0
|
|
34
|
+
[ -n "${MULTI_AGENT_UNATTENDED:-}" ] && [ "${MULTI_AGENT_UNATTENDED}" != "0" ] && exit 0
|
|
35
|
+
[ -n "${MULTI_AGENT_TASK_ID:-}${MULTI_AGENT_PHASE:-}" ] && exit 0
|
|
36
|
+
[ -n "${CLAUDE_CODE_SESSION_ATTENDED:-}" ] && [ "${CLAUDE_CODE_SESSION_ATTENDED}" != "1" ] && exit 0
|
|
37
|
+
[[ "${CLAUDE_CODE_ENTRYPOINT:-}" == sdk* ]] && exit 0
|
|
38
|
+
|
|
39
|
+
# Off unless the preferences switch it on. Only builtins read the file, and only
|
|
40
|
+
# when it is a regular file under 256 KiB (a FIFO or a huge file reads as off).
|
|
41
|
+
PREFS="${MULTI_AGENT_PREFS:-$HOME/.claude/multi-agent-preferences.json}"
|
|
42
|
+
[ -f "$PREFS" ] || exit 0
|
|
43
|
+
PREFS_TEXT=""
|
|
44
|
+
IFS= read -r -d '' -n 262144 PREFS_TEXT <"$PREFS" 2>/dev/null
|
|
45
|
+
[ "${#PREFS_TEXT}" -lt 262144 ] || exit 0
|
|
46
|
+
[[ "$PREFS_TEXT" == *sessionBrief* ]] || exit 0
|
|
47
|
+
ON='"sessionBrief"[[:space:]]*:[[:space:]]*\{[^{}]*"enabled"[[:space:]]*:[[:space:]]*true'
|
|
48
|
+
[[ "$PREFS_TEXT" =~ $ON ]] || exit 0
|
|
49
|
+
|
|
50
|
+
export LC_ALL=C
|
|
51
|
+
{
|
|
52
|
+
IFS= read -r COMMON
|
|
53
|
+
IFS= read -r TOP
|
|
54
|
+
IFS= read -r HEAD_SHA
|
|
55
|
+
} < <(git rev-parse --path-format=absolute --git-common-dir --show-toplevel HEAD 2>/dev/null)
|
|
56
|
+
[ -n "${COMMON:-}" ] && [ -n "${TOP:-}" ] || exit 0
|
|
57
|
+
|
|
58
|
+
if [ -n "${MULTI_AGENT_REPO_SLUG:-}" ]; then
|
|
59
|
+
SLUG="$MULTI_AGENT_REPO_SLUG"
|
|
60
|
+
else
|
|
61
|
+
SLUG="${COMMON%/}"
|
|
62
|
+
if [ "${SLUG##*/}" = ".git" ]; then
|
|
63
|
+
SLUG="${SLUG%/.git}"
|
|
64
|
+
SLUG="${SLUG##*/}"
|
|
65
|
+
else
|
|
66
|
+
SLUG="${SLUG##*/}"
|
|
67
|
+
SLUG="${SLUG%.git}"
|
|
68
|
+
fi
|
|
69
|
+
fi
|
|
70
|
+
SAFE="${SLUG//[^A-Za-z0-9._-]/_}"
|
|
71
|
+
[ -n "$SAFE" ] || exit 0
|
|
72
|
+
|
|
73
|
+
# 32-bit djb2 over the common dir's bytes: the cache file name, as in
|
|
74
|
+
# pathHash() in session-brief.mjs.
|
|
75
|
+
h=5381
|
|
76
|
+
for ((i = 0; i < ${#COMMON}; i++)); do
|
|
77
|
+
printf -v c '%d' "'${COMMON:i:1}"
|
|
78
|
+
h=$(((h * 33 + c) & 0xffffffff))
|
|
79
|
+
done
|
|
80
|
+
printf -v HASH '%08x' "$h"
|
|
81
|
+
|
|
82
|
+
MEM="$HOME/.claude/memory/multi-agent"
|
|
83
|
+
DIR="$MEM/_session-brief"
|
|
84
|
+
CACHE="$DIR/$SAFE-$HASH.json"
|
|
85
|
+
STORE="$MEM/$SLUG"
|
|
86
|
+
EXPECT="#sb1|$COMMON|$HEAD_SHA"
|
|
87
|
+
|
|
88
|
+
CONTENT=""
|
|
89
|
+
if [ -f "$CACHE" ] && [ ! -L "$CACHE" ]; then
|
|
90
|
+
IFS= read -r -d '' -n 16000 CONTENT <"$CACHE" 2>/dev/null
|
|
91
|
+
[ "${#CONTENT}" -lt 16000 ] || CONTENT=""
|
|
92
|
+
fi
|
|
93
|
+
HEADER="${CONTENT%%$'\n'*}"
|
|
94
|
+
|
|
95
|
+
stale=0
|
|
96
|
+
if [ "$HEADER" != "$EXPECT" ]; then
|
|
97
|
+
stale=1
|
|
98
|
+
else
|
|
99
|
+
for dep in "$STORE/learnings-ledger.jsonl" "$STORE/learnings-feedback.jsonl" \
|
|
100
|
+
"$MEM/_global/learnings-ledger.jsonl" "$HOME/.claude/knowledge/$SLUG/code-graph.json" \
|
|
101
|
+
"$PREFS" "$HOME/.claude/settings.json" "$HOME/.claude/settings.local.json" \
|
|
102
|
+
"$TOP/.claude/settings.json" "$TOP/.claude/settings.local.json" \
|
|
103
|
+
"$HOME/.claude/plugins/installed_plugins.json"; do
|
|
104
|
+
if [ -f "$dep" ] && [ "$dep" -nt "$CACHE" ]; then stale=1; break; fi
|
|
105
|
+
done
|
|
106
|
+
fi
|
|
107
|
+
|
|
108
|
+
if [ "$stale" = "1" ]; then
|
|
109
|
+
CORE="${BASH_SOURCE[0]%/*}/session-brief.mjs"
|
|
110
|
+
if [ -f "$CORE" ] && command -v node >/dev/null 2>&1; then
|
|
111
|
+
(umask 077; mkdir -p "$DIR" 2>/dev/null)
|
|
112
|
+
LOCK="$DIR/$SAFE-$HASH.lock"
|
|
113
|
+
if [ -d "$LOCK" ] && [ -n "$(find "$LOCK" -maxdepth 0 -mmin +5 2>/dev/null)" ]; then
|
|
114
|
+
rmdir "$LOCK" 2>/dev/null
|
|
115
|
+
fi
|
|
116
|
+
if mkdir "$LOCK" 2>/dev/null; then
|
|
117
|
+
nohup node "$CORE" build --cwd "$PWD" </dev/null >/dev/null 2>&1 &
|
|
118
|
+
fi
|
|
119
|
+
fi
|
|
120
|
+
fi
|
|
121
|
+
|
|
122
|
+
# Print only a cache built for this repository and HEAD whose body is one line
|
|
123
|
+
# without control characters.
|
|
124
|
+
[ "$HEADER" = "$EXPECT" ] || exit 0
|
|
125
|
+
BODY="${CONTENT#*$'\n'}"
|
|
126
|
+
BODY="${BODY%$'\n'}"
|
|
127
|
+
[ -n "$BODY" ] && [ "$BODY" != "$CONTENT" ] || exit 0
|
|
128
|
+
[[ "$BODY" == *[[:cntrl:]]* ]] && exit 0
|
|
129
|
+
printf '%s\n' "$BODY"
|
|
130
|
+
exit 0
|
|
@@ -32,10 +32,9 @@
|
|
|
32
32
|
*
|
|
33
33
|
* Two kinds of entry are never prune candidates:
|
|
34
34
|
*
|
|
35
|
-
* rename aliases a SKILL.md carrying `renamed-to
|
|
36
|
-
* is left out of the catalog
|
|
37
|
-
*
|
|
38
|
-
* counts as a use of the skill it points at.
|
|
35
|
+
* rename aliases a SKILL.md carrying `renamed-to:`, left on a machine by an
|
|
36
|
+
* earlier release, is left out of the catalog. A call under
|
|
37
|
+
* the old name counts as a use of the skill it points at.
|
|
39
38
|
* commands everything under ~/.claude/commands is listed as not
|
|
40
39
|
* observable. A slash command the user types expands in
|
|
41
40
|
* the prompt without a Skill tool call, so the hook never
|
|
@@ -65,7 +64,6 @@ import { exitOnHelp } from "../lib/cli-help.mjs";
|
|
|
65
64
|
import { invokedDirectly } from "../lib/invoked-directly.mjs";
|
|
66
65
|
import { marketplacePluginNames, pluginSkillRootCandidates } from "../lib/plugin-skill-roots.mjs";
|
|
67
66
|
import { readRegularFile } from "../lib/regular-file.mjs";
|
|
68
|
-
import { aliasTarget } from "./_renamed-skills.mjs";
|
|
69
67
|
import { LOG_FILE, MAX_LOG_BYTES, SKILL_NAME, logDir } from "./note-skill-use.mjs";
|
|
70
68
|
|
|
71
69
|
exitOnHelp(import.meta.url);
|
|
@@ -76,9 +74,22 @@ const DAY_MS = 86_400_000;
|
|
|
76
74
|
const READ_CAP = MAX_LOG_BYTES * 4;
|
|
77
75
|
const OUTCOMES = new Set(["ok", "error"]);
|
|
78
76
|
|
|
77
|
+
const ALIAS_TARGET = /^ {2}renamed-to: ([a-z0-9-]+)$/m;
|
|
78
|
+
|
|
79
79
|
const home = (env) => env.HOME || homedir();
|
|
80
80
|
const hidden = (name) => name.startsWith("_") || name.startsWith(".");
|
|
81
81
|
|
|
82
|
+
function aliasTarget(skillMdPath) {
|
|
83
|
+
try {
|
|
84
|
+
return (
|
|
85
|
+
ALIAS_TARGET.exec(readRegularFile(skillMdPath, { maxBytes: 65_536, noFollow: true }))?.[1] ??
|
|
86
|
+
null
|
|
87
|
+
);
|
|
88
|
+
} catch {
|
|
89
|
+
return null;
|
|
90
|
+
}
|
|
91
|
+
}
|
|
92
|
+
|
|
82
93
|
function entries(dir) {
|
|
83
94
|
try {
|
|
84
95
|
return readdirSync(dir, { withFileTypes: true });
|
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
{
|
|
2
|
+
"$schema": "https://json-schema.org/draft/2020-12/schema",
|
|
3
|
+
"stack": "cpp",
|
|
4
|
+
"description": "C and C++ test gap rules. Headers and sources are both source; tests carry a _test or Test suffix or live under a test directory.",
|
|
5
|
+
"sourceExtensions": [".c", ".h", ".cc", ".cpp", ".cxx", ".hpp", ".hh", ".hxx"],
|
|
6
|
+
"testPathSuffixes": ["_test.cpp", "_test.cc", "_test.c", "Test.cpp", "Tests.cpp", "Test.cc"],
|
|
7
|
+
"testPathContains": ["/test/", "/tests/", "/unittests/"],
|
|
8
|
+
"excludePathGlobs": [
|
|
9
|
+
"build/",
|
|
10
|
+
"cmake-build-debug/",
|
|
11
|
+
"cmake-build-release/",
|
|
12
|
+
"third_party/",
|
|
13
|
+
"vendor/",
|
|
14
|
+
"external/",
|
|
15
|
+
"*.pb.cc",
|
|
16
|
+
"*.pb.h"
|
|
17
|
+
],
|
|
18
|
+
"publicApiPatterns": [
|
|
19
|
+
{
|
|
20
|
+
"id": "class",
|
|
21
|
+
"regex": "\\b(?:class|struct)\\s+([A-Z][A-Za-z0-9_]*)\\s*(?:final\\s*)?(?::[^;{]*)?\\{"
|
|
22
|
+
}
|
|
23
|
+
],
|
|
24
|
+
"hint": "Cover each class with a test that includes its header. A free function is covered through the public entry point that calls it."
|
|
25
|
+
}
|
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
{
|
|
2
|
+
"$schema": "https://json-schema.org/draft/2020-12/schema",
|
|
3
|
+
"stack": "csharp",
|
|
4
|
+
"description": "C# test gap rules. Sources in *.cs; tests sit in a sibling project named *.Tests or *Tests with a Tests or Test suffix on the class file.",
|
|
5
|
+
"sourceExtensions": [".cs"],
|
|
6
|
+
"testPathSuffixes": ["Tests.cs", "Test.cs"],
|
|
7
|
+
"testPathContains": [".Tests/", "Tests/", ".Test/"],
|
|
8
|
+
"excludePathGlobs": ["bin/", "obj/", "*.g.cs", "*.Designer.cs", "*.generated.cs", "Migrations/"],
|
|
9
|
+
"publicApiPatterns": [
|
|
10
|
+
{
|
|
11
|
+
"id": "public_type",
|
|
12
|
+
"regex": "\\bpublic\\s+(?:static\\s+|abstract\\s+|sealed\\s+|partial\\s+)*(?:class|interface|struct|enum|record)\\s+([A-Z][A-Za-z0-9_]*)"
|
|
13
|
+
},
|
|
14
|
+
{
|
|
15
|
+
"id": "public_method",
|
|
16
|
+
"regex": "\\bpublic\\s+(?:static\\s+|virtual\\s+|override\\s+|async\\s+)*[\\w<>\\[\\],.? ]+\\s+([A-Z][A-Za-z0-9_]*)\\s*\\("
|
|
17
|
+
}
|
|
18
|
+
],
|
|
19
|
+
"hint": "Cover public types and methods with a test class named <Type>Tests in the matching test project."
|
|
20
|
+
}
|