sprag-cli 3.111.0 → 3.112.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/package.json +1 -1
- package/src/brief.js +58 -1
- package/src/route-inject.js +24 -3
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "sprag-cli",
|
|
3
|
-
"version": "3.
|
|
3
|
+
"version": "3.112.0",
|
|
4
4
|
"description": "The delegation layer for Claude Code and Codex: each task goes to the model and effort that fits it, down to cheaper models for lookups and up to higher effort when a cheaper run would miss, backed by public replay cases, with a live statusline and team rules for Pro and Enterprise.",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"bin": {
|
package/src/brief.js
CHANGED
|
@@ -14,7 +14,8 @@
|
|
|
14
14
|
* transcript_path) and the "already briefed" markers are keyed by session_id.
|
|
15
15
|
*
|
|
16
16
|
* State: <stateDir>/brief-state.json
|
|
17
|
-
* { sessions: { [session_id]: { ts, ctxTier, briefed: [signature] } } }
|
|
17
|
+
* { sessions: { [session_id]: { ts, ctxTier, startedAt, briefed: [signature] } } }
|
|
18
|
+
* startedAt caches the transcript's first timestamp for the session-age warning.
|
|
18
19
|
* Sessions untouched for 7 days are pruned on every write.
|
|
19
20
|
*
|
|
20
21
|
* Division of labor with the SessionStart hook: SessionStart prints the
|
|
@@ -169,6 +170,49 @@ function ctxTierOf(pct) {
|
|
|
169
170
|
|
|
170
171
|
const fmtK = (n) => `${Math.round(n / 1000)}k`;
|
|
171
172
|
|
|
173
|
+
// A session left open for days re-reads everything it ever loaded on every
|
|
174
|
+
// request, and each auto-compaction blurs the decisions made early on. Past a
|
|
175
|
+
// day the briefing asks the model to write a handoff and send the user to a
|
|
176
|
+
// new session, once per whole day of age.
|
|
177
|
+
export const SESSION_AGE_DAY_MS = 24 * 60 * 60 * 1000;
|
|
178
|
+
const HEAD_BYTES = 64 * 1024;
|
|
179
|
+
|
|
180
|
+
/**
|
|
181
|
+
* When THIS session started: the first `timestamp` in the transcript head.
|
|
182
|
+
* A resumed session keeps its original messages, so the age counts from the
|
|
183
|
+
* first request rather than from the resume. Falls back to the file's birth
|
|
184
|
+
* time; null when neither is readable.
|
|
185
|
+
*/
|
|
186
|
+
export function sessionStartedAt(transcriptPath) {
|
|
187
|
+
let fd;
|
|
188
|
+
try {
|
|
189
|
+
fd = openSync(transcriptPath, 'r');
|
|
190
|
+
const buf = Buffer.alloc(HEAD_BYTES);
|
|
191
|
+
const n = readSync(fd, buf, 0, HEAD_BYTES, 0);
|
|
192
|
+
for (const m of buf.toString('utf8', 0, n).matchAll(/"timestamp"\s*:\s*"([^"]+)"/g)) {
|
|
193
|
+
const t = Date.parse(m[1]);
|
|
194
|
+
if (Number.isFinite(t)) return t;
|
|
195
|
+
}
|
|
196
|
+
} catch {
|
|
197
|
+
return null;
|
|
198
|
+
} finally {
|
|
199
|
+
if (fd !== undefined) try { closeSync(fd); } catch { /* already closed */ }
|
|
200
|
+
}
|
|
201
|
+
try {
|
|
202
|
+
const b = statSync(transcriptPath).birthtimeMs;
|
|
203
|
+
return b > 0 ? b : null;
|
|
204
|
+
} catch {
|
|
205
|
+
return null;
|
|
206
|
+
}
|
|
207
|
+
}
|
|
208
|
+
|
|
209
|
+
const pad2 = (n) => String(n).padStart(2, '0');
|
|
210
|
+
const fmtLocal = (ms) => { const d = new Date(ms); return `${d.getFullYear()}-${pad2(d.getMonth() + 1)}-${pad2(d.getDate())} ${pad2(d.getHours())}:${pad2(d.getMinutes())}`; };
|
|
211
|
+
|
|
212
|
+
export function sessionAgeMessage(days, startedAt) {
|
|
213
|
+
return `이 세션을 시작한 지 ${days}일이 넘었습니다(시작 ${fmtLocal(startedAt)}). 오래 켜 둔 세션은 요청마다 그동안 쌓인 대화를 다시 읽어 비용이 커집니다. 자동 압축을 거칠 때마다 앞서 정한 내용도 흐려집니다. 사용자에게 이 사실을 알리고 지금 하던 일을 마무리한 뒤 \`sprag handoff\`로 핸드오프 파일을 만들어 빈 칸(한 일, 남은 일, 이어갈 지점, 주의할 점)을 채우십시오. 그다음 사용자에게 새 세션을 열어 "<만든 핸드오프 파일 경로> 핸드오프 이어서 해줘"라고 입력하라고 파일 경로를 넣은 문장 그대로 안내하십시오.`;
|
|
214
|
+
}
|
|
215
|
+
|
|
172
216
|
/**
|
|
173
217
|
* Called by the SessionStart hook after it prints the session-start snapshot:
|
|
174
218
|
* records the signatures it actually briefed so runBrief suppresses exactly
|
|
@@ -233,6 +277,19 @@ export async function runBrief({ sessionId, transcriptPath, root = process.cwd()
|
|
|
233
277
|
}
|
|
234
278
|
}
|
|
235
279
|
|
|
280
|
+
// ── session age (per-session, once per whole day) ──
|
|
281
|
+
if (s.startedAt == null && transcriptPath) s.startedAt = sessionStartedAt(transcriptPath);
|
|
282
|
+
const ageDays = s.startedAt ? Math.floor((now - s.startedAt) / SESSION_AGE_DAY_MS) : 0;
|
|
283
|
+
if (ageDays >= 1) {
|
|
284
|
+
const sig = `age|${ageDays}`;
|
|
285
|
+
const briefed = new Set(s.briefed || []);
|
|
286
|
+
if (!briefed.has(sig)) {
|
|
287
|
+
briefed.add(sig);
|
|
288
|
+
s.briefed = [...briefed];
|
|
289
|
+
items.push(sessionAgeMessage(ageDays, s.startedAt));
|
|
290
|
+
}
|
|
291
|
+
}
|
|
292
|
+
|
|
236
293
|
// ── mid-session route-scan / rule-health changes (global state, briefed
|
|
237
294
|
// at most once per session per signature). Skipped while the routing
|
|
238
295
|
// master switch is off. ──
|
package/src/route-inject.js
CHANGED
|
@@ -78,6 +78,27 @@ export function isSystemPrompt(text) {
|
|
|
78
78
|
return SYSTEM_PROMPT_PREFIXES.some((p) => t.startsWith(p));
|
|
79
79
|
}
|
|
80
80
|
|
|
81
|
+
/**
|
|
82
|
+
* A paragraph that opens with a short bracketed label ("[운영 규칙] …",
|
|
83
|
+
* "[리마인더] …") is a standing instruction a wrapper adds to every message,
|
|
84
|
+
* such as a Slack bot's prompt suffix.
|
|
85
|
+
*/
|
|
86
|
+
const STANDING_PARA_RE = /^\[[^\]\n]{1,24}\][ \t]/;
|
|
87
|
+
|
|
88
|
+
/**
|
|
89
|
+
* The user's request without the standing-instruction paragraphs a wrapper puts
|
|
90
|
+
* before or after it. A 130-character "[운영 규칙]" suffix on every Slack message
|
|
91
|
+
* made each prompt read as a long spec: over 260 such prompts the delegation hint
|
|
92
|
+
* fired 0 times instead of 24, and the implementation reminder 236 times instead
|
|
93
|
+
* of 21. A prompt that is nothing but such a paragraph is kept as it is.
|
|
94
|
+
*/
|
|
95
|
+
export function stripStandingInstructions(text) {
|
|
96
|
+
const paras = String(text || '').trim().split(/\n[ \t]*\n/);
|
|
97
|
+
while (paras.length > 1 && STANDING_PARA_RE.test(paras[paras.length - 1].trim())) paras.pop();
|
|
98
|
+
while (paras.length > 1 && STANDING_PARA_RE.test(paras[0].trim())) paras.shift();
|
|
99
|
+
return paras.join('\n\n').trim();
|
|
100
|
+
}
|
|
101
|
+
|
|
81
102
|
/** Endings that ask what the model thinks ("좋은가", "괜찮지 않을까", "should we"). */
|
|
82
103
|
const OPINION_RE = /(?:좋은가|좋을까|좋겠지|좋지\s*않|낫겠|낫지\s*않|나을까|나을\s*듯|괜찮(?:을까|은가|겠|지\s*않)|어때|어떨까|어떤가|맞(?:을까|는\s*건가|는가)|아닐까|아닌가|싶은데|듯\s*한데|생각(?:해|이)|의견|\bshould\s+(?:we|i)\b|\bwhat do you think\b|\bis it (?:better|worth)\b)/i;
|
|
83
104
|
/** A request verb in the same text turns the opinion ending back into a task ("…아닐까 확인해줘"). */
|
|
@@ -148,7 +169,7 @@ export function looksLikeContextOrSpec(text) {
|
|
|
148
169
|
* split at prompt time. Harness-written messages and acks are not requests.
|
|
149
170
|
*/
|
|
150
171
|
export function looksLikeImplementation(text) {
|
|
151
|
-
const t =
|
|
172
|
+
const t = stripStandingInstructions(text);
|
|
152
173
|
if (t.length < MIN_LEN || isSystemPrompt(t)) return false;
|
|
153
174
|
if (OUTWARD_RE.test(t) || OPEN_RESEARCH_RE.test(t)) return false;
|
|
154
175
|
return EDIT_RE.test(t) || EDIT_MORE_RE.test(t) || (t.length > SPEC_LEN && !looksPasted(t));
|
|
@@ -257,7 +278,7 @@ export function unreachableTiers(env = process.env) {
|
|
|
257
278
|
* one this session cannot reach
|
|
258
279
|
*/
|
|
259
280
|
export function routeMatch(text, { rules, sessionRank = null, root, env = process.env, grade = delegationGrade() } = {}) {
|
|
260
|
-
const t =
|
|
281
|
+
const t = stripStandingInstructions(text);
|
|
261
282
|
if (t.length < MIN_LEN) return null;
|
|
262
283
|
// A task notification or command echo is not a request, whatever words it holds.
|
|
263
284
|
if (isSystemPrompt(t)) return null;
|
|
@@ -351,7 +372,7 @@ const ACTION_RE = new RegExp(
|
|
|
351
372
|
* grade 'quality'), 'action' an irreversible step with no judgement word.
|
|
352
373
|
*/
|
|
353
374
|
export function judgementMatch(text, { grade = delegationGrade() } = {}) {
|
|
354
|
-
const t =
|
|
375
|
+
const t = stripStandingInstructions(text);
|
|
355
376
|
if (t.length < MIN_LEN || isSystemPrompt(t)) return null;
|
|
356
377
|
if (ESCALATE_RE.test(t)) {
|
|
357
378
|
const kind = ESCALATE_RE.test(t.replace(ACTION_RE, ' ')) ? 'escalate' : 'action';
|