archbyte 0.6.0 → 0.7.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.
@@ -0,0 +1,3 @@
1
+ import type { AgentSession } from "../types.js";
2
+ /** Import a .archbyte/ directory into AgentSession(s) */
3
+ export declare function importArchbyte(archbyteDir: string): Promise<AgentSession[]>;
@@ -0,0 +1,104 @@
1
+ // Archbyte Adapter — reads .archbyte/runs/ + session.json + metadata.json
2
+ // Converts archbyte pipeline run data into AgentSession for the Sessions panel
3
+ import { readFile, readdir } from "fs/promises";
4
+ import { existsSync, readFileSync } from "fs";
5
+ import path from "path";
6
+ /** Read a text file if it exists, return null otherwise */
7
+ async function readOptional(filePath) {
8
+ if (!existsSync(filePath))
9
+ return null;
10
+ try {
11
+ return await readFile(filePath, "utf-8");
12
+ }
13
+ catch {
14
+ return null;
15
+ }
16
+ }
17
+ /** Read and parse a JSON file, return null on failure */
18
+ function readJsonSync(filePath) {
19
+ if (!existsSync(filePath))
20
+ return null;
21
+ try {
22
+ return JSON.parse(readFileSync(filePath, "utf-8"));
23
+ }
24
+ catch {
25
+ return null;
26
+ }
27
+ }
28
+ /** Import a .archbyte/ directory into AgentSession(s) */
29
+ export async function importArchbyte(archbyteDir) {
30
+ const runsDir = path.join(archbyteDir, "runs");
31
+ if (!existsSync(runsDir))
32
+ return [];
33
+ // Read run subdirectories
34
+ let entries;
35
+ try {
36
+ const dirEntries = await readdir(runsDir, { withFileTypes: true });
37
+ entries = dirEntries.filter(e => e.isDirectory()).map(e => e.name).sort();
38
+ }
39
+ catch {
40
+ return [];
41
+ }
42
+ if (entries.length === 0)
43
+ return [];
44
+ // Read session.json for session-level metadata
45
+ const session = readJsonSync(path.join(archbyteDir, "session.json"));
46
+ const metadata = readJsonSync(path.join(archbyteDir, "metadata.json"));
47
+ const sessionId = session?.sessionId ?? `archbyte-${path.basename(path.dirname(archbyteDir))}`;
48
+ // Build runs from subdirectories
49
+ const runs = [];
50
+ for (const dirName of entries) {
51
+ const runPath = path.join(runsDir, dirName);
52
+ const meta = readJsonSync(path.join(runPath, "meta.json"));
53
+ if (!meta)
54
+ continue;
55
+ const prompt = await readOptional(path.join(runPath, "prompt.md"));
56
+ const output = await readOptional(path.join(runPath, "output.md"));
57
+ runs.push({
58
+ ...meta,
59
+ artifacts: {
60
+ ...(prompt ? { prompt } : {}),
61
+ ...(output ? { output } : {}),
62
+ },
63
+ });
64
+ }
65
+ if (runs.length === 0)
66
+ return [];
67
+ // Derive session summary
68
+ const totalElapsed = session?.totalElapsedSeconds ?? runs.reduce((s, r) => s + (r.elapsedSeconds ?? 0), 0);
69
+ const totalTokens = session?.totalTokens ?? {
70
+ input: runs.reduce((s, r) => s + (r.tokens?.input ?? 0), 0),
71
+ output: runs.reduce((s, r) => s + (r.tokens?.output ?? 0), 0),
72
+ };
73
+ const phases = [...new Set(runs.map(r => r.phase))];
74
+ const models = [...new Set(runs.map(r => r.model))];
75
+ const successfulRuns = runs.filter(r => r.status === "success").length;
76
+ const failedRuns = runs.filter(r => r.status === "error").length;
77
+ const skippedRuns = runs.filter(r => r.status === "skipped").length;
78
+ const firstRun = runs[0];
79
+ const lastRun = runs[runs.length - 1];
80
+ const startedAt = session?.startedAt ?? firstRun.startedAt;
81
+ const completedAt = session?.completedAt ?? lastRun.completedAt ?? lastRun.startedAt;
82
+ const status = failedRuns > 0 ? "partial" : "success";
83
+ return [{
84
+ sessionId,
85
+ startedAt,
86
+ completedAt,
87
+ status: session?.status ?? status,
88
+ source: "archbyte",
89
+ projectMeta: {
90
+ mode: session?.mode ?? metadata?.mode ?? "pipeline",
91
+ },
92
+ summary: {
93
+ totalRuns: runs.length,
94
+ successfulRuns,
95
+ failedRuns,
96
+ skippedRuns,
97
+ totalElapsedSeconds: totalElapsed,
98
+ totalTokens,
99
+ phases,
100
+ models,
101
+ },
102
+ runs,
103
+ }];
104
+ }
@@ -0,0 +1,31 @@
1
+ import type { AgentSession } from "../types.js";
2
+ /** Invalidate cached index entries. Call with a path to invalidate one file, or no args to clear all. */
3
+ export declare function invalidateIndexCache(filePath?: string): void;
4
+ export declare function getClaudeProjectsDir(): string;
5
+ export declare function encodeProjectPath(cwd: string): string;
6
+ export declare function getProjectTranscriptDir(cwd: string): string | null;
7
+ export type SessionCategory = "implementation" | "exploration" | "conversation" | "pipeline";
8
+ export interface SessionIndexEntry {
9
+ sessionId: string;
10
+ startedAt: string;
11
+ completedAt?: string;
12
+ status: "success" | "partial";
13
+ runCount: number;
14
+ phases: string[];
15
+ source: string;
16
+ model?: string;
17
+ version?: string;
18
+ gitBranch?: string;
19
+ subagentCount?: number;
20
+ category?: SessionCategory;
21
+ label?: string;
22
+ touchedDirs?: string[];
23
+ eventCount?: number;
24
+ dirMetrics?: Record<string, {
25
+ reads: number;
26
+ writes: number;
27
+ }>;
28
+ estimatedCost?: number;
29
+ }
30
+ export declare function scanTranscriptIndex(projectDir: string): Promise<SessionIndexEntry[]>;
31
+ export declare function importClaudeTranscript(projectDir: string, sessionId: string): Promise<AgentSession | null>;