harness-craft 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/LICENSE +21 -0
- package/README.md +42 -2
- package/dist/claude/config.js +34 -0
- package/dist/claude/definitions.js +53 -0
- package/dist/claude/index.js +45 -0
- package/dist/claude/mcp.js +25 -0
- package/dist/claude/plugins.js +42 -0
- package/dist/cli.js +121 -0
- package/dist/codex/config.js +17 -0
- package/dist/codex/index.js +55 -0
- package/dist/collect.js +22 -0
- package/dist/context.js +1 -0
- package/dist/definitions.js +62 -0
- package/dist/diagnostics.js +34 -0
- package/dist/frontmatter.js +51 -0
- package/dist/fsutil.js +85 -0
- package/dist/hookLabel.js +101 -0
- package/dist/hooks.js +53 -0
- package/dist/items.js +75 -0
- package/dist/licenses/NEODGM-OFL.txt +94 -0
- package/dist/licenses/PRESSSTART2P-OFL.txt +93 -0
- package/dist/mcp.js +108 -0
- package/dist/mcpHosts.js +34 -0
- package/dist/redact.js +106 -0
- package/dist/share-template.html +98 -0
- package/dist/shareCommand.js +33 -0
- package/dist/shareFormat.js +10 -0
- package/dist/shareHtml.js +32 -0
- package/dist/shareProfile.js +89 -0
- package/dist/summary.js +48 -0
- package/dist/types.js +1 -0
- package/dist/usage/claude.js +127 -0
- package/dist/usage/codex.js +82 -0
- package/dist/usage/lines.js +75 -0
- package/dist/version.js +9 -0
- package/package.json +54 -3
package/LICENSE
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2026 sese2204
|
|
4
|
+
|
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
7
|
+
in the Software without restriction, including without limitation the rights
|
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
10
|
+
furnished to do so, subject to the following conditions:
|
|
11
|
+
|
|
12
|
+
The above copyright notice and this permission notice shall be included in all
|
|
13
|
+
copies or substantial portions of the Software.
|
|
14
|
+
|
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
21
|
+
SOFTWARE.
|
package/README.md
CHANGED
|
@@ -1,3 +1,43 @@
|
|
|
1
|
-
#
|
|
1
|
+
# harness-craft
|
|
2
2
|
|
|
3
|
-
|
|
3
|
+
내 Claude Code·Codex 하네스(MCP·스킬·훅·서브에이전트)와 사용 기록을 픽셀 RPG 캐릭터 시트로 만든다.
|
|
4
|
+
결과는 혼자 열리는 HTML 한 장이고, 그 파일만 보내면 된다. 네트워크는 쓰지 않는다.
|
|
5
|
+
|
|
6
|
+
Turn your Claude Code and Codex harness into a pixel-RPG character sheet: one self-contained HTML file, no network.
|
|
7
|
+
|
|
8
|
+
## 쓰는 법
|
|
9
|
+
|
|
10
|
+
```bash
|
|
11
|
+
npx harness-craft share --handle <내-아이디>
|
|
12
|
+
# → ./harness-sheet.html
|
|
13
|
+
```
|
|
14
|
+
|
|
15
|
+
| 옵션 | 동작 |
|
|
16
|
+
|---|---|
|
|
17
|
+
| `--handle <이름>` | 시트에 보일 이름. 영문·숫자·`_.-` 39자까지. 기본 `player` |
|
|
18
|
+
| `--hide <glob>` | 이름이 맞는 MCP·스킬·에이전트·플러그인·훅을 파일에서 아예 뺀다. `*` 와일드카드, 대소문자 무시, 여러 번 쓸 수 있다 |
|
|
19
|
+
| `--descriptions` | 스킬·에이전트 설명을 넣는다. 기본은 뺀다 |
|
|
20
|
+
| `--out <파일>` | 저장 위치. 기본 `./harness-sheet.html` |
|
|
21
|
+
| `--no-usage` | 대화 기록 집계를 건너뛴다(빠르지만 레벨·사용 횟수가 0) |
|
|
22
|
+
|
|
23
|
+
회사 도구처럼 보이고 싶지 않은 이름은 `--hide` 로 뺀다. 예: `--hide 'acme-*' --hide internal-wiki`.
|
|
24
|
+
|
|
25
|
+
원본 데이터만 필요하면 `npx harness-craft` 로 `harness-profile.json` 을 만든다.
|
|
26
|
+
|
|
27
|
+
## 무엇을 읽고, 무엇을 담나
|
|
28
|
+
|
|
29
|
+
| 읽는 곳 | 담는 것 |
|
|
30
|
+
|---|---|
|
|
31
|
+
| `~/.claude.json`, `~/.claude/settings.json` | MCP 서버 이름, 훅 이벤트, 모델, 플러그인 |
|
|
32
|
+
| `~/.claude/skills`, `~/.claude/agents`, 플러그인 | 스킬·에이전트 이름(설명은 `--descriptions` 일 때만) |
|
|
33
|
+
| `~/.claude/projects/**/*.jsonl` | 도구·스킬·에이전트·MCP 호출 횟수와 활동일 |
|
|
34
|
+
| `~/.codex/config.toml`, `hooks.json`, `skills`, `sessions` | 같은 항목의 Codex 쪽 값 |
|
|
35
|
+
|
|
36
|
+
환경변수 값, 헤더, 명령 인자, 파일 본문, 절대 경로, 대화 내용은 담지 않는다.
|
|
37
|
+
`~/.codex/auth.json`, `~/.claude/.credentials.json`, sqlite 파일은 열지 않는다.
|
|
38
|
+
MCP 서버 주소는 공개 서비스로 알려진 곳만 남기고, 공유 파일에서는 그마저 뺀다.
|
|
39
|
+
|
|
40
|
+
## 라이선스
|
|
41
|
+
|
|
42
|
+
MIT. 공유 HTML 에 들어가는 폰트 NeoDunggeunmo 와 Press Start 2P 는 SIL Open Font License 1.1 이며,
|
|
43
|
+
원문은 패키지의 `dist/licenses/` 에 있다. React 의 MIT 고지는 공유 HTML 안에 그대로 남는다.
|
|
@@ -0,0 +1,34 @@
|
|
|
1
|
+
import { join } from 'node:path';
|
|
2
|
+
import { isRecord, readJsonOrNull } from '../fsutil.js';
|
|
3
|
+
async function readObject(path, diag) {
|
|
4
|
+
const value = await readJsonOrNull(path, diag);
|
|
5
|
+
if (value === null)
|
|
6
|
+
return {};
|
|
7
|
+
if (!isRecord(value)) {
|
|
8
|
+
diag.warn(path, '최상위가 객체가 아님');
|
|
9
|
+
return {};
|
|
10
|
+
}
|
|
11
|
+
return value;
|
|
12
|
+
}
|
|
13
|
+
export async function readClaudeConfig(home, diag) {
|
|
14
|
+
const claudeDir = join(home, '.claude');
|
|
15
|
+
const settingsPath = join(claudeDir, 'settings.json');
|
|
16
|
+
return {
|
|
17
|
+
claudeDir,
|
|
18
|
+
settingsPath,
|
|
19
|
+
settings: await readObject(settingsPath, diag),
|
|
20
|
+
claudeJson: await readObject(join(home, '.claude.json'), diag),
|
|
21
|
+
};
|
|
22
|
+
}
|
|
23
|
+
export function recordField(obj, key) {
|
|
24
|
+
const v = obj[key];
|
|
25
|
+
return isRecord(v) ? v : {};
|
|
26
|
+
}
|
|
27
|
+
export function numberField(obj, key) {
|
|
28
|
+
const v = obj[key];
|
|
29
|
+
return typeof v === 'number' && Number.isFinite(v) ? v : null;
|
|
30
|
+
}
|
|
31
|
+
export function stringValue(obj, key) {
|
|
32
|
+
const v = obj[key];
|
|
33
|
+
return typeof v === 'string' && v.length > 0 ? v : null;
|
|
34
|
+
}
|
|
@@ -0,0 +1,53 @@
|
|
|
1
|
+
import { join } from 'node:path';
|
|
2
|
+
import { definitionName, toAgent, toSkill, usageKeys } from '../definitions.js';
|
|
3
|
+
import { sortByName } from '../fsutil.js';
|
|
4
|
+
import { readFlatDefinitions, readSkillDefinitions } from '../items.js';
|
|
5
|
+
import { numberField, recordField } from './config.js';
|
|
6
|
+
const EMPTY_COUNTS = { skillCalls: new Map(), slashCalls: new Map(), agentCalls: new Map() };
|
|
7
|
+
async function gather(userDir, plugins, sub, ctx) {
|
|
8
|
+
const read = sub === 'skills' ? readSkillDefinitions : readFlatDefinitions;
|
|
9
|
+
const out = (await read(userDir, ctx.diag)).map((def) => ({ def, source: 'user' }));
|
|
10
|
+
for (const p of plugins) {
|
|
11
|
+
if (!p.installPath)
|
|
12
|
+
continue;
|
|
13
|
+
const defs = await read(join(p.installPath, sub), ctx.diag);
|
|
14
|
+
out.push(...defs.map((def) => ({ def, source: `plugin:${p.name}` })));
|
|
15
|
+
}
|
|
16
|
+
return out;
|
|
17
|
+
}
|
|
18
|
+
/**
|
|
19
|
+
* uses = max(skillUsage usageCount, transcript Skill calls + same-name slash calls).
|
|
20
|
+
* Plugin skills look up both '<plugin>:<name>' and '<name>' (summed per side).
|
|
21
|
+
*/
|
|
22
|
+
export function skillUsageLookup(claudeJson, counts) {
|
|
23
|
+
const skillUsage = recordField(claudeJson, 'skillUsage');
|
|
24
|
+
return (keys) => {
|
|
25
|
+
let recorded = 0;
|
|
26
|
+
let transcript = 0;
|
|
27
|
+
let last = null;
|
|
28
|
+
for (const key of keys) {
|
|
29
|
+
const entry = recordField(skillUsage, key);
|
|
30
|
+
recorded += numberField(entry, 'usageCount') ?? 0;
|
|
31
|
+
const at = numberField(entry, 'lastUsedAt');
|
|
32
|
+
if (at !== null && (last === null || at > last))
|
|
33
|
+
last = at;
|
|
34
|
+
transcript += (counts.skillCalls.get(key) ?? 0) + (counts.slashCalls.get(key) ?? 0);
|
|
35
|
+
}
|
|
36
|
+
return { uses: Math.max(recorded, transcript), lastUsedAt: last === null ? null : new Date(last).toISOString() };
|
|
37
|
+
};
|
|
38
|
+
}
|
|
39
|
+
export async function collectClaudeSkills(claudeDir, plugins, claudeJson, counts, ctx) {
|
|
40
|
+
const items = await gather(join(claudeDir, 'skills'), plugins, 'skills', ctx);
|
|
41
|
+
const userNames = new Set(items.filter((i) => i.source === 'user').map((i) => definitionName(i.def)));
|
|
42
|
+
const lookup = skillUsageLookup(claudeJson, counts ?? EMPTY_COUNTS);
|
|
43
|
+
return sortByName(items.map(({ def, source }) => toSkill(def, source, lookup(usageKeys(definitionName(def), source, userNames)), ctx)));
|
|
44
|
+
}
|
|
45
|
+
export async function collectClaudeAgents(claudeDir, plugins, counts, ctx) {
|
|
46
|
+
const items = await gather(join(claudeDir, 'agents'), plugins, 'agents', ctx);
|
|
47
|
+
const userNames = new Set(items.filter((i) => i.source === 'user').map((i) => definitionName(i.def)));
|
|
48
|
+
const agentCalls = (counts ?? EMPTY_COUNTS).agentCalls;
|
|
49
|
+
return sortByName(items.map(({ def, source }) => {
|
|
50
|
+
const uses = usageKeys(definitionName(def), source, userNames).reduce((sum, k) => sum + (agentCalls.get(k) ?? 0), 0);
|
|
51
|
+
return toAgent(def, source, uses, ctx);
|
|
52
|
+
}));
|
|
53
|
+
}
|
|
@@ -0,0 +1,45 @@
|
|
|
1
|
+
import { join } from 'node:path';
|
|
2
|
+
import { describeError } from '../diagnostics.js';
|
|
3
|
+
import { parseHooks } from '../hooks.js';
|
|
4
|
+
import { pathExists, sortByName } from '../fsutil.js';
|
|
5
|
+
import { readInstructions, readNestedDefinitions } from '../items.js';
|
|
6
|
+
import { toCommand } from '../definitions.js';
|
|
7
|
+
import { scanClaudeTranscripts } from '../usage/claude.js';
|
|
8
|
+
import { numberField, readClaudeConfig, stringValue } from './config.js';
|
|
9
|
+
import { collectClaudeAgents, collectClaudeSkills } from './definitions.js';
|
|
10
|
+
import { collectClaudeMcp } from './mcp.js';
|
|
11
|
+
import { readInstalledPlugins, toPlugins } from './plugins.js';
|
|
12
|
+
const MAX_SHORT_FIELD_LENGTH = 64;
|
|
13
|
+
async function scanUsage(claudeDir, ctx) {
|
|
14
|
+
try {
|
|
15
|
+
return await scanClaudeTranscripts(claudeDir, ctx.diag, ctx.onProgress?.('대화 기록 읽는 중'));
|
|
16
|
+
}
|
|
17
|
+
catch (err) {
|
|
18
|
+
ctx.diag.warn(join(claudeDir, 'projects'), `대화 기록 집계 실패 (${describeError(err)})`);
|
|
19
|
+
return null;
|
|
20
|
+
}
|
|
21
|
+
}
|
|
22
|
+
/** Returns null when neither ~/.claude nor ~/.claude.json exists. */
|
|
23
|
+
export async function collectClaudeCode(ctx, options) {
|
|
24
|
+
const claudeDir = join(ctx.home, '.claude');
|
|
25
|
+
const [hasDir, hasJson] = await Promise.all([pathExists(claudeDir), pathExists(join(ctx.home, '.claude.json'))]);
|
|
26
|
+
if (!hasDir && !hasJson)
|
|
27
|
+
return null;
|
|
28
|
+
const config = await readClaudeConfig(ctx.home, ctx.diag);
|
|
29
|
+
const scan = options.usage ? await scanUsage(claudeDir, ctx) : null;
|
|
30
|
+
const installed = await readInstalledPlugins(claudeDir, ctx);
|
|
31
|
+
const { settings, claudeJson } = config;
|
|
32
|
+
return {
|
|
33
|
+
model: ctx.redactor.optional(stringValue(settings, 'model'), MAX_SHORT_FIELD_LENGTH),
|
|
34
|
+
since: ctx.redactor.optional(stringValue(claudeJson, 'claudeCodeFirstTokenDate') ?? stringValue(claudeJson, 'firstStartTime'), MAX_SHORT_FIELD_LENGTH),
|
|
35
|
+
startups: numberField(claudeJson, 'numStartups'),
|
|
36
|
+
mcpServers: collectClaudeMcp(claudeJson, scan?.mcpCalls ?? new Map(), ctx),
|
|
37
|
+
skills: await collectClaudeSkills(claudeDir, installed, claudeJson, scan, ctx),
|
|
38
|
+
agents: await collectClaudeAgents(claudeDir, installed, scan, ctx),
|
|
39
|
+
hooks: parseHooks(settings.hooks, config.settingsPath, ctx.redactor, ctx.diag),
|
|
40
|
+
plugins: toPlugins(installed, settings, claudeJson, ctx),
|
|
41
|
+
commands: sortByName((await readNestedDefinitions(join(claudeDir, 'commands'), ctx.diag)).map((d) => toCommand(d, ctx))),
|
|
42
|
+
instructions: await readInstructions(join(claudeDir, 'CLAUDE.md'), ctx.diag),
|
|
43
|
+
usage: scan?.usage ?? null,
|
|
44
|
+
};
|
|
45
|
+
}
|
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
import { sortByName } from '../fsutil.js';
|
|
2
|
+
import { buildMcpServer, normalizeServerName } from '../mcp.js';
|
|
3
|
+
import { recordField } from './config.js';
|
|
4
|
+
/**
|
|
5
|
+
* User scope = ~/.claude.json mcpServers; project scope = projects[*].mcpServers, deduplicated by name.
|
|
6
|
+
* A project server whose name is already a user server is dropped. Project paths are never exported.
|
|
7
|
+
*/
|
|
8
|
+
export function collectClaudeMcp(claudeJson, calls, ctx) {
|
|
9
|
+
const callsOf = (name) => calls.get(normalizeServerName(name)) ?? 0;
|
|
10
|
+
const user = recordField(claudeJson, 'mcpServers');
|
|
11
|
+
const project = new Map();
|
|
12
|
+
for (const projectEntry of Object.values(recordField(claudeJson, 'projects'))) {
|
|
13
|
+
if (typeof projectEntry !== 'object' || projectEntry === null)
|
|
14
|
+
continue;
|
|
15
|
+
const servers = recordField(projectEntry, 'mcpServers');
|
|
16
|
+
for (const [name, raw] of Object.entries(servers)) {
|
|
17
|
+
if (!(name in user) && !project.has(name))
|
|
18
|
+
project.set(name, raw);
|
|
19
|
+
}
|
|
20
|
+
}
|
|
21
|
+
return sortByName([
|
|
22
|
+
...Object.entries(user).map(([name, raw]) => buildMcpServer(name, raw, 'user', callsOf(name), ctx.redactor)),
|
|
23
|
+
...[...project].map(([name, raw]) => buildMcpServer(name, raw, 'project', callsOf(name), ctx.redactor)),
|
|
24
|
+
]);
|
|
25
|
+
}
|
|
@@ -0,0 +1,42 @@
|
|
|
1
|
+
import { join } from 'node:path';
|
|
2
|
+
import { isRecord, readJsonOrNull, sortByName } from '../fsutil.js';
|
|
3
|
+
import { numberField, recordField } from './config.js';
|
|
4
|
+
const MAX_FIELD_LENGTH = 120;
|
|
5
|
+
export function splitPluginKey(key) {
|
|
6
|
+
const at = key.lastIndexOf('@');
|
|
7
|
+
return at > 0 ? { name: key.slice(0, at), marketplace: key.slice(at + 1) } : { name: key, marketplace: '' };
|
|
8
|
+
}
|
|
9
|
+
export async function readInstalledPlugins(claudeDir, ctx) {
|
|
10
|
+
const path = join(claudeDir, 'plugins', 'installed_plugins.json');
|
|
11
|
+
const json = await readJsonOrNull(path, ctx.diag);
|
|
12
|
+
if (json === null)
|
|
13
|
+
return [];
|
|
14
|
+
const plugins = isRecord(json) ? json.plugins : undefined;
|
|
15
|
+
if (!isRecord(plugins)) {
|
|
16
|
+
ctx.diag.warn(path, 'plugins 필드가 없거나 객체가 아님');
|
|
17
|
+
return [];
|
|
18
|
+
}
|
|
19
|
+
return Object.entries(plugins)
|
|
20
|
+
.map(([key, installs]) => {
|
|
21
|
+
const first = Array.isArray(installs) ? installs[0] : undefined;
|
|
22
|
+
const install = isRecord(first) ? first : {};
|
|
23
|
+
return {
|
|
24
|
+
key,
|
|
25
|
+
...splitPluginKey(key),
|
|
26
|
+
installPath: typeof install.installPath === 'string' ? install.installPath : null,
|
|
27
|
+
version: typeof install.version === 'string' ? install.version : null,
|
|
28
|
+
};
|
|
29
|
+
})
|
|
30
|
+
.sort((a, b) => (a.key < b.key ? -1 : a.key > b.key ? 1 : 0));
|
|
31
|
+
}
|
|
32
|
+
export function toPlugins(installed, settings, claudeJson, ctx) {
|
|
33
|
+
const enabled = recordField(settings, 'enabledPlugins');
|
|
34
|
+
const usage = recordField(claudeJson, 'pluginUsage');
|
|
35
|
+
return sortByName(installed.map((p) => ({
|
|
36
|
+
name: ctx.redactor.text(p.name, MAX_FIELD_LENGTH),
|
|
37
|
+
marketplace: ctx.redactor.text(p.marketplace, MAX_FIELD_LENGTH),
|
|
38
|
+
version: ctx.redactor.optional(p.version, MAX_FIELD_LENGTH),
|
|
39
|
+
enabled: enabled[p.key] === true,
|
|
40
|
+
uses: numberField(recordField(usage, p.key), 'usageCount') ?? 0,
|
|
41
|
+
})));
|
|
42
|
+
}
|
package/dist/cli.js
ADDED
|
@@ -0,0 +1,121 @@
|
|
|
1
|
+
#!/usr/bin/env node
|
|
2
|
+
import { writeFile } from 'node:fs/promises';
|
|
3
|
+
import { homedir } from 'node:os';
|
|
4
|
+
import { resolve } from 'node:path';
|
|
5
|
+
import { parseArgs } from 'node:util';
|
|
6
|
+
import { collectProfile } from './collect.js';
|
|
7
|
+
import { writeShareSheet, formatShareSummary } from './shareCommand.js';
|
|
8
|
+
import { DEFAULT_SHARE_HANDLE, SHARE_HANDLE_PATTERN } from './shareFormat.js';
|
|
9
|
+
import { formatSummary } from './summary.js';
|
|
10
|
+
const DEFAULT_OUT = 'harness-profile.json';
|
|
11
|
+
const DEFAULT_SHARE_OUT = 'harness-sheet.html';
|
|
12
|
+
const USAGE = `사용법: harness-craft [scan] [--out <file>] [--json] [--no-usage] [--home <dir>]
|
|
13
|
+
harness-craft share [--out <file>] [--handle <name>] [--hide <glob>]... [--descriptions] [--no-usage] [--home <dir>]
|
|
14
|
+
|
|
15
|
+
scan (기본) — 설정과 사용 기록을 읽어 harness-profile.json 을 만든다
|
|
16
|
+
--out <file> 저장 위치 (기본 ./${DEFAULT_OUT})
|
|
17
|
+
--json JSON 을 stdout 으로만 내보내고 파일은 쓰지 않음
|
|
18
|
+
|
|
19
|
+
share — 혼자 열리는 캐릭터 시트 HTML 한 장을 만든다
|
|
20
|
+
--out <file> 저장 위치 (기본 ./${DEFAULT_SHARE_OUT})
|
|
21
|
+
--handle <name> 시트에 쓸 이름 (영문·숫자·_.- 39자까지, 기본 ${DEFAULT_SHARE_HANDLE})
|
|
22
|
+
--hide <glob> 이름이 맞는 MCP·스킬·에이전트·플러그인·명령·훅을 파일에서 뺌 (대소문자 무시, * 가능, 여러 번)
|
|
23
|
+
--descriptions 설명을 파일에 넣음 (기본은 뺌)
|
|
24
|
+
|
|
25
|
+
공통
|
|
26
|
+
--no-usage 대화 기록 집계를 건너뜀 (usage 는 null)
|
|
27
|
+
--home <dir> 홈 디렉터리 대신 쓸 경로 (테스트·디버그용)
|
|
28
|
+
`;
|
|
29
|
+
class UsageError extends Error {
|
|
30
|
+
}
|
|
31
|
+
const SCAN_ONLY = ['json'];
|
|
32
|
+
const SHARE_ONLY = ['handle', 'hide', 'descriptions'];
|
|
33
|
+
function parseCli(argv) {
|
|
34
|
+
const { values, positionals } = parseArgs({
|
|
35
|
+
args: [...argv],
|
|
36
|
+
allowPositionals: true,
|
|
37
|
+
strict: true,
|
|
38
|
+
options: {
|
|
39
|
+
out: { type: 'string' },
|
|
40
|
+
json: { type: 'boolean' },
|
|
41
|
+
'no-usage': { type: 'boolean', default: false },
|
|
42
|
+
home: { type: 'string' },
|
|
43
|
+
handle: { type: 'string' },
|
|
44
|
+
hide: { type: 'string', multiple: true },
|
|
45
|
+
descriptions: { type: 'boolean' },
|
|
46
|
+
help: { type: 'boolean', short: 'h', default: false },
|
|
47
|
+
},
|
|
48
|
+
});
|
|
49
|
+
if (values.help)
|
|
50
|
+
return 'help';
|
|
51
|
+
const command = positionals[0] ?? 'scan';
|
|
52
|
+
if (positionals.length > 1 || (command !== 'scan' && command !== 'share')) {
|
|
53
|
+
throw new UsageError(`알 수 없는 명령: ${positionals.join(' ')}`);
|
|
54
|
+
}
|
|
55
|
+
const foreign = (command === 'scan' ? SHARE_ONLY : SCAN_ONLY).filter((key) => values[key] !== undefined);
|
|
56
|
+
if (foreign.length > 0)
|
|
57
|
+
throw new UsageError(`${command} 에는 쓸 수 없는 옵션: ${foreign.map((k) => `--${k}`).join(' ')}`);
|
|
58
|
+
const common = { usage: values['no-usage'] !== true, home: resolve(values.home ?? homedir()) };
|
|
59
|
+
if (command === 'scan') {
|
|
60
|
+
return { ...common, command, out: resolve(values.out ?? DEFAULT_OUT), json: values.json === true };
|
|
61
|
+
}
|
|
62
|
+
const handle = values.handle ?? DEFAULT_SHARE_HANDLE;
|
|
63
|
+
if (!SHARE_HANDLE_PATTERN.test(handle)) {
|
|
64
|
+
throw new UsageError(`--handle 은 영문·숫자·_.- 로 1~39자여야 합니다: ${JSON.stringify(handle)}`);
|
|
65
|
+
}
|
|
66
|
+
return {
|
|
67
|
+
...common,
|
|
68
|
+
command,
|
|
69
|
+
out: resolve(values.out ?? DEFAULT_SHARE_OUT),
|
|
70
|
+
handle,
|
|
71
|
+
hide: values.hide ?? [],
|
|
72
|
+
descriptions: values.descriptions === true,
|
|
73
|
+
};
|
|
74
|
+
}
|
|
75
|
+
function progressReporter(label) {
|
|
76
|
+
return (done, total) => {
|
|
77
|
+
process.stderr.write(`\r${label} ${done}/${total}`);
|
|
78
|
+
if (done === total)
|
|
79
|
+
process.stderr.write('\n');
|
|
80
|
+
};
|
|
81
|
+
}
|
|
82
|
+
async function runScan(options) {
|
|
83
|
+
const profile = await collectProfile({ home: options.home, usage: options.usage, onProgress: progressReporter });
|
|
84
|
+
const json = JSON.stringify(profile, null, 2) + '\n';
|
|
85
|
+
if (options.json) {
|
|
86
|
+
process.stdout.write(json);
|
|
87
|
+
process.stderr.write(formatSummary(profile, null));
|
|
88
|
+
}
|
|
89
|
+
else {
|
|
90
|
+
await writeFile(options.out, json, 'utf8');
|
|
91
|
+
process.stderr.write(formatSummary(profile, options.out));
|
|
92
|
+
}
|
|
93
|
+
return 0;
|
|
94
|
+
}
|
|
95
|
+
async function runShare(options) {
|
|
96
|
+
const profile = await collectProfile({ home: options.home, usage: options.usage, onProgress: progressReporter });
|
|
97
|
+
const result = await writeShareSheet(profile, options);
|
|
98
|
+
process.stderr.write(formatShareSummary(result, options.descriptions));
|
|
99
|
+
return 0;
|
|
100
|
+
}
|
|
101
|
+
async function main(argv) {
|
|
102
|
+
let options;
|
|
103
|
+
try {
|
|
104
|
+
options = parseCli(argv);
|
|
105
|
+
}
|
|
106
|
+
catch (err) {
|
|
107
|
+
process.stderr.write(`${err instanceof Error ? err.message : String(err)}\n\n${USAGE}`);
|
|
108
|
+
return 2;
|
|
109
|
+
}
|
|
110
|
+
if (options === 'help') {
|
|
111
|
+
process.stdout.write(USAGE);
|
|
112
|
+
return 0;
|
|
113
|
+
}
|
|
114
|
+
return options.command === 'share' ? runShare(options) : runScan(options);
|
|
115
|
+
}
|
|
116
|
+
main(process.argv.slice(2)).then((code) => {
|
|
117
|
+
process.exitCode = code;
|
|
118
|
+
}, (err) => {
|
|
119
|
+
process.stderr.write(`harness-craft 실패: ${err instanceof Error ? (err.stack ?? err.message) : String(err)}\n`);
|
|
120
|
+
process.exitCode = 1;
|
|
121
|
+
});
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
import { parse } from 'smol-toml';
|
|
2
|
+
import { isRecord, readTextOrNull } from '../fsutil.js';
|
|
3
|
+
/** Parses ~/.codex/config.toml. Missing -> {}; broken -> warning + {}. */
|
|
4
|
+
export async function readCodexConfig(path, diag) {
|
|
5
|
+
const text = await readTextOrNull(path, diag);
|
|
6
|
+
if (text === null)
|
|
7
|
+
return {};
|
|
8
|
+
try {
|
|
9
|
+
const parsed = parse(text);
|
|
10
|
+
return isRecord(parsed) ? parsed : {};
|
|
11
|
+
}
|
|
12
|
+
catch (err) {
|
|
13
|
+
const message = err instanceof Error ? err.message.split('\n')[0] ?? '' : String(err);
|
|
14
|
+
diag.warn(path, `TOML 파싱 실패 (${message.slice(0, 120)})`);
|
|
15
|
+
return {};
|
|
16
|
+
}
|
|
17
|
+
}
|
|
@@ -0,0 +1,55 @@
|
|
|
1
|
+
import { join } from 'node:path';
|
|
2
|
+
import { toCommand, toSkill } from '../definitions.js';
|
|
3
|
+
import { describeError } from '../diagnostics.js';
|
|
4
|
+
import { isRecord, pathExists, readJsonOrNull, sortByName } from '../fsutil.js';
|
|
5
|
+
import { parseHooks } from '../hooks.js';
|
|
6
|
+
import { countFiles, readFlatDefinitions, readInstructions, readSkillDefinitions } from '../items.js';
|
|
7
|
+
import { buildMcpServer } from '../mcp.js';
|
|
8
|
+
import { scanCodexSessions } from '../usage/codex.js';
|
|
9
|
+
import { readCodexConfig } from './config.js';
|
|
10
|
+
const MAX_SHORT_FIELD_LENGTH = 64;
|
|
11
|
+
const NO_USAGE = { uses: 0, lastUsedAt: null };
|
|
12
|
+
async function scanUsage(codexDir, ctx) {
|
|
13
|
+
try {
|
|
14
|
+
return await scanCodexSessions(codexDir, ctx.diag, ctx.onProgress?.('Codex 세션 읽는 중'));
|
|
15
|
+
}
|
|
16
|
+
catch (err) {
|
|
17
|
+
ctx.diag.warn(join(codexDir, 'sessions'), `세션 집계 실패 (${describeError(err)})`);
|
|
18
|
+
return null;
|
|
19
|
+
}
|
|
20
|
+
}
|
|
21
|
+
function collectMcp(config, calls, ctx) {
|
|
22
|
+
const servers = isRecord(config.mcp_servers) ? config.mcp_servers : {};
|
|
23
|
+
return sortByName(Object.entries(servers).map(([name, raw]) => buildMcpServer(name, raw, 'user', calls.get(name) ?? 0, ctx.redactor)));
|
|
24
|
+
}
|
|
25
|
+
async function collectHooks(path, ctx) {
|
|
26
|
+
const json = await readJsonOrNull(path, ctx.diag);
|
|
27
|
+
if (json === null)
|
|
28
|
+
return [];
|
|
29
|
+
if (!isRecord(json)) {
|
|
30
|
+
ctx.diag.warn(path, '최상위가 객체가 아님');
|
|
31
|
+
return [];
|
|
32
|
+
}
|
|
33
|
+
return parseHooks(json.hooks, path, ctx.redactor, ctx.diag);
|
|
34
|
+
}
|
|
35
|
+
/** Returns null when ~/.codex does not exist. */
|
|
36
|
+
export async function collectCodex(ctx, options) {
|
|
37
|
+
const codexDir = join(ctx.home, '.codex');
|
|
38
|
+
if (!(await pathExists(codexDir)))
|
|
39
|
+
return null;
|
|
40
|
+
const config = await readCodexConfig(join(codexDir, 'config.toml'), ctx.diag);
|
|
41
|
+
const scan = options.usage ? await scanUsage(codexDir, ctx) : null;
|
|
42
|
+
const skills = await readSkillDefinitions(join(codexDir, 'skills'), ctx.diag);
|
|
43
|
+
const prompts = await readFlatDefinitions(join(codexDir, 'prompts'), ctx.diag);
|
|
44
|
+
return {
|
|
45
|
+
model: ctx.redactor.optional(config.model, MAX_SHORT_FIELD_LENGTH),
|
|
46
|
+
reasoningEffort: ctx.redactor.optional(config.model_reasoning_effort, MAX_SHORT_FIELD_LENGTH),
|
|
47
|
+
mcpServers: collectMcp(config, scan?.mcpCalls ?? new Map(), ctx),
|
|
48
|
+
skills: sortByName(skills.map((def) => toSkill(def, 'user', NO_USAGE, ctx))),
|
|
49
|
+
hooks: await collectHooks(join(codexDir, 'hooks.json'), ctx),
|
|
50
|
+
commands: sortByName(prompts.map((def) => toCommand(def, ctx))),
|
|
51
|
+
instructions: await readInstructions(join(codexDir, 'AGENTS.md'), ctx.diag),
|
|
52
|
+
rulesFiles: await countFiles(join(codexDir, 'rules'), ctx.diag),
|
|
53
|
+
usage: scan?.usage ?? null,
|
|
54
|
+
};
|
|
55
|
+
}
|
package/dist/collect.js
ADDED
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
import { collectClaudeCode } from './claude/index.js';
|
|
2
|
+
import { collectCodex } from './codex/index.js';
|
|
3
|
+
import { Diagnostics } from './diagnostics.js';
|
|
4
|
+
import { Redactor } from './redact.js';
|
|
5
|
+
import { collectorVersion } from './version.js';
|
|
6
|
+
/** Scans one home directory and returns the profile. Reads only; never touches the network. */
|
|
7
|
+
export async function collectProfile(options) {
|
|
8
|
+
const redactor = new Redactor(options.home);
|
|
9
|
+
const diag = new Diagnostics(options.home);
|
|
10
|
+
const ctx = { home: options.home, redactor, diag, onProgress: options.onProgress };
|
|
11
|
+
const claudeCode = await collectClaudeCode(ctx, { usage: options.usage });
|
|
12
|
+
const codex = await collectCodex(ctx, { usage: options.usage });
|
|
13
|
+
return {
|
|
14
|
+
schemaVersion: 1,
|
|
15
|
+
generatedAt: (options.now ?? (() => new Date()))().toISOString(),
|
|
16
|
+
collector: { name: 'harness-craft', version: collectorVersion() },
|
|
17
|
+
claudeCode,
|
|
18
|
+
codex,
|
|
19
|
+
redactions: redactor.totals(),
|
|
20
|
+
warnings: diag.list(),
|
|
21
|
+
};
|
|
22
|
+
}
|
package/dist/context.js
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
|
@@ -0,0 +1,62 @@
|
|
|
1
|
+
import { stringField } from './items.js';
|
|
2
|
+
const MAX_NAME_LENGTH = 120;
|
|
3
|
+
const MAX_SHORT_FIELD_LENGTH = 64;
|
|
4
|
+
export function definitionName(def) {
|
|
5
|
+
return stringField(def.data, 'name') ?? def.fallbackName;
|
|
6
|
+
}
|
|
7
|
+
/** Keys to look up usage under: plugin items are tried as '<plugin>:<name>' and bare '<name>'. */
|
|
8
|
+
export function usageKeys(name, source, userNames) {
|
|
9
|
+
if (source === 'user')
|
|
10
|
+
return [name];
|
|
11
|
+
const plugin = source.slice('plugin:'.length);
|
|
12
|
+
// A bare name owned by a user-level item is not attributed to the plugin item.
|
|
13
|
+
return userNames.has(name) ? [`${plugin}:${name}`] : [`${plugin}:${name}`, name];
|
|
14
|
+
}
|
|
15
|
+
export function qualifiedName(name, source) {
|
|
16
|
+
return source === 'user' ? name : `${source.slice('plugin:'.length)}:${name}`;
|
|
17
|
+
}
|
|
18
|
+
export function toSkill(def, source, usage, ctx) {
|
|
19
|
+
return {
|
|
20
|
+
name: ctx.redactor.text(qualifiedName(definitionName(def), source), MAX_NAME_LENGTH),
|
|
21
|
+
description: ctx.redactor.text(stringField(def.data, 'description') ?? ''),
|
|
22
|
+
source: source === 'user' ? 'user' : `plugin:${ctx.redactor.text(source.slice('plugin:'.length), MAX_NAME_LENGTH)}`,
|
|
23
|
+
uses: usage.uses,
|
|
24
|
+
lastUsedAt: usage.lastUsedAt,
|
|
25
|
+
};
|
|
26
|
+
}
|
|
27
|
+
function toolList(value) {
|
|
28
|
+
if (Array.isArray(value))
|
|
29
|
+
return value.filter((t) => typeof t === 'string').map((t) => t.trim()).filter(Boolean);
|
|
30
|
+
if (typeof value === 'string')
|
|
31
|
+
return value.split(',').map((t) => t.trim()).filter(Boolean);
|
|
32
|
+
return null;
|
|
33
|
+
}
|
|
34
|
+
function mcpServersOf(tools) {
|
|
35
|
+
const servers = new Set();
|
|
36
|
+
for (const tool of tools) {
|
|
37
|
+
const parts = tool.split('__');
|
|
38
|
+
if (parts[0] === 'mcp' && parts.length >= 2 && (parts[1] ?? '').length > 0)
|
|
39
|
+
servers.add(parts[1]);
|
|
40
|
+
}
|
|
41
|
+
return [...servers].sort();
|
|
42
|
+
}
|
|
43
|
+
export function toAgent(def, source, uses, ctx) {
|
|
44
|
+
const { redactor } = ctx;
|
|
45
|
+
const tools = toolList(def.data.tools);
|
|
46
|
+
return {
|
|
47
|
+
name: redactor.text(qualifiedName(definitionName(def), source), MAX_NAME_LENGTH),
|
|
48
|
+
description: redactor.text(stringField(def.data, 'description') ?? ''),
|
|
49
|
+
model: redactor.optional(stringField(def.data, 'model'), MAX_SHORT_FIELD_LENGTH),
|
|
50
|
+
effort: redactor.optional(stringField(def.data, 'effort'), MAX_SHORT_FIELD_LENGTH),
|
|
51
|
+
toolCount: tools === null ? null : tools.length,
|
|
52
|
+
mcpServers: mcpServersOf(tools ?? []).map((s) => redactor.text(s, MAX_NAME_LENGTH)),
|
|
53
|
+
source: source === 'user' ? 'user' : `plugin:${redactor.text(source.slice('plugin:'.length), MAX_NAME_LENGTH)}`,
|
|
54
|
+
uses,
|
|
55
|
+
};
|
|
56
|
+
}
|
|
57
|
+
export function toCommand(def, ctx) {
|
|
58
|
+
return {
|
|
59
|
+
name: ctx.redactor.text(def.fallbackName, MAX_NAME_LENGTH),
|
|
60
|
+
description: ctx.redactor.text(stringField(def.data, 'description') ?? ''),
|
|
61
|
+
};
|
|
62
|
+
}
|
|
@@ -0,0 +1,34 @@
|
|
|
1
|
+
import { redactText } from './redact.js';
|
|
2
|
+
/** Collects warnings for one scan. Paths are shortened to `~` and scrubbed (not counted as redactions). */
|
|
3
|
+
export class Diagnostics {
|
|
4
|
+
home;
|
|
5
|
+
items = [];
|
|
6
|
+
constructor(home) {
|
|
7
|
+
this.home = home;
|
|
8
|
+
}
|
|
9
|
+
warn(path, reason) {
|
|
10
|
+
const raw = `${this.shorten(path)}: ${reason}`;
|
|
11
|
+
this.items.push(redactText(raw, { home: this.home, maxLength: 400 }).text);
|
|
12
|
+
}
|
|
13
|
+
shorten(path) {
|
|
14
|
+
if (path === this.home)
|
|
15
|
+
return '~';
|
|
16
|
+
return path.startsWith(this.home + '/') ? '~' + path.slice(this.home.length) : path;
|
|
17
|
+
}
|
|
18
|
+
list() {
|
|
19
|
+
return [...this.items];
|
|
20
|
+
}
|
|
21
|
+
}
|
|
22
|
+
/** Short, path-free description of an error (fs error messages embed absolute paths). */
|
|
23
|
+
export function describeError(err) {
|
|
24
|
+
if (err && typeof err === 'object') {
|
|
25
|
+
const code = err.code;
|
|
26
|
+
if (typeof code === 'string')
|
|
27
|
+
return code;
|
|
28
|
+
if (err instanceof SyntaxError)
|
|
29
|
+
return `파싱 실패 (${err.message.slice(0, 120)})`;
|
|
30
|
+
if (err instanceof Error)
|
|
31
|
+
return err.message.slice(0, 160);
|
|
32
|
+
}
|
|
33
|
+
return String(err).slice(0, 160);
|
|
34
|
+
}
|
|
@@ -0,0 +1,51 @@
|
|
|
1
|
+
import { parse } from 'yaml';
|
|
2
|
+
import { isRecord } from './fsutil.js';
|
|
3
|
+
const FRONTMATTER_PATTERN = /^?---[ \t]*\r?\n([\s\S]*?)\r?\n---[ \t]*(?:\r?\n|$)/;
|
|
4
|
+
const TOP_LEVEL_LINE = /^([A-Za-z_][\w-]*):[ \t]+(.+)$/;
|
|
5
|
+
function unquote(value) {
|
|
6
|
+
const v = value.trim();
|
|
7
|
+
const q = v[0];
|
|
8
|
+
return (q === '"' || q === "'") && v.length >= 2 && v.endsWith(q) ? v.slice(1, -1) : v;
|
|
9
|
+
}
|
|
10
|
+
/**
|
|
11
|
+
* Claude Code accepts frontmatter that strict YAML rejects (e.g. an unquoted ': ' inside a
|
|
12
|
+
* description). Falls back to single-line top-level `key: value` pairs; block values are skipped.
|
|
13
|
+
*/
|
|
14
|
+
function lenientParse(block) {
|
|
15
|
+
const data = {};
|
|
16
|
+
for (const line of block.split(/\r?\n/)) {
|
|
17
|
+
const m = TOP_LEVEL_LINE.exec(line);
|
|
18
|
+
if (!m)
|
|
19
|
+
continue;
|
|
20
|
+
const value = unquote(m[2]);
|
|
21
|
+
if (value.length > 0 && !/^[|>][-+]?$/.test(value))
|
|
22
|
+
data[m[1]] = value;
|
|
23
|
+
}
|
|
24
|
+
return data;
|
|
25
|
+
}
|
|
26
|
+
/** Parses a leading YAML frontmatter block. The body is never returned. */
|
|
27
|
+
export function parseFrontmatter(text) {
|
|
28
|
+
const match = FRONTMATTER_PATTERN.exec(text);
|
|
29
|
+
if (!match)
|
|
30
|
+
return { data: {}, error: null };
|
|
31
|
+
const block = match[1] ?? '';
|
|
32
|
+
try {
|
|
33
|
+
const parsed = parse(block);
|
|
34
|
+
return { data: isRecord(parsed) ? parsed : {}, error: null };
|
|
35
|
+
}
|
|
36
|
+
catch (err) {
|
|
37
|
+
const recovered = lenientParse(block);
|
|
38
|
+
if (Object.keys(recovered).length > 0)
|
|
39
|
+
return { data: recovered, error: null };
|
|
40
|
+
const message = err instanceof Error ? err.message.split('\n')[0] ?? '' : String(err);
|
|
41
|
+
return { data: {}, error: `frontmatter YAML 파싱 실패 (${message.slice(0, 120)})` };
|
|
42
|
+
}
|
|
43
|
+
}
|
|
44
|
+
export function stringField(data, key) {
|
|
45
|
+
const v = data[key];
|
|
46
|
+
if (typeof v === 'string' && v.trim().length > 0)
|
|
47
|
+
return v.trim();
|
|
48
|
+
if (typeof v === 'number')
|
|
49
|
+
return String(v);
|
|
50
|
+
return null;
|
|
51
|
+
}
|