@installagent/sdk 0.1.0 → 0.2.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.
Files changed (80) hide show
  1. package/dist/agent-templates.d.ts +36 -2
  2. package/dist/agent-templates.js +173 -3
  3. package/dist/client-linear-create.d.ts +26 -0
  4. package/dist/client-linear-create.js +46 -0
  5. package/dist/client-linear.d.ts +28 -9
  6. package/dist/client-linear.js +36 -14
  7. package/dist/docs-search.d.ts +19 -6
  8. package/dist/docs-search.js +32 -11
  9. package/dist/doctor.d.ts +9 -0
  10. package/dist/doctor.js +126 -23
  11. package/dist/env-fill.d.ts +13 -0
  12. package/dist/env-fill.js +34 -9
  13. package/dist/env-push.d.ts +3 -0
  14. package/dist/env-push.js +11 -6
  15. package/dist/env-registry.d.ts +25 -0
  16. package/dist/env-registry.js +69 -7
  17. package/dist/exec.js +15 -2
  18. package/dist/index.d.ts +14 -6
  19. package/dist/index.js +14 -6
  20. package/dist/linear-project.d.ts +2 -2
  21. package/dist/linear-project.js +2 -2
  22. package/dist/log.d.ts +28 -0
  23. package/dist/log.js +73 -0
  24. package/dist/n8n-executions.d.ts +85 -0
  25. package/dist/n8n-executions.js +259 -0
  26. package/dist/op-cli.d.ts +29 -0
  27. package/dist/op-cli.js +52 -0
  28. package/dist/platform.d.ts +35 -0
  29. package/dist/platform.js +39 -0
  30. package/dist/portal-admin.d.ts +40 -0
  31. package/dist/portal-admin.js +30 -0
  32. package/dist/standup.d.ts +88 -0
  33. package/dist/standup.js +235 -0
  34. package/dist/sync-repos.d.ts +47 -0
  35. package/dist/sync-repos.js +80 -0
  36. package/dist/template-sync.d.ts +10 -0
  37. package/dist/template-sync.js +11 -0
  38. package/dist/wizard.d.ts +15 -0
  39. package/dist/wizard.js +35 -56
  40. package/dist/workspace-docs.d.ts +44 -0
  41. package/dist/workspace-docs.js +73 -0
  42. package/package.json +2 -2
  43. package/templates/env.example +33 -23
  44. package/templates/workspace-root/AGENT.md +7 -5
  45. package/templates/workspace-root/ONBOARDING.md +65 -8
  46. package/templates/workspace-root/skills/.github/workflows/pr-to-slack.yml +102 -0
  47. package/templates/workspace-root/skills/CLAUDE.md +24 -6
  48. package/templates/workspace-root/skills/README.md +156 -0
  49. package/templates/workspace-root/skills/backtest-acceptance-gates/SKILL.md +293 -0
  50. package/templates/workspace-root/skills/backtest-acceptance-gates/backtest-acceptance-gates-guide.pdf +0 -0
  51. package/templates/workspace-root/skills/backtest-acceptance-gates/references/evidence-record-template.md +128 -0
  52. package/templates/workspace-root/skills/backtest-acceptance-gates/references/harness-checklist.md +90 -0
  53. package/templates/workspace-root/skills/client-latest/SKILL.md +301 -0
  54. package/templates/workspace-root/skills/client-latest/catchup.command.md +17 -0
  55. package/templates/workspace-root/skills/cloud-devops/SKILL.md +235 -0
  56. package/templates/workspace-root/skills/email-triage-rollout/SKILL.md +181 -0
  57. package/templates/workspace-root/skills/gcloud-cli-setup/SKILL.md +100 -0
  58. package/templates/workspace-root/skills/google-chat-app-setup/SKILL.md +136 -0
  59. package/templates/workspace-root/skills/google-chat-app-setup/google-chat-app-setup-guide.pdf +0 -0
  60. package/templates/workspace-root/skills/house-voice/SKILL.md +80 -4
  61. package/templates/workspace-root/skills/ia-cli/SKILL.md +19 -6
  62. package/templates/workspace-root/skills/installagent-brand-kit/SKILL.md +59 -10
  63. package/templates/workspace-root/skills/installagent-brand-kit/assets/installagent-deck-template.pptx +0 -0
  64. package/templates/workspace-root/skills/installagent-brand-kit/references/deck-guide.md +181 -0
  65. package/templates/workspace-root/skills/installagent-brand-kit/scripts/deck.py +652 -0
  66. package/templates/workspace-root/skills/installagent-brand-kit/scripts/deck_lint.py +201 -0
  67. package/templates/workspace-root/skills/installagent-brand-kit/scripts/logo_raster.py +102 -0
  68. package/templates/workspace-root/skills/installagent-brand-kit/scripts/make_deck_template.py +290 -0
  69. package/templates/workspace-root/skills/salesforce-api-snapshot/SKILL.md +379 -0
  70. package/templates/workspace-root/skills/salesforce-api-snapshot/references/schema-discovery-soql.md +153 -0
  71. package/templates/workspace-root/skills/salesforce-api-snapshot/references/snapshot-storage.md +122 -0
  72. package/templates/workspace-root/skills/salesforce-api-snapshot/salesforce-api-snapshot-guide.pdf +0 -0
  73. package/templates/workspace-root/skills/slack-voice/SKILL.md +158 -0
  74. package/templates/workspace-root/skills/sso-gated-client-app/SKILL.md +337 -0
  75. package/templates/workspace-root/skills/sso-gated-client-app/sso-gated-client-app-guide.pdf +0 -0
  76. package/templates/workspace-root/skills/tech-call-prep/SKILL.md +146 -47
  77. package/templates/workspace-root/skills/vendor-feed-ingestion/SKILL.md +323 -0
  78. package/templates/workspace-root/skills/vendor-feed-ingestion/references/delivery-contract-template.md +110 -0
  79. package/templates/workspace-root/skills/vendor-feed-ingestion/references/feed-guards.md +134 -0
  80. package/templates/workspace-root/skills/vendor-feed-ingestion/vendor-feed-ingestion-guide.pdf +0 -0
package/dist/op-cli.js ADDED
@@ -0,0 +1,52 @@
1
+ /**
2
+ * The one remedy for every "op isn't usable" path — shared by `ia doctor`,
3
+ * `ia env fill`, `ia env push` and the wizard's next steps, so the advice
4
+ * can't drift between them.
5
+ *
6
+ * Deliberately does NOT tell anyone to run `op signin`. A session from
7
+ * `eval $(op signin)` lives in the environment of the single shell that
8
+ * created it, so `ia env fill` succeeds in that one window and reports every
9
+ * shared var as `not-in-vault` in any other — indistinguishable from never
10
+ * having been granted the vault. The desktop app integration authenticates op
11
+ * in every shell instead. It is 1Password 8 only: v7 has no Developer tab and
12
+ * fails with "operation not supported by device".
13
+ *
14
+ * Platform-aware because the macOS advice is actively wrong on Windows:
15
+ * 1Password documents PowerShell as the ONLY supported Windows shell, so the
16
+ * desktop-app integration cannot authenticate `op` from Git Bash at all. A
17
+ * technician following `brew install` text on Windows loses an hour finding
18
+ * that out. See platform.ts for why we don't try to tell PowerShell from cmd.
19
+ */
20
+ import { detectPlatformInfo, opNeedsAnotherShell } from "./platform.js";
21
+ const V8_NOTE = 'tick "Integrate with 1Password CLI" (v7 has no Developer tab — install v8 from 1password.com/downloads)';
22
+ const NO_SIGNIN_NOTE = "Don't rely on `op signin` alone — it scopes the session to the one shell that ran it";
23
+ /**
24
+ * How to make `op` authenticate in every shell on this machine. Callers pass
25
+ * the detected platform; omit it and the running machine is used.
26
+ */
27
+ export function opIntegrationFix(info = detectPlatformInfo()) {
28
+ if (opNeedsAnotherShell(info)) {
29
+ return ("`op` cannot reach the 1Password desktop app from Git Bash — 1Password supports PowerShell only on " +
30
+ "Windows. Re-run this command in PowerShell. In the 1Password 8 desktop app go to Settings → Developer and " +
31
+ `${V8_NOTE}, then \`op whoami\` works in any PowerShell window. ${NO_SIGNIN_NOTE}`);
32
+ }
33
+ if (info.platform === "win32") {
34
+ return ("turn on the desktop app integration (1Password 8 → Settings → Developer → " +
35
+ `${V8_NOTE}; Settings → Security → Windows Hello unlock makes it seamless), then \`op whoami\` works in ` +
36
+ `every PowerShell window. ${NO_SIGNIN_NOTE}`);
37
+ }
38
+ return ("turn on the desktop app integration (1Password 8 → Settings → Developer → " +
39
+ `${V8_NOTE}), then \`op whoami\` works in every shell. ${NO_SIGNIN_NOTE}`);
40
+ }
41
+ /** Same, prefixed with the install step, for when op isn't on PATH at all. */
42
+ export function opInstallFix(info = detectPlatformInfo()) {
43
+ return `install the 1Password CLI (${opInstallCommand(info)}), then ${opIntegrationFix(info)}`;
44
+ }
45
+ /** The package-manager one-liner that puts `op` on PATH for this platform. */
46
+ export function opInstallCommand(info = detectPlatformInfo()) {
47
+ if (info.platform === "win32")
48
+ return "`winget install 1password-cli` from PowerShell";
49
+ if (info.platform === "linux")
50
+ return "see 1password.com/downloads/linux";
51
+ return "`brew install 1password-cli`";
52
+ }
@@ -0,0 +1,35 @@
1
+ /**
2
+ * Which machine (and which shell) an `ia` command is running on, so fix-it
3
+ * text can name the right installer and the right terminal instead of always
4
+ * saying `brew`.
5
+ *
6
+ * Deliberately narrow. The only shell distinction that changes any advice is
7
+ * Git Bash on Windows: 1Password's own docs list PowerShell as the sole
8
+ * supported Windows shell, so the desktop-app CLI integration cannot
9
+ * authenticate `op` from an MSYS shell. Everything else (PowerShell, cmd,
10
+ * Windows Terminal) behaves the same for our purposes, so we do not guess
11
+ * between them — there is no reliable env marker that separates PowerShell
12
+ * from cmd, and a wrong guess would print worse advice than none.
13
+ */
14
+ export type Platform = "darwin" | "win32" | "linux";
15
+ /**
16
+ * `gitbash` — an MSYS/MinGW bash on Windows, where `op` cannot reach the
17
+ * desktop app. `windows-native` — PowerShell or cmd, where it can.
18
+ * `posix` — macOS or Linux.
19
+ */
20
+ export type Shell = "gitbash" | "windows-native" | "posix";
21
+ export interface PlatformInfo {
22
+ platform: Platform;
23
+ shell: Shell;
24
+ }
25
+ /** Anything that isn't macOS or Windows is treated as Linux. */
26
+ export declare function detectPlatform(platformImpl?: string): Platform;
27
+ /**
28
+ * Git Bash sets MSYSTEM (MINGW64, MINGW32, MSYS) — it is the marker Git for
29
+ * Windows itself uses, and the only one present in every MSYS shell whether
30
+ * launched from the Start menu, a terminal profile, or an IDE.
31
+ */
32
+ export declare function detectShell(platform: Platform, env?: Record<string, string | undefined>): Shell;
33
+ export declare function detectPlatformInfo(env?: Record<string, string | undefined>, platformImpl?: string): PlatformInfo;
34
+ /** True when `op` cannot reach the 1Password desktop app from this shell. */
35
+ export declare function opNeedsAnotherShell(info: PlatformInfo): boolean;
@@ -0,0 +1,39 @@
1
+ /**
2
+ * Which machine (and which shell) an `ia` command is running on, so fix-it
3
+ * text can name the right installer and the right terminal instead of always
4
+ * saying `brew`.
5
+ *
6
+ * Deliberately narrow. The only shell distinction that changes any advice is
7
+ * Git Bash on Windows: 1Password's own docs list PowerShell as the sole
8
+ * supported Windows shell, so the desktop-app CLI integration cannot
9
+ * authenticate `op` from an MSYS shell. Everything else (PowerShell, cmd,
10
+ * Windows Terminal) behaves the same for our purposes, so we do not guess
11
+ * between them — there is no reliable env marker that separates PowerShell
12
+ * from cmd, and a wrong guess would print worse advice than none.
13
+ */
14
+ /** Anything that isn't macOS or Windows is treated as Linux. */
15
+ export function detectPlatform(platformImpl = process.platform) {
16
+ if (platformImpl === "darwin")
17
+ return "darwin";
18
+ if (platformImpl === "win32")
19
+ return "win32";
20
+ return "linux";
21
+ }
22
+ /**
23
+ * Git Bash sets MSYSTEM (MINGW64, MINGW32, MSYS) — it is the marker Git for
24
+ * Windows itself uses, and the only one present in every MSYS shell whether
25
+ * launched from the Start menu, a terminal profile, or an IDE.
26
+ */
27
+ export function detectShell(platform, env = process.env) {
28
+ if (platform !== "win32")
29
+ return "posix";
30
+ return typeof env.MSYSTEM === "string" && env.MSYSTEM.length > 0 ? "gitbash" : "windows-native";
31
+ }
32
+ export function detectPlatformInfo(env = process.env, platformImpl = process.platform) {
33
+ const platform = detectPlatform(platformImpl);
34
+ return { platform, shell: detectShell(platform, env) };
35
+ }
36
+ /** True when `op` cannot reach the 1Password desktop app from this shell. */
37
+ export function opNeedsAnotherShell(info) {
38
+ return info.shell === "gitbash";
39
+ }
@@ -92,6 +92,34 @@ export interface PortalSetAgentStatusResult {
92
92
  agent: string;
93
93
  status: "active" | "paused" | "retired";
94
94
  }
95
+ export interface PortalSetAgentNameInput {
96
+ slug: string;
97
+ agent: string;
98
+ /** The client-facing label on the agent card. */
99
+ name: string;
100
+ }
101
+ export interface PortalSetAgentNameResult {
102
+ org: string;
103
+ agent: string;
104
+ previousName: string;
105
+ name: string;
106
+ /** False when the name was already that — the call is idempotent. */
107
+ changed: boolean;
108
+ }
109
+ export interface PortalSetAgentWorkflowInput {
110
+ slug: string;
111
+ agent: string;
112
+ /** The n8n workflow id the agent should report as from now on. */
113
+ workflowId: string;
114
+ }
115
+ export interface PortalSetAgentWorkflowResult {
116
+ org: string;
117
+ agent: string;
118
+ previousWorkflowId: string;
119
+ workflowId: string;
120
+ /** False when the agent already pointed there — the call is idempotent. */
121
+ changed: boolean;
122
+ }
95
123
  export interface PortalListAgentsResult {
96
124
  agents: PortalAgent[];
97
125
  }
@@ -125,6 +153,18 @@ export declare function portalCreateAgent(input: PortalCreateAgentInput, options
125
153
  agent: PortalAgent;
126
154
  }>;
127
155
  export declare function portalSetAgentStatus(input: PortalSetAgentStatusInput, options?: PortalAdminOptions): Promise<PortalSetAgentStatusResult>;
156
+ /**
157
+ * Rename an agent — the client-facing label on its card. The agent slug is the
158
+ * stable identifier, so a rename breaks no reference.
159
+ */
160
+ export declare function portalSetAgentName(input: PortalSetAgentNameInput, options?: PortalAdminOptions): Promise<PortalSetAgentNameResult>;
161
+ /**
162
+ * Repoint an agent at a different n8n workflow — for a version bump (v2
163
+ * replacing a retired v1), which is the same agent from the client's side.
164
+ * The row keeps its slug, name, and run history; the portal re-observes the
165
+ * new workflow's live state on the next sync.
166
+ */
167
+ export declare function portalSetAgentWorkflow(input: PortalSetAgentWorkflowInput, options?: PortalAdminOptions): Promise<PortalSetAgentWorkflowResult>;
128
168
  export declare function portalListAgents(input?: {
129
169
  slug?: string;
130
170
  }, options?: PortalAdminOptions): Promise<PortalListAgentsResult>;
@@ -118,6 +118,36 @@ export async function portalSetAgentStatus(input, options = {}) {
118
118
  status: input.status,
119
119
  });
120
120
  }
121
+ /**
122
+ * Rename an agent — the client-facing label on its card. The agent slug is the
123
+ * stable identifier, so a rename breaks no reference.
124
+ */
125
+ export async function portalSetAgentName(input, options = {}) {
126
+ const slug = normalizeSlug(input.slug, "org");
127
+ const agent = normalizeSlug(input.agent, "agent");
128
+ const name = input.name.trim();
129
+ if (!name)
130
+ throw new Error("name required");
131
+ return portalRequest("POST", "/api/admin/agents/name", options, { slug, agent, name });
132
+ }
133
+ /**
134
+ * Repoint an agent at a different n8n workflow — for a version bump (v2
135
+ * replacing a retired v1), which is the same agent from the client's side.
136
+ * The row keeps its slug, name, and run history; the portal re-observes the
137
+ * new workflow's live state on the next sync.
138
+ */
139
+ export async function portalSetAgentWorkflow(input, options = {}) {
140
+ const slug = normalizeSlug(input.slug, "org");
141
+ const agent = normalizeSlug(input.agent, "agent");
142
+ const workflowId = input.workflowId.trim();
143
+ if (!workflowId)
144
+ throw new Error("workflowId required");
145
+ return portalRequest("POST", "/api/admin/agents/workflow-id", options, {
146
+ slug,
147
+ agent,
148
+ workflowId,
149
+ });
150
+ }
121
151
  export async function portalListAgents(input = {}, options = {}) {
122
152
  const query = input.slug ? `?slug=${encodeURIComponent(normalizeSlug(input.slug, "org"))}` : "";
123
153
  return portalRequest("GET", `/api/admin/agents${query}`, options);
@@ -0,0 +1,88 @@
1
+ import { type ExecFileFn } from "./exec.js";
2
+ export interface StandupGitState {
3
+ staged: number;
4
+ unstaged: number;
5
+ untracked: number;
6
+ }
7
+ export interface StandupRepoLint {
8
+ ok: boolean;
9
+ /** First line of the lint output when it failed — a pointer, not the report. */
10
+ detail?: string;
11
+ }
12
+ export type StandupCallPrepStatus = "fresh" | "stale" | "missing-agenda" | "no-calls" | "no-registry";
13
+ export interface StandupCallPrep {
14
+ status: StandupCallPrepStatus;
15
+ /** ISO date of the newest registry call file, when one exists. */
16
+ latestCall?: string;
17
+ }
18
+ export interface StandupIssueRef {
19
+ identifier: string;
20
+ title: string;
21
+ state: string;
22
+ }
23
+ export type StandupLinear = {
24
+ status: "ok";
25
+ open: number;
26
+ inProgress: number;
27
+ next: StandupIssueRef | null;
28
+ } | {
29
+ status: "skipped";
30
+ reason: string;
31
+ } | {
32
+ status: "error";
33
+ reason: string;
34
+ };
35
+ export interface StandupRepo {
36
+ slug: string;
37
+ dir: string;
38
+ /** null when `git status` itself failed (detail in gitError). */
39
+ git: StandupGitState | null;
40
+ gitError?: string;
41
+ /** null when the repo has no ci/repo-lint.mjs to run. */
42
+ repoLint: StandupRepoLint | null;
43
+ hooksInstalled: boolean;
44
+ /** Newest ISO date found in docs/00-delivery-log.md, or null. */
45
+ lastShipped: string | null;
46
+ lastShippedAgeDays: number | null;
47
+ callPrep: StandupCallPrep;
48
+ linear: StandupLinear;
49
+ /** Human-ready flags, worst first — empty means nothing needs attention. */
50
+ attention: string[];
51
+ }
52
+ export interface StandupStaleTodo {
53
+ /** Workspace-relative path, e.g. "team-web/todo/posthog-integration.md". */
54
+ file: string;
55
+ ageDays: number;
56
+ }
57
+ export interface StandupResult {
58
+ workspaceDir: string;
59
+ generatedAt: string;
60
+ /** False when Linear was skipped (offline, or no $LINEAR_API_TOKEN). */
61
+ linearEnabled: boolean;
62
+ /** Most actionable first. */
63
+ repos: StandupRepo[];
64
+ staleTodos: StandupStaleTodo[];
65
+ }
66
+ export interface StandupOptions {
67
+ /** The installagent/ workspace root (contains clients/, team-clients/). */
68
+ workspaceDir?: string;
69
+ /** Skip the Linear reads entirely — everything else is local. */
70
+ offline?: boolean;
71
+ /** Linear API key; defaults to $LINEAR_API_TOKEN. */
72
+ linearToken?: string;
73
+ /** Injectable for tests. */
74
+ execFileImpl?: ExecFileFn;
75
+ fetchImpl?: typeof fetch;
76
+ env?: NodeJS.ProcessEnv;
77
+ now?: () => Date;
78
+ }
79
+ /**
80
+ * Cross-client morning report: for every clients/client-* checkout — git
81
+ * state, repo-lint, lefthook hooks, delivery-log recency, call-prep
82
+ * freshness, and the client's open Linear issues — plus workspace todo/
83
+ * files older than 30 days. Strictly read-only, by decision: it reports and
84
+ * never fixes (fixes route to `ia template-sync`, `npx lefthook install`,
85
+ * `ia client <slug>`). The only network calls are Linear reads, skipped
86
+ * gracefully when offline or the token is absent.
87
+ */
88
+ export declare function standup(options?: StandupOptions): Promise<StandupResult>;
@@ -0,0 +1,235 @@
1
+ import { existsSync, readdirSync, readFileSync, statSync } from "node:fs";
2
+ import { join, resolve } from "node:path";
3
+ import { parseLinearProjectSlugId } from "./client-linear.js";
4
+ import { execFailureDetail, execFileAsync } from "./exec.js";
5
+ import { findProjectBySlugId, LINEAR_API_TOKEN_ENV, linearProjectIssues, } from "./linear-project.js";
6
+ import { createLogger } from "./log.js";
7
+ // `ia standup` — the cross-client "where do I start this morning?" report.
8
+ // Scope decided 2026-08-22 (docs/standup-plan.md): all local
9
+ // clients/client-* checkouts, Linear on by default with graceful skip,
10
+ // registry reads limited to calls/ file NAMES and mtimes (never content),
11
+ // and report-only — this module must never gain a write or an --apply.
12
+ /** Same field CLIENT.md records for client-linear — parsed locally here. */
13
+ const LINEAR_PROJECT_FIELD_PATTERN = /^linear_project:\s*(\S+)\s*$/m;
14
+ /** Call-note files are ISO-dated: YYYY-MM-DD.md or YYYY-MM-DD-<hint>.md. */
15
+ const CALL_DATE_PATTERN = /^(\d{4}-\d{2}-\d{2})/;
16
+ const DATE_PATTERN = /\b20\d{2}-\d{2}-\d{2}\b/g;
17
+ const DAY_MS = 24 * 60 * 60 * 1000;
18
+ /** Fetch enough open issues that the counts are honest, then summarize. */
19
+ const LINEAR_COUNT_LIMIT = 250;
20
+ const STALE_TODO_DAYS = 30;
21
+ const log = createLogger("sdk.standup");
22
+ function parseGitPorcelain(output) {
23
+ const state = { staged: 0, unstaged: 0, untracked: 0 };
24
+ for (const line of output.split("\n")) {
25
+ if (line.length < 2)
26
+ continue;
27
+ const x = line[0];
28
+ const y = line[1];
29
+ if (x === "?" && y === "?") {
30
+ state.untracked += 1;
31
+ continue;
32
+ }
33
+ if (x !== " ")
34
+ state.staged += 1;
35
+ if (y !== " ")
36
+ state.unstaged += 1;
37
+ }
38
+ return state;
39
+ }
40
+ function ageDays(isoDate, now) {
41
+ const then = Date.parse(`${isoDate}T00:00:00Z`);
42
+ return Math.max(0, Math.floor((now.getTime() - then) / DAY_MS));
43
+ }
44
+ function lastShippedDate(repoDir) {
45
+ const logPath = join(repoDir, "docs", "00-delivery-log.md");
46
+ if (!existsSync(logPath))
47
+ return null;
48
+ const dates = readFileSync(logPath, "utf8").match(DATE_PATTERN);
49
+ if (!dates || dates.length === 0)
50
+ return null;
51
+ return [...dates].sort().at(-1) ?? null;
52
+ }
53
+ /**
54
+ * Registry read, deliberately minimal: call file NAMES (for their ISO date
55
+ * prefix) and the agenda file's mtime. Never call content — that boundary is
56
+ * part of the decided scope, not an optimization.
57
+ */
58
+ function callPrep(workspaceDir, slug, repoDir) {
59
+ const registryDir = join(workspaceDir, "team-clients", "clients", slug);
60
+ if (!existsSync(registryDir))
61
+ return { status: "no-registry" };
62
+ const callsDir = join(registryDir, "calls");
63
+ const callDates = existsSync(callsDir)
64
+ ? readdirSync(callsDir)
65
+ .map((file) => CALL_DATE_PATTERN.exec(file)?.[1])
66
+ .filter((date) => Boolean(date))
67
+ .sort()
68
+ : [];
69
+ const latestCall = callDates.at(-1);
70
+ if (!latestCall)
71
+ return { status: "no-calls" };
72
+ const agendaPath = join(repoDir, "docs", "05-call-agenda.md");
73
+ if (!existsSync(agendaPath))
74
+ return { status: "missing-agenda", latestCall };
75
+ const agendaDay = statSync(agendaPath).mtime.toISOString().slice(0, 10);
76
+ return { status: agendaDay < latestCall ? "stale" : "fresh", latestCall };
77
+ }
78
+ async function linearSummary(repoDir, slug, enabled, token, fetchImpl) {
79
+ if (!enabled || !token) {
80
+ return { status: "skipped", reason: token ? "offline" : `$${LINEAR_API_TOKEN_ENV} not set` };
81
+ }
82
+ const clientMdPath = join(repoDir, "CLIENT.md");
83
+ if (!existsSync(clientMdPath)) {
84
+ return { status: "skipped", reason: "no CLIENT.md" };
85
+ }
86
+ const url = LINEAR_PROJECT_FIELD_PATTERN.exec(readFileSync(clientMdPath, "utf8"))?.[1];
87
+ if (!url) {
88
+ return { status: "skipped", reason: "no linear_project in CLIENT.md" };
89
+ }
90
+ if (!url.startsWith("http")) {
91
+ // Scaffolded-but-unfilled CLIENT.md (e.g. "<LINEAR_PROJECT_URL_HERE>").
92
+ return { status: "skipped", reason: "linear_project not filled in CLIENT.md" };
93
+ }
94
+ const slugId = parseLinearProjectSlugId(url);
95
+ if (!slugId) {
96
+ return { status: "skipped", reason: "no linear_project in CLIENT.md" };
97
+ }
98
+ try {
99
+ const project = await findProjectBySlugId(fetchImpl, token, slugId);
100
+ const { issues } = await linearProjectIssues(fetchImpl, token, project, {
101
+ limit: LINEAR_COUNT_LIMIT,
102
+ });
103
+ const next = issues[0];
104
+ return {
105
+ status: "ok",
106
+ open: issues.length,
107
+ inProgress: issues.filter((issue) => issue.stateType === "started").length,
108
+ next: next ? { identifier: next.identifier, title: next.title, state: next.state } : null,
109
+ };
110
+ }
111
+ catch (error) {
112
+ // One client's Linear hiccup must not sink the whole morning report.
113
+ log.debug("linear-summary-failed", { slug });
114
+ return { status: "error", reason: error instanceof Error ? error.message : String(error) };
115
+ }
116
+ }
117
+ function staleTodos(workspaceDir, now) {
118
+ const found = [];
119
+ for (const entry of readdirSync(workspaceDir, { withFileTypes: true })) {
120
+ if (!entry.isDirectory())
121
+ continue;
122
+ const todoDir = join(workspaceDir, entry.name, "todo");
123
+ if (!existsSync(todoDir))
124
+ continue;
125
+ for (const file of readdirSync(todoDir)) {
126
+ if (!file.endsWith(".md") || file.toLowerCase() === "readme.md")
127
+ continue;
128
+ const days = Math.floor((now.getTime() - statSync(join(todoDir, file)).mtime.getTime()) / DAY_MS);
129
+ if (days >= STALE_TODO_DAYS) {
130
+ found.push({ file: `${entry.name}/todo/${file}`, ageDays: days });
131
+ }
132
+ }
133
+ }
134
+ return found.sort((a, b) => b.ageDays - a.ageDays);
135
+ }
136
+ function attentionFlags(repo) {
137
+ const flags = [];
138
+ if (repo.repoLint && !repo.repoLint.ok)
139
+ flags.push("repo-lint failing");
140
+ if (repo.gitError)
141
+ flags.push("git status failed");
142
+ if (repo.git && repo.git.staged + repo.git.unstaged + repo.git.untracked > 0) {
143
+ flags.push("uncommitted work");
144
+ }
145
+ if (!repo.hooksInstalled)
146
+ flags.push("lefthook hooks not installed");
147
+ if (repo.callPrep.status === "stale" || repo.callPrep.status === "missing-agenda") {
148
+ flags.push("call prep stale");
149
+ }
150
+ return flags;
151
+ }
152
+ /**
153
+ * Cross-client morning report: for every clients/client-* checkout — git
154
+ * state, repo-lint, lefthook hooks, delivery-log recency, call-prep
155
+ * freshness, and the client's open Linear issues — plus workspace todo/
156
+ * files older than 30 days. Strictly read-only, by decision: it reports and
157
+ * never fixes (fixes route to `ia template-sync`, `npx lefthook install`,
158
+ * `ia client <slug>`). The only network calls are Linear reads, skipped
159
+ * gracefully when offline or the token is absent.
160
+ */
161
+ export async function standup(options = {}) {
162
+ const workspaceDir = resolve(options.workspaceDir ?? ".");
163
+ const execFileImpl = options.execFileImpl ?? execFileAsync;
164
+ const fetchImpl = options.fetchImpl ?? fetch;
165
+ const env = options.env ?? process.env;
166
+ const now = (options.now ?? (() => new Date()))();
167
+ const offline = options.offline ?? false;
168
+ const linearToken = options.linearToken ?? env[LINEAR_API_TOKEN_ENV];
169
+ const linearEnabled = !offline && Boolean(linearToken);
170
+ const clientsDir = join(workspaceDir, "clients");
171
+ const repoDirs = existsSync(clientsDir)
172
+ ? readdirSync(clientsDir, { withFileTypes: true })
173
+ .filter((entry) => entry.isDirectory() && entry.name.startsWith("client-"))
174
+ .map((entry) => entry.name)
175
+ .filter((name) => name !== "client-template")
176
+ .filter((name) => existsSync(join(clientsDir, name, ".git")))
177
+ .sort()
178
+ : [];
179
+ const repos = [];
180
+ for (const name of repoDirs) {
181
+ const dir = join(clientsDir, name);
182
+ const slug = name.slice("client-".length);
183
+ let git = null;
184
+ let gitError;
185
+ try {
186
+ const { stdout } = await execFileImpl("git", ["-C", dir, "status", "--porcelain"]);
187
+ git = parseGitPorcelain(stdout);
188
+ }
189
+ catch (error) {
190
+ gitError = execFailureDetail(error).detail.split("\n")[0];
191
+ }
192
+ let repoLint = null;
193
+ const lintScript = join(dir, "ci", "repo-lint.mjs");
194
+ if (existsSync(lintScript)) {
195
+ try {
196
+ await execFileImpl(process.execPath, [lintScript, dir]);
197
+ repoLint = { ok: true };
198
+ }
199
+ catch (error) {
200
+ const { detail } = execFailureDetail(error);
201
+ repoLint = { ok: false, detail: detail.split("\n").find(Boolean) ?? "exit 1" };
202
+ }
203
+ }
204
+ const hookPath = join(dir, ".git", "hooks", "pre-commit");
205
+ const hooksInstalled = existsSync(hookPath) && readFileSync(hookPath, "utf8").includes("lefthook");
206
+ const lastShipped = lastShippedDate(dir);
207
+ const partial = {
208
+ slug,
209
+ dir,
210
+ git,
211
+ ...(gitError ? { gitError } : {}),
212
+ repoLint,
213
+ hooksInstalled,
214
+ lastShipped,
215
+ lastShippedAgeDays: lastShipped ? ageDays(lastShipped, now) : null,
216
+ callPrep: callPrep(workspaceDir, slug, dir),
217
+ linear: await linearSummary(dir, slug, linearEnabled, linearToken, fetchImpl),
218
+ };
219
+ repos.push({ ...partial, attention: attentionFlags(partial) });
220
+ }
221
+ // Most actionable first: more attention flags, then staler delivery logs.
222
+ repos.sort((a, b) => {
223
+ if (b.attention.length !== a.attention.length) {
224
+ return b.attention.length - a.attention.length;
225
+ }
226
+ return (b.lastShippedAgeDays ?? -1) - (a.lastShippedAgeDays ?? -1);
227
+ });
228
+ return {
229
+ workspaceDir,
230
+ generatedAt: now.toISOString(),
231
+ linearEnabled,
232
+ repos,
233
+ staleTodos: staleTodos(workspaceDir, now),
234
+ };
235
+ }
@@ -0,0 +1,47 @@
1
+ import { type PullFn } from "./git.js";
2
+ import { type EnvExampleStatus, type WorkspaceDocsResult } from "./workspace-docs.js";
3
+ /**
4
+ * `ia sync` — bring every repo in the workspace up to date in one command.
5
+ *
6
+ * Exists because `ia wizard --update` was the only way to pull, and it does
7
+ * more than a technician wants day to day: it also rewrites root docs and
8
+ * skills. Worse, it never touched `clients/client-*` at all, so the repos
9
+ * holding the actual client work were the ones nobody was pulling. `ia sync`
10
+ * covers every clone including those, and leaves docs alone unless asked.
11
+ *
12
+ * Never merges. Every pull is fast-forward-only, so a repo with local commits
13
+ * or a dirty tree fails loudly and keeps its work — losing a technician's
14
+ * uncommitted client changes to a convenience command would be unforgivable.
15
+ * `.env` is never read or written here.
16
+ */
17
+ export interface SyncReposOptions {
18
+ /** installagent/ workspace root. Defaults to the current dir. */
19
+ dir?: string;
20
+ /**
21
+ * Also refresh drifted root docs + skills/ from the templates (what
22
+ * `ia wizard --update` does). Default false — a plain sync only pulls git
23
+ * repos, so it can never touch a file a technician edited.
24
+ */
25
+ docs?: boolean;
26
+ /** Injectable for tests; defaults to real `git pull --ff-only`. */
27
+ pull?: PullFn;
28
+ }
29
+ export type SyncRepoStatus = "updated" | "absent" | "failed";
30
+ export interface SyncRepoResult {
31
+ /** Path relative to the workspace root, e.g. `clients/client-mpnrealty`. */
32
+ name: string;
33
+ status: SyncRepoStatus;
34
+ detail: string;
35
+ }
36
+ export interface SyncReposResult {
37
+ /** False when any repo failed to pull. */
38
+ ok: boolean;
39
+ dir: string;
40
+ repos: SyncRepoResult[];
41
+ /** Present only when `docs` was set. */
42
+ docs?: WorkspaceDocsResult;
43
+ /** Present only when `docs` was set. `.env` itself is never touched. */
44
+ envExample?: EnvExampleStatus;
45
+ nextSteps: string[];
46
+ }
47
+ export declare function syncRepos(options?: SyncReposOptions): Promise<SyncReposResult>;
@@ -0,0 +1,80 @@
1
+ import { existsSync, readdirSync } from "node:fs";
2
+ import { join, resolve } from "node:path";
3
+ import { gitPullFfOnly } from "./git.js";
4
+ import { WIZARD_REPO_NAMES } from "./wizard.js";
5
+ import { refreshEnvExample, refreshWorkspaceDocs, } from "./workspace-docs.js";
6
+ /**
7
+ * Every `clients/client-*` directory that is a git clone, sorted.
8
+ *
9
+ * Returns POSIX-separated relative paths deliberately, NOT `join()` output:
10
+ * these strings are the `name` a technician reads and an MCP caller matches
11
+ * on, so `clients/client-acme` must not become `clients\\client-acme` on
12
+ * Windows. Only the filesystem probe below uses platform separators.
13
+ */
14
+ function clientRepoPaths(workspaceDir) {
15
+ const clientsDir = join(workspaceDir, "clients");
16
+ if (!existsSync(clientsDir))
17
+ return [];
18
+ return readdirSync(clientsDir, { withFileTypes: true })
19
+ .filter((entry) => entry.isDirectory() && entry.name.startsWith("client-"))
20
+ .map((entry) => `clients/${entry.name}`)
21
+ .filter((rel) => existsSync(join(workspaceDir, ...rel.split("/"), ".git")))
22
+ .sort();
23
+ }
24
+ export async function syncRepos(options = {}) {
25
+ const dir = resolve(options.dir ?? ".");
26
+ const pull = options.pull ?? gitPullFfOnly;
27
+ const withDocs = options.docs ?? false;
28
+ // Team repos first (team-tools carries the templates a --docs refresh
29
+ // reads, so it must be current before the docs step runs), then every
30
+ // client clone the technician actually has.
31
+ const targets = [...WIZARD_REPO_NAMES.map(String), ...clientRepoPaths(dir)];
32
+ const repos = [];
33
+ for (const rel of targets) {
34
+ // rel is always POSIX (see clientRepoPaths); split it back out so the
35
+ // filesystem sees native separators.
36
+ const path = join(dir, ...rel.split("/"));
37
+ if (!existsSync(join(path, ".git"))) {
38
+ repos.push({
39
+ name: rel,
40
+ status: "absent",
41
+ detail: "not cloned on this machine — `ia wizard` clones the team repos",
42
+ });
43
+ continue;
44
+ }
45
+ try {
46
+ await pull(path);
47
+ repos.push({ name: rel, status: "updated", detail: "pulled (fast-forward only)" });
48
+ }
49
+ catch (error) {
50
+ repos.push({
51
+ name: rel,
52
+ status: "failed",
53
+ detail: String(error instanceof Error ? error.message : error),
54
+ });
55
+ }
56
+ }
57
+ const docs = withDocs ? await refreshWorkspaceDocs(dir, { overwrite: true }) : undefined;
58
+ const envExample = withDocs ? await refreshEnvExample(dir, { overwrite: true }) : undefined;
59
+ const failed = repos.filter((repo) => repo.status === "failed");
60
+ const nextSteps = [];
61
+ if (failed.length > 0) {
62
+ nextSteps.push(`${failed.length} repo(s) would not fast-forward — commit, stash or push your work in ${failed
63
+ .map((repo) => repo.name)
64
+ .join(", ")}, then re-run \`ia sync\` (nothing was merged or discarded)`);
65
+ }
66
+ if (!withDocs) {
67
+ nextSteps.push("`ia sync --docs` also refreshes the root docs, skills/ and .env.example");
68
+ }
69
+ if (nextSteps.length === 0) {
70
+ nextSteps.push(`run \`ia doctor -w ${dir}\` if anything looks off`);
71
+ }
72
+ return {
73
+ ok: failed.length === 0,
74
+ dir,
75
+ repos,
76
+ ...(docs ? { docs } : {}),
77
+ ...(envExample ? { envExample } : {}),
78
+ nextSteps,
79
+ };
80
+ }