sprag-cli 3.124.0 → 3.124.2
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/claude-price.js +1 -1
- package/src/commands/team.js +2 -2
- package/src/routing-state.js +70 -0
- package/src/team-standing.js +1 -1
- package/src/team-sync.js +33 -3
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "sprag-cli",
|
|
3
|
-
"version": "3.124.
|
|
3
|
+
"version": "3.124.2",
|
|
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/claude-price.js
CHANGED
|
@@ -49,7 +49,7 @@ function noteUnpriced(model, env, now, at, totals) {
|
|
|
49
49
|
if (isUnknownModel(model)) {
|
|
50
50
|
const t = totals || {};
|
|
51
51
|
const sum = (t.input || 0) + (t.cacheCreation || 0) + (t.cacheRead || 0) + (t.output || 0);
|
|
52
|
-
recordDiag('price:unpriced', new Error(`model=unknown
|
|
52
|
+
recordDiag('price:unpriced', new Error(`model=unknown size=${tokenBucket(sum)} via=${callerFrame(new Error().stack)}`), { env });
|
|
53
53
|
return;
|
|
54
54
|
}
|
|
55
55
|
const { reason, keys } = gatewayPriceMiss(model, env, now, at);
|
package/src/commands/team.js
CHANGED
|
@@ -132,7 +132,7 @@ const T = {
|
|
|
132
132
|
willSend: '참여하면 집계만 올라갑니다. 로컬 날짜별로는 다음과 같습니다.\n - 지출(USD)\n - 절감(USD)\n - 위임 실행 횟수\n - 모델 계열 비중\n위임 룰은 카테고리와 티어별 요약 한 벌이 올라갑니다.\n - 카테고리, 티어, 위임 횟수, 실패율, 절감액(USD)\nsprag 자체의 오류 메시지(이 기기의 문제를 고치는 데 씁니다). 홈 경로, 호스트 이름, 비밀 값은 가려서 보냅니다.\n프롬프트, 룰 본문, 예시, 파일 경로, 대화 기록은 보내지 않습니다.',
|
|
133
133
|
rulesPayload: '위임 룰 요약 (member_rules_report)',
|
|
134
134
|
asName: (n) => `표시 이름: ${n}`,
|
|
135
|
-
asDevice: (d) => `기기 ID: ${d} (다시 참여해도 조직이 이
|
|
135
|
+
asDevice: (d) => `기기 ID: ${d} (다시 참여해도 조직이 이 PC를 한 좌석으로 셉니다)`,
|
|
136
136
|
ask: '참여할까요? [y/N] ',
|
|
137
137
|
needYes: '터미널이 아닙니다. 확인하려면 --yes 를 붙여 다시 실행하세요: sprag team join <토큰> --yes',
|
|
138
138
|
noToken: '초대 토큰이 없습니다. 인자로 넘기거나 SPRAG_TEAM_TOKEN 을 설정하세요.',
|
|
@@ -151,7 +151,7 @@ const T = {
|
|
|
151
151
|
lastSync: (t, n) => `마지막 동기화: ${t} (${n}행)`,
|
|
152
152
|
neverSynced: '마지막 동기화: 아직 없음',
|
|
153
153
|
lastError: '마지막 오류',
|
|
154
|
-
orgMin: (min, cur) => `조직 최소 버전: v${min} (이
|
|
154
|
+
orgMin: (min, cur) => `조직 최소 버전: v${min} (이 PC는 v${cur} 실행 중)`,
|
|
155
155
|
orgUpgradeRunning: (t) => `조직 정책에 따라 v${t} 로 백그라운드 업그레이드를 진행 중입니다 (로그: org-upgrade.log)`,
|
|
156
156
|
orgUpgradeOk: (t, when) => `마지막 조직 업그레이드: v${t} 설치 완료 (${when})`,
|
|
157
157
|
orgUpgradeFailed: (t, when, e) => `마지막 조직 업그레이드: v${t} 설치 실패 (${when}): ${e}. sprag upgrade 를 직접 실행하십시오.`,
|
|
@@ -0,0 +1,70 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* routing-state — what this PC can tell the team dashboard about delegation.
|
|
3
|
+
*
|
|
4
|
+
* A machine that never delegates has three distinct causes the dashboard could
|
|
5
|
+
* not tell apart: routing switched off, the rules never loaded into the
|
|
6
|
+
* session, or the delegation agents missing. routingState() answers each one:
|
|
7
|
+
*
|
|
8
|
+
* on routing is not switched off (config `routing`)
|
|
9
|
+
* loaded the global CLAUDE.md Claude Code reads imports ratchet-model.md and
|
|
10
|
+
* the imported file exists
|
|
11
|
+
* agents every delegation agent sprag installs is in the agents directory
|
|
12
|
+
*
|
|
13
|
+
* Each field is a boolean, or null when it could not be determined. Nothing here
|
|
14
|
+
* throws, and nothing that names the machine (path, user) leaves it.
|
|
15
|
+
*/
|
|
16
|
+
|
|
17
|
+
import { existsSync, readFileSync } from 'node:fs';
|
|
18
|
+
import { homedir } from 'node:os';
|
|
19
|
+
import { join, isAbsolute } from 'node:path';
|
|
20
|
+
import { routingEnabled } from './routing-switch.js';
|
|
21
|
+
import { definitions } from './delegation-agents.js';
|
|
22
|
+
import { debug } from './debug.js';
|
|
23
|
+
|
|
24
|
+
/** The directory Claude Code reads CLAUDE.md and agents from: CLAUDE_CONFIG_DIR, else ~/.claude. */
|
|
25
|
+
export function claudeConfigDir({ env = process.env, home = homedir() } = {}) {
|
|
26
|
+
const custom = env && env.CLAUDE_CONFIG_DIR;
|
|
27
|
+
return custom ? String(custom) : join(home, '.claude');
|
|
28
|
+
}
|
|
29
|
+
|
|
30
|
+
/** Paths of the `@...ratchet-model.md` import lines in a CLAUDE.md, with `~` expanded. Project-relative imports are skipped. */
|
|
31
|
+
function modelRatchetImports(text, home) {
|
|
32
|
+
const out = [];
|
|
33
|
+
for (const line of String(text).split(/\r?\n/)) {
|
|
34
|
+
const m = line.trim().match(/^@(\S*ratchet-model\.md)$/);
|
|
35
|
+
if (!m) continue;
|
|
36
|
+
const p = m[1].startsWith('~/') ? join(home, m[1].slice(2)) : m[1];
|
|
37
|
+
if (isAbsolute(p)) out.push(p);
|
|
38
|
+
}
|
|
39
|
+
return out;
|
|
40
|
+
}
|
|
41
|
+
|
|
42
|
+
function loadedState({ env, home }) {
|
|
43
|
+
const claudeMd = join(claudeConfigDir({ env, home }), 'CLAUDE.md');
|
|
44
|
+
if (!existsSync(claudeMd)) return false;
|
|
45
|
+
const imports = modelRatchetImports(readFileSync(claudeMd, 'utf8'), home);
|
|
46
|
+
return imports.some((p) => existsSync(p));
|
|
47
|
+
}
|
|
48
|
+
|
|
49
|
+
function agentsState({ env, home, names }) {
|
|
50
|
+
const list = names || definitions().map((d) => d && d.name).filter(Boolean);
|
|
51
|
+
if (!list.length) return null;
|
|
52
|
+
const dir = join(claudeConfigDir({ env, home }), 'agents');
|
|
53
|
+
return list.every((n) => existsSync(join(dir, `${n}.md`)));
|
|
54
|
+
}
|
|
55
|
+
|
|
56
|
+
function attempt(scope, fn) {
|
|
57
|
+
try { return fn(); } catch (e) { debug(`routing-state:${scope}`, e); return null; }
|
|
58
|
+
}
|
|
59
|
+
|
|
60
|
+
/**
|
|
61
|
+
* @param {object} [o] test hooks: cfg (config object), env, home, names (agent names)
|
|
62
|
+
* @returns {{ on: boolean|null, loaded: boolean|null, agents: boolean|null }}
|
|
63
|
+
*/
|
|
64
|
+
export function routingState({ cfg, env = process.env, home = homedir(), names } = {}) {
|
|
65
|
+
return {
|
|
66
|
+
on: attempt('on', () => (cfg === undefined ? routingEnabled() : routingEnabled(cfg))),
|
|
67
|
+
loaded: attempt('loaded', () => loadedState({ env, home })),
|
|
68
|
+
agents: attempt('agents', () => agentsState({ env, home, names })),
|
|
69
|
+
};
|
|
70
|
+
}
|
package/src/team-standing.js
CHANGED
|
@@ -177,7 +177,7 @@ export function standingGuideLines(st, { lang = 'en', org = null, team = null }
|
|
|
177
177
|
parts.push(ko ? `위임 비율 ${pct(st.dlg)}${rk ? ` (${rk}` : ''}${med}` : `delegation share ${pct(st.dlg)}${rk ? ` (${rk}` : ''}${med}`);
|
|
178
178
|
}
|
|
179
179
|
if (has(st.scorePct)) parts.push(ko ? `점수 백분위 ${pct(st.scorePct)}` : `score percentile ${pct(st.scorePct)}`);
|
|
180
|
-
lines.push(` ${ko ? '이
|
|
180
|
+
lines.push(` ${ko ? '이 PC' : 'This machine'}: ${parts.join(' · ')}`);
|
|
181
181
|
}
|
|
182
182
|
|
|
183
183
|
// The next species up, as the office drawer says it. The percentile is the
|
package/src/team-sync.js
CHANGED
|
@@ -45,6 +45,7 @@ import { writeStateFile } from './state-file.js';
|
|
|
45
45
|
import { memberId, readMemberId } from './member-id.js';
|
|
46
46
|
import { userLanguage } from './config.js';
|
|
47
47
|
import { debug } from './debug.js';
|
|
48
|
+
import { routingState } from './routing-state.js';
|
|
48
49
|
import { trustSystemCA } from './system-ca.js';
|
|
49
50
|
import { loadLedger, modelFamily, roundUsd, changedSinceForSync, clearChangedSince } from './savings-ledger.js';
|
|
50
51
|
import { partCost, pricedParts } from './claude-price.js';
|
|
@@ -725,13 +726,42 @@ export function deviceInfo({
|
|
|
725
726
|
|
|
726
727
|
// Reports device info once after a join and again only when it changes. Fails
|
|
727
728
|
// soft: the next sync retries. Never runs while uploads are switched off.
|
|
728
|
-
|
|
729
|
+
// The routing state (routing on, rules loaded, agents present) rides along as the
|
|
730
|
+
// optional `routing` argument, so the dashboard can tell why a PC does not
|
|
731
|
+
// delegate. A server from before that argument answers PGRST202 ("Could not find
|
|
732
|
+
// the function"): the call is repeated once without it.
|
|
733
|
+
const ROUTING_RETRY_MS = 3600 * 1000;
|
|
734
|
+
export async function reportDeviceInfo({ state, dir = userDataDir(), fetch, env = process.env, routing } = {}) {
|
|
729
735
|
if (teamSyncDisabled(env) || !isJoined(state)) return state;
|
|
730
736
|
const info = deviceInfo();
|
|
731
|
-
|
|
737
|
+
let route = routing;
|
|
738
|
+
if (route === undefined) {
|
|
739
|
+
try { route = routingState(); } catch (e) { debug('team-sync', e); route = null; }
|
|
740
|
+
}
|
|
741
|
+
const same = state.deviceInfo && JSON.stringify(state.deviceInfo) === JSON.stringify(info);
|
|
742
|
+
// After a fallback the server cannot take the argument yet: look again after an hour, not on every sync.
|
|
743
|
+
// A wait stored by 3.124.1 (a day) is cut to the hour, so PCs that upgraded before the server did report soon.
|
|
744
|
+
const retryAt = Number(state.routingRetryAt), now = Date.now();
|
|
745
|
+
const waiting = retryAt > now && retryAt <= now + ROUTING_RETRY_MS;
|
|
746
|
+
const routeSame = !route || waiting || JSON.stringify(state.routing || null) === JSON.stringify(route);
|
|
747
|
+
if (same && routeSame) return state;
|
|
732
748
|
try {
|
|
733
|
-
|
|
749
|
+
const params = { member_key: state.memberKey, ...info };
|
|
750
|
+
let unsupported = false;
|
|
751
|
+
if (route) {
|
|
752
|
+
try {
|
|
753
|
+
await rpc('member_set_info', { ...params, routing: route }, { fetch });
|
|
754
|
+
} catch (e) {
|
|
755
|
+
if (!/routing|Could not find the function|PGRST202/i.test(String(e && e.message))) throw e;
|
|
756
|
+
unsupported = true;
|
|
757
|
+
await rpc('member_set_info', params, { fetch });
|
|
758
|
+
}
|
|
759
|
+
} else {
|
|
760
|
+
await rpc('member_set_info', params, { fetch });
|
|
761
|
+
}
|
|
734
762
|
const next = { ...state, deviceInfo: info };
|
|
763
|
+
if (route && !unsupported) next.routing = route; else delete next.routing;
|
|
764
|
+
if (unsupported) next.routingRetryAt = Date.now() + ROUTING_RETRY_MS; else delete next.routingRetryAt;
|
|
735
765
|
saveTeamState(next, dir);
|
|
736
766
|
return next;
|
|
737
767
|
} catch (e) {
|