@kairyou/agent-tools 0.13.0 → 0.13.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/dist/log/hook.mjs CHANGED
@@ -899,7 +899,7 @@ async function main() {
899
899
  await fs.mkdir(CACHE_ROOT, { recursive: true });
900
900
  await cleanupCache(day);
901
901
  const state = await loadState(statePath, day);
902
- await handleEvent(state, hookInput, { now, snapshotsRoot, effective, scopeKey });
902
+ await handleEvent(state, hookInput, { now, snapshotsRoot, effective, scopeKey, scopePath: scope?.path || "" });
903
903
  await writeFileAtomic(statePath, `${JSON.stringify(state, null, 2)}
904
904
  `);
905
905
  if (effective.format === "detailed") {
@@ -981,11 +981,11 @@ async function handleEvent(state, input, context) {
981
981
  session.last_time = timestamp;
982
982
  if (eventName === "UserPromptSubmit") {
983
983
  session.turns.push(
984
- createTurn(session, timestamp, getPromptText(input), resolveProjectLabel(input), context.scopeKey)
984
+ createTurn(session, timestamp, getPromptText(input), resolveProjectLabel(input, context.scopePath), context.scopeKey)
985
985
  );
986
986
  return;
987
987
  }
988
- const turn = ensureCurrentTurn(session, timestamp, resolveProjectLabel(input), context.scopeKey);
988
+ const turn = ensureCurrentTurn(session, timestamp, resolveProjectLabel(input, context.scopePath), context.scopeKey);
989
989
  turn.last_time = timestamp;
990
990
  if (eventName === "PreToolUse") {
991
991
  if (context.effective.format === "detailed") {
@@ -1003,14 +1003,21 @@ async function handleEvent(state, input, context) {
1003
1003
  }
1004
1004
  recordToolUse(turn, input, { timestamp });
1005
1005
  }
1006
- function resolveProjectLabel(input) {
1006
+ function resolveProjectLabel(input, scopePath) {
1007
1007
  const cwd = eventCwd(input);
1008
1008
  const result = spawnSync("git", ["-C", cwd, "rev-parse", "--show-toplevel"], {
1009
1009
  encoding: "utf8",
1010
1010
  windowsHide: true
1011
1011
  });
1012
- const root = result.status === 0 ? result.stdout.trim() : "";
1013
- return path.basename(root || cwd);
1012
+ const base = result.status === 0 && result.stdout.trim() || cwd;
1013
+ if (scopePath) {
1014
+ const baseKey = pathKey(base);
1015
+ const scopeKey = pathKey(scopePath);
1016
+ if (scopeKey === baseKey || scopeKey.startsWith(`${baseKey}/`)) {
1017
+ return path.basename(scopePath);
1018
+ }
1019
+ }
1020
+ return path.basename(base);
1014
1021
  }
1015
1022
  async function cleanupCache(day) {
1016
1023
  let entries = [];
@@ -70,7 +70,7 @@ async function main() {
70
70
  await cleanupCache(day);
71
71
 
72
72
  const state = await loadState(statePath, day);
73
- await handleEvent(state, hookInput, { now, snapshotsRoot, effective, scopeKey });
73
+ await handleEvent(state, hookInput, { now, snapshotsRoot, effective, scopeKey, scopePath: scope?.path || "" });
74
74
  await writeFileAtomic(statePath, `${JSON.stringify(state, null, 2)}\n`);
75
75
 
76
76
  if (effective.format === "detailed") {
@@ -174,12 +174,12 @@ async function handleEvent(state, input, context) {
174
174
  // let this prompt's Stop overwrite the previous result summary. Trivial
175
175
  // turns are filtered at render time instead.
176
176
  session.turns.push(
177
- createTurn(session, timestamp, getPromptText(input), resolveProjectLabel(input), context.scopeKey)
177
+ createTurn(session, timestamp, getPromptText(input), resolveProjectLabel(input, context.scopePath), context.scopeKey)
178
178
  );
179
179
  return;
180
180
  }
181
181
 
182
- const turn = ensureCurrentTurn(session, timestamp, resolveProjectLabel(input), context.scopeKey);
182
+ const turn = ensureCurrentTurn(session, timestamp, resolveProjectLabel(input, context.scopePath), context.scopeKey);
183
183
  turn.last_time = timestamp;
184
184
 
185
185
  if (eventName === "PreToolUse") {
@@ -202,14 +202,24 @@ async function handleEvent(state, input, context) {
202
202
  recordToolUse(turn, input, { timestamp });
203
203
  }
204
204
 
205
- function resolveProjectLabel(input) {
205
+ function resolveProjectLabel(input, scopePath) {
206
206
  const cwd = eventCwd(input);
207
207
  const result = spawnSync("git", ["-C", cwd, "rev-parse", "--show-toplevel"], {
208
208
  encoding: "utf8",
209
209
  windowsHide: true,
210
210
  });
211
- const root = result.status === 0 ? result.stdout.trim() : "";
212
- return path.basename(root || cwd);
211
+ const base = (result.status === 0 && result.stdout.trim()) || cwd;
212
+ // A scope deeper than the repo (a monorepo team dir such as src/webfront)
213
+ // labels entries better than the repo name; a scope broader than the repo
214
+ // (a directory holding many repos) keeps the repo name.
215
+ if (scopePath) {
216
+ const baseKey = pathKey(base);
217
+ const scopeKey = pathKey(scopePath);
218
+ if (scopeKey === baseKey || scopeKey.startsWith(`${baseKey}/`)) {
219
+ return path.basename(scopePath);
220
+ }
221
+ }
222
+ return path.basename(base);
213
223
  }
214
224
 
215
225
  async function cleanupCache(day) {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@kairyou/agent-tools",
3
- "version": "0.13.0",
3
+ "version": "0.13.1",
4
4
  "description": "Reusable Agent Skills, plus integrations (statusline, provider usage, vision) that install into Codex, Claude Code, and opencode.",
5
5
  "license": "MIT",
6
6
  "repository": {