aws-samples / aws-samples/sample-kiro-coding-metrics-collector

[Bug] Execution-log discovery relies on the "414d" directory prefix and reports success when 0 watchers are installed`

Open
#4 0 comments 0 reactions 0 assignees View on GitHub
bug
Dominant language
Rust
Stars
2
Forks
2
PR merge metrics
No merged PRs in 30d

Description

## Environment

- **OS**: ``
- **Plugin version**: ``
- **Kiro IDE version**: ``
- **Git version**: ``
- **Workspace structure**: ``

## Problem

AI-edit detection only ever looks at execution-log directories whose **name begins with the
four characters `414d`**, and treats "found nothing to watch" as a successful startup.

In `kiro-plugin/src/sessionLogWatcher.ts`:

```ts
// start()
for (const subEntry of subEntries) {
if (!subEntry.startsWith("414d")) continue; // ← everything else is invisible
...
}

// watchParentDir()
const watcher = fs.watch(parentPath, (eventType, filename) => {
if (!filename || !filename.startsWith("414d")) return; // ← same filter for new dirs
...
});
```

The same filter appears in `kiro-plugin/src/sessionLogScanner.ts` → `scanForAIEdits()`.

`414d` is an undocumented prefix over an opaque hash namespace in Kiro's private storage.
Nothing in Kiro's public surface commits to keeping that prefix, or to keeping execution-log
directories exactly one level below the workspace-hash directory. A related assumption sits one
level up: `sessionLogScanner.ts` → `resolveAgentDir()` hard-codes the path
`.../Kiro/User/globalStorage/kiro.kiroagent`.

When either assumption stops holding, the failure is not reported:

- Missing agent dir → `console.warn("Agent Dir does not exist, SessionLogWatcher not starting")`,
then `return`. The extension keeps running.
- No matching subdirectory → `start()` still logs
`SessionLogWatcher started with N watcher(s)` where **N can be 0**, and returns normally.

Subsequent commits are then attributed entirely to human, because git-ai only ever receives the
Human checkpoint from `pre-commit`. That is correct behaviour for git-ai given its input — the
input is just missing.

## Steps to reproduce

1. Confirm the plugin is working: make an AI edit via Kiro's built-in chat, Accept, commit, and
verify `ai_additions > 0` in `.git/ai/last_upload_payload.json`.
2. Rename the agent dir `.../globalStorage/kiro.kiroagent` →
`.../globalStorage/kiro.kiroagent.bak`, or rename one `414d*` execution-log directory to
something else. Restart Kiro.
3. Repeat step 1: AI edit via built-in chat, Accept, wait a few seconds, commit.

## Expected

A visible signal that AI detection is not operating — status bar warning, and/or the commit
recorded as *unattributed* rather than human.

## Actual

``.
`.git/ai/working_logs/` is empty, `git notes --ref=ai show HEAD` shows `prompts: {}`, and
`post_commit_debug.log` contains only a `kind=Human` checkpoint. The only trace is a
`console.warn` in DevTools.

## Plugin log

> Kiro IDE → Help → Toggle Developer Tools → Console → filter `git-ai-kiro`

```

```

## Suggested direction

1. Discover execution-log directories by **content probing** — a directory containing files that
parse to a known schema — rather than by name prefix.
2. Failing that, make the prefix a configuration value with a documented default, and log a
distinct warning when a workspace-hash directory has subdirectories but none match. That
situation is a good signal that Kiro's layout has changed.
3. Treat `watchers_installed === 0` as an error state rather than logging
`started with 0 watcher(s)` and continuing.
4. Add a `git-ai-kiro: Run detector self-check` command that resolves the agent dir, enumerates
candidate log directories, parses the most recent log, and reports what it found — so
"AI shows 0, is it broken or did I not use AI?" is one command instead of a diagnostics bundle.

## Acceptance criteria

- With the agent dir renamed or absent, a commit following an AI edit is reported as
unattributed rather than 100% human, and the user sees a warning.
- Renaming a `414d*` directory does not silently disable detection.
- A self-check command reports, on demand, whether the agent dir resolved and how many watchers
were installed.

Contributor guide

Open the contributing guide

Research direction

Read kiro-plugin/src/sessionLogWatcher.ts, especially start() and watchParentDir(), then inspect sessionLogScanner.ts for scanForAIEdits() and resolveAgentDir(). Trace how missing agent directories and zero installed watchers are currently logged, and review the acceptance criteria before choosing an implementation direction. Done means renamed or missing directories produce a visible warning, detection is not silently disabled, and a self-check reports agent resolution and watcher counts.

Written by the indexing model from the issue text.

Assessment

Tech stack
git, typescript
Domain
devtools
Issue type
Bug
Difficulty
5/5
Estimated time
Over a week
Activity status
Quiet
Clarity
Mostly clear
Newbie friendliness
38/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.