opencode-dev-framework 1.9.3 → 1.9.5
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/dist/index.js +23 -12
- package/dist/logger.js +30 -1
- package/dist/registry.d.ts +32 -5
- package/dist/registry.js +72 -24
- package/dist/review.js +4 -0
- package/package.json +1 -1
- package/templates/.opencode/skills/peer-review/SKILL.md +6 -1
package/dist/index.js
CHANGED
|
@@ -36,7 +36,7 @@ import { runCommand } from "./host.js";
|
|
|
36
36
|
import { createLintLimiter, detectPreCommitAvailability, isLintFailure, lintFile, summarizeLint, } from "./lint.js";
|
|
37
37
|
import { createLogger } from "./logger.js";
|
|
38
38
|
import { checkToolCall, extractCommand, extractFilePath, extractRedirectTargets, FILE_TOOLS, SHELL_TOOLS, toPermissionGuard, } from "./protect.js";
|
|
39
|
-
import { clearSessionDirectory, hasSeenSessionStart, markSessionStartSeen,
|
|
39
|
+
import { clearSessionDirectory, hasSeenSessionStart, markSessionStartSeen, resolveChildSession, } from "./registry.js";
|
|
40
40
|
import { findRosterIndex, renderDutyRoster, rosterPresent } from "./roster.js";
|
|
41
41
|
import { constitutionPresent, loadConstitution } from "./rules.js";
|
|
42
42
|
import { writeRuntimeStatus } from "./runtime-status.js";
|
|
@@ -184,8 +184,8 @@ function runCompletion(state, sessionID) {
|
|
|
184
184
|
* Build the host session lookup for child detection, defensively: older
|
|
185
185
|
* cores (and stub contexts in tests) may not expose `session.get`, in
|
|
186
186
|
* which case every session reads as top-level and behavior is unchanged.
|
|
187
|
-
* The lookup is cached per sessionID inside `
|
|
188
|
-
* steady state pays one
|
|
187
|
+
* The lookup is cached per sessionID inside `resolveChildSession`, so the
|
|
188
|
+
* steady state pays one walk per session lifetime.
|
|
189
189
|
*/
|
|
190
190
|
function childSessionGetter(ctx) {
|
|
191
191
|
const session = ctx.session;
|
|
@@ -474,10 +474,18 @@ const plugin = Plugin.define({
|
|
|
474
474
|
// Child sessions owe no review duty (plan 23 phase 1): the review
|
|
475
475
|
// artifact belongs to the top-level session, so a child idling on
|
|
476
476
|
// a dirty tree must never be blocked or told to write it. Skip
|
|
477
|
-
// before any gate work; both levers share this predicate.
|
|
478
|
-
|
|
477
|
+
// before any gate work; both levers share this predicate. The
|
|
478
|
+
// tripwire depth (plan 24) rides the same walk, so this costs one
|
|
479
|
+
// cached lookup per session lifetime — never two.
|
|
480
|
+
const child = await resolveChildSession(sessionID, sessionGetter);
|
|
481
|
+
if (child.isChild) {
|
|
482
|
+
// Tripwire (plan 24): log the chain depth on every child-gated
|
|
483
|
+
// decision. Depth 1 is the entire world at core's default
|
|
484
|
+
// `experimental.subagent_depth`; anything deeper means nesting
|
|
485
|
+
// arrived via a raised limit or a non-tool creation path.
|
|
479
486
|
await safeLog(state, "debug", "completion gate skipped: child session owes no review duty", {
|
|
480
487
|
sessionID,
|
|
488
|
+
depth: child.depth,
|
|
481
489
|
});
|
|
482
490
|
return;
|
|
483
491
|
}
|
|
@@ -625,15 +633,16 @@ const plugin = Plugin.define({
|
|
|
625
633
|
}
|
|
626
634
|
if (resourceHitsArtifact) {
|
|
627
635
|
const childID = typeof event.sessionID === "string" ? event.sessionID : "";
|
|
628
|
-
|
|
636
|
+
const child = await resolveChildSession(childID, sessionGetter);
|
|
637
|
+
if (child.isChild) {
|
|
629
638
|
const reason = childArtifactDenial();
|
|
630
639
|
if (state.config.profile === "advisory") {
|
|
631
|
-
await safeLog(state, "debug", reason, { ...baseExtra });
|
|
640
|
+
await safeLog(state, "debug", reason, { ...baseExtra, depth: child.depth });
|
|
632
641
|
}
|
|
633
642
|
else {
|
|
634
643
|
event.effect = "deny";
|
|
635
644
|
event.message = reason;
|
|
636
|
-
await safeLog(state, "error", reason, { ...baseExtra });
|
|
645
|
+
await safeLog(state, "error", reason, { ...baseExtra, depth: child.depth });
|
|
637
646
|
}
|
|
638
647
|
return;
|
|
639
648
|
}
|
|
@@ -695,9 +704,10 @@ const plugin = Plugin.define({
|
|
|
695
704
|
extractRedirectTargets(extractCommand(input) ?? "").some((t) => isReviewArtifact(t, state.directory)));
|
|
696
705
|
if (writesArtifact) {
|
|
697
706
|
const childID = typeof sessionID === "string" ? sessionID : "";
|
|
698
|
-
|
|
707
|
+
const child = await resolveChildSession(childID, sessionGetter);
|
|
708
|
+
if (child.isChild) {
|
|
699
709
|
const reason = childArtifactDenial();
|
|
700
|
-
const extra = { tool: toolName, sessionID };
|
|
710
|
+
const extra = { tool: toolName, sessionID, depth: child.depth };
|
|
701
711
|
if (state.config.profile === "advisory") {
|
|
702
712
|
await safeLog(state, "warn", reason, extra);
|
|
703
713
|
}
|
|
@@ -1136,8 +1146,9 @@ const plugin = Plugin.define({
|
|
|
1136
1146
|
continue;
|
|
1137
1147
|
// Same child-session skip as the hook lever above: no duty, no
|
|
1138
1148
|
// verdict, no re-prompt — the parent answers for the tree.
|
|
1139
|
-
|
|
1140
|
-
|
|
1149
|
+
const child = await resolveChildSession(sessionID, sessionGetter);
|
|
1150
|
+
if (child.isChild) {
|
|
1151
|
+
await safeLog(state, "debug", "completion gate skipped: child session owes no review duty", { sessionID, depth: child.depth });
|
|
1141
1152
|
continue;
|
|
1142
1153
|
}
|
|
1143
1154
|
// The §1b hook completed an evaluation for this boundary — one
|
package/dist/logger.js
CHANGED
|
@@ -4,6 +4,19 @@
|
|
|
4
4
|
import { appendFile, mkdir, rename, rm, stat } from "node:fs/promises";
|
|
5
5
|
import { homedir, tmpdir } from "node:os";
|
|
6
6
|
import { dirname, isAbsolute, join } from "node:path";
|
|
7
|
+
/** Severity order for the `OPENCODE_DEV_FRAMEWORK_LOG_LEVEL` gate below. */
|
|
8
|
+
const LOG_SEVERITIES = { debug: 0, info: 1, warn: 2, error: 3 };
|
|
9
|
+
/**
|
|
10
|
+
* Minimum level that reaches stderr/file, from
|
|
11
|
+
* `OPENCODE_DEV_FRAMEWORK_LOG_LEVEL` (default `debug` = current behavior:
|
|
12
|
+
* everything is emitted). Unknown values fall back to `debug`.
|
|
13
|
+
* Defense-in-depth so one chatty future call site cannot spam the log —
|
|
14
|
+
* today every site is disciplined, so the default changes nothing.
|
|
15
|
+
*/
|
|
16
|
+
function resolveMinLevel(env = process.env) {
|
|
17
|
+
const raw = env.OPENCODE_DEV_FRAMEWORK_LOG_LEVEL?.toLowerCase();
|
|
18
|
+
return raw === "info" || raw === "warn" || raw === "error" ? raw : "debug";
|
|
19
|
+
}
|
|
7
20
|
export const LOG_SERVICE = "opencode-dev-framework";
|
|
8
21
|
/** Leaf directory/file for the default user-level log. */
|
|
9
22
|
export const LOG_DIR_NAME = "opencode-dev-framework";
|
|
@@ -64,10 +77,23 @@ function safeTmpdir() {
|
|
|
64
77
|
return null;
|
|
65
78
|
}
|
|
66
79
|
}
|
|
80
|
+
/**
|
|
81
|
+
* Directories already created by `appendLogFile` this process: the log
|
|
82
|
+
* path is fixed, so `mkdir -p` on every line is pure syscall overhead.
|
|
83
|
+
* Best-effort like everything else here — a failed `mkdir` simply never
|
|
84
|
+
* lands in the set and is retried next write.
|
|
85
|
+
*/
|
|
86
|
+
const createdDirs = new Set();
|
|
67
87
|
/** Best-effort file write: creates the parent dir, rotates past the cap, never throws. */
|
|
68
88
|
async function appendLogFile(filePath, line, maxBytes = MAX_LOG_BYTES) {
|
|
69
89
|
try {
|
|
70
|
-
|
|
90
|
+
// The log path is fixed per process, so the parent dir only needs
|
|
91
|
+
// creating once — not on every line.
|
|
92
|
+
const dir = dirname(filePath);
|
|
93
|
+
if (!createdDirs.has(dir)) {
|
|
94
|
+
await mkdir(dir, { recursive: true });
|
|
95
|
+
createdDirs.add(dir);
|
|
96
|
+
}
|
|
71
97
|
await rotateLogFile(filePath, maxBytes);
|
|
72
98
|
await appendFile(filePath, `${line}\n`);
|
|
73
99
|
}
|
|
@@ -110,7 +136,10 @@ export function createLogger(client) {
|
|
|
110
136
|
// configuration. Resolved once: the path cannot change under
|
|
111
137
|
// a running server.
|
|
112
138
|
const filePath = process.env.OPENCODE_DEV_FRAMEWORK_LOG_FILE ?? resolveDefaultLogFile() ?? undefined;
|
|
139
|
+
const minLevel = resolveMinLevel();
|
|
113
140
|
return async (level, message, extra) => {
|
|
141
|
+
if (LOG_SEVERITIES[level] < LOG_SEVERITIES[minLevel])
|
|
142
|
+
return;
|
|
114
143
|
const line = JSON.stringify({
|
|
115
144
|
timestamp: new Date().toISOString(),
|
|
116
145
|
service: LOG_SERVICE,
|
package/dist/registry.d.ts
CHANGED
|
@@ -49,14 +49,41 @@ export declare function updateHookState(directory: string, updates: Partial<Hook
|
|
|
49
49
|
export interface SessionParentInfo {
|
|
50
50
|
parentID?: string | null | undefined;
|
|
51
51
|
}
|
|
52
|
+
/** Outcome of one ancestry walk: duty verdict plus best-effort depth. */
|
|
53
|
+
export interface ChildSessionResolution {
|
|
54
|
+
isChild: boolean;
|
|
55
|
+
depth: number | null;
|
|
56
|
+
}
|
|
57
|
+
/**
|
|
58
|
+
* Walk the `parentID` chain once, returning the duty verdict and the
|
|
59
|
+
* depth together (depth 0 = top-level, null = unknown). Only a confirmed
|
|
60
|
+
* not-found/deleted hop ends the walk as dead; any lookup failure
|
|
61
|
+
* abandons it as unknown rather than guessing. Fails closed to
|
|
62
|
+
* `{ isChild: false, depth: null }` (top-level): a missing getter (older
|
|
63
|
+
* core), an empty sessionID, or a lookup throw preserves the pre-guard
|
|
64
|
+
* behavior exactly. Results cache per sessionID, but only fully-resolved
|
|
65
|
+
* walks: a throw or a nullish info (unknown to the host) returns
|
|
66
|
+
* top-level WITHOUT caching, so one transient failure can never
|
|
67
|
+
* permanently pin a session. Never throws. A pathological parent cycle
|
|
68
|
+
* terminates via the visited set (the core API cannot currently produce
|
|
69
|
+
* one: no `parentID` mutation, unknown parents rejected at creation).
|
|
70
|
+
*/
|
|
71
|
+
export declare function resolveChildSession(sessionID: string, getSession?: (id: string) => Promise<SessionParentInfo | null | undefined>): Promise<ChildSessionResolution>;
|
|
52
72
|
/**
|
|
53
|
-
* True when the session is a child (subagent):
|
|
54
|
-
*
|
|
55
|
-
*
|
|
56
|
-
* lookup throw preserves the pre-guard behavior exactly — the session is
|
|
57
|
-
* gated and may write, as before. Never throws.
|
|
73
|
+
* True when the session is a child (subagent): it shares the
|
|
74
|
+
* `resolveChildSession` cache, so pairing this with a depth read costs
|
|
75
|
+
* nothing extra. Same fail-closed contract as the combined resolver.
|
|
58
76
|
*/
|
|
59
77
|
export declare function resolveIsChildSession(sessionID: string, getSession?: (id: string) => Promise<SessionParentInfo | null | undefined>): Promise<boolean>;
|
|
78
|
+
/**
|
|
79
|
+
* Best-effort session-tree depth for the plan-24 tripwire: the number of
|
|
80
|
+
* `parentID` hops from the session to its top-level root (0 = top-level).
|
|
81
|
+
* Shares the `resolveChildSession` walk and cache, so pairing a duty
|
|
82
|
+
* check with a depth read costs nothing extra. Same fail-closed contract:
|
|
83
|
+
* empty sessionID, missing getter, or any lookup failure yields null
|
|
84
|
+
* (unknown) rather than a misleading partial count. Never throws.
|
|
85
|
+
*/
|
|
86
|
+
export declare function resolveSessionDepth(sessionID: string, getSession?: (id: string) => Promise<SessionParentInfo | null | undefined>): Promise<number | null>;
|
|
60
87
|
export declare function setSessionDirectory(sessionID: string, directory: string): void;
|
|
61
88
|
export declare function getDirectoryForSession(sessionID: string): string | null;
|
|
62
89
|
/** Forget a session's directory mapping (called on `session.deleted`). */
|
package/dist/registry.js
CHANGED
|
@@ -49,45 +49,93 @@ export function updateHookState(directory, updates) {
|
|
|
49
49
|
* session ID can still find their state. */
|
|
50
50
|
const sessionToDirectory = new Map();
|
|
51
51
|
/**
|
|
52
|
-
* Child-session
|
|
53
|
-
*
|
|
54
|
-
*
|
|
55
|
-
*
|
|
52
|
+
* Child-session resolution: one cached host walk per session lifetime.
|
|
53
|
+
* `isChild` powers the plan-23 duty skip; `depth` is the plan-24 tripwire
|
|
54
|
+
* (null = unknown). Resolved together so child-gated branches never pay
|
|
55
|
+
* for the same lookup twice. Populated lazily and cleared with everything
|
|
56
|
+
* else in `clearSessionDirectory`/`resetRegistry`. Memory-only like the
|
|
57
|
+
* directory map.
|
|
56
58
|
*/
|
|
57
59
|
const childSessionCache = new Map();
|
|
58
60
|
/**
|
|
59
|
-
*
|
|
60
|
-
*
|
|
61
|
-
*
|
|
62
|
-
*
|
|
63
|
-
*
|
|
61
|
+
* Walk the `parentID` chain once, returning the duty verdict and the
|
|
62
|
+
* depth together (depth 0 = top-level, null = unknown). Only a confirmed
|
|
63
|
+
* not-found/deleted hop ends the walk as dead; any lookup failure
|
|
64
|
+
* abandons it as unknown rather than guessing. Fails closed to
|
|
65
|
+
* `{ isChild: false, depth: null }` (top-level): a missing getter (older
|
|
66
|
+
* core), an empty sessionID, or a lookup throw preserves the pre-guard
|
|
67
|
+
* behavior exactly. Results cache per sessionID, but only fully-resolved
|
|
68
|
+
* walks: a throw or a nullish info (unknown to the host) returns
|
|
69
|
+
* top-level WITHOUT caching, so one transient failure can never
|
|
70
|
+
* permanently pin a session. Never throws. A pathological parent cycle
|
|
71
|
+
* terminates via the visited set (the core API cannot currently produce
|
|
72
|
+
* one: no `parentID` mutation, unknown parents rejected at creation).
|
|
64
73
|
*/
|
|
65
|
-
export async function
|
|
74
|
+
export async function resolveChildSession(sessionID, getSession) {
|
|
66
75
|
if (sessionID === "")
|
|
67
|
-
return false;
|
|
76
|
+
return { isChild: false, depth: null };
|
|
68
77
|
const cached = childSessionCache.get(sessionID);
|
|
69
78
|
if (cached !== undefined)
|
|
70
79
|
return cached;
|
|
71
|
-
|
|
80
|
+
const fallback = { isChild: false, depth: null };
|
|
72
81
|
if (getSession === undefined)
|
|
73
|
-
return
|
|
82
|
+
return fallback;
|
|
74
83
|
try {
|
|
75
|
-
|
|
76
|
-
//
|
|
77
|
-
//
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
+
// An unknown first hop (nullish info) returns top-level WITHOUT
|
|
85
|
+
// caching, so one transient failure can never permanently pin a
|
|
86
|
+
// child as top-level (which would re-enable the original bug).
|
|
87
|
+
const first = await getSession(sessionID);
|
|
88
|
+
if (first === null || first === undefined)
|
|
89
|
+
return fallback;
|
|
90
|
+
const seen = new Set([sessionID]);
|
|
91
|
+
let current = sessionID;
|
|
92
|
+
let parent = first.parentID;
|
|
93
|
+
let depth = 0;
|
|
94
|
+
let isChild = false;
|
|
95
|
+
while (typeof parent === "string" && parent !== "" && !seen.has(parent)) {
|
|
96
|
+
seen.add(parent);
|
|
97
|
+
isChild = true;
|
|
98
|
+
depth++;
|
|
99
|
+
current = parent;
|
|
100
|
+
try {
|
|
101
|
+
parent = (await getSession(current))?.parentID;
|
|
102
|
+
}
|
|
103
|
+
catch {
|
|
104
|
+
// Writer is live (first hop resolved) but deeper ancestry is
|
|
105
|
+
// unknown: keep the duty verdict, abandon the depth, and do NOT
|
|
106
|
+
// cache — the next call re-walks instead of pinning unknown.
|
|
107
|
+
return { isChild: true, depth: null };
|
|
108
|
+
}
|
|
84
109
|
}
|
|
85
|
-
|
|
110
|
+
// Fully-resolved walks cache (top-level `{false, 0}` too: parentage
|
|
111
|
+
// is immutable and deletion evicts via `clearSessionDirectory`).
|
|
112
|
+
const resolved = { isChild, depth };
|
|
113
|
+
childSessionCache.set(sessionID, resolved);
|
|
114
|
+
return resolved;
|
|
86
115
|
}
|
|
87
116
|
catch {
|
|
88
|
-
return
|
|
117
|
+
return fallback;
|
|
89
118
|
}
|
|
90
119
|
}
|
|
120
|
+
/**
|
|
121
|
+
* True when the session is a child (subagent): it shares the
|
|
122
|
+
* `resolveChildSession` cache, so pairing this with a depth read costs
|
|
123
|
+
* nothing extra. Same fail-closed contract as the combined resolver.
|
|
124
|
+
*/
|
|
125
|
+
export async function resolveIsChildSession(sessionID, getSession) {
|
|
126
|
+
return (await resolveChildSession(sessionID, getSession)).isChild;
|
|
127
|
+
}
|
|
128
|
+
/**
|
|
129
|
+
* Best-effort session-tree depth for the plan-24 tripwire: the number of
|
|
130
|
+
* `parentID` hops from the session to its top-level root (0 = top-level).
|
|
131
|
+
* Shares the `resolveChildSession` walk and cache, so pairing a duty
|
|
132
|
+
* check with a depth read costs nothing extra. Same fail-closed contract:
|
|
133
|
+
* empty sessionID, missing getter, or any lookup failure yields null
|
|
134
|
+
* (unknown) rather than a misleading partial count. Never throws.
|
|
135
|
+
*/
|
|
136
|
+
export async function resolveSessionDepth(sessionID, getSession) {
|
|
137
|
+
return (await resolveChildSession(sessionID, getSession)).depth;
|
|
138
|
+
}
|
|
91
139
|
export function setSessionDirectory(sessionID, directory) {
|
|
92
140
|
sessionToDirectory.set(sessionID, directory);
|
|
93
141
|
}
|
package/dist/review.js
CHANGED
|
@@ -71,6 +71,10 @@ function reviewCadenceReminder() {
|
|
|
71
71
|
`fail without the change, commands that actually pass), and code-reviewer / pattern-guardian ` +
|
|
72
72
|
`for correctness and drift. Resolve every blocking finding, then write a summary of the ` +
|
|
73
73
|
`review findings and their resolution to ${REVIEW_REL}.\n\n` +
|
|
74
|
+
`Scope the battery to the change: product code gets the full battery above. ` +
|
|
75
|
+
`Docs-only changes (no product code) get markdown lint instead of specialists — ` +
|
|
76
|
+
`run lint:md on the changed files and record scope plus result in the review. ` +
|
|
77
|
+
`That is the entire docs cadence.\n\n` +
|
|
74
78
|
`Do not re-run a specialist whose scope has not changed since its last report — ` +
|
|
75
79
|
`reuse that report and only re-run what your fixes invalidate.\n\n` +
|
|
76
80
|
`Investigation-only reviewers: do not ask them to edit product code.`);
|
package/package.json
CHANGED
|
@@ -37,7 +37,12 @@ to write the review file.
|
|
|
37
37
|
|
|
38
38
|
If there is nothing to review, say so and stop.
|
|
39
39
|
|
|
40
|
-
|
|
40
|
+
Docs-only changes (no product code) skip the battery: run
|
|
41
|
+
`npm run lint:md` on the changed files and record scope plus result
|
|
42
|
+
in the review artifact. That is the entire docs cadence.
|
|
43
|
+
|
|
44
|
+
2. **Run the specialists in parallel (product code only).** For docs-only
|
|
45
|
+
changes, see the carve-out above — no battery. Delegate each as a subagent, giving
|
|
41
46
|
each the diff scope and the relevant file paths:
|
|
42
47
|
- **pattern-guardian** — duplication, re-invented helpers, divergent
|
|
43
48
|
conventions, a second way to do a thing, unjustified new dependencies.
|