harness-craft 0.1.0 → 0.1.1
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 +5 -5
- 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 +1 -0
- package/dist/usage/codex.js +142 -17
- package/package.json +2 -2
|
@@ -0,0 +1,116 @@
|
|
|
1
|
+
// Codex skills: user roots, bundled system skills and plugin skills, with usage from session logs (docs/collector-spec.md).
|
|
2
|
+
import { realpath } from 'node:fs/promises';
|
|
3
|
+
import { dirname, join, resolve } from 'node:path';
|
|
4
|
+
import { definitionName, qualifiedName, toSkill } from '../definitions.js';
|
|
5
|
+
import { isMissing, isRecord, sortByName } from '../fsutil.js';
|
|
6
|
+
import { readSkillDefinitions } from '../items.js';
|
|
7
|
+
const SYSTEM_SKILLS_DIR = '.system';
|
|
8
|
+
/** Real path, or null when it is gone. Other failures (permissions) are counted for one warning. */
|
|
9
|
+
async function realOrNull(path, failures) {
|
|
10
|
+
try {
|
|
11
|
+
return await realpath(path);
|
|
12
|
+
}
|
|
13
|
+
catch (err) {
|
|
14
|
+
if (!isMissing(err))
|
|
15
|
+
failures.count += 1;
|
|
16
|
+
return null;
|
|
17
|
+
}
|
|
18
|
+
}
|
|
19
|
+
/** `[skills.bundled] enabled = false` turns off the system skills. */
|
|
20
|
+
function bundledEnabled(config) {
|
|
21
|
+
const skills = isRecord(config.skills) ? config.skills : {};
|
|
22
|
+
return !(isRecord(skills.bundled) && skills.bundled.enabled === false);
|
|
23
|
+
}
|
|
24
|
+
/** `[[skills.config]]` entries: `name` or `path` (absolute SKILL.md) plus `enabled`. If several match, the last wins. */
|
|
25
|
+
function configRules(config) {
|
|
26
|
+
const skills = isRecord(config.skills) ? config.skills : {};
|
|
27
|
+
const entries = Array.isArray(skills.config) ? skills.config : [];
|
|
28
|
+
return entries
|
|
29
|
+
.filter((e) => isRecord(e) && typeof e.enabled === 'boolean')
|
|
30
|
+
.map((e) => ({
|
|
31
|
+
name: typeof e.name === 'string' ? e.name : null,
|
|
32
|
+
path: typeof e.path === 'string' ? resolve(e.path) : null,
|
|
33
|
+
enabled: e.enabled,
|
|
34
|
+
}));
|
|
35
|
+
}
|
|
36
|
+
async function isDisabled(item, rules, failures) {
|
|
37
|
+
if (rules.length === 0)
|
|
38
|
+
return false;
|
|
39
|
+
const file = item.def.path ?? '';
|
|
40
|
+
const paths = new Set([file, (await realOrNull(file, failures)) ?? file]);
|
|
41
|
+
const bare = definitionName(item.def);
|
|
42
|
+
const match = rules.filter((r) => (r.name !== null && (r.name === bare || r.name === item.name)) || (r.path !== null && paths.has(r.path)));
|
|
43
|
+
return match.length > 0 && match[match.length - 1]?.enabled === false;
|
|
44
|
+
}
|
|
45
|
+
/** Roots in priority order: user roots first, so a user skill wins over a plugin or system skill of the same name. */
|
|
46
|
+
async function gather(config, plugins, ctx) {
|
|
47
|
+
const roots = [
|
|
48
|
+
[join(ctx.codexHome, 'skills'), 'user', false],
|
|
49
|
+
[join(ctx.home, '.agents', 'skills'), 'user', false],
|
|
50
|
+
...plugins
|
|
51
|
+
.filter((p) => p.enabled && p.skillsDir !== null)
|
|
52
|
+
.map((p) => [p.skillsDir, `plugin:${p.name}`, p.bundled]),
|
|
53
|
+
...(bundledEnabled(config) ? [[join(ctx.codexHome, 'skills', SYSTEM_SKILLS_DIR), 'builtin', true]] : []),
|
|
54
|
+
];
|
|
55
|
+
const out = [];
|
|
56
|
+
for (const [dir, source, shownWhenUsed] of roots) {
|
|
57
|
+
for (const def of await readSkillDefinitions(dir, ctx.diag)) {
|
|
58
|
+
out.push({ def, source, name: qualifiedName(definitionName(def), source), shownWhenUsed });
|
|
59
|
+
}
|
|
60
|
+
}
|
|
61
|
+
return out;
|
|
62
|
+
}
|
|
63
|
+
/** Turns per skill name, matched by the real path of the SKILL.md folder (roots are often symlinks). */
|
|
64
|
+
async function usageByName(items, refs, failures) {
|
|
65
|
+
const nameByDir = new Map();
|
|
66
|
+
for (const item of items) {
|
|
67
|
+
const dir = item.def.path ? await realOrNull(dirname(item.def.path), failures) : null;
|
|
68
|
+
if (dir !== null && !nameByDir.has(dir))
|
|
69
|
+
nameByDir.set(dir, item.name);
|
|
70
|
+
}
|
|
71
|
+
const out = new Map();
|
|
72
|
+
for (const [path, ref] of refs) {
|
|
73
|
+
const dir = await realOrNull(dirname(path), failures);
|
|
74
|
+
const name = dir === null ? undefined : nameByDir.get(dir);
|
|
75
|
+
if (name === undefined)
|
|
76
|
+
continue; // Not a skill Codex loads (another tool's folder, a repo-scoped skill, a deleted one).
|
|
77
|
+
const prev = out.get(name) ?? { turns: new Set(), last: null };
|
|
78
|
+
const last = prev.last === null || (ref.last !== null && ref.last > prev.last) ? ref.last : prev.last;
|
|
79
|
+
out.set(name, { turns: new Set([...prev.turns, ...ref.turns]), last });
|
|
80
|
+
}
|
|
81
|
+
return out;
|
|
82
|
+
}
|
|
83
|
+
/**
|
|
84
|
+
* Skills deduped by name (first root wins), minus `[[skills.config]]`-disabled ones. System skills appear only when
|
|
85
|
+
* used. `refs` is null without a session scan.
|
|
86
|
+
*/
|
|
87
|
+
export async function collectCodexSkills(config, plugins, refs, ctx) {
|
|
88
|
+
const rules = configRules(config);
|
|
89
|
+
const failures = { count: 0 };
|
|
90
|
+
const enabled = [];
|
|
91
|
+
for (const item of await gather(config, plugins, ctx))
|
|
92
|
+
if (!(await isDisabled(item, rules, failures)))
|
|
93
|
+
enabled.push(item);
|
|
94
|
+
const usage = await usageByName(enabled, refs ?? new Map(), failures);
|
|
95
|
+
// Paths come from session logs, so they are not named in the warning.
|
|
96
|
+
if (failures.count > 0)
|
|
97
|
+
ctx.diag.warn(ctx.codexHome, `스킬 경로 ${failures.count}개를 확인하지 못해 사용 횟수에서 뺌`);
|
|
98
|
+
const kept = new Map();
|
|
99
|
+
for (const item of enabled)
|
|
100
|
+
if (!kept.has(item.name))
|
|
101
|
+
kept.set(item.name, item);
|
|
102
|
+
const skills = [];
|
|
103
|
+
const pluginUses = new Map();
|
|
104
|
+
for (const { def, source, name, shownWhenUsed } of kept.values()) {
|
|
105
|
+
const u = usage.get(name);
|
|
106
|
+
const uses = u?.turns.size ?? 0;
|
|
107
|
+
if (shownWhenUsed && uses === 0)
|
|
108
|
+
continue;
|
|
109
|
+
if (source.startsWith('plugin:')) {
|
|
110
|
+
const plugin = source.slice('plugin:'.length);
|
|
111
|
+
pluginUses.set(plugin, (pluginUses.get(plugin) ?? 0) + uses);
|
|
112
|
+
}
|
|
113
|
+
skills.push(toSkill(def, source, { uses, lastUsedAt: u?.last ?? null }, ctx));
|
|
114
|
+
}
|
|
115
|
+
return { skills: sortByName(skills), pluginUses };
|
|
116
|
+
}
|
package/dist/collect.js
CHANGED
|
@@ -1,21 +1,35 @@
|
|
|
1
|
+
import { join } from 'node:path';
|
|
1
2
|
import { collectClaudeCode } from './claude/index.js';
|
|
2
3
|
import { collectCodex } from './codex/index.js';
|
|
3
4
|
import { Diagnostics } from './diagnostics.js';
|
|
4
5
|
import { Redactor } from './redact.js';
|
|
6
|
+
import { dateRange } from './usage/lines.js';
|
|
5
7
|
import { collectorVersion } from './version.js';
|
|
8
|
+
/**
|
|
9
|
+
* Active days across both tools: the union of dates, so a day used in both counts once. Only the count and the first
|
|
10
|
+
* and last day go out; the day list itself would show the work schedule. null when no usage scan ran.
|
|
11
|
+
*/
|
|
12
|
+
export function unionActivity(...daySets) {
|
|
13
|
+
const ran = daySets.filter((d) => d !== null);
|
|
14
|
+
if (ran.length === 0)
|
|
15
|
+
return null;
|
|
16
|
+
return dateRange(new Set(ran.flatMap((d) => [...d])));
|
|
17
|
+
}
|
|
6
18
|
/** Scans one home directory and returns the profile. Reads only; never touches the network. */
|
|
7
19
|
export async function collectProfile(options) {
|
|
8
20
|
const redactor = new Redactor(options.home);
|
|
9
21
|
const diag = new Diagnostics(options.home);
|
|
10
|
-
const
|
|
11
|
-
const
|
|
22
|
+
const codexHome = options.codexHome ?? join(options.home, '.codex');
|
|
23
|
+
const ctx = { home: options.home, codexHome, redactor, diag, onProgress: options.onProgress };
|
|
24
|
+
const claude = await collectClaudeCode(ctx, { usage: options.usage });
|
|
12
25
|
const codex = await collectCodex(ctx, { usage: options.usage });
|
|
13
26
|
return {
|
|
14
27
|
schemaVersion: 1,
|
|
15
28
|
generatedAt: (options.now ?? (() => new Date()))().toISOString(),
|
|
16
29
|
collector: { name: 'harness-craft', version: collectorVersion() },
|
|
17
|
-
claudeCode,
|
|
18
|
-
codex,
|
|
30
|
+
claudeCode: claude.source,
|
|
31
|
+
codex: codex.source,
|
|
32
|
+
activity: unionActivity(claude.days, codex.days),
|
|
19
33
|
redactions: redactor.totals(),
|
|
20
34
|
warnings: diag.list(),
|
|
21
35
|
};
|
package/dist/definitions.js
CHANGED
|
@@ -4,22 +4,31 @@ const MAX_SHORT_FIELD_LENGTH = 64;
|
|
|
4
4
|
export function definitionName(def) {
|
|
5
5
|
return stringField(def.data, 'name') ?? def.fallbackName;
|
|
6
6
|
}
|
|
7
|
+
/** Plugin name of a `plugin:<name>` source, null for 'user' and 'builtin'. */
|
|
8
|
+
export function pluginOf(source) {
|
|
9
|
+
return source.startsWith('plugin:') ? source.slice('plugin:'.length) : null;
|
|
10
|
+
}
|
|
7
11
|
/** Keys to look up usage under: plugin items are tried as '<plugin>:<name>' and bare '<name>'. */
|
|
8
12
|
export function usageKeys(name, source, userNames) {
|
|
9
|
-
|
|
13
|
+
const plugin = pluginOf(source);
|
|
14
|
+
if (plugin === null)
|
|
10
15
|
return [name];
|
|
11
|
-
const plugin = source.slice('plugin:'.length);
|
|
12
16
|
// A bare name owned by a user-level item is not attributed to the plugin item.
|
|
13
17
|
return userNames.has(name) ? [`${plugin}:${name}`] : [`${plugin}:${name}`, name];
|
|
14
18
|
}
|
|
15
19
|
export function qualifiedName(name, source) {
|
|
16
|
-
|
|
20
|
+
const plugin = pluginOf(source);
|
|
21
|
+
return plugin === null ? name : `${plugin}:${name}`;
|
|
22
|
+
}
|
|
23
|
+
function redactedSource(source, ctx) {
|
|
24
|
+
const plugin = pluginOf(source);
|
|
25
|
+
return plugin === null ? source : `plugin:${ctx.redactor.text(plugin, MAX_NAME_LENGTH)}`;
|
|
17
26
|
}
|
|
18
27
|
export function toSkill(def, source, usage, ctx) {
|
|
19
28
|
return {
|
|
20
29
|
name: ctx.redactor.text(qualifiedName(definitionName(def), source), MAX_NAME_LENGTH),
|
|
21
30
|
description: ctx.redactor.text(stringField(def.data, 'description') ?? ''),
|
|
22
|
-
source: source
|
|
31
|
+
source: redactedSource(source, ctx),
|
|
23
32
|
uses: usage.uses,
|
|
24
33
|
lastUsedAt: usage.lastUsedAt,
|
|
25
34
|
};
|
|
@@ -50,10 +59,20 @@ export function toAgent(def, source, uses, ctx) {
|
|
|
50
59
|
effort: redactor.optional(stringField(def.data, 'effort'), MAX_SHORT_FIELD_LENGTH),
|
|
51
60
|
toolCount: tools === null ? null : tools.length,
|
|
52
61
|
mcpServers: mcpServersOf(tools ?? []).map((s) => redactor.text(s, MAX_NAME_LENGTH)),
|
|
53
|
-
source:
|
|
62
|
+
source: redactedSource(source, ctx),
|
|
54
63
|
uses,
|
|
55
64
|
};
|
|
56
65
|
}
|
|
66
|
+
/** An agent that ships with the tool. Listed only when used, so `uses` is at least 1. Name is a constant, not user text. */
|
|
67
|
+
export function builtinAgent(name, uses) {
|
|
68
|
+
return { name, description: '', model: null, effort: null, toolCount: null, mcpServers: [], source: 'builtin', uses };
|
|
69
|
+
}
|
|
70
|
+
/** Built-ins that were used and are not shadowed by a defined agent of the same name. */
|
|
71
|
+
export function usedBuiltinAgents(builtins, defined, calls) {
|
|
72
|
+
return builtins
|
|
73
|
+
.filter((name) => !defined.has(name) && (calls.get(name) ?? 0) > 0)
|
|
74
|
+
.map((name) => builtinAgent(name, calls.get(name) ?? 0));
|
|
75
|
+
}
|
|
57
76
|
export function toCommand(def, ctx) {
|
|
58
77
|
return {
|
|
59
78
|
name: ctx.redactor.text(def.fallbackName, MAX_NAME_LENGTH),
|
package/dist/items.js
CHANGED
|
@@ -10,7 +10,7 @@ async function readDefinition(path, fallbackName, diag) {
|
|
|
10
10
|
const fm = parseFrontmatter(text);
|
|
11
11
|
if (fm.error)
|
|
12
12
|
diag.warn(path, fm.error);
|
|
13
|
-
return { fallbackName, data: fm.data };
|
|
13
|
+
return { fallbackName, data: fm.data, path };
|
|
14
14
|
}
|
|
15
15
|
/** `<dir>/<name>/SKILL.md` for each direct sub-folder that has one (symlinks followed). */
|
|
16
16
|
export async function readSkillDefinitions(dir, diag) {
|