harness-craft 0.1.0 → 0.1.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/README.md +9 -3
- package/dist/claude/definitions.js +10 -3
- package/dist/claude/index.js +4 -3
- package/dist/cli.js +30 -14
- package/dist/codex/agents.js +107 -0
- package/dist/codex/config.js +8 -4
- package/dist/codex/hooks.js +62 -0
- package/dist/codex/index.js +49 -34
- package/dist/codex/plugins.js +87 -0
- package/dist/codex/skills.js +116 -0
- package/dist/collect.js +18 -4
- package/dist/definitions.js +24 -5
- package/dist/items.js +1 -1
- package/dist/share-template.html +9 -8
- package/dist/shareCommand.js +1 -1
- package/dist/shareFormat.js +17 -2
- package/dist/shareProfile.js +10 -2
- package/dist/summary.js +3 -2
- package/dist/usage/claude.js +63 -3
- package/dist/usage/codex.js +158 -19
- package/dist/usage/lines.js +6 -0
- package/package.json +2 -2
package/dist/shareCommand.js
CHANGED
|
@@ -20,7 +20,7 @@ export function formatShareSummary(result, descriptions) {
|
|
|
20
20
|
const x = result.profile.codex;
|
|
21
21
|
const mcp = (c?.mcpServers.length ?? 0) + (x?.mcpServers.length ?? 0);
|
|
22
22
|
const skills = (c?.skills.length ?? 0) + (x?.skills.length ?? 0);
|
|
23
|
-
const agents = c?.agents.length ?? 0;
|
|
23
|
+
const agents = (c?.agents.length ?? 0) + (x?.agents?.length ?? 0);
|
|
24
24
|
const hooks = (c?.hooks.length ?? 0) + (x?.hooks.length ?? 0);
|
|
25
25
|
const lines = [
|
|
26
26
|
`저장: ${result.out} (${formatSize(result.bytes)})`,
|
package/dist/shareFormat.js
CHANGED
|
@@ -6,5 +6,20 @@ export const SHARE_DATA_ID = 'harness-share-data';
|
|
|
6
6
|
export const SHARE_PLACEHOLDER = '__HARNESS_SHARE_DATA__';
|
|
7
7
|
export const SHARE_TEMPLATE_FILE = 'share-template.html';
|
|
8
8
|
export const DEFAULT_SHARE_HANDLE = 'player';
|
|
9
|
-
/**
|
|
10
|
-
export const
|
|
9
|
+
/** Display name only (nothing is verified or sent), counted in code points so Korean and emoji count as one each. */
|
|
10
|
+
export const SHARE_NAME_MAX_LENGTH = 32;
|
|
11
|
+
// C0 controls and DEL. Other text (Korean, emoji, `<`) is fine: the CLI escapes the JSON before it goes into HTML.
|
|
12
|
+
const CONTROL_CHARS = /[\u0000-\u001f\u007f]/;
|
|
13
|
+
/** Trims and drops leading `@`. Empty → DEFAULT_SHARE_HANDLE. Control characters or more than 32 characters → error. */
|
|
14
|
+
export function validateShareName(raw) {
|
|
15
|
+
const name = raw.trim().replace(/^@+/, '').trim();
|
|
16
|
+
if (name === '')
|
|
17
|
+
return { ok: true, name: DEFAULT_SHARE_HANDLE };
|
|
18
|
+
if (CONTROL_CHARS.test(name))
|
|
19
|
+
return { ok: false, error: '제어 문자(줄바꿈·탭 등)는 쓸 수 없습니다' };
|
|
20
|
+
const length = [...name].length;
|
|
21
|
+
if (length > SHARE_NAME_MAX_LENGTH) {
|
|
22
|
+
return { ok: false, error: `${SHARE_NAME_MAX_LENGTH}자까지 쓸 수 있습니다 (지금 ${length}자)` };
|
|
23
|
+
}
|
|
24
|
+
return { ok: true, name };
|
|
25
|
+
}
|
package/dist/shareProfile.js
CHANGED
|
@@ -55,13 +55,18 @@ function shareCodex(c, filter) {
|
|
|
55
55
|
skills: keep(c.skills, filter, (s) => fromHiddenPlugin(s.source, filter)).map((s) => described(s, filter)),
|
|
56
56
|
hooks: shareHooks(c.hooks, filter),
|
|
57
57
|
commands: keep(c.commands, filter).map((cmd) => described(cmd, filter)),
|
|
58
|
+
// Older profiles have no Codex agents or plugins; keep the keys absent rather than inventing empty lists.
|
|
59
|
+
...(c.agents ? { agents: shareAgents(c.agents, filter) } : {}),
|
|
60
|
+
...(c.plugins ? { plugins: keep(c.plugins, filter).map((p) => ({ ...p })) } : {}),
|
|
58
61
|
};
|
|
59
62
|
}
|
|
60
63
|
function itemCount(profile) {
|
|
61
64
|
const c = profile.claudeCode;
|
|
62
65
|
const x = profile.codex;
|
|
63
66
|
const claude = c ? c.mcpServers.length + c.skills.length + c.agents.length + c.hooks.length + c.plugins.length + c.commands.length : 0;
|
|
64
|
-
const codex = x
|
|
67
|
+
const codex = x
|
|
68
|
+
? x.mcpServers.length + x.skills.length + (x.agents?.length ?? 0) + (x.plugins?.length ?? 0) + x.hooks.length + x.commands.length
|
|
69
|
+
: 0;
|
|
65
70
|
return claude + codex;
|
|
66
71
|
}
|
|
67
72
|
/**
|
|
@@ -71,7 +76,8 @@ function itemCount(profile) {
|
|
|
71
76
|
*/
|
|
72
77
|
export function prepareShareProfile(profile, options) {
|
|
73
78
|
const isHidden = globMatcher(options.hide);
|
|
74
|
-
|
|
79
|
+
// A hidden plugin name takes that plugin's skills and agents with it, in either tool.
|
|
80
|
+
const plugins = [...(profile.claudeCode?.plugins ?? []), ...(profile.codex?.plugins ?? [])];
|
|
75
81
|
const filter = {
|
|
76
82
|
isHidden,
|
|
77
83
|
hiddenPlugins: new Set(plugins.filter((p) => isHidden(p.name)).map((p) => p.name)),
|
|
@@ -82,6 +88,8 @@ export function prepareShareProfile(profile, options) {
|
|
|
82
88
|
collector: { ...profile.collector },
|
|
83
89
|
claudeCode: profile.claudeCode ? shareClaude(profile.claudeCode, filter) : null,
|
|
84
90
|
codex: profile.codex ? shareCodex(profile.codex, filter) : null,
|
|
91
|
+
// Counts and first/last day only, so it goes through unchanged.
|
|
92
|
+
...(profile.activity !== undefined ? { activity: profile.activity && { ...profile.activity } } : {}),
|
|
85
93
|
redactions: { ...profile.redactions },
|
|
86
94
|
warnings: [],
|
|
87
95
|
};
|
package/dist/summary.js
CHANGED
|
@@ -18,12 +18,12 @@ function claudeLines(c) {
|
|
|
18
18
|
function codexLines(c) {
|
|
19
19
|
const lines = [
|
|
20
20
|
`Codex — 모델 ${c.model ?? '-'}${c.reasoningEffort ? ` (${c.reasoningEffort})` : ''}`,
|
|
21
|
-
` MCP ${c.mcpServers.length} · 스킬 ${c.skills.length} · 훅 ${c.hooks.length} · 프롬프트 ${c.commands.length} · 규칙 파일 ${c.rulesFiles}`,
|
|
21
|
+
` MCP ${c.mcpServers.length} · 스킬 ${c.skills.length} · 에이전트 ${c.agents?.length ?? 0} · 훅 ${c.hooks.length} · 플러그인 ${c.plugins?.length ?? 0} · 프롬프트 ${c.commands.length} · 규칙 파일 ${c.rulesFiles}`,
|
|
22
22
|
` AGENTS.md ${c.instructions.present ? `${c.instructions.lines}줄` : '없음'}`,
|
|
23
23
|
];
|
|
24
24
|
const u = c.usage;
|
|
25
25
|
if (u) {
|
|
26
|
-
lines.push(` 사용 기록: 세션 ${u.sessions} · MCP 호출 ${u.mcpCalls} · 서브에이전트 ${u.subagentActivities} · 명령 실행 ${u.commandExecutions} · 활동일 ${u.activeDays}${range(u.firstActivity, u.lastActivity)}`);
|
|
26
|
+
lines.push(` 사용 기록: 세션 ${u.sessions}${u.execSessions ? ` (+ exec ${u.execSessions})` : ''} · MCP 호출 ${u.mcpCalls} · 서브에이전트 실행 ${u.subagentActivities} · 명령 실행 ${u.commandExecutions} · 활동일 ${u.activeDays}${range(u.firstActivity, u.lastActivity)}`);
|
|
27
27
|
}
|
|
28
28
|
return lines;
|
|
29
29
|
}
|
|
@@ -34,6 +34,7 @@ export function formatSummary(profile, savedTo) {
|
|
|
34
34
|
`harness-craft ${profile.collector.version} 스캔 결과`,
|
|
35
35
|
...(profile.claudeCode ? claudeLines(profile.claudeCode) : ['Claude Code — 찾지 못함']),
|
|
36
36
|
...(profile.codex ? codexLines(profile.codex) : ['Codex — 찾지 못함']),
|
|
37
|
+
...(profile.activity ? [`활동일 합계 ${profile.activity.activeDays}일 (두 도구 중 하루라도 쓴 날)${range(profile.activity.firstActivity, profile.activity.lastActivity)}`] : []),
|
|
37
38
|
`가림 처리: 경로 ${r.paths} · 이메일 ${r.emails} · 비밀값 ${r.secrets} · URL ${r.urls}`,
|
|
38
39
|
];
|
|
39
40
|
if (profile.warnings.length > 0) {
|
package/dist/usage/claude.js
CHANGED
|
@@ -2,13 +2,22 @@ import { readdir } from 'node:fs/promises';
|
|
|
2
2
|
import { join } from 'node:path';
|
|
3
3
|
import { describeError } from '../diagnostics.js';
|
|
4
4
|
import { compareStrings, isMissing, isRecord } from '../fsutil.js';
|
|
5
|
-
import { dateRange, forEachLine, incr, listFilesRecursive, runPool } from './lines.js';
|
|
5
|
+
import { dateRange, forEachLine, incr, listFilesRecursive, modelKey, runPool } from './lines.js';
|
|
6
6
|
const TOOL_USE_MARK = Buffer.from('"tool_use"');
|
|
7
7
|
const COMMAND_MARK = Buffer.from('<command-name>');
|
|
8
8
|
const TIMESTAMP_MARK = Buffer.from('"timestamp":"');
|
|
9
9
|
const DATE_LENGTH = 10;
|
|
10
10
|
const DATE_PATTERN = /^\d{4}-\d{2}-\d{2}$/;
|
|
11
11
|
const COMMAND_NAME_PATTERN = /<command-name>\/?([^<\s]+)<\/command-name>/g;
|
|
12
|
+
/** Assistant records open their message with the model; on 102k real lines `"message":{` sat within the first 206 bytes. */
|
|
13
|
+
const MESSAGE_HEAD_BYTES = 1024;
|
|
14
|
+
const MESSAGE_MARK = Buffer.from('"message":{');
|
|
15
|
+
const MODEL_MARK = Buffer.from('"model":"');
|
|
16
|
+
const ID_MARK = Buffer.from('"id":"');
|
|
17
|
+
const CONTENT_MARK = Buffer.from('"content":');
|
|
18
|
+
const QUOTE = 0x22;
|
|
19
|
+
/** Placeholder model on locally generated messages (errors, interruptions); not a model the user ran. */
|
|
20
|
+
const SYNTHETIC_MODEL = '<synthetic>';
|
|
12
21
|
const FILE_CONCURRENCY = 8;
|
|
13
22
|
export const PROGRESS_EVERY_FILES = 100;
|
|
14
23
|
/** `mcp__<server>__<tool>` -> server (assumes no `__` inside the server name). */
|
|
@@ -56,6 +65,49 @@ function countRecord(acc, record) {
|
|
|
56
65
|
incr(acc.slashCalls, m[1]);
|
|
57
66
|
}
|
|
58
67
|
}
|
|
68
|
+
/** One count per API message: a message is split over several lines (one per content block) sharing message.id. */
|
|
69
|
+
function countModel(acc, model, id) {
|
|
70
|
+
if (model === SYNTHETIC_MODEL)
|
|
71
|
+
return;
|
|
72
|
+
if (id !== null) {
|
|
73
|
+
if (acc.messageIds.has(id))
|
|
74
|
+
return;
|
|
75
|
+
acc.messageIds.add(id);
|
|
76
|
+
}
|
|
77
|
+
incr(acc.models, modelKey(model));
|
|
78
|
+
}
|
|
79
|
+
function quotedAfter(line, at, mark) {
|
|
80
|
+
const start = at + mark.length;
|
|
81
|
+
const end = line.indexOf(QUOTE, start);
|
|
82
|
+
return end === -1 ? null : line.toString('utf8', start, end);
|
|
83
|
+
}
|
|
84
|
+
/**
|
|
85
|
+
* Reads message.model / message.id without JSON.parse or a full-line search. Only a message object that opens with
|
|
86
|
+
* `"model":"` within the first MESSAGE_HEAD_BYTES counts (that is how assistant records are written; user and system
|
|
87
|
+
* messages open with "role"), and the id must come before `"content":`, so a `"model"` key inside tool input is never
|
|
88
|
+
* used. Other lines get a model only when they are parsed anyway (tool_use / slash-command lines).
|
|
89
|
+
*/
|
|
90
|
+
function fastModel(line) {
|
|
91
|
+
const msg = line.subarray(0, MESSAGE_HEAD_BYTES).indexOf(MESSAGE_MARK);
|
|
92
|
+
if (msg === -1)
|
|
93
|
+
return null;
|
|
94
|
+
const model = msg + MESSAGE_MARK.length;
|
|
95
|
+
if (line.compare(MODEL_MARK, 0, MODEL_MARK.length, model, model + MODEL_MARK.length) !== 0)
|
|
96
|
+
return null;
|
|
97
|
+
const content = line.indexOf(CONTENT_MARK, msg);
|
|
98
|
+
const id = line.indexOf(ID_MARK, msg);
|
|
99
|
+
if (content === -1 || (id !== -1 && id > content))
|
|
100
|
+
return null;
|
|
101
|
+
const name = quotedAfter(line, model, MODEL_MARK);
|
|
102
|
+
return name === null ? null : { model: name, id: id === -1 ? null : quotedAfter(line, id, ID_MARK) };
|
|
103
|
+
}
|
|
104
|
+
function countParsedModel(acc, record) {
|
|
105
|
+
if (!isRecord(record) || record.type !== 'assistant' || !isRecord(record.message))
|
|
106
|
+
return;
|
|
107
|
+
const { model, id } = record.message;
|
|
108
|
+
if (typeof model === 'string')
|
|
109
|
+
countModel(acc, model, typeof id === 'string' ? id : null);
|
|
110
|
+
}
|
|
59
111
|
function scanLine(acc, line) {
|
|
60
112
|
const ts = line.indexOf(TIMESTAMP_MARK);
|
|
61
113
|
if (ts !== -1) {
|
|
@@ -64,10 +116,16 @@ function scanLine(acc, line) {
|
|
|
64
116
|
if (DATE_PATTERN.test(day))
|
|
65
117
|
acc.days.add(day);
|
|
66
118
|
}
|
|
119
|
+
const fast = fastModel(line);
|
|
120
|
+
if (fast)
|
|
121
|
+
countModel(acc, fast.model, fast.id);
|
|
67
122
|
if (line.indexOf(TOOL_USE_MARK) === -1 && line.indexOf(COMMAND_MARK) === -1)
|
|
68
123
|
return;
|
|
69
124
|
try {
|
|
70
|
-
|
|
125
|
+
const record = JSON.parse(line.toString('utf8'));
|
|
126
|
+
if (fast === null)
|
|
127
|
+
countParsedModel(acc, record);
|
|
128
|
+
countRecord(acc, record);
|
|
71
129
|
}
|
|
72
130
|
catch {
|
|
73
131
|
acc.badLines += 1;
|
|
@@ -93,7 +151,7 @@ export async function scanClaudeTranscripts(claudeDir, diag, onProgress) {
|
|
|
93
151
|
const files = await listFilesRecursive(projectsDir, '.jsonl');
|
|
94
152
|
const acc = {
|
|
95
153
|
toolIds: new Set(), days: new Set(), builtin: new Map(), mcpCalls: new Map(),
|
|
96
|
-
skillCalls: new Map(), slashCalls: new Map(), agentCalls: new Map(), badLines: 0,
|
|
154
|
+
skillCalls: new Map(), slashCalls: new Map(), agentCalls: new Map(), messageIds: new Set(), models: new Map(), badLines: 0,
|
|
97
155
|
};
|
|
98
156
|
let done = 0;
|
|
99
157
|
await runPool(files, FILE_CONCURRENCY, async (rel) => {
|
|
@@ -117,11 +175,13 @@ export async function scanClaudeTranscripts(claudeDir, diag, onProgress) {
|
|
|
117
175
|
projects: await countProjectDirs(projectsDir),
|
|
118
176
|
toolCalls: acc.toolIds.size,
|
|
119
177
|
builtinTools: sortedRecord(acc.builtin),
|
|
178
|
+
models: sortedRecord(acc.models),
|
|
120
179
|
...dateRange(acc.days),
|
|
121
180
|
},
|
|
122
181
|
mcpCalls: acc.mcpCalls,
|
|
123
182
|
skillCalls: acc.skillCalls,
|
|
124
183
|
slashCalls: acc.slashCalls,
|
|
125
184
|
agentCalls: acc.agentCalls,
|
|
185
|
+
days: acc.days,
|
|
126
186
|
};
|
|
127
187
|
}
|
package/dist/usage/codex.js
CHANGED
|
@@ -1,21 +1,71 @@
|
|
|
1
|
-
import { join } from 'node:path';
|
|
1
|
+
import { isAbsolute, join, resolve } from 'node:path';
|
|
2
2
|
import { describeError } from '../diagnostics.js';
|
|
3
|
-
import { isRecord } from '../fsutil.js';
|
|
4
|
-
import { dateRange, forEachLine, incr, listFilesRecursive, runPool } from './lines.js';
|
|
3
|
+
import { compareStrings, isRecord } from '../fsutil.js';
|
|
4
|
+
import { dateRange, forEachLine, incr, listFilesRecursive, modelKey, runPool } from './lines.js';
|
|
5
5
|
const ITEM_COMPLETED_MARK = Buffer.from('"item_completed"');
|
|
6
|
+
const SESSION_META_MARK = Buffer.from('"session_meta"');
|
|
7
|
+
const TURN_CONTEXT_MARK = Buffer.from('"turn_context"');
|
|
6
8
|
const PATH_DATE_PATTERN = /(?:^|\/)(\d{4})\/(\d{2})\/(\d{2})\//;
|
|
9
|
+
const SKILL_FILE_SUFFIX = '/SKILL.md';
|
|
7
10
|
const FILE_CONCURRENCY = 8;
|
|
8
11
|
const PROGRESS_EVERY_FILES = 100;
|
|
9
|
-
|
|
12
|
+
/** The built-in agent a spawned subagent runs as when its `agent_role` is null. */
|
|
13
|
+
export const CODEX_DEFAULT_ROLE = 'default';
|
|
14
|
+
/** session_meta of a non-interactive `codex exec` run. */
|
|
15
|
+
const EXEC_SOURCE = 'exec';
|
|
16
|
+
const EXEC_ORIGINATOR = 'codex_exec';
|
|
17
|
+
/** turn_context without an effort field. */
|
|
18
|
+
export const NO_EFFORT = '';
|
|
19
|
+
function addSkillRef(acc, path, turn, at) {
|
|
20
|
+
const ref = acc.skillRefs.get(path) ?? { turns: new Set(), last: null };
|
|
21
|
+
ref.turns.add(turn);
|
|
22
|
+
if (at !== null && (ref.last === null || at > ref.last))
|
|
23
|
+
ref.last = at;
|
|
24
|
+
acc.skillRefs.set(path, ref);
|
|
25
|
+
}
|
|
26
|
+
/** SKILL.md paths named by an item: explicit `$skill` mentions and implicit reads by a command. */
|
|
27
|
+
function skillPaths(item) {
|
|
28
|
+
if (item.type === 'UserMessage' && Array.isArray(item.content)) {
|
|
29
|
+
return item.content
|
|
30
|
+
.filter((c) => isRecord(c) && c.type === 'skill' && typeof c.path === 'string')
|
|
31
|
+
.map((c) => c.path)
|
|
32
|
+
.filter((p) => isAbsolute(p));
|
|
33
|
+
}
|
|
34
|
+
if (item.type === 'CommandExecution' && Array.isArray(item.parsed_cmd)) {
|
|
35
|
+
const cwd = typeof item.cwd === 'string' && isAbsolute(item.cwd) ? item.cwd : null;
|
|
36
|
+
return item.parsed_cmd
|
|
37
|
+
.filter((c) => isRecord(c) && c.type === 'read' && typeof c.path === 'string')
|
|
38
|
+
.map((c) => c.path)
|
|
39
|
+
.filter((p) => p.endsWith(SKILL_FILE_SUFFIX) && (isAbsolute(p) || cwd !== null))
|
|
40
|
+
.map((p) => (isAbsolute(p) ? p : resolve(cwd, p)));
|
|
41
|
+
}
|
|
42
|
+
return [];
|
|
43
|
+
}
|
|
44
|
+
function countSkillRefs(acc, file, record, item) {
|
|
45
|
+
const paths = skillPaths(item);
|
|
46
|
+
if (paths.length === 0)
|
|
47
|
+
return;
|
|
48
|
+
const payload = record.payload;
|
|
49
|
+
// One use per skill per turn: reading SKILL.md twice, or $skill plus a read, in the same turn is one use.
|
|
50
|
+
const turn = typeof payload.turn_id === 'string' ? `turn:${payload.turn_id}` : `file:${file.rel}`;
|
|
51
|
+
const at = typeof record.timestamp === 'string' ? record.timestamp : file.day && `${file.day}T00:00:00.000Z`;
|
|
52
|
+
for (const path of paths)
|
|
53
|
+
addSkillRef(acc, path, turn, at);
|
|
54
|
+
}
|
|
55
|
+
function countItem(acc, file, record) {
|
|
10
56
|
if (!isRecord(record) || record.type !== 'event_msg' || !isRecord(record.payload))
|
|
11
57
|
return;
|
|
12
58
|
const { payload } = record;
|
|
13
59
|
if (payload.type !== 'item_completed' || !isRecord(payload.item))
|
|
14
60
|
return;
|
|
15
61
|
const { item } = payload;
|
|
62
|
+
countSkillRefs(acc, file, record, item);
|
|
16
63
|
const type = item.type;
|
|
17
64
|
if (type !== 'McpToolCall' && type !== 'SubAgentActivity' && type !== 'CommandExecution')
|
|
18
65
|
return;
|
|
66
|
+
// A subagent reports started / interacted / completed; only the spawn counts.
|
|
67
|
+
if (type === 'SubAgentActivity' && item.kind !== 'started')
|
|
68
|
+
return;
|
|
19
69
|
if (typeof item.id === 'string') {
|
|
20
70
|
const key = `${type}:${item.id}`;
|
|
21
71
|
if (acc.seen.has(key))
|
|
@@ -34,35 +84,114 @@ function countItem(acc, record) {
|
|
|
34
84
|
acc.commands += 1;
|
|
35
85
|
}
|
|
36
86
|
}
|
|
37
|
-
|
|
38
|
-
|
|
87
|
+
/** `payload.source.subagent.thread_spawn.agent_role`: a string role, null for the default agent, undefined if not spawned. */
|
|
88
|
+
function spawnedRole(subagent) {
|
|
89
|
+
if (!isRecord(subagent) || !isRecord(subagent.thread_spawn))
|
|
90
|
+
return undefined;
|
|
91
|
+
const role = subagent.thread_spawn.agent_role;
|
|
92
|
+
return typeof role === 'string' && role.trim().length > 0 ? role.trim() : null;
|
|
93
|
+
}
|
|
94
|
+
function readSessionMeta(acc, file, record) {
|
|
95
|
+
if (file.metaSeen || !isRecord(record) || record.type !== 'session_meta' || !isRecord(record.payload))
|
|
96
|
+
return;
|
|
97
|
+
file.metaSeen = true;
|
|
98
|
+
const { payload } = record;
|
|
99
|
+
if (payload.source === EXEC_SOURCE || payload.originator === EXEC_ORIGINATOR) {
|
|
100
|
+
file.kind = 'exec';
|
|
101
|
+
acc.execFiles += 1;
|
|
102
|
+
return;
|
|
103
|
+
}
|
|
104
|
+
if (!isRecord(payload.source) || payload.source.subagent === undefined)
|
|
105
|
+
return;
|
|
106
|
+
file.kind = 'subagent';
|
|
107
|
+
acc.subagentFiles += 1;
|
|
108
|
+
const role = spawnedRole(payload.source.subagent);
|
|
109
|
+
if (role === undefined)
|
|
110
|
+
return;
|
|
111
|
+
if (typeof payload.id === 'string') {
|
|
112
|
+
if (acc.metaIds.has(payload.id))
|
|
113
|
+
return;
|
|
114
|
+
acc.metaIds.add(payload.id);
|
|
115
|
+
}
|
|
116
|
+
incr(acc.roleCalls, role ?? CODEX_DEFAULT_ROLE);
|
|
117
|
+
}
|
|
118
|
+
function addTurn(bucket, model, effort, turnId) {
|
|
119
|
+
if (typeof turnId === 'string') {
|
|
120
|
+
if (bucket.ids.has(turnId))
|
|
121
|
+
return;
|
|
122
|
+
bucket.ids.add(turnId);
|
|
123
|
+
}
|
|
124
|
+
const efforts = bucket.turns.get(model) ?? new Map();
|
|
125
|
+
incr(efforts, effort);
|
|
126
|
+
bucket.turns.set(model, efforts);
|
|
127
|
+
}
|
|
128
|
+
/**
|
|
129
|
+
* One count per turn. Each bucket dedupes turn_id on its own: a forked subagent rollout repeats its parent's turns,
|
|
130
|
+
* and those copies must not keep the parent's turn out of the interactive bucket.
|
|
131
|
+
*/
|
|
132
|
+
function readTurnContext(acc, file, record) {
|
|
133
|
+
if (!isRecord(record) || record.type !== 'turn_context' || !isRecord(record.payload))
|
|
134
|
+
return;
|
|
135
|
+
const { payload } = record;
|
|
136
|
+
if (typeof payload.model !== 'string' || payload.model.trim().length === 0)
|
|
137
|
+
return;
|
|
138
|
+
const effort = typeof payload.effort === 'string' && payload.effort.length > 0 ? payload.effort : NO_EFFORT;
|
|
139
|
+
addTurn(acc.allModels, payload.model, effort, payload.turn_id);
|
|
140
|
+
if (file.kind === 'interactive')
|
|
141
|
+
addTurn(acc.interactiveModels, payload.model, effort, payload.turn_id);
|
|
142
|
+
}
|
|
143
|
+
function scanLine(acc, file, line) {
|
|
144
|
+
const meta = !file.metaSeen && line.indexOf(SESSION_META_MARK) !== -1;
|
|
145
|
+
const turn = line.indexOf(TURN_CONTEXT_MARK) !== -1;
|
|
146
|
+
if (!meta && !turn && line.indexOf(ITEM_COMPLETED_MARK) === -1)
|
|
39
147
|
return;
|
|
40
148
|
try {
|
|
41
|
-
|
|
149
|
+
const record = JSON.parse(line.toString('utf8'));
|
|
150
|
+
if (meta)
|
|
151
|
+
readSessionMeta(acc, file, record);
|
|
152
|
+
if (turn)
|
|
153
|
+
readTurnContext(acc, file, record);
|
|
154
|
+
countItem(acc, file, record);
|
|
42
155
|
}
|
|
43
156
|
catch {
|
|
44
157
|
acc.badLines += 1;
|
|
45
158
|
}
|
|
46
159
|
}
|
|
47
|
-
/**
|
|
48
|
-
|
|
49
|
-
const
|
|
160
|
+
/** Turns per model id (validated), from interactive turns, or every turn when there are no interactive ones. */
|
|
161
|
+
function modelCounts(acc) {
|
|
162
|
+
const turns = acc.interactiveModels.turns.size > 0 ? acc.interactiveModels.turns : acc.allModels.turns;
|
|
163
|
+
const counts = new Map();
|
|
164
|
+
for (const [model, efforts] of turns)
|
|
165
|
+
incr(counts, modelKey(model), [...efforts.values()].reduce((a, b) => a + b, 0));
|
|
166
|
+
return Object.fromEntries([...counts].sort((a, b) => compareStrings(a[0], b[0])));
|
|
167
|
+
}
|
|
168
|
+
function pathDay(rel) {
|
|
169
|
+
const m = PATH_DATE_PATTERN.exec(rel);
|
|
170
|
+
return m ? `${m[1]}-${m[2]}-${m[3]}` : null;
|
|
171
|
+
}
|
|
172
|
+
/** Aggregates `<codexHome>/sessions/YYYY/MM/DD/*.jsonl`. Activity dates come from the path. */
|
|
173
|
+
export async function scanCodexSessions(codexHome, diag, onProgress) {
|
|
174
|
+
const sessionsDir = join(codexHome, 'sessions');
|
|
50
175
|
const files = await listFilesRecursive(sessionsDir, '.jsonl');
|
|
51
|
-
const acc = {
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
176
|
+
const acc = {
|
|
177
|
+
seen: new Set(), metaIds: new Set(), mcpCalls: new Map(), roleCalls: new Map(), skillRefs: new Map(),
|
|
178
|
+
allModels: { turns: new Map(), ids: new Set() }, interactiveModels: { turns: new Map(), ids: new Set() },
|
|
179
|
+
mcpTotal: 0, subagent: 0, subagentFiles: 0, execFiles: 0, commands: 0, badLines: 0,
|
|
180
|
+
};
|
|
181
|
+
const days = new Set(files.map(pathDay).filter((d) => d !== null));
|
|
182
|
+
const interactiveDays = new Set();
|
|
58
183
|
let done = 0;
|
|
59
184
|
await runPool(files, FILE_CONCURRENCY, async (rel) => {
|
|
185
|
+
// A file without session_meta counts as interactive, as for `sessions`.
|
|
186
|
+
const file = { metaSeen: false, rel, day: pathDay(rel), kind: 'interactive' };
|
|
60
187
|
try {
|
|
61
|
-
await forEachLine(join(sessionsDir, rel), (line) => scanLine(acc, line));
|
|
188
|
+
await forEachLine(join(sessionsDir, rel), (line) => scanLine(acc, file, line));
|
|
62
189
|
}
|
|
63
190
|
catch (err) {
|
|
64
191
|
diag.warn(join(sessionsDir, rel), `읽기 실패 (${describeError(err)})`);
|
|
65
192
|
}
|
|
193
|
+
if (file.kind === 'interactive' && file.day)
|
|
194
|
+
interactiveDays.add(file.day);
|
|
66
195
|
done += 1;
|
|
67
196
|
if (onProgress && (done % PROGRESS_EVERY_FILES === 0 || done === files.length))
|
|
68
197
|
onProgress(done, files.length);
|
|
@@ -71,12 +200,22 @@ export async function scanCodexSessions(codexDir, diag, onProgress) {
|
|
|
71
200
|
diag.warn(sessionsDir, `JSON 파싱 실패 줄 ${acc.badLines}개 건너뜀`);
|
|
72
201
|
return {
|
|
73
202
|
usage: {
|
|
74
|
-
sessions:
|
|
203
|
+
// Interactive sessions only: not subagent rollouts, not `codex exec`. A file without session_meta still counts.
|
|
204
|
+
sessions: files.length - acc.subagentFiles - acc.execFiles,
|
|
205
|
+
execSessions: acc.execFiles,
|
|
75
206
|
mcpCalls: acc.mcpTotal,
|
|
76
207
|
subagentActivities: acc.subagent,
|
|
77
208
|
commandExecutions: acc.commands,
|
|
209
|
+
models: modelCounts(acc),
|
|
210
|
+
// Days with a session a person opened; the sheet uses it to pick the main tool (exec runs are often automation).
|
|
211
|
+
interactiveDays: interactiveDays.size,
|
|
78
212
|
...dateRange(days),
|
|
79
213
|
},
|
|
80
214
|
mcpCalls: acc.mcpCalls,
|
|
215
|
+
roleCalls: acc.roleCalls,
|
|
216
|
+
days,
|
|
217
|
+
skillRefs: acc.skillRefs,
|
|
218
|
+
modelTurns: acc.allModels.turns,
|
|
219
|
+
interactiveModelTurns: acc.interactiveModels.turns,
|
|
81
220
|
};
|
|
82
221
|
}
|
package/dist/usage/lines.js
CHANGED
|
@@ -70,6 +70,12 @@ export function dateRange(days) {
|
|
|
70
70
|
activeDays: sorted.length,
|
|
71
71
|
};
|
|
72
72
|
}
|
|
73
|
+
/** Public model ids only; anything else (a custom deployment name, a path) is counted under OTHER_MODEL. */
|
|
74
|
+
const MODEL_ID_PATTERN = /^[a-z0-9][a-z0-9.\-_]{0,63}$/i;
|
|
75
|
+
export const OTHER_MODEL = 'other';
|
|
76
|
+
export function modelKey(model) {
|
|
77
|
+
return MODEL_ID_PATTERN.test(model) ? model : OTHER_MODEL;
|
|
78
|
+
}
|
|
73
79
|
export function incr(map, key, by = 1) {
|
|
74
80
|
map.set(key, (map.get(key) ?? 0) + by);
|
|
75
81
|
}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "harness-craft",
|
|
3
|
-
"version": "0.1.
|
|
3
|
+
"version": "0.1.2",
|
|
4
4
|
"description": "Turn your Claude Code and Codex harness (MCP, skills, hooks, subagents) into a pixel-RPG character sheet HTML. No network.",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"claude-code",
|
|
@@ -45,8 +45,8 @@
|
|
|
45
45
|
"react-dom": "^19.3.1",
|
|
46
46
|
"tsx": "^4.23.15",
|
|
47
47
|
"typescript": "^5.9.0",
|
|
48
|
-
"@harness-craft/sheet": "0.1.0",
|
|
49
48
|
"@harness-craft/schema": "0.1.0",
|
|
49
|
+
"@harness-craft/sheet": "0.1.0",
|
|
50
50
|
"@harness-craft/sheet-ui": "0.1.0"
|
|
51
51
|
},
|
|
52
52
|
"scripts": {
|