mirror of
https://github.com/Ark0N/Codeman.git
synced 2026-10-04 14:39:42 +02:00
feat(agent-cases): tag agent-spawned case dirs and sweep their leftovers
A long orchestration creates one case directory per worker and deleting the sessions never removed them, so ~/codeman-cases accumulated scratch folders that were indistinguishable from real projects. They are now labelled and have a cleanup path. - src/agent-case-marker.ts: a case dir quick-start CREATES for an agent-driven spawn gets a .codeman-agent-case.json marker (when, by whom, parent session, mode). Only the create branch writes it, so a linked case, a cloned repo or any pre-existing path is never labelled; reading is total, so a malformed marker means "not agent-created" rather than a half-trusted entry. - The signal is the new X-Codeman-Agent-Origin header the skill preamble sets on its shared curl (preamble bumped to 1.22.0), or an agentOrigin body field, falling back to a resolved parentSessionId so a worker spawned by a stale skill copy is still labelled. - GET /api/cases publishes it as agentCreated; GET /api/cases/agent-created is a read-only cleanup listing adding inUse and modifiedAt; Add Case -> Manage badges each case and offers a review-then-delete sweep that names every directory in its confirm and skips any case a live session is working in. Removal stays on the existing DELETE /api/cases/:name. - Agent preamble caches are collected too: ~/.cache/codeman-agent-<id>.sh was written per claude session and never removed (236 leftovers measured on a working machine). Now deleted with the session and swept at boot, guarded by a live-session keep set plus a 7-day age floor. Verified end to end on an isolated instance: marker written for header, body and lineage-only spawns, absent with no agent signal and for a pre-existing directory; inUse flipping on session end; badge, sticky bar, confirm and sweep driven in a browser; preamble seeded on create, removed on delete, boot sweep taking only the aged orphans. Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com>
This commit is contained in:
@@ -157,6 +157,20 @@ export interface CaseInfo {
|
||||
location?: 'local' | 'linked-local' | 'remote' | 'docker';
|
||||
/** Whether this is a linked local folder */
|
||||
linked?: boolean;
|
||||
/**
|
||||
* Present when Codeman scaffolded this case directory for an AGENT-spawned session
|
||||
* (the packaged skill's workers, or any spawn naming a parent session), read back
|
||||
* from the case's own marker file — see `src/agent-case-marker.ts`. Absent for every
|
||||
* case a human created, linked or cloned, which is what makes it usable as the
|
||||
* "safe to clean up" signal in the Manage tab.
|
||||
*/
|
||||
agentCreated?: {
|
||||
createdAt: string;
|
||||
createdBy: string;
|
||||
parentSessionId?: string;
|
||||
parentSessionName?: string;
|
||||
mode?: string;
|
||||
};
|
||||
/** Remote case metadata for display and session creation */
|
||||
remote?: {
|
||||
hostId: string;
|
||||
@@ -192,6 +206,25 @@ export interface CaseInfo {
|
||||
};
|
||||
}
|
||||
|
||||
/**
|
||||
* One agent-created case as `GET /api/cases/agent-created` reports it: the cleanup
|
||||
* view over `CaseInfo.agentCreated`, with the two facts a human needs before deleting
|
||||
* a directory — whether an agent is still working in it, and when it was last touched.
|
||||
*/
|
||||
export interface AgentCaseSummary {
|
||||
name: string;
|
||||
path: string;
|
||||
createdAt: string;
|
||||
createdBy: string;
|
||||
parentSessionId?: string;
|
||||
parentSessionName?: string;
|
||||
mode?: string;
|
||||
/** A live session's working directory is this case — deleting it would pull the rug. */
|
||||
inUse: boolean;
|
||||
/** Directory mtime, so "nothing has touched this in a week" is answerable. */
|
||||
modifiedAt?: string;
|
||||
}
|
||||
|
||||
// ========== Error Handling Utilities ==========
|
||||
|
||||
/**
|
||||
|
||||
Reference in New Issue
Block a user