@installagent/sdk 0.3.0 → 0.4.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/claude-hours.d.ts +19 -3
- package/dist/claude-hours.js +140 -25
- package/dist/client-linear-create.d.ts +10 -0
- package/dist/client-linear-create.js +30 -3
- package/dist/hours-ledger.d.ts +8 -0
- package/dist/hours-ledger.js +47 -3
- package/dist/index.d.ts +2 -2
- package/dist/index.js +2 -2
- package/package.json +1 -1
- package/templates/workspace-root/AGENT.md +2 -1
- package/templates/workspace-root/ONBOARDING.md +1 -1
- package/templates/workspace-root/skills/.github/workflows/pr-to-slack.yml +7 -2
package/dist/claude-hours.d.ts
CHANGED
|
@@ -1,4 +1,6 @@
|
|
|
1
|
-
export declare const HOURS_EXPORT_SCHEMA = "ia-hours-export/
|
|
1
|
+
export declare const HOURS_EXPORT_SCHEMA = "ia-hours-export/3";
|
|
2
|
+
/** Activity counts this long after the person's own action in the same session. */
|
|
3
|
+
export declare const PROMPT_WINDOW_MINUTES = 30;
|
|
2
4
|
/** Claude Code's own config-dir override; scanned in addition to the defaults. */
|
|
3
5
|
export declare const CLAUDE_CONFIG_DIR_ENV = "CLAUDE_CONFIG_DIR";
|
|
4
6
|
/** The pseudo-slug for Install Agent work that named no client. */
|
|
@@ -9,9 +11,14 @@ export interface ClaudeHoursSummaryRow {
|
|
|
9
11
|
slug: string;
|
|
10
12
|
/** False when this machine has no clients/client-<slug> repo — the ledger files it as other-lead. */
|
|
11
13
|
known: boolean;
|
|
14
|
+
/** Counted minutes (within PROMPT_WINDOW_MINUTES of the person's own action). */
|
|
12
15
|
activeMinutes: number;
|
|
16
|
+
/** Minutes of activity nobody started — listed, not counted. */
|
|
17
|
+
automationMinutes: number;
|
|
13
18
|
hoursByMonth: Record<string, number>;
|
|
14
19
|
hoursTotal: number;
|
|
20
|
+
/** What the same rules give if every minute counted, as schema /2 did — for spotting a loop. */
|
|
21
|
+
hoursAllActivity: number;
|
|
15
22
|
}
|
|
16
23
|
export interface ClaudeHoursExportResult {
|
|
17
24
|
schema: typeof HOURS_EXPORT_SCHEMA;
|
|
@@ -29,12 +36,20 @@ export interface ClaudeHoursExportResult {
|
|
|
29
36
|
last: string | null;
|
|
30
37
|
lines: number;
|
|
31
38
|
};
|
|
32
|
-
/**
|
|
39
|
+
/**
|
|
40
|
+
* slug → sorted counted minutes, each "YYYY-MM-DDTHH:MMZ": activity within
|
|
41
|
+
* PROMPT_WINDOW_MINUTES after the person's own action in the same session.
|
|
42
|
+
* The ledger's raw input.
|
|
43
|
+
*/
|
|
33
44
|
minutes: Record<string, string[]>;
|
|
45
|
+
/** slug → sorted minutes of activity with no prompt or answer from the person in the window before it (loops, wake-ups, background tasks). Never counted. */
|
|
46
|
+
automationMinutes: Record<string, string[]>;
|
|
34
47
|
/** Claude Code on its own, by the ledger's rules — the human summary, most hours first. */
|
|
35
48
|
summary: ClaudeHoursSummaryRow[];
|
|
36
49
|
/** Sessions that named no client and ran outside the workspace — other work, left out. */
|
|
37
50
|
skippedSessions: number;
|
|
51
|
+
/** Sessions with activity but no prompt-origin marks at all (an old Claude Code) — nothing in them could be checked. */
|
|
52
|
+
unmarkedSessions: number;
|
|
38
53
|
/** Session files that could not be read (permissions, mid-write) — reported, never thrown. */
|
|
39
54
|
unreadableSessions: string[];
|
|
40
55
|
}
|
|
@@ -106,8 +121,9 @@ export interface DeliverClaudeHoursExportResult {
|
|
|
106
121
|
/** Save the export, then send it unless `send` is false. A failed send never loses the file. */
|
|
107
122
|
export declare function deliverClaudeHoursExport(result: ClaudeHoursExportResult, options?: DeliverClaudeHoursExportOptions): Promise<DeliverClaudeHoursExportResult>;
|
|
108
123
|
/** The export minus its per-minute lists (replaced by counts) — for showing to a person or an agent. */
|
|
109
|
-
export declare function compactClaudeHoursExport(result: ClaudeHoursExportResult): Omit<ClaudeHoursExportResult, "minutes"> & {
|
|
124
|
+
export declare function compactClaudeHoursExport(result: ClaudeHoursExportResult): Omit<ClaudeHoursExportResult, "minutes" | "automationMinutes"> & {
|
|
110
125
|
minuteCounts: Record<string, number>;
|
|
126
|
+
automationMinuteCounts: Record<string, number>;
|
|
111
127
|
};
|
|
112
128
|
/**
|
|
113
129
|
* Read this machine's Claude Code session logs and return one person's
|
package/dist/claude-hours.js
CHANGED
|
@@ -16,8 +16,20 @@ import { createLogger } from "./log.js";
|
|
|
16
16
|
// Linear activity so a minute counts once, and monthly totals cannot be
|
|
17
17
|
// lined up. A small hours summary rides along for the person running it.
|
|
18
18
|
//
|
|
19
|
+
// Only time a person started counts (schema /3, 2026-10-05). A minute of
|
|
20
|
+
// activity counts when it falls within PROMPT_WINDOW_MINUTES after that
|
|
21
|
+
// person's own action in the SAME session: a prompt Claude Code marks as
|
|
22
|
+
// human (`origin.kind` / `turnOrigin`), or their answer to a question or a
|
|
23
|
+
// plan (the tool_result of a HUMAN_ANSWER_TOOLS call). Everything else — a
|
|
24
|
+
// loop or scheduled wake-up, a background task finishing, a subagent's
|
|
25
|
+
// message — is exported as `automationMinutes`: kept for review, never
|
|
26
|
+
// counted. Before this, an unattended check loop that woke Claude every 30
|
|
27
|
+
// minutes held one weekend session open for 55 hours.
|
|
28
|
+
//
|
|
19
29
|
// What is inspected, per session-log line: its `type`, `timestamp`,
|
|
20
|
-
// `isSidechain` flag, `cwd`,
|
|
30
|
+
// `isSidechain` flag, `cwd`, its prompt-origin marks (`origin.kind`,
|
|
31
|
+
// `turnOrigin`), the `id`/`name` of `tool_use` blocks and the `tool_use_id`
|
|
32
|
+
// of `tool_result` blocks (to spot an answer), and — on assistant lines — the
|
|
21
33
|
// path/command fields of `tool_use` inputs (TOOL_INPUT_PATH_KEYS), with
|
|
22
34
|
// heredoc bodies cut out of commands. Never message text, `tool_result`
|
|
23
35
|
// output, file contents a tool writes (Write/Edit), or prompts sent to
|
|
@@ -33,7 +45,11 @@ import { createLogger } from "./log.js";
|
|
|
33
45
|
// as `unattributed` when it ran inside the Install Agent workspace, and is
|
|
34
46
|
// skipped otherwise (other work on the same machine).
|
|
35
47
|
const log = createLogger("sdk.claude-hours");
|
|
36
|
-
export const HOURS_EXPORT_SCHEMA = "ia-hours-export/
|
|
48
|
+
export const HOURS_EXPORT_SCHEMA = "ia-hours-export/3";
|
|
49
|
+
/** Activity counts this long after the person's own action in the same session. */
|
|
50
|
+
export const PROMPT_WINDOW_MINUTES = 30;
|
|
51
|
+
/** Tools whose result is the person's own answer: a question answered, a plan approved. */
|
|
52
|
+
const HUMAN_ANSWER_TOOLS = new Set(["AskUserQuestion", "ExitPlanMode"]);
|
|
37
53
|
/** Claude Code's own config-dir override; scanned in addition to the defaults. */
|
|
38
54
|
export const CLAUDE_CONFIG_DIR_ENV = "CLAUDE_CONFIG_DIR";
|
|
39
55
|
/**
|
|
@@ -281,9 +297,57 @@ function isInsideWorkspace(cwd, workspaceRoot) {
|
|
|
281
297
|
}
|
|
282
298
|
return cwd.toLowerCase().includes("installagent");
|
|
283
299
|
}
|
|
300
|
+
/** The `tool_use` ids in an assistant line whose result will be the person's own answer. */
|
|
301
|
+
function answerToolIds(line, out) {
|
|
302
|
+
if (line.type !== "assistant" || !line.message || typeof line.message !== "object")
|
|
303
|
+
return;
|
|
304
|
+
const content = line.message.content;
|
|
305
|
+
if (!Array.isArray(content))
|
|
306
|
+
return;
|
|
307
|
+
for (const block of content) {
|
|
308
|
+
if (!block || typeof block !== "object")
|
|
309
|
+
continue;
|
|
310
|
+
const { type, id, name } = block;
|
|
311
|
+
if (type === "tool_use" && typeof id === "string" && typeof name === "string") {
|
|
312
|
+
if (HUMAN_ANSWER_TOOLS.has(name))
|
|
313
|
+
out.add(id);
|
|
314
|
+
}
|
|
315
|
+
}
|
|
316
|
+
}
|
|
317
|
+
/**
|
|
318
|
+
* Did the person act on this line? Claude Code marks every prompt with who
|
|
319
|
+
* started it: `origin.kind` ("human", "task-notification", "peer",
|
|
320
|
+
* "auto-continuation", …) and, on some lines, `turnOrigin`. When `origin` is
|
|
321
|
+
* there it decides; `turnOrigin` covers the lines that carry only that (a
|
|
322
|
+
* typed `!` command's output). An answer to a question or a plan approval
|
|
323
|
+
* arrives as a tool_result instead, matched by its tool_use id.
|
|
324
|
+
*/
|
|
325
|
+
function isHumanAction(line, answerIds) {
|
|
326
|
+
if (line.type !== "user")
|
|
327
|
+
return false;
|
|
328
|
+
const origin = line.origin;
|
|
329
|
+
if (origin && typeof origin === "object")
|
|
330
|
+
return origin.kind === "human";
|
|
331
|
+
if (line.turnOrigin === "human")
|
|
332
|
+
return true;
|
|
333
|
+
const content = line.message && typeof line.message === "object"
|
|
334
|
+
? line.message.content
|
|
335
|
+
: undefined;
|
|
336
|
+
if (!Array.isArray(content))
|
|
337
|
+
return false;
|
|
338
|
+
return content.some((block) => {
|
|
339
|
+
if (!block || typeof block !== "object")
|
|
340
|
+
return false;
|
|
341
|
+
const { type, tool_use_id } = block;
|
|
342
|
+
return type === "tool_result" && typeof tool_use_id === "string" && answerIds.has(tool_use_id);
|
|
343
|
+
});
|
|
344
|
+
}
|
|
284
345
|
function sessionPoints(raw, known, workspaceRoot, sinceMs, untilMs) {
|
|
285
346
|
const events = [];
|
|
347
|
+
const answerIds = new Set();
|
|
286
348
|
let insideWorkspace = false;
|
|
349
|
+
let marked = false;
|
|
350
|
+
let worked = false;
|
|
287
351
|
let lines = 0;
|
|
288
352
|
let first = null;
|
|
289
353
|
let last = null;
|
|
@@ -308,9 +372,18 @@ function sessionPoints(raw, known, workspaceRoot, sinceMs, untilMs) {
|
|
|
308
372
|
if (typeof line.cwd === "string" && isInsideWorkspace(line.cwd, workspaceRoot)) {
|
|
309
373
|
insideWorkspace = true;
|
|
310
374
|
}
|
|
311
|
-
|
|
375
|
+
if ("origin" in line || "turnOrigin" in line)
|
|
376
|
+
marked = true;
|
|
377
|
+
answerToolIds(line, answerIds);
|
|
378
|
+
events.push({
|
|
379
|
+
ts,
|
|
380
|
+
slug: mostMentioned(slugsInLine(line, known)),
|
|
381
|
+
human: isHumanAction(line, answerIds),
|
|
382
|
+
});
|
|
312
383
|
if ((sinceMs === null || ts >= sinceMs) && (untilMs === null || ts <= untilMs)) {
|
|
313
384
|
lines += 1;
|
|
385
|
+
if (line.type === "assistant")
|
|
386
|
+
worked = true;
|
|
314
387
|
if (first === null || ts < first)
|
|
315
388
|
first = ts;
|
|
316
389
|
if (last === null || ts > last)
|
|
@@ -320,20 +393,27 @@ function sessionPoints(raw, known, workspaceRoot, sinceMs, untilMs) {
|
|
|
320
393
|
events.sort((a, b) => a.ts - b.ts);
|
|
321
394
|
const firstSlug = events.find((event) => event.slug !== null)?.slug ?? null;
|
|
322
395
|
if (firstSlug === null && !insideWorkspace) {
|
|
323
|
-
return { points: [], skipped: events.length > 0, lines, first, last };
|
|
396
|
+
return { points: [], skipped: events.length > 0, unmarked: false, lines, first, last };
|
|
324
397
|
}
|
|
325
398
|
// Carry the last-seen client forward; the lines before the first mention take the first one.
|
|
399
|
+
// The person's last action is tracked over the whole file, so a prompt just before --since
|
|
400
|
+
// still counts the minutes it started inside the window.
|
|
326
401
|
let current = firstSlug ?? UNATTRIBUTED_SLUG;
|
|
402
|
+
let lastHuman = null;
|
|
327
403
|
const points = [];
|
|
328
404
|
for (const event of events) {
|
|
329
405
|
current = event.slug ?? current;
|
|
406
|
+
const minute = minuteOf(event.ts);
|
|
407
|
+
if (event.human)
|
|
408
|
+
lastHuman = minute;
|
|
330
409
|
if (sinceMs !== null && event.ts < sinceMs)
|
|
331
410
|
continue;
|
|
332
411
|
if (untilMs !== null && event.ts > untilMs)
|
|
333
412
|
continue;
|
|
334
|
-
|
|
413
|
+
const counted = lastHuman !== null && minute - lastHuman < PROMPT_WINDOW_MINUTES;
|
|
414
|
+
points.push({ ts: event.ts, slug: current, counted });
|
|
335
415
|
}
|
|
336
|
-
return { points, skipped: false, lines, first, last };
|
|
416
|
+
return { points, skipped: false, unmarked: !marked && worked, lines, first, last };
|
|
337
417
|
}
|
|
338
418
|
function minuteIso(minute) {
|
|
339
419
|
return `${new Date(minute * 60_000).toISOString().slice(0, 16)}Z`;
|
|
@@ -421,11 +501,13 @@ export async function deliverClaudeHoursExport(result, options = {}) {
|
|
|
421
501
|
}
|
|
422
502
|
/** The export minus its per-minute lists (replaced by counts) — for showing to a person or an agent. */
|
|
423
503
|
export function compactClaudeHoursExport(result) {
|
|
424
|
-
const { minutes, ...rest } = result;
|
|
425
|
-
const
|
|
426
|
-
|
|
427
|
-
|
|
428
|
-
|
|
504
|
+
const { minutes, automationMinutes, ...rest } = result;
|
|
505
|
+
const counts = (lists) => Object.fromEntries(Object.entries(lists).map(([slug, list]) => [slug, list.length]));
|
|
506
|
+
return {
|
|
507
|
+
...rest,
|
|
508
|
+
minuteCounts: counts(minutes),
|
|
509
|
+
automationMinuteCounts: counts(automationMinutes),
|
|
510
|
+
};
|
|
429
511
|
}
|
|
430
512
|
/**
|
|
431
513
|
* Read this machine's Claude Code session logs and return one person's
|
|
@@ -450,8 +532,15 @@ export async function exportClaudeHours(options) {
|
|
|
450
532
|
const workspaceRoot = options.workspaceRoot === undefined ? findWorkspaceRoot() : options.workspaceRoot;
|
|
451
533
|
const known = knownSlugsIn(workspaceRoot);
|
|
452
534
|
const unreadableSessions = [];
|
|
453
|
-
const
|
|
535
|
+
const countedSets = new Map();
|
|
536
|
+
const activitySets = new Map();
|
|
537
|
+
const addMinute = (sets, slug, minute) => {
|
|
538
|
+
const set = sets.get(slug) ?? new Set();
|
|
539
|
+
set.add(minute);
|
|
540
|
+
sets.set(slug, set);
|
|
541
|
+
};
|
|
454
542
|
let skippedSessions = 0;
|
|
543
|
+
let unmarkedSessions = 0;
|
|
455
544
|
let lines = 0;
|
|
456
545
|
let firstMs = null;
|
|
457
546
|
let lastMs = null;
|
|
@@ -474,34 +563,58 @@ export async function exportClaudeHours(options) {
|
|
|
474
563
|
lastMs = session.last;
|
|
475
564
|
if (session.skipped)
|
|
476
565
|
skippedSessions += 1;
|
|
566
|
+
if (session.unmarked)
|
|
567
|
+
unmarkedSessions += 1;
|
|
477
568
|
for (const point of session.points) {
|
|
478
|
-
const
|
|
479
|
-
|
|
480
|
-
|
|
569
|
+
const minute = minuteOf(point.ts);
|
|
570
|
+
addMinute(activitySets, point.slug, minute);
|
|
571
|
+
if (point.counted)
|
|
572
|
+
addMinute(countedSets, point.slug, minute);
|
|
481
573
|
}
|
|
482
574
|
}
|
|
575
|
+
// A minute another session counted is not automation, even if a loop also ran in it.
|
|
483
576
|
const minutes = {};
|
|
484
|
-
const
|
|
485
|
-
|
|
486
|
-
|
|
487
|
-
|
|
488
|
-
|
|
489
|
-
|
|
490
|
-
|
|
577
|
+
const automationMinutes = {};
|
|
578
|
+
const countedEvents = [];
|
|
579
|
+
const activityEvents = [];
|
|
580
|
+
const slugs = [...activitySets.keys()].sort();
|
|
581
|
+
for (const slug of slugs) {
|
|
582
|
+
const counted = countedSets.get(slug) ?? new Set();
|
|
583
|
+
const all = [...(activitySets.get(slug) ?? [])].sort((a, b) => a - b);
|
|
584
|
+
const kept = all.filter((minute) => counted.has(minute));
|
|
585
|
+
const automation = all.filter((minute) => !counted.has(minute));
|
|
586
|
+
if (kept.length > 0)
|
|
587
|
+
minutes[slug] = kept.map(minuteIso);
|
|
588
|
+
if (automation.length > 0)
|
|
589
|
+
automationMinutes[slug] = automation.map(minuteIso);
|
|
590
|
+
const event = (minute) => ({
|
|
591
|
+
source: "claude",
|
|
592
|
+
person,
|
|
593
|
+
slug,
|
|
594
|
+
ts: minute * 60_000,
|
|
595
|
+
durationMin: null,
|
|
596
|
+
});
|
|
597
|
+
countedEvents.push(...kept.map(event));
|
|
598
|
+
activityEvents.push(...all.map(event));
|
|
491
599
|
}
|
|
492
|
-
const estimate = estimateHours(
|
|
493
|
-
const
|
|
600
|
+
const estimate = estimateHours(countedEvents).hours[person] ?? {};
|
|
601
|
+
const allActivity = estimateHours(activityEvents).hours[person] ?? {};
|
|
602
|
+
const summary = slugs
|
|
494
603
|
.map((slug) => {
|
|
495
604
|
const { byMonth, total } = roundMonths(estimate[slug]);
|
|
496
605
|
return {
|
|
497
606
|
slug,
|
|
498
607
|
known: known.has(slug) || slug === UNATTRIBUTED_SLUG,
|
|
499
608
|
activeMinutes: minutes[slug]?.length ?? 0,
|
|
609
|
+
automationMinutes: automationMinutes[slug]?.length ?? 0,
|
|
500
610
|
hoursByMonth: byMonth,
|
|
501
611
|
hoursTotal: total,
|
|
612
|
+
hoursAllActivity: roundMonths(allActivity[slug]).total,
|
|
502
613
|
};
|
|
503
614
|
})
|
|
504
|
-
.sort((a, b) => b.hoursTotal - a.hoursTotal ||
|
|
615
|
+
.sort((a, b) => b.hoursTotal - a.hoursTotal ||
|
|
616
|
+
b.hoursAllActivity - a.hoursAllActivity ||
|
|
617
|
+
a.slug.localeCompare(b.slug));
|
|
505
618
|
return {
|
|
506
619
|
schema: HOURS_EXPORT_SCHEMA,
|
|
507
620
|
person,
|
|
@@ -516,8 +629,10 @@ export async function exportClaudeHours(options) {
|
|
|
516
629
|
lines,
|
|
517
630
|
},
|
|
518
631
|
minutes,
|
|
632
|
+
automationMinutes,
|
|
519
633
|
summary,
|
|
520
634
|
skippedSessions,
|
|
635
|
+
unmarkedSessions,
|
|
521
636
|
unreadableSessions,
|
|
522
637
|
};
|
|
523
638
|
}
|
|
@@ -5,10 +5,20 @@ export interface ClientLinearCreateIssueInput {
|
|
|
5
5
|
title: string;
|
|
6
6
|
/** Optional markdown body. */
|
|
7
7
|
description?: string;
|
|
8
|
+
/**
|
|
9
|
+
* Optional workspace/team label NAMES to attach (exact, case-insensitive).
|
|
10
|
+
* Resolved to ids before the create; an unknown name fails the whole call
|
|
11
|
+
* rather than silently filing an unlabeled issue — a caller that asks for
|
|
12
|
+
* "Waiting on client" is relying on that label to drive a follow-up loop.
|
|
13
|
+
*/
|
|
14
|
+
labelNames?: string[];
|
|
8
15
|
}
|
|
9
16
|
export interface ClientLinearCreateIssueResult {
|
|
10
17
|
project: ProjectNode;
|
|
18
|
+
/** The team the issue landed in (the project's first team). */
|
|
19
|
+
teamId: string;
|
|
11
20
|
issue: {
|
|
21
|
+
id: string;
|
|
12
22
|
identifier: string;
|
|
13
23
|
title: string;
|
|
14
24
|
url: string;
|
|
@@ -7,11 +7,18 @@ const PROJECT_TEAMS_QUERY = `
|
|
|
7
7
|
}
|
|
8
8
|
}
|
|
9
9
|
`;
|
|
10
|
+
const LABELS_QUERY = `
|
|
11
|
+
query IssueLabelsByName($names: [String!]!) {
|
|
12
|
+
issueLabels(filter: { name: { in: $names } }, first: 50) {
|
|
13
|
+
nodes { id name }
|
|
14
|
+
}
|
|
15
|
+
}
|
|
16
|
+
`;
|
|
10
17
|
const CREATE_ISSUE_MUTATION = `
|
|
11
18
|
mutation CreateIssue($input: IssueCreateInput!) {
|
|
12
19
|
issueCreate(input: $input) {
|
|
13
20
|
success
|
|
14
|
-
issue { identifier title url }
|
|
21
|
+
issue { id identifier title url }
|
|
15
22
|
}
|
|
16
23
|
}
|
|
17
24
|
`;
|
|
@@ -36,11 +43,31 @@ export async function clientLinearCreateIssue(slug, input, options = {}) {
|
|
|
36
43
|
if (!teamId) {
|
|
37
44
|
throw new Error(`Linear project "${project.name}" has no team — can't create an issue without one.`);
|
|
38
45
|
}
|
|
46
|
+
const labelIds = await resolveLabelIds(fetchImpl, linearToken, input.labelNames ?? []);
|
|
39
47
|
const created = await linearRequest(fetchImpl, linearToken, CREATE_ISSUE_MUTATION, {
|
|
40
|
-
input: {
|
|
48
|
+
input: {
|
|
49
|
+
teamId,
|
|
50
|
+
projectId: project.id,
|
|
51
|
+
title,
|
|
52
|
+
...(description ? { description } : {}),
|
|
53
|
+
...(labelIds.length ? { labelIds } : {}),
|
|
54
|
+
},
|
|
41
55
|
});
|
|
42
56
|
if (!created.issueCreate.success || !created.issueCreate.issue) {
|
|
43
57
|
throw new Error(`Linear did not create the issue in "${project.name}" (success=false).`);
|
|
44
58
|
}
|
|
45
|
-
return { project, issue: created.issueCreate.issue };
|
|
59
|
+
return { project, teamId, issue: created.issueCreate.issue };
|
|
60
|
+
}
|
|
61
|
+
/** Label names → ids. Empty in, empty out (no request). Any unresolved name throws. */
|
|
62
|
+
async function resolveLabelIds(fetchImpl, token, names) {
|
|
63
|
+
const wanted = names.map((n) => n.trim()).filter(Boolean);
|
|
64
|
+
if (wanted.length === 0)
|
|
65
|
+
return [];
|
|
66
|
+
const result = await linearRequest(fetchImpl, token, LABELS_QUERY, { names: wanted });
|
|
67
|
+
const byName = new Map(result.issueLabels.nodes.map((n) => [n.name.toLowerCase(), n.id]));
|
|
68
|
+
const missing = wanted.filter((n) => !byName.has(n.toLowerCase()));
|
|
69
|
+
if (missing.length) {
|
|
70
|
+
throw new Error(`Linear has no label named ${missing.map((m) => `"${m}"`).join(", ")}.`);
|
|
71
|
+
}
|
|
72
|
+
return wanted.map((n) => byName.get(n.toLowerCase()));
|
|
46
73
|
}
|
package/dist/hours-ledger.d.ts
CHANGED
|
@@ -51,6 +51,12 @@ export interface HoursLedgerData {
|
|
|
51
51
|
claude_missing: string[];
|
|
52
52
|
/** person → last day their Claude Code data reaches. */
|
|
53
53
|
claude_through: Record<string, string>;
|
|
54
|
+
/**
|
|
55
|
+
* person → [first day, last day, minutes] of stored Claude Code minutes from
|
|
56
|
+
* an export older than the current schema (it also counted Claude running on
|
|
57
|
+
* its own). Kept and counted; their logs are gone, so they cannot be redone.
|
|
58
|
+
*/
|
|
59
|
+
claude_not_corrected: Record<string, [string, string, number]>;
|
|
54
60
|
/** source → last day of a source that only comes from frozen files. */
|
|
55
61
|
frozen_sources: Record<string, string>;
|
|
56
62
|
first_event: string | null;
|
|
@@ -58,6 +64,8 @@ export interface HoursLedgerData {
|
|
|
58
64
|
gap_min: number;
|
|
59
65
|
lead_heavy_min: number;
|
|
60
66
|
lead_light_min: number;
|
|
67
|
+
/** Claude Code minutes count only this long after the person's own action. */
|
|
68
|
+
prompt_window_min: number;
|
|
61
69
|
time_zone: string;
|
|
62
70
|
};
|
|
63
71
|
/** source → person → [first day, last day, event count]. */
|
package/dist/hours-ledger.js
CHANGED
|
@@ -3,7 +3,7 @@ import { existsSync, mkdirSync, readdirSync, readFileSync, writeFileSync } from
|
|
|
3
3
|
import { homedir } from "node:os";
|
|
4
4
|
import { basename, join, resolve } from "node:path";
|
|
5
5
|
import { promisify } from "node:util";
|
|
6
|
-
import { CLAUDE_CONFIG_DIR_ENV, exportClaudeHours, HOURS_EXPORT_SCHEMA, parseLedgerDate, parseMinuteIso, UNATTRIBUTED_SLUG, } from "./claude-hours.js";
|
|
6
|
+
import { CLAUDE_CONFIG_DIR_ENV, exportClaudeHours, HOURS_EXPORT_SCHEMA, PROMPT_WINDOW_MINUTES, parseLedgerDate, parseMinuteIso, UNATTRIBUTED_SLUG, } from "./claude-hours.js";
|
|
7
7
|
import { AIRTABLE_API_TOKEN_ENV, DEFAULT_AIRTABLE_BASE_ID, DEFAULT_AIRTABLE_TABLE_ID, } from "./client-drive.js";
|
|
8
8
|
import { parseLinearProjectSlugId } from "./client-linear.js";
|
|
9
9
|
import { findWorkspaceRoot } from "./env-file.js";
|
|
@@ -474,9 +474,40 @@ function mergeExport(store, exported, file, nowIso) {
|
|
|
474
474
|
store.minutes = merged;
|
|
475
475
|
const from = new Date(fromMinute * 60_000).toISOString();
|
|
476
476
|
const to = new Date(toMs).toISOString();
|
|
477
|
-
store.coverage.push({ from, to, file, ingestedAt: nowIso });
|
|
477
|
+
store.coverage.push({ from, to, file, ingestedAt: nowIso, schema: exported.schema });
|
|
478
478
|
return { person: store.person, file, from, to, minutes: added };
|
|
479
479
|
}
|
|
480
|
+
/**
|
|
481
|
+
* Stored minutes no current-schema export has covered: they came from an
|
|
482
|
+
* older export that also counted Claude running on its own (loops, wake-ups,
|
|
483
|
+
* background tasks), and the logs that could correct them are gone. Kept and
|
|
484
|
+
* counted, but named so nobody mistakes them for checked time.
|
|
485
|
+
*/
|
|
486
|
+
function notCorrected(store, window) {
|
|
487
|
+
const checked = store.coverage
|
|
488
|
+
.filter((range) => range.schema === HOURS_EXPORT_SCHEMA)
|
|
489
|
+
.map((range) => ({ from: Date.parse(range.from), to: Date.parse(range.to) }));
|
|
490
|
+
let first = null;
|
|
491
|
+
let last = null;
|
|
492
|
+
let count = 0;
|
|
493
|
+
for (const list of Object.values(store.minutes)) {
|
|
494
|
+
for (const minute of list) {
|
|
495
|
+
const ms = parseMinuteIso(minute);
|
|
496
|
+
if (ms < window.sinceMs || ms > window.untilMs)
|
|
497
|
+
continue;
|
|
498
|
+
if (checked.some((range) => ms >= range.from && ms <= range.to))
|
|
499
|
+
continue;
|
|
500
|
+
count += 1;
|
|
501
|
+
if (first === null || ms < first)
|
|
502
|
+
first = ms;
|
|
503
|
+
if (last === null || ms > last)
|
|
504
|
+
last = ms;
|
|
505
|
+
}
|
|
506
|
+
}
|
|
507
|
+
if (first === null || last === null)
|
|
508
|
+
return null;
|
|
509
|
+
return [ledgerDay(first), ledgerDay(last), count];
|
|
510
|
+
}
|
|
480
511
|
// ---------- frozen CSV sources ----------
|
|
481
512
|
/** Minimal RFC 4180 reader — the frozen files come from Python's csv writer. */
|
|
482
513
|
function parseCsv(text) {
|
|
@@ -647,7 +678,8 @@ export async function buildHoursLedger(options = {}) {
|
|
|
647
678
|
};
|
|
648
679
|
const ingest = (exported, file) => {
|
|
649
680
|
if (exported.schema !== HOURS_EXPORT_SCHEMA) {
|
|
650
|
-
warnings.push(`${basename(file)} was made by an older \`ia hours-export\` (
|
|
681
|
+
warnings.push(`${basename(file)} was made by an older \`ia hours-export\` (${exported.schema ?? "no schema"}, ` +
|
|
682
|
+
`which counts Claude running on its own as work) — skipped; ask ` +
|
|
651
683
|
`${exported.person ?? "its sender"} to update team-tools and run it again`);
|
|
652
684
|
return;
|
|
653
685
|
}
|
|
@@ -710,6 +742,12 @@ export async function buildHoursLedger(options = {}) {
|
|
|
710
742
|
}
|
|
711
743
|
}
|
|
712
744
|
}
|
|
745
|
+
const claudeNotCorrected = {};
|
|
746
|
+
for (const person of people) {
|
|
747
|
+
const range = notCorrected(storeFor(person), { sinceMs, untilMs });
|
|
748
|
+
if (range)
|
|
749
|
+
claudeNotCorrected[person] = range;
|
|
750
|
+
}
|
|
713
751
|
log.debug("sources-start", { repos: repos.length, buildSlugs: buildSlugs.length });
|
|
714
752
|
const [crm, git, linear] = await Promise.all([
|
|
715
753
|
loadCrm(fetchImpl, airtableToken, matchPerson),
|
|
@@ -822,12 +860,14 @@ export async function buildHoursLedger(options = {}) {
|
|
|
822
860
|
people,
|
|
823
861
|
claude_missing: people.filter((person) => !claudeThrough[person]),
|
|
824
862
|
claude_through: claudeThrough,
|
|
863
|
+
claude_not_corrected: claudeNotCorrected,
|
|
825
864
|
frozen_sources: frozenSources,
|
|
826
865
|
first_event: firstTs === null ? null : ledgerDay(firstTs),
|
|
827
866
|
rules: {
|
|
828
867
|
gap_min: SESSION_GAP_MINUTES,
|
|
829
868
|
lead_heavy_min: LEAD_HEAVY_MINUTES,
|
|
830
869
|
lead_light_min: LEAD_LIGHT_MINUTES,
|
|
870
|
+
prompt_window_min: PROMPT_WINDOW_MINUTES,
|
|
831
871
|
time_zone: LEDGER_TIME_ZONE,
|
|
832
872
|
},
|
|
833
873
|
source_ranges: sourceRanges,
|
|
@@ -857,6 +897,10 @@ export async function buildHoursLedger(options = {}) {
|
|
|
857
897
|
warnings.push(`claude: no Claude Code data yet for ${data.claude_missing.join(", ")} — they run ` +
|
|
858
898
|
`\`ia hours-export --person <Name>\` and send the file; drop it in ${inboxDir}`);
|
|
859
899
|
}
|
|
900
|
+
for (const [person, [from, to, minutes]] of Object.entries(claudeNotCorrected)) {
|
|
901
|
+
warnings.push(`claude: ${person}'s ${minutes} minute(s) from ${from} to ${to} come from an older export ` +
|
|
902
|
+
"that also counted Claude running on its own — kept, not corrected (those logs are gone)");
|
|
903
|
+
}
|
|
860
904
|
for (const [person, day] of Object.entries(claudeThrough)) {
|
|
861
905
|
if (Date.parse(`${generated}T12:00:00Z`) - Date.parse(`${day}T12:00:00Z`) >
|
|
862
906
|
STALE_CLAUDE_DAYS * DAY_MS) {
|
package/dist/index.d.ts
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
export { type AgentMirrorOptions, type AgentMirrorResult, checkAgentMirror, type MirrorRow, type MirrorState, type MirrorSummary, } from "./agent-mirror.js";
|
|
2
2
|
export { type AgentBankOptions, type AgentTemplateInfo, type AgentTemplateMatch, type CreateFromTemplateInput, type CreateFromTemplateResult, createFromAgentTemplate, type ListAgentTemplatesResult, listAgentTemplates, N8N_API_KEY_ENV, N8N_API_URL_ENV, N8nAuthError, type SanitizedWorkflow, type SaveAgentTemplateInput, type SaveAgentTemplateOptions, type SaveAgentTemplateResult, type SearchAgentTemplatesOptions, type SearchAgentTemplatesResult, type SopState, type StrippedCredential, sanitizeN8nWorkflow, saveAgentTemplate, searchAgentTemplates, } from "./agent-templates.js";
|
|
3
|
-
export { CLAUDE_CONFIG_DIR_ENV, type ClaudeHoursExportOptions, type ClaudeHoursExportResult, type ClaudeHoursSummaryRow, compactClaudeHoursExport, type DeliverClaudeHoursExportOptions, type DeliverClaudeHoursExportResult, deliverClaudeHoursExport, exportClaudeHours, HOURS_EXPORT_DIR, HOURS_EXPORT_SCHEMA, HOURS_EXPORT_SECRET_ENV, HOURS_EXPORT_SECRET_HEADER, HOURS_EXPORT_WEBHOOK_URL, parseLedgerDate, parseMinuteIso, type SaveClaudeHoursExportOptions, type SendClaudeHoursExportOptions, saveClaudeHoursExport, sendClaudeHoursExport, TOOL_INPUT_PATH_KEYS, UNATTRIBUTED_SLUG, } from "./claude-hours.js";
|
|
3
|
+
export { CLAUDE_CONFIG_DIR_ENV, type ClaudeHoursExportOptions, type ClaudeHoursExportResult, type ClaudeHoursSummaryRow, compactClaudeHoursExport, type DeliverClaudeHoursExportOptions, type DeliverClaudeHoursExportResult, deliverClaudeHoursExport, exportClaudeHours, HOURS_EXPORT_DIR, HOURS_EXPORT_SCHEMA, HOURS_EXPORT_SECRET_ENV, HOURS_EXPORT_SECRET_HEADER, HOURS_EXPORT_WEBHOOK_URL, PROMPT_WINDOW_MINUTES, parseLedgerDate, parseMinuteIso, type SaveClaudeHoursExportOptions, type SendClaudeHoursExportOptions, saveClaudeHoursExport, sendClaudeHoursExport, TOOL_INPUT_PATH_KEYS, UNATTRIBUTED_SLUG, } from "./claude-hours.js";
|
|
4
4
|
export { ClientBuildAuthError, type ClientBuildDoc, type ClientBuildOptions, type ClientBuildResult, clientBuild, GITHUB_API_TOKEN_ENV, } from "./client-build.js";
|
|
5
5
|
export { type ClientCall, type ClientContextOptions, type ClientContextResult, clientContext, } from "./client-context.js";
|
|
6
6
|
export { AIRTABLE_API_TOKEN_ENV, buildAssertionClaims, ClientDriveAuthError, type ClientDriveDoc, type ClientDriveSearchOptions, type ClientDriveSearchResult, clientDriveSearch, GOOGLE_SERVICE_ACCOUNT_KEY_ENV, parseServiceAccountKey, } from "./client-drive.js";
|
|
@@ -23,7 +23,7 @@ export { type ActivityEvent, type EstimateHoursOptions, estimateHours, HOURS_SOU
|
|
|
23
23
|
export { type HoursExportScheduleOptions, type HoursExportScheduleResult, installHoursExportSchedule, type UninstallHoursExportScheduleOptions, uninstallHoursExportSchedule, } from "./hours-export-schedule.js";
|
|
24
24
|
export { buildHoursLedger, CLIENT_FIELDS, DEFAULT_HOURS_LEDGER_DIR, type HoursLedgerConfig, type HoursLedgerData, type HoursLedgerIngest, type HoursLedgerOptions, type HoursLedgerPersonTotal, type HoursLedgerResult, type HoursLedgerRow, identityMatches, LEDGER_WINDOW_START, OTHER_LEAD_SLUG, TEAM_FIELDS, } from "./hours-ledger.js";
|
|
25
25
|
export { CLIENT_TEMPLATE_URL, type InitStep, type InitWorkspaceOptions, type InitWorkspaceResult, initWorkspace, MCP_RECOMMENDATIONS, type McpRecommendation, TEAM_CLIENTS_URL, } from "./init.js";
|
|
26
|
-
export { findProjectBySlugId, LINEAR_API_TOKEN_ENV, LinearAuthError, type LinearIssue, LinearProjectNotFoundError, type LinearProjectOptions, type LinearProjectResult, linearProject, linearProjectIssues, type ProjectNode, } from "./linear-project.js";
|
|
26
|
+
export { findProjectBySlugId, LINEAR_API_TOKEN_ENV, LinearAuthError, type LinearIssue, LinearProjectNotFoundError, type LinearProjectOptions, type LinearProjectResult, linearProject, linearProjectIssues, linearRequest, type ProjectNode, } from "./linear-project.js";
|
|
27
27
|
export { type CreateLoggerOptions, createLogger, type LogFields, type Logger, type LogLevel, redactFields, } from "./log.js";
|
|
28
28
|
export { type ExtractNodeOutputsOptions, extractNodeOutputs, listN8nExecutions, listNodesRun, type N8nExecutionDetail, type N8nExecutionStatus, type N8nExecutionSummary, type N8nExecutionsInput, type N8nExecutionsOptions, type N8nExecutionsResult, type N8nNodeOutput, unflattenExecutionData, } from "./n8n-executions.js";
|
|
29
29
|
export { type NewClientOptions, type NewClientResult, newClient, SLUG_PATTERN, } from "./new-client.js";
|
package/dist/index.js
CHANGED
|
@@ -3,7 +3,7 @@
|
|
|
3
3
|
// reachable from both. See ../../docs/spec.md.
|
|
4
4
|
export { checkAgentMirror, } from "./agent-mirror.js";
|
|
5
5
|
export { createFromAgentTemplate, listAgentTemplates, N8N_API_KEY_ENV, N8N_API_URL_ENV, N8nAuthError, sanitizeN8nWorkflow, saveAgentTemplate, searchAgentTemplates, } from "./agent-templates.js";
|
|
6
|
-
export { CLAUDE_CONFIG_DIR_ENV, compactClaudeHoursExport, deliverClaudeHoursExport, exportClaudeHours, HOURS_EXPORT_DIR, HOURS_EXPORT_SCHEMA, HOURS_EXPORT_SECRET_ENV, HOURS_EXPORT_SECRET_HEADER, HOURS_EXPORT_WEBHOOK_URL, parseLedgerDate, parseMinuteIso, saveClaudeHoursExport, sendClaudeHoursExport, TOOL_INPUT_PATH_KEYS, UNATTRIBUTED_SLUG, } from "./claude-hours.js";
|
|
6
|
+
export { CLAUDE_CONFIG_DIR_ENV, compactClaudeHoursExport, deliverClaudeHoursExport, exportClaudeHours, HOURS_EXPORT_DIR, HOURS_EXPORT_SCHEMA, HOURS_EXPORT_SECRET_ENV, HOURS_EXPORT_SECRET_HEADER, HOURS_EXPORT_WEBHOOK_URL, PROMPT_WINDOW_MINUTES, parseLedgerDate, parseMinuteIso, saveClaudeHoursExport, sendClaudeHoursExport, TOOL_INPUT_PATH_KEYS, UNATTRIBUTED_SLUG, } from "./claude-hours.js";
|
|
7
7
|
export { ClientBuildAuthError, clientBuild, GITHUB_API_TOKEN_ENV, } from "./client-build.js";
|
|
8
8
|
export { clientContext, } from "./client-context.js";
|
|
9
9
|
export { AIRTABLE_API_TOKEN_ENV, buildAssertionClaims, ClientDriveAuthError, clientDriveSearch, GOOGLE_SERVICE_ACCOUNT_KEY_ENV, parseServiceAccountKey, } from "./client-drive.js";
|
|
@@ -26,7 +26,7 @@ export { estimateHours, HOURS_SOURCES, LEAD_HEAVY_MINUTES, LEAD_LIGHT_MINUTES, L
|
|
|
26
26
|
export { installHoursExportSchedule, uninstallHoursExportSchedule, } from "./hours-export-schedule.js";
|
|
27
27
|
export { buildHoursLedger, CLIENT_FIELDS, DEFAULT_HOURS_LEDGER_DIR, identityMatches, LEDGER_WINDOW_START, OTHER_LEAD_SLUG, TEAM_FIELDS, } from "./hours-ledger.js";
|
|
28
28
|
export { CLIENT_TEMPLATE_URL, initWorkspace, MCP_RECOMMENDATIONS, TEAM_CLIENTS_URL, } from "./init.js";
|
|
29
|
-
export { findProjectBySlugId, LINEAR_API_TOKEN_ENV, LinearAuthError, LinearProjectNotFoundError, linearProject, linearProjectIssues, } from "./linear-project.js";
|
|
29
|
+
export { findProjectBySlugId, LINEAR_API_TOKEN_ENV, LinearAuthError, LinearProjectNotFoundError, linearProject, linearProjectIssues, linearRequest, } from "./linear-project.js";
|
|
30
30
|
export { createLogger, redactFields, } from "./log.js";
|
|
31
31
|
export { extractNodeOutputs, listN8nExecutions, listNodesRun, unflattenExecutionData, } from "./n8n-executions.js";
|
|
32
32
|
export { newClient, SLUG_PATTERN, } from "./new-client.js";
|
package/package.json
CHANGED
|
@@ -29,7 +29,7 @@ installagent/
|
|
|
29
29
|
│ ├── client-template/ # THE baseline — every client repo is created from this
|
|
30
30
|
│ └── client-<slug>/ # e.g. client-carvision, client-kingdom, …
|
|
31
31
|
├── team-clients/ # Client REGISTRY (CRM-as-code): who each client is + call history (PRIVATE, PII allowed)
|
|
32
|
-
├── team-infra/ # AWS CDK hosting (n8n, SFTP), the n8n workflow library, shared automation skills
|
|
32
|
+
├── team-infra/ # AWS CDK hosting (n8n, SFTP), the n8n workflow library, shared automation skills, the pdf compress service
|
|
33
33
|
├── team-web/ # Public web: installagent.com (apps/web) + team hub (apps/docs)
|
|
34
34
|
├── team-design/ # Install Agent design system source (tokens, components, guidelines)
|
|
35
35
|
├── team-branding/ # Logo files (static assets only)
|
|
@@ -49,6 +49,7 @@ installagent/
|
|
|
49
49
|
| Answer "what did we ship for X / does it work?" | `clients/client-<slug>/docs/00-delivery-log.md` + `evidence/` | same |
|
|
50
50
|
| Check or change deal status | **Airtable (`Clients - Master`)** — never a file in git | — |
|
|
51
51
|
| Build or edit an n8n workflow (ours or a client's) | **check `agents/` (the bank) first**, then the client repo's `workflows/` or `team-infra/n8n-workflows/` | `agents/README.md` + `team-infra/skills/n8n-workflow.md` |
|
|
52
|
+
| An n8n workflow sends a PDF on to a size-capped step (a Vercel app, an email, an LLM, a vendor upload) | the **`pdf` compress service** on the n8n box (`http://pdf:8080`): compress first, keep the size gate, keep the original on any error | `team-infra/skills/n8n-workflow.md` § 3 + `team-infra/pdf-service/README.md` |
|
|
52
53
|
| See what automations we can redeploy / scope a deal against them | `agents/` — catalog table in its README, plain-language `template.md` per template | `agents/README.md` |
|
|
53
54
|
| Reuse or bank a workflow template (`ia agent save\|templates\|create`) | `agents/` | `agents/AGENT.md` |
|
|
54
55
|
| Infra (n8n hosting, SFTP, AWS) | `team-infra/` | `team-infra/AGENT.md` |
|
|
@@ -128,7 +128,7 @@ installagent/
|
|
|
128
128
|
├── agents/ # the WORKFLOW BANK — reusable n8n templates + plain-language manifests
|
|
129
129
|
├── clients/ # one build repo per client + client-template (the baseline)
|
|
130
130
|
├── team-clients/ # client REGISTRY: who each client is + call history (private, PII allowed)
|
|
131
|
-
├── team-infra/ # AWS hosting (n8n, SFTP), n8n workflow library, automation skills
|
|
131
|
+
├── team-infra/ # AWS hosting (n8n, SFTP), n8n workflow library, automation skills, pdf compress service
|
|
132
132
|
├── team-web/ # installagent.com + team hub (Next.js pnpm workspace)
|
|
133
133
|
├── team-design/ # Install Agent design system source
|
|
134
134
|
├── team-branding/ # logo files
|
|
@@ -1,7 +1,8 @@
|
|
|
1
1
|
name: PR → Slack (approve / close)
|
|
2
2
|
|
|
3
3
|
# Posts every new PR to Slack (as @Agent Zero) with "Merge" and "Close"
|
|
4
|
-
# buttons
|
|
4
|
+
# buttons — except new-lead `add-client/*` PRs (see the job's `if:`).
|
|
5
|
+
# This workflow only POSTS (it is read-only). The button clicks are
|
|
5
6
|
# handled by @Agent Zero itself — team-tools/apps/slack-agent, Bolt Socket
|
|
6
7
|
# Mode, the `pr_merge`/`pr_close` action handlers in src/app.ts — which
|
|
7
8
|
# squash-merges (or closes) via the GitHub API using its own write-scoped
|
|
@@ -38,7 +39,11 @@ jobs:
|
|
|
38
39
|
notify:
|
|
39
40
|
# Drafts are not ready to review, and skipping them also stops the
|
|
40
41
|
# duplicate post a draft would otherwise make on opened + ready_for_review.
|
|
41
|
-
|
|
42
|
+
# `add-client/*` branches are new-lead PRs (n8n "New lead v3" opens them
|
|
43
|
+
# in team-clients). Their Merge/Close buttons live on the lead card in
|
|
44
|
+
# #notify-leads (`lead_pr_merge`/`lead_pr_close`), so they skip
|
|
45
|
+
# #notify-prs. Every other branch, `add-call/*` included, still posts.
|
|
46
|
+
if: github.event.pull_request.draft == false && !startsWith(github.event.pull_request.head.ref, 'add-client/')
|
|
42
47
|
runs-on: ubuntu-latest
|
|
43
48
|
steps:
|
|
44
49
|
- name: Post PR to Slack with action buttons
|