@letsrebase/verify 0.0.0-stage → 0.1.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/.claude/commands/rebase-verify.md +118 -0
- package/LICENSE +21 -0
- package/PRIVACY.md +113 -0
- package/README.md +209 -2
- package/SECURITY.md +33 -0
- package/bin/rebase-verify.mjs +699 -0
- package/package.json +38 -4
- package/share/practices.json +224 -0
- package/share/tech-labels.json +57 -0
- package/share/tech-lexicon.json +62 -0
- package/src/adapters/claude-code.mjs +225 -0
- package/src/adapters/codex.mjs +476 -0
- package/src/adapters/cursor.mjs +584 -0
- package/src/adapters/kimi.mjs +594 -0
- package/src/adapters/omp.mjs +59 -0
- package/src/adapters/opencode.mjs +439 -0
- package/src/adapters/pi.mjs +414 -0
- package/src/adapters/tool-vocab.mjs +15 -0
- package/src/agent-run.mjs +10 -0
- package/src/agentic-literacy.mjs +211 -0
- package/src/agents/acp.mjs +364 -0
- package/src/agents/json-answer.mjs +72 -0
- package/src/agents/registry.mjs +370 -0
- package/src/agents/run.mjs +131 -0
- package/src/ai-relationship.mjs +95 -0
- package/src/consistency.mjs +357 -0
- package/src/days.mjs +45 -0
- package/src/digest.mjs +501 -0
- package/src/distribution.mjs +54 -0
- package/src/enrich.mjs +118 -0
- package/src/fingerprint.mjs +134 -0
- package/src/forensics.mjs +178 -0
- package/src/groundedness.mjs +347 -0
- package/src/hub.mjs +136 -0
- package/src/intensity.mjs +132 -0
- package/src/live-status.mjs +79 -0
- package/src/practices-llm.mjs +90 -0
- package/src/practices-rules.mjs +295 -0
- package/src/practices-sample.mjs +111 -0
- package/src/practices.mjs +272 -0
- package/src/profile-llm.mjs +249 -0
- package/src/profile.mjs +497 -0
- package/src/redact.mjs +97 -0
- package/src/sources.mjs +91 -0
- package/src/submit.mjs +65 -0
- package/src/system-text.mjs +3 -0
- package/src/tech-usage.mjs +88 -0
- package/src/trajectory.mjs +264 -0
- package/src/wizard.mjs +411 -0
|
@@ -0,0 +1,295 @@
|
|
|
1
|
+
// Rules behind the code-counted work practices of `rebase-practices/v1`: which
|
|
2
|
+
// paths are tests, sources, design documents or plans, and which shell commands
|
|
3
|
+
// are checks, security scans, diff displays or commits. share/practices.json
|
|
4
|
+
// publishes the same patterns (`npm run practices`), because a freelancer
|
|
5
|
+
// consents to them; test/practices-artifact.test.mjs keeps both in step.
|
|
6
|
+
import { splitTopLevel, stripHeredocs } from "./digest.mjs";
|
|
7
|
+
|
|
8
|
+
export const RUBRIC = "rebase-practices/v1";
|
|
9
|
+
|
|
10
|
+
// ---- Paths (every path treats `\` as `/`, case-insensitive) ----
|
|
11
|
+
|
|
12
|
+
export const TEST_PATH_PATTERNS = [
|
|
13
|
+
{ id: "test-dir", re: /(?:^|\/)(?:tests?|__tests__|spec)\// },
|
|
14
|
+
{ id: "test-file", re: /\.(?:test|spec)\.[^/]+$/ },
|
|
15
|
+
{ id: "go-style-test", re: /_test\.[^/]+$/ },
|
|
16
|
+
{ id: "python-test", re: /(?:^|\/)test_[^/]*\.py$/ },
|
|
17
|
+
];
|
|
18
|
+
|
|
19
|
+
export const SOURCE_EXT = [
|
|
20
|
+
"js", "mjs", "cjs", "jsx", "ts", "mts", "cts", "tsx", "vue", "svelte", "py", "go", "rs", "java", "kt",
|
|
21
|
+
"kts", "scala", "rb", "php", "cs", "c", "cc", "cpp", "h", "hpp", "swift", "m", "dart", "ex", "exs", "lua",
|
|
22
|
+
];
|
|
23
|
+
export const SOURCE_PATH_PATTERNS = [{ id: "code-extension", re: new RegExp(`\\.(?:${SOURCE_EXT.join("|")})$`) }];
|
|
24
|
+
|
|
25
|
+
// Code-looking files that are configuration or documentation, not source.
|
|
26
|
+
export const SOURCE_EXCLUSION_PATTERNS = [
|
|
27
|
+
{ id: "config-file", re: /\.config\.[^/]+$/ },
|
|
28
|
+
{ id: "type-declarations", re: /\.d\.[cm]?ts$/ },
|
|
29
|
+
{ id: "conftest", re: /(?:^|\/)conftest\.py$/ },
|
|
30
|
+
{ id: "setup-script", re: /(?:^|\/)setup\.py$/ },
|
|
31
|
+
{ id: "docs-dir", re: /(?:^|\/)docs\// },
|
|
32
|
+
];
|
|
33
|
+
|
|
34
|
+
export const DESIGN_PATH_PATTERNS = [
|
|
35
|
+
{ id: "adr-dir", re: /(?:^|\/)adr\// },
|
|
36
|
+
{ id: "rfc-dir", re: /(?:^|\/)(?:rfcs\/|docs\/rfc\/)/ },
|
|
37
|
+
{ id: "design-dir", re: /(?:^|\/)docs\/design\// },
|
|
38
|
+
{ id: "specs-dir", re: /(?:^|\/)specs\// },
|
|
39
|
+
{ id: "adr-file", re: /(?:^|\/)(?:adr-[^/]*|[^/]*-adr\.md)$/ },
|
|
40
|
+
{ id: "rfc-file", re: /(?:^|\/)rfc[^/]*$/ },
|
|
41
|
+
{ id: "design-file", re: /(?:^|\/)(?:[^/]*-design|design)\.md$/ },
|
|
42
|
+
{ id: "spec-file", re: /(?:^|\/)[^/]*-spec\.md$/ },
|
|
43
|
+
];
|
|
44
|
+
|
|
45
|
+
// A spec file counts as a plan too.
|
|
46
|
+
export const PLAN_PATH_PATTERNS = [
|
|
47
|
+
{ id: "plans-dir", re: /(?:^|\/)plans\// },
|
|
48
|
+
{ id: "plan-file", re: /(?:^|\/)(?:[^/]*-plan|plan)\.md$/ },
|
|
49
|
+
{ id: "specs-dir", re: /(?:^|\/)specs\// },
|
|
50
|
+
{ id: "spec-file", re: /(?:^|\/)[^/]*-spec\.md$/ },
|
|
51
|
+
];
|
|
52
|
+
|
|
53
|
+
const norm = (p) => String(p ?? "").replace(/\\/g, "/").toLowerCase();
|
|
54
|
+
const anyMatch = (patterns, s) => patterns.some(({ re }) => re.test(s));
|
|
55
|
+
|
|
56
|
+
export const isTestPath = (path) => anyMatch(TEST_PATH_PATTERNS, norm(path));
|
|
57
|
+
export const isSourcePath = (path) => {
|
|
58
|
+
const p = norm(path);
|
|
59
|
+
return anyMatch(SOURCE_PATH_PATTERNS, p) && !isTestPath(p) && !anyMatch(SOURCE_EXCLUSION_PATTERNS, p);
|
|
60
|
+
};
|
|
61
|
+
export const isDesignDocPath = (path) => anyMatch(DESIGN_PATH_PATTERNS, norm(path));
|
|
62
|
+
export const isPlanPath = (path) => anyMatch(PLAN_PATH_PATTERNS, norm(path));
|
|
63
|
+
|
|
64
|
+
// ---- Commands ----
|
|
65
|
+
|
|
66
|
+
const ENV_ASSIGN = /^(?:[A-Za-z_][A-Za-z0-9_]*=(?:"(?:[^"\\]|\\.)*"|'[^']*'|\\.|[^\s"'\\])*\s+)+/;
|
|
67
|
+
const WRAPPER = /^(?:npx(?:\s+(?:-[-\w]+|--))*|bunx|pnpm\s+(?:exec|dlx)|npm\s+exec(?:\s+--)?|uv\s+run(?:\s+--?[-\w]+)*|poetry\s+run|pipenv\s+run|python3?\s+-m|py\s+-m)\s+/;
|
|
68
|
+
|
|
69
|
+
// One top-level sub-command reduced to its executable position: openers,
|
|
70
|
+
// control-flow keywords, env assignments and runner prefixes (npx, uv run,
|
|
71
|
+
// python -m, pnpm exec) are removed.
|
|
72
|
+
export function stripToExecutable(raw) {
|
|
73
|
+
let part = raw.trim().replace(/^[({\s]+/, "").replace(/^(?:do|then|else)\s+/, "").replace(ENV_ASSIGN, "").replace(/[)}\s]+$/, "");
|
|
74
|
+
for (let i = 0; i < 3 && WRAPPER.test(part); i++) part = part.replace(WRAPPER, "");
|
|
75
|
+
return part;
|
|
76
|
+
}
|
|
77
|
+
|
|
78
|
+
// The executable position of each top-level sub-command; arguments never match.
|
|
79
|
+
function executables(cmd) {
|
|
80
|
+
const out = [];
|
|
81
|
+
for (const raw of splitTopLevel(stripHeredocs(String(cmd ?? "")))) {
|
|
82
|
+
const part = stripToExecutable(raw);
|
|
83
|
+
if (part) out.push(part);
|
|
84
|
+
}
|
|
85
|
+
return out;
|
|
86
|
+
}
|
|
87
|
+
const anyCommand = (patterns, cmd) => executables(cmd).some((e) => patterns.some(({ re }) => re.test(e)));
|
|
88
|
+
|
|
89
|
+
const END = String.raw`(?=\s|$)`;
|
|
90
|
+
const GIT = String.raw`git(?:\s+(?:-C\s+\S+|-c\s+\S+|--no-pager))*`;
|
|
91
|
+
const SCRIPT = String.raw`(?:run\s+)?(?:test|tests|lint|typecheck|type-check|check|build|ci)`;
|
|
92
|
+
|
|
93
|
+
export const CHECK_PATTERNS = [
|
|
94
|
+
{ id: "pytest", re: new RegExp(String.raw`^(?:py\.test|pytest)${END}`) },
|
|
95
|
+
{ id: "ruff", re: new RegExp(String.raw`^ruff\s+check${END}`) },
|
|
96
|
+
{ id: "mypy", re: new RegExp(String.raw`^(?:mypy|pyright|flake8|pylint)${END}`) },
|
|
97
|
+
{ id: "go-test", re: new RegExp(String.raw`^go\s+(?:test|vet|build)${END}`) },
|
|
98
|
+
{ id: "golangci-lint", re: new RegExp(String.raw`^golangci-lint\s+run${END}`) },
|
|
99
|
+
{ id: "cargo", re: new RegExp(String.raw`^cargo\s+(?:test|clippy|check|build|nextest)${END}`) },
|
|
100
|
+
{ id: "maven", re: new RegExp(String.raw`^(?:mvn|\./mvnw)\s+(?:\S+\s+)*?(?:test|verify|package)${END}`) },
|
|
101
|
+
{ id: "gradle", re: new RegExp(String.raw`^(?:gradle|\./gradlew)\s+(?:\S+\s+)*?(?:test|check|build)${END}`) },
|
|
102
|
+
{ id: "dotnet", re: new RegExp(String.raw`^dotnet\s+(?:test|build)${END}`) },
|
|
103
|
+
{ id: "phpunit", re: new RegExp(String.raw`^(?:\./)?(?:vendor/bin/)?(?:phpunit|phpstan|pest)${END}`) },
|
|
104
|
+
{ id: "rspec", re: new RegExp(String.raw`^(?:bundle\s+exec\s+)?(?:rspec|rubocop)${END}`) },
|
|
105
|
+
{ id: "tsc", re: new RegExp(String.raw`^tsc${END}`) },
|
|
106
|
+
{ id: "eslint", re: new RegExp(String.raw`^(?:eslint|biome\s+(?:check|lint|ci))${END}`) },
|
|
107
|
+
{ id: "vitest", re: new RegExp(String.raw`^vitest${END}`) },
|
|
108
|
+
{ id: "jest", re: new RegExp(String.raw`^jest${END}`) },
|
|
109
|
+
{ id: "playwright", re: new RegExp(String.raw`^(?:playwright|cypress)\s+(?:test|run)${END}`) },
|
|
110
|
+
{ id: "node-test", re: new RegExp(String.raw`^node\s+(?:\S+\s+)*?--test${END}`) },
|
|
111
|
+
{ id: "package-script", re: new RegExp(String.raw`^(?:npm|pnpm|yarn|bun)\s+${SCRIPT}${END}`) },
|
|
112
|
+
{ id: "make", re: new RegExp(String.raw`^make\s+(?:test|tests|check|lint|build|ci)${END}`) },
|
|
113
|
+
];
|
|
114
|
+
|
|
115
|
+
export const SECURITY_PATTERNS = [
|
|
116
|
+
{ id: "package-audit", re: new RegExp(String.raw`^(?:npm|pnpm|yarn|bun)\s+audit${END}`) },
|
|
117
|
+
{ id: "pip-audit", re: new RegExp(String.raw`^(?:pip-audit|safety\s+check|bandit)${END}`) },
|
|
118
|
+
{ id: "cargo-audit", re: new RegExp(String.raw`^cargo\s+(?:audit|deny)${END}`) },
|
|
119
|
+
{ id: "scanner", re: new RegExp(String.raw`^(?:trivy|semgrep|gitleaks|trufflehog|snyk|grype|osv-scanner|brakeman|bundler-audit|govulncheck)${END}`) },
|
|
120
|
+
];
|
|
121
|
+
|
|
122
|
+
export const DIFF_PATTERNS = [
|
|
123
|
+
// `--stat`, `--name-only` and `git show <rev>:<path>` do not display a diff.
|
|
124
|
+
{ id: "git-diff", re: new RegExp(String.raw`^${GIT}\s+diff${END}(?!.*\s--(?:stat|numstat|shortstat|name-only|name-status)\b)`) },
|
|
125
|
+
{ id: "git-show", re: new RegExp(String.raw`^${GIT}\s+show${END}(?!.*\s--(?:stat|numstat|shortstat|name-only|name-status)\b)(?!.*\s[^\s-]\S*:\S)`) },
|
|
126
|
+
{ id: "gh-pr-diff", re: new RegExp(String.raw`^gh\s+pr\s+diff${END}`) },
|
|
127
|
+
];
|
|
128
|
+
|
|
129
|
+
export const COMMIT_PATTERNS = [{ id: "git-commit", re: new RegExp(String.raw`^${GIT}\s+commit${END}`) }];
|
|
130
|
+
export const PULL_REQUEST_PATTERNS = [{ id: "gh-pr-create", re: new RegExp(String.raw`^gh\s+pr\s+create${END}`) }];
|
|
131
|
+
|
|
132
|
+
// The canonical edit names every adapter maps onto (codex apply_patch and
|
|
133
|
+
// opencode patch arrive as "Edit", cursor StrReplace as "Edit"), and the tools
|
|
134
|
+
// that are a planning step.
|
|
135
|
+
export const EDIT_TOOLS = ["Edit", "Write", "NotebookEdit", "MultiEdit"];
|
|
136
|
+
export const PLAN_TOOLS = ["ExitPlanMode", "TodoWrite"];
|
|
137
|
+
|
|
138
|
+
export const isCheckCommand = (cmd) => anyCommand(CHECK_PATTERNS, cmd);
|
|
139
|
+
export const isSecurityCommand = (cmd) => anyCommand(SECURITY_PATTERNS, cmd);
|
|
140
|
+
export const isDiffCommand = (cmd) => anyCommand(DIFF_PATTERNS, cmd);
|
|
141
|
+
export const isCommitCommand = (cmd) => anyCommand(COMMIT_PATTERNS, cmd);
|
|
142
|
+
export const isPullRequestCommand = (cmd) => anyCommand(PULL_REQUEST_PATTERNS, cmd);
|
|
143
|
+
|
|
144
|
+
// ---- The list ----
|
|
145
|
+
|
|
146
|
+
const CMD = "toolUses.cmd";
|
|
147
|
+
const PATH = "toolUses.path";
|
|
148
|
+
const ERR = "toolResults.isError";
|
|
149
|
+
|
|
150
|
+
export const CODE_PRACTICES = [
|
|
151
|
+
{
|
|
152
|
+
id: "checks_before_commit",
|
|
153
|
+
method: "code",
|
|
154
|
+
definition: "After the last file edit before a git commit, a check ran in the session: tests, a linter, a type check or a build.",
|
|
155
|
+
denominator: "Sessions with a commit.",
|
|
156
|
+
needs: [CMD, PATH],
|
|
157
|
+
},
|
|
158
|
+
{
|
|
159
|
+
id: "tests_with_changes",
|
|
160
|
+
method: "code",
|
|
161
|
+
definition: "Both a source file and a test file were edited in the session.",
|
|
162
|
+
denominator: "Sessions that edited a source file.",
|
|
163
|
+
needs: [PATH],
|
|
164
|
+
},
|
|
165
|
+
{
|
|
166
|
+
id: "failure_reproduced_before_fix",
|
|
167
|
+
method: "code",
|
|
168
|
+
definition: "A check command (tests, a linter, a type check or a build) failed, files were edited, and then the same check succeeded in the session.",
|
|
169
|
+
denominator: "Sessions where a check command failed.",
|
|
170
|
+
needs: [CMD, PATH, ERR],
|
|
171
|
+
},
|
|
172
|
+
{
|
|
173
|
+
id: "plan_before_edit",
|
|
174
|
+
method: "code",
|
|
175
|
+
definition: "A planning step came before the first file edit in the session: plan mode, a task list, or writing a plan or spec file.",
|
|
176
|
+
denominator: "Sessions with an edit.",
|
|
177
|
+
needs: [PATH],
|
|
178
|
+
},
|
|
179
|
+
{
|
|
180
|
+
id: "reviews_changes",
|
|
181
|
+
method: "code",
|
|
182
|
+
definition:
|
|
183
|
+
"Before a commit or a pull request, the diff appeared in the session (git diff, git show or gh pr diff), whoever asked for it; the session cannot show whether anyone read it.",
|
|
184
|
+
denominator: "Sessions with a commit or a pull request.",
|
|
185
|
+
needs: [CMD],
|
|
186
|
+
},
|
|
187
|
+
{
|
|
188
|
+
id: "design_documents",
|
|
189
|
+
method: "code",
|
|
190
|
+
definition: "A design document (an ADR, RFC, spec or design file, by path) was written or edited in the session.",
|
|
191
|
+
denominator: "Sessions with an edit.",
|
|
192
|
+
needs: [PATH],
|
|
193
|
+
},
|
|
194
|
+
{
|
|
195
|
+
id: "security_checks",
|
|
196
|
+
method: "code",
|
|
197
|
+
definition: "A dependency audit or a security scanner ran in the session.",
|
|
198
|
+
denominator: "Sessions with an edit.",
|
|
199
|
+
needs: [CMD, PATH],
|
|
200
|
+
},
|
|
201
|
+
];
|
|
202
|
+
|
|
203
|
+
// Adapters whose logs cannot show a practice are left out of its denominator,
|
|
204
|
+
// never counted as "not seen". Cursor reads an absent failure flag as success.
|
|
205
|
+
export const ADAPTERS_WITHOUT = { failure_reproduced_before_fix: ["pi", "omp", "cursor"] };
|
|
206
|
+
|
|
207
|
+
const sources = (patterns) => patterns.map(({ re }) => re.source);
|
|
208
|
+
|
|
209
|
+
export const NOTES = [
|
|
210
|
+
"rebase-verify reads each command up to its first 240 characters, so a check at the end of a long chained command can be missed.",
|
|
211
|
+
"Paths are compared lower-cased, with a backslash read as a forward slash, and are read relative to the project folder of the session, so a folder above the project named test or specs changes nothing.",
|
|
212
|
+
"Sessions with no time are left out, as they cannot be placed in a month.",
|
|
213
|
+
"Leading environment assignments and runner wrappers such as npx, uv run, python -m and pnpm exec are skipped before a command is matched.",
|
|
214
|
+
"Two runs count as the same check when their command words match: the words before the first flag or path, wrappers dropped, so a narrower run of the same check (pytest tests/a.py after pytest) is the same command.",
|
|
215
|
+
"A failed command that holds a check counts as a failed check, and in a chain such as npm test && git push the exit status cannot say which part failed, so the chain counts as its first check.",
|
|
216
|
+
"Options that list files or statistics instead of the diff, such as git diff --stat and --name-only, and git show <rev>:<path>, are not read as a diff appearing.",
|
|
217
|
+
];
|
|
218
|
+
|
|
219
|
+
// One sentence for the artifact and the prompt: the same words in both.
|
|
220
|
+
export const TONE_RULE = "Tone, feelings, politeness and wording quality are never grounds for a yes.";
|
|
221
|
+
|
|
222
|
+
// The four that passed the gate (REB-1146), measured with the shipped prompt
|
|
223
|
+
// wording and message selection and all six candidates in the prompt.
|
|
224
|
+
// gives_context_and_constraints (agreement and stability) and raises_risks
|
|
225
|
+
// (stability) stayed under the 90% threshold and are not published.
|
|
226
|
+
export const PUBLISHED_MODEL_IDS = ["asks_for_alternatives", "pushes_back_with_reason", "states_done_criteria", "limits_scope"];
|
|
227
|
+
|
|
228
|
+
// The six candidates for the model practices; only the published ones leave
|
|
229
|
+
// the machine (PUBLISHED_MODEL_IDS), the gate checks the rest.
|
|
230
|
+
export const MODEL_PRACTICE_CANDIDATES = [
|
|
231
|
+
{
|
|
232
|
+
id: "asks_for_alternatives", method: "model",
|
|
233
|
+
definition: "asks for options or trade-offs before choosing one",
|
|
234
|
+
positive: ["Before we pick a queue library, give me two or three options with their trade-offs.", "Is there another way to do this besides a cron job? Compare them for me."],
|
|
235
|
+
negative: ["Use Redis for the queue.", "What does this function return when the list is empty?"],
|
|
236
|
+
},
|
|
237
|
+
{
|
|
238
|
+
id: "pushes_back_with_reason", method: "model",
|
|
239
|
+
definition: "rejects or corrects what the agent proposed or did, and says why",
|
|
240
|
+
positive: ["No, don't mock the database here: the bug was in the real query, so the test would hide it.", "That rename breaks the public API for existing users, revert it."],
|
|
241
|
+
negative: ["No, not like that.", "Why did you choose a map here instead of a list?"],
|
|
242
|
+
},
|
|
243
|
+
{
|
|
244
|
+
id: "states_done_criteria", method: "model",
|
|
245
|
+
definition: "states acceptance criteria, the expected behaviour, or the check that proves it",
|
|
246
|
+
positive: ["Done when the export returns all rows and the integration test for empty results passes.", "It should redirect to /login when the session expires; I'll check that by hand."],
|
|
247
|
+
negative: ["Make the export work.", "Make sure it works properly when you are done."],
|
|
248
|
+
},
|
|
249
|
+
{
|
|
250
|
+
id: "gives_context_and_constraints", method: "model",
|
|
251
|
+
definition: "explains the goal, the constraints, or who the work is for, before asking for changes",
|
|
252
|
+
positive: ["This page is for non-technical admins and must work without JavaScript, so render it on the server.", "We ship Friday and cannot add dependencies; add the filter using what we already have."],
|
|
253
|
+
negative: ["Add a filter to the page.", "Fix the bug in the parser."],
|
|
254
|
+
},
|
|
255
|
+
{
|
|
256
|
+
id: "raises_risks", method: "model",
|
|
257
|
+
definition: "raises a risk: security, data loss, cost, performance, compatibility, rollout",
|
|
258
|
+
positive: ["This migration drops the column; what happens to rows written during the deploy?", "Calling the API on every keystroke will blow our rate limit and the bill."],
|
|
259
|
+
negative: ["Be careful with this change.", "Make it fast."],
|
|
260
|
+
},
|
|
261
|
+
{
|
|
262
|
+
id: "limits_scope", method: "model",
|
|
263
|
+
definition: "cuts, splits or defers part of the work explicitly",
|
|
264
|
+
positive: ["Only do the backend for now; leave the UI for a separate change.", "Skip the refactor, just fix the crash in this PR."],
|
|
265
|
+
negative: ["Do the backend and the UI and the docs.", "Can you also look at the other files while you are there?"],
|
|
266
|
+
},
|
|
267
|
+
];
|
|
268
|
+
|
|
269
|
+
export function practicesArtifact() {
|
|
270
|
+
return {
|
|
271
|
+
rubric: RUBRIC,
|
|
272
|
+
notes: NOTES,
|
|
273
|
+
practices: [
|
|
274
|
+
...CODE_PRACTICES.map(({ id, method, definition, denominator }) => ({ id, method, definition, denominator })),
|
|
275
|
+
...PUBLISHED_MODEL_IDS.map((id) => {
|
|
276
|
+
const { method, definition, positive, negative } = MODEL_PRACTICE_CANDIDATES.find((c) => c.id === id);
|
|
277
|
+
return { id, method, definition, positive, negative, tone: TONE_RULE };
|
|
278
|
+
}),
|
|
279
|
+
],
|
|
280
|
+
rules: {
|
|
281
|
+
testPaths: sources(TEST_PATH_PATTERNS),
|
|
282
|
+
sourceExclusions: sources(SOURCE_EXCLUSION_PATTERNS),
|
|
283
|
+
designPaths: sources(DESIGN_PATH_PATTERNS),
|
|
284
|
+
planPaths: sources(PLAN_PATH_PATTERNS),
|
|
285
|
+
checks: sources(CHECK_PATTERNS),
|
|
286
|
+
security: sources(SECURITY_PATTERNS),
|
|
287
|
+
diff: sources(DIFF_PATTERNS),
|
|
288
|
+
commit: sources(COMMIT_PATTERNS),
|
|
289
|
+
pullRequest: sources(PULL_REQUEST_PATTERNS),
|
|
290
|
+
sourceExtensions: SOURCE_EXT,
|
|
291
|
+
planningTools: PLAN_TOOLS,
|
|
292
|
+
editTools: EDIT_TOOLS,
|
|
293
|
+
},
|
|
294
|
+
};
|
|
295
|
+
}
|
|
@@ -0,0 +1,111 @@
|
|
|
1
|
+
// The sample the model step reads: the person's own words only, from at most
|
|
2
|
+
// MAX_SESSIONS sessions spread over products and months. Real session ids,
|
|
3
|
+
// products and months stay in the local sample file; the model sees `sNN`.
|
|
4
|
+
import { DEFAULT_TZ, dayKeyFor } from "./days.mjs";
|
|
5
|
+
import { eachSession } from "./practices.mjs";
|
|
6
|
+
import { RUBRIC } from "./practices-rules.mjs";
|
|
7
|
+
import { redactText } from "./redact.mjs";
|
|
8
|
+
import { scrubProperNouns } from "./profile-llm.mjs";
|
|
9
|
+
import { SYSTEM_PROMPT_RE } from "./system-text.mjs";
|
|
10
|
+
|
|
11
|
+
export const MAX_SESSIONS = 60;
|
|
12
|
+
export const MAX_MESSAGES = 12;
|
|
13
|
+
export const MAX_CHARS = 600;
|
|
14
|
+
|
|
15
|
+
// Only what the person typed: not sub-agent briefs (sidechain records), injected
|
|
16
|
+
// or compaction records, nor the framework's own prompts.
|
|
17
|
+
const ownTexts = (session) =>
|
|
18
|
+
(Array.isArray(session?.messages) ? session.messages : [])
|
|
19
|
+
.filter(
|
|
20
|
+
(m) =>
|
|
21
|
+
m?.role === "user" &&
|
|
22
|
+
!m.isSidechain &&
|
|
23
|
+
!m.isMeta &&
|
|
24
|
+
!m.isCompactSummary &&
|
|
25
|
+
typeof m.textRedacted === "string" &&
|
|
26
|
+
m.textRedacted.trim() !== "" &&
|
|
27
|
+
!SYSTEM_PROMPT_RE.test(m.textRedacted.trim()),
|
|
28
|
+
)
|
|
29
|
+
.map((m) => m.textRedacted);
|
|
30
|
+
|
|
31
|
+
// The person's own messages: the first and evenly spaced ones when there are
|
|
32
|
+
// more than MAX_MESSAGES, each cut, redacted and scrubbed of proper nouns.
|
|
33
|
+
export function personMessages(session) {
|
|
34
|
+
const all = ownTexts(session);
|
|
35
|
+
let picked = all;
|
|
36
|
+
if (all.length > MAX_MESSAGES) {
|
|
37
|
+
const idx = new Set();
|
|
38
|
+
for (let k = 0; k < MAX_MESSAGES; k++) idx.add(Math.round((k * (all.length - 1)) / (MAX_MESSAGES - 1)));
|
|
39
|
+
picked = [...idx].sort((a, b) => a - b).map((i) => all[i]);
|
|
40
|
+
}
|
|
41
|
+
return picked.map((t) => scrubProperNouns(redactText(t.slice(0, MAX_CHARS))));
|
|
42
|
+
}
|
|
43
|
+
|
|
44
|
+
const asc = (a, b) => (a < b ? -1 : a > b ? 1 : 0);
|
|
45
|
+
|
|
46
|
+
export function sampleSessions(parsed, { tz = DEFAULT_TZ } = {}) {
|
|
47
|
+
const dayKey = dayKeyFor(tz);
|
|
48
|
+
const products = new Map(); // product -> Map(month -> entries[])
|
|
49
|
+
for (const { session, meta } of eachSession(parsed, tz)) {
|
|
50
|
+
if (session?.parentId) continue; // an opencode child session: an agent's brief and work, not the person's
|
|
51
|
+
if (!meta.month || ownTexts(session).length < 2) continue; // no time: cannot be placed in a month
|
|
52
|
+
let ts = null;
|
|
53
|
+
for (const m of session.messages) {
|
|
54
|
+
const t = m?.ts ? Date.parse(m.ts) : NaN;
|
|
55
|
+
if (Number.isFinite(t)) { ts = t; break; }
|
|
56
|
+
}
|
|
57
|
+
const entry = { session: meta.id, date: dayKey(ts), product: meta.product, month: meta.month, raw: session };
|
|
58
|
+
if (!products.has(meta.product)) products.set(meta.product, new Map());
|
|
59
|
+
const months = products.get(meta.product);
|
|
60
|
+
if (!months.has(entry.month)) months.set(entry.month, []);
|
|
61
|
+
months.get(entry.month).push(entry);
|
|
62
|
+
}
|
|
63
|
+
const lanes = [...products.keys()].sort(asc).map((p) => {
|
|
64
|
+
const months = products.get(p);
|
|
65
|
+
return { buckets: [...months.keys()].sort(asc).map((m) => months.get(m).slice()), next: 0 };
|
|
66
|
+
});
|
|
67
|
+
const out = [];
|
|
68
|
+
while (out.length < MAX_SESSIONS && lanes.some((l) => l.buckets.some((b) => b.length))) {
|
|
69
|
+
for (const lane of lanes) {
|
|
70
|
+
if (out.length >= MAX_SESSIONS) break;
|
|
71
|
+
for (let tries = 0; tries < lane.buckets.length; tries++) {
|
|
72
|
+
const b = lane.buckets[lane.next % lane.buckets.length];
|
|
73
|
+
lane.next++;
|
|
74
|
+
if (b.length) {
|
|
75
|
+
const e = b.shift();
|
|
76
|
+
const id = `s${String(out.length + 1).padStart(2, "0")}`;
|
|
77
|
+
out.push({ id, session: e.session, date: e.date, product: e.product, month: e.month, messages: personMessages(e.raw) });
|
|
78
|
+
break;
|
|
79
|
+
}
|
|
80
|
+
}
|
|
81
|
+
}
|
|
82
|
+
}
|
|
83
|
+
return out;
|
|
84
|
+
}
|
|
85
|
+
|
|
86
|
+
// What the model reads: opaque ids and the person's messages, nothing else.
|
|
87
|
+
export function buildPracticesInput(parsed, { tz = DEFAULT_TZ, practices = [], sample = sampleSessions(parsed, { tz }) } = {}) {
|
|
88
|
+
return {
|
|
89
|
+
rubric: RUBRIC,
|
|
90
|
+
practices: practices.map((p) => ({
|
|
91
|
+
id: p.id,
|
|
92
|
+
definition: p.definition,
|
|
93
|
+
...(p.positive ? { positive: p.positive } : {}),
|
|
94
|
+
...(p.negative ? { negative: p.negative } : {}),
|
|
95
|
+
})),
|
|
96
|
+
sessions: sample.map((s) => ({ id: s.id, messages: s.messages })),
|
|
97
|
+
};
|
|
98
|
+
}
|
|
99
|
+
|
|
100
|
+
// The local-only sample file: the real session behind each opaque id.
|
|
101
|
+
export function sampleFile(sample) {
|
|
102
|
+
return sample.map(({ id, session, date, product, month }) => ({ id, session, date, product, month }));
|
|
103
|
+
}
|
|
104
|
+
|
|
105
|
+
// What to write, or null when nothing is published or nothing was sampled.
|
|
106
|
+
export function practicesFiles(parsed, { tz = DEFAULT_TZ, practices = [] } = {}) {
|
|
107
|
+
if (!practices.length) return null;
|
|
108
|
+
const sample = sampleSessions(parsed, { tz });
|
|
109
|
+
if (!sample.length) return null;
|
|
110
|
+
return { input: buildPracticesInput(parsed, { tz, practices, sample }), sample: sampleFile(sample) };
|
|
111
|
+
}
|