@installagent/sdk 0.6.0 → 0.8.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.
package/dist/index.d.ts CHANGED
@@ -1,3 +1,4 @@
1
+ export { type AccessCheckItem, type AccessCheckOptions, type AccessCheckResult, type AccessService, type AccessStatus, accessCheck, classifyKey, clientVaultFor, } from "./access-check.js";
1
2
  export { type AgentMirrorOptions, type AgentMirrorResult, checkAgentMirror, type MirrorRow, type MirrorState, type MirrorSummary, } from "./agent-mirror.js";
2
3
  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
4
  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";
@@ -7,6 +8,7 @@ export { AIRTABLE_API_TOKEN_ENV, buildAssertionClaims, ClientDriveAuthError, typ
7
8
  export { ClientIntakeAuthError, type ClientIntakeInput, type ClientIntakeOptions, type ClientIntakeResult, type ClientIntakeStep, clientIntake, LINEAR_CLIENT_TEAM_ID_ENV, } from "./client-intake.js";
8
9
  export { ClientLinearAuthError, type ClientLinearProjectOptions, clientLinearProject, parseLinearProjectSlugId, type ResolvedClientLinearProject, resolveClientLinearProject, } from "./client-linear.js";
9
10
  export { type ClientLinearCreateIssueInput, type ClientLinearCreateIssueResult, clientLinearCreateIssue, } from "./client-linear-create.js";
11
+ export { GCP_MANIFEST_KEYS, type GcpManifest, type GcpManifestKey, readGcpManifest, readGcpManifestFromRepo, readManifestKey, } from "./client-manifest.js";
10
12
  export { DOCS_SEARCH_TOKEN_ENV, DOCS_SESSION_ENV, type DocsSearchOptions, type DocsSearchResponse, type DocsSearchResult, DocsSessionError, docsSearch, TEAM_DOCS_BASE_URL, } from "./docs-search.js";
11
13
  export { type DoctorCheck, type DoctorOptions, type DoctorResult, type DoctorStatus, doctor, } from "./doctor.js";
12
14
  export { findWorkspaceRoot, type LoadWorkspaceEnvOptions, type LoadWorkspaceEnvResult, loadWorkspaceEnv, parseEnvFile, } from "./env-file.js";
@@ -14,7 +16,10 @@ export { type EnvFillOptions, type EnvFillResult, type EnvFillVarResult, type En
14
16
  export { type EnvPushOptions, type EnvPushResult, type EnvPushVarResult, type EnvPushVarStatus, envPush, } from "./env-push.js";
15
17
  export { ADMIN_ENV_VARS, DEFAULT_TECH_VAULT, ENV_VARS, type EnvVarRole, type EnvVarSource, type EnvVarSpec, type EnvVarTier, envVarRole, envVarsForRole, GEMINI_API_KEY_ENV, INFRA_VAULT, opSecretReference, renderEnvExample, TECH_ENV_VARS, } from "./env-registry.js";
16
18
  export { FATHOM_API_BASE_URL, FATHOM_API_KEY_ENV, FATHOM_INCLUDES, FATHOM_TRIGGERS, type MintFathomWebhookOptions, type MintFathomWebhookResult, mintFathomWebhook, } from "./fathom-webhook.js";
19
+ export { DWD_ADMIN_CONSOLE_URL, dwdAdminText, type GcpDwdOptions, type GcpDwdResult, type GcpDwdStep, gcpDwd, KEY_CREATION_POLICY, normalizeDwdScope, } from "./gcp-dwd.js";
20
+ export { describePolicy, GCP_INSPECT_KEY_APIS, GCP_INSPECT_POLICIES, GCP_KEY_MAX_AGE_DAYS, type GcpApiCaller, type GcpApiCallsInfo, type GcpApisInfo, type GcpIamInfo, type GcpInspectOptions, type GcpInspectResult, type GcpKeyInfo, type GcpPolicyState, type GcpProjectInfo, type GcpSection, type GcpServiceAccountInfo, gcloudArgs, gcpInspect, maskCredential, maskMember, validateGcpTarget, } from "./gcp-inspect.js";
17
21
  export { type ExecFileFn, MINT_HANDOFF_WARNING, type MintGcpServiceAccountKeyOptions, type MintGcpServiceAccountKeyResult, mintGcpServiceAccountKey, } from "./gcp-service-account-key.js";
22
+ export { formatGcloud, GCP_TEAM_DOMAIN, type GcpSetupOptions, type GcpSetupResult, type GcpStep, type GcpStepStatus, gcpSetup, SERVICE_USAGE_ADMIN, } from "./gcp-setup.js";
18
23
  export { DEFAULT_GEMINI_KEY_DISPLAY_NAME, GEMINI_API_TARGET, type MintGeminiApiKeyOptions, type MintGeminiApiKeyResult, mintGeminiApiKey, } from "./gemini-api-key.js";
19
24
  export { type CloneFn, type CloneOptions, gitClone, gitPullFfOnly, type PullFn } from "./git.js";
20
25
  export { GITHUB_TOKEN_FIX, type ResolvedGithubToken, type ResolveGithubTokenOptions, resolveGithubToken, } from "./github-token.js";
@@ -30,6 +35,7 @@ export { applyClientDefaults, clientWorkflowName, DEFAULT_EXECUTION_TIMEOUT_S, D
30
35
  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";
31
36
  export { type NewClientOptions, type NewClientResult, newClient, SLUG_PATTERN, } from "./new-client.js";
32
37
  export { opInstallCommand, opInstallFix, opIntegrationFix } from "./op-cli.js";
38
+ export { defaultOpTitle, type MintImpls, type MintToOpOptions, type MintToOpRequest, type MintToOpResult, mintToOnePassword, } from "./op-store.js";
33
39
  export { type PingResult, ping } from "./ping.js";
34
40
  export { detectPlatform, detectPlatformInfo, detectShell, opNeedsAnotherShell, type Platform, type PlatformInfo, type Shell, } from "./platform.js";
35
41
  export { DEFAULT_PORTAL_URL, PORTAL_ADMIN_SECRET_ENV, PORTAL_BUILD_TYPES, PORTAL_PASSWORD_WARNING, PORTAL_SYNC_MAX_DAYS, PORTAL_URL_ENV, type PortalAddUserInput, type PortalAddUserResult, PortalAdminAuthError, type PortalAdminOptions, type PortalAgent, type PortalAgentSyncRow, type PortalBuild, type PortalBuildType, type PortalCreateAgentInput, type PortalCreateBuildInput, type PortalCreateOrgInput, type PortalCreateOrgResult, type PortalListAgentsResult, type PortalListBuildsResult, type PortalListOrgsResult, type PortalOrg, type PortalOrgUser, PortalRequestError, type PortalSetAgentNameInput, type PortalSetAgentNameResult, type PortalSetAgentStatusInput, type PortalSetAgentStatusResult, type PortalSetAgentTriageResult, type PortalSetAgentWorkflowInput, type PortalSetAgentWorkflowResult, type PortalSetBuildStatusInput, type PortalSetDriveFolderResult, type PortalSetPasswordResult, type PortalSetUserInput, type PortalSetUserResult, type PortalSyncRunsResult, type PortalTriageBackfillResult, type PortalTriageProvider, type PortalTriageRecordsPage, portalAddUser, portalBackfillTriageRecords, portalBuildType, portalBuildWorkflowId, portalCreateAgent, portalCreateBuild, portalCreateOrg, portalListAgents, portalListBuilds, portalListOrgs, portalReadTriageRecords, portalSetAgentName, portalSetAgentStatus, portalSetAgentTriage, portalSetAgentWorkflow, portalSetBuildName, portalSetBuildStatus, portalSetBuildTriage, portalSetBuildWorkflow, portalSetDriveFolder, portalSetOrgSlackChannel, portalSetPassword, portalSetUser, portalSyncRuns, validatePortalBuildFields, } from "./portal-admin.js";
package/dist/index.js CHANGED
@@ -1,6 +1,7 @@
1
1
  // @installagent/sdk — the only place with real logic. apps/cli and
2
2
  // apps/mcp are thin adapters over these exports; every operation here must be
3
3
  // reachable from both. See ../../docs/spec.md.
4
+ export { accessCheck, classifyKey, clientVaultFor, } from "./access-check.js";
4
5
  export { checkAgentMirror, } from "./agent-mirror.js";
5
6
  export { createFromAgentTemplate, listAgentTemplates, N8N_API_KEY_ENV, N8N_API_URL_ENV, N8nAuthError, sanitizeN8nWorkflow, saveAgentTemplate, searchAgentTemplates, } from "./agent-templates.js";
6
7
  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";
@@ -10,6 +11,7 @@ export { AIRTABLE_API_TOKEN_ENV, buildAssertionClaims, ClientDriveAuthError, cli
10
11
  export { ClientIntakeAuthError, clientIntake, LINEAR_CLIENT_TEAM_ID_ENV, } from "./client-intake.js";
11
12
  export { ClientLinearAuthError, clientLinearProject, parseLinearProjectSlugId, resolveClientLinearProject, } from "./client-linear.js";
12
13
  export { clientLinearCreateIssue, } from "./client-linear-create.js";
14
+ export { GCP_MANIFEST_KEYS, readGcpManifest, readGcpManifestFromRepo, readManifestKey, } from "./client-manifest.js";
13
15
  export { DOCS_SEARCH_TOKEN_ENV, DOCS_SESSION_ENV, DocsSessionError, docsSearch, TEAM_DOCS_BASE_URL, } from "./docs-search.js";
14
16
  export { doctor, } from "./doctor.js";
15
17
  export { findWorkspaceRoot, loadWorkspaceEnv, parseEnvFile, } from "./env-file.js";
@@ -17,7 +19,10 @@ export { envFill, } from "./env-fill.js";
17
19
  export { envPush, } from "./env-push.js";
18
20
  export { ADMIN_ENV_VARS, DEFAULT_TECH_VAULT, ENV_VARS, envVarRole, envVarsForRole, GEMINI_API_KEY_ENV, INFRA_VAULT, opSecretReference, renderEnvExample, TECH_ENV_VARS, } from "./env-registry.js";
19
21
  export { FATHOM_API_BASE_URL, FATHOM_API_KEY_ENV, FATHOM_INCLUDES, FATHOM_TRIGGERS, mintFathomWebhook, } from "./fathom-webhook.js";
22
+ export { DWD_ADMIN_CONSOLE_URL, dwdAdminText, gcpDwd, KEY_CREATION_POLICY, normalizeDwdScope, } from "./gcp-dwd.js";
23
+ export { describePolicy, GCP_INSPECT_KEY_APIS, GCP_INSPECT_POLICIES, GCP_KEY_MAX_AGE_DAYS, gcloudArgs, gcpInspect, maskCredential, maskMember, validateGcpTarget, } from "./gcp-inspect.js";
20
24
  export { MINT_HANDOFF_WARNING, mintGcpServiceAccountKey, } from "./gcp-service-account-key.js";
25
+ export { formatGcloud, GCP_TEAM_DOMAIN, gcpSetup, SERVICE_USAGE_ADMIN, } from "./gcp-setup.js";
21
26
  export { DEFAULT_GEMINI_KEY_DISPLAY_NAME, GEMINI_API_TARGET, mintGeminiApiKey, } from "./gemini-api-key.js";
22
27
  export { gitClone, gitPullFfOnly } from "./git.js";
23
28
  export { GITHUB_TOKEN_FIX, resolveGithubToken, } from "./github-token.js";
@@ -33,6 +38,7 @@ export { applyClientDefaults, clientWorkflowName, DEFAULT_EXECUTION_TIMEOUT_S, D
33
38
  export { extractNodeOutputs, listN8nExecutions, listNodesRun, unflattenExecutionData, } from "./n8n-executions.js";
34
39
  export { newClient, SLUG_PATTERN, } from "./new-client.js";
35
40
  export { opInstallCommand, opInstallFix, opIntegrationFix } from "./op-cli.js";
41
+ export { defaultOpTitle, mintToOnePassword, } from "./op-store.js";
36
42
  export { ping } from "./ping.js";
37
43
  export { detectPlatform, detectPlatformInfo, detectShell, opNeedsAnotherShell, } from "./platform.js";
38
44
  export { DEFAULT_PORTAL_URL, PORTAL_ADMIN_SECRET_ENV, PORTAL_BUILD_TYPES, PORTAL_PASSWORD_WARNING, PORTAL_SYNC_MAX_DAYS, PORTAL_URL_ENV, PortalAdminAuthError, PortalRequestError, portalAddUser, portalBackfillTriageRecords, portalBuildType, portalBuildWorkflowId, portalCreateAgent, portalCreateBuild, portalCreateOrg, portalListAgents, portalListBuilds, portalListOrgs, portalReadTriageRecords, portalSetAgentName, portalSetAgentStatus, portalSetAgentTriage, portalSetAgentWorkflow, portalSetBuildName, portalSetBuildStatus, portalSetBuildTriage, portalSetBuildWorkflow, portalSetDriveFolder, portalSetOrgSlackChannel, portalSetPassword, portalSetUser, portalSyncRuns, validatePortalBuildFields, } from "./portal-admin.js";
package/dist/op-cli.d.ts CHANGED
@@ -17,7 +17,21 @@
17
17
  * technician following `brew install` text on Windows loses an hour finding
18
18
  * that out. See platform.ts for why we don't try to tell PowerShell from cmd.
19
19
  */
20
+ import { type ExecFileFn } from "./exec.js";
20
21
  import { type PlatformInfo } from "./platform.js";
22
+ /**
23
+ * True when op is installed and can reach the vaults; otherwise the fix-it step.
24
+ * Shared by `ia env fill`, `ia env push` and `ia secrets mint --to-op`.
25
+ *
26
+ * `op whoami` is the obvious probe but NOT a sufficient one: with the desktop
27
+ * app integration on, op 2.35 answers "account is not signed in" to `whoami`
28
+ * while `op read` and `op vault list` both work — the CLI has no session of its
29
+ * own, and the app authorizes each call. Failing there told a technician to
30
+ * enable an integration that was already enabled, and blocked a command that
31
+ * would have succeeded. So a `whoami` failure falls through to `op vault list`,
32
+ * which also starts the app's sign-in prompt.
33
+ */
34
+ export declare function opReachable(execFileImpl: ExecFileFn, platform: PlatformInfo): Promise<true | string>;
21
35
  /**
22
36
  * How to make `op` authenticate in every shell on this machine. Callers pass
23
37
  * the detected platform; omit it and the running machine is used.
package/dist/op-cli.js CHANGED
@@ -17,7 +17,39 @@
17
17
  * technician following `brew install` text on Windows loses an hour finding
18
18
  * that out. See platform.ts for why we don't try to tell PowerShell from cmd.
19
19
  */
20
+ import { execFailureDetail } from "./exec.js";
20
21
  import { detectPlatformInfo, opNeedsAnotherShell } from "./platform.js";
22
+ /**
23
+ * True when op is installed and can reach the vaults; otherwise the fix-it step.
24
+ * Shared by `ia env fill`, `ia env push` and `ia secrets mint --to-op`.
25
+ *
26
+ * `op whoami` is the obvious probe but NOT a sufficient one: with the desktop
27
+ * app integration on, op 2.35 answers "account is not signed in" to `whoami`
28
+ * while `op read` and `op vault list` both work — the CLI has no session of its
29
+ * own, and the app authorizes each call. Failing there told a technician to
30
+ * enable an integration that was already enabled, and blocked a command that
31
+ * would have succeeded. So a `whoami` failure falls through to `op vault list`,
32
+ * which also starts the app's sign-in prompt.
33
+ */
34
+ export async function opReachable(execFileImpl, platform) {
35
+ try {
36
+ await execFileImpl("op", ["whoami"]);
37
+ return true;
38
+ }
39
+ catch (error) {
40
+ if (execFailureDetail(error).code === "ENOENT")
41
+ return opInstallFix(platform);
42
+ try {
43
+ await execFileImpl("op", ["vault", "list", "--format=json"]);
44
+ return true;
45
+ }
46
+ catch (fallbackError) {
47
+ if (execFailureDetail(fallbackError).code === "ENOENT")
48
+ return opInstallFix(platform);
49
+ return `authenticate the 1Password CLI: ${opIntegrationFix(platform)}`;
50
+ }
51
+ }
52
+ }
21
53
  const V8_NOTE = 'tick "Integrate with 1Password CLI" (v7 has no Developer tab — install v8 from 1password.com/downloads)';
22
54
  const NO_SIGNIN_NOTE = "Don't rely on `op signin` alone — it scopes the session to the one shell that ran it";
23
55
  /**
@@ -28,15 +60,15 @@ export function opIntegrationFix(info = detectPlatformInfo()) {
28
60
  if (opNeedsAnotherShell(info)) {
29
61
  return ("`op` cannot reach the 1Password desktop app from Git Bash — 1Password supports PowerShell only on " +
30
62
  "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}`);
63
+ `${V8_NOTE}, then \`op vault list\` works in any PowerShell window. ${NO_SIGNIN_NOTE}`);
32
64
  }
33
65
  if (info.platform === "win32") {
34
66
  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 ` +
67
+ `${V8_NOTE}; Settings → Security → Windows Hello unlock makes it seamless), then \`op vault list\` works in ` +
36
68
  `every PowerShell window. ${NO_SIGNIN_NOTE}`);
37
69
  }
38
70
  return ("turn on the desktop app integration (1Password 8 → Settings → Developer → " +
39
- `${V8_NOTE}), then \`op whoami\` works in every shell. ${NO_SIGNIN_NOTE}`);
71
+ `${V8_NOTE}), then \`op vault list\` works in every shell. ${NO_SIGNIN_NOTE}`);
40
72
  }
41
73
  /** Same, prefixed with the install step, for when op isn't on PATH at all. */
42
74
  export function opInstallFix(info = detectPlatformInfo()) {
@@ -0,0 +1,60 @@
1
+ import { type ExecFileFn } from "./exec.js";
2
+ import { type MintFathomWebhookOptions, type MintFathomWebhookResult } from "./fathom-webhook.js";
3
+ import { type MintGcpServiceAccountKeyOptions, type MintGcpServiceAccountKeyResult } from "./gcp-service-account-key.js";
4
+ import { type MintGeminiApiKeyOptions, type MintGeminiApiKeyResult } from "./gemini-api-key.js";
5
+ import { type PlatformInfo } from "./platform.js";
6
+ /**
7
+ * `ia secrets mint … --to-op <vault>` (docs/secrets-minting-plan.md § v2,
8
+ * 2026-10-25): mint a secret and write it straight into a 1Password vault.
9
+ * The secret never reaches stdout, the result object, a log line or an argv
10
+ * (`ps` shows argv to every local user) — it goes to `op` through a 0600 file
11
+ * in a private temp dir that is deleted in the same call.
12
+ *
13
+ * Order is the safety: `op` is checked (installed, signed in, vault visible,
14
+ * title free) BEFORE anything is minted, so the common failures never leave
15
+ * a live secret behind. If the store still fails after the mint, the result
16
+ * is an error that names the exact revoke step — the secret is never printed
17
+ * as a fallback.
18
+ */
19
+ export type MintToOpRequest = ({
20
+ type: "gcp-service-account-key";
21
+ } & Omit<MintGcpServiceAccountKeyOptions, "execFileImpl">) | ({
22
+ type: "gemini-api-key";
23
+ } & Omit<MintGeminiApiKeyOptions, "execFileImpl">) | ({
24
+ type: "fathom-webhook";
25
+ } & Omit<MintFathomWebhookOptions, "fetchImpl">);
26
+ /** The three mints, injectable so tests never call gcloud or Fathom. */
27
+ export interface MintImpls {
28
+ gcp: (o: MintGcpServiceAccountKeyOptions) => Promise<MintGcpServiceAccountKeyResult>;
29
+ gemini: (o: MintGeminiApiKeyOptions) => Promise<MintGeminiApiKeyResult>;
30
+ fathom: (o: MintFathomWebhookOptions) => Promise<MintFathomWebhookResult>;
31
+ }
32
+ export interface MintToOpOptions {
33
+ request: MintToOpRequest;
34
+ /** 1Password vault name, e.g. `client-<slug>` (CLIENT.md `onepassword_vault`). */
35
+ vault: string;
36
+ /** Item title; defaults to `defaultOpTitle(request)`. Must not exist in the vault yet. */
37
+ title?: string;
38
+ /** Injectable for tests; defaults to real `op` via execFile. */
39
+ execFileImpl?: ExecFileFn;
40
+ mints?: Partial<MintImpls>;
41
+ platform?: PlatformInfo;
42
+ }
43
+ export type MintToOpResult = {
44
+ ok: true;
45
+ type: MintToOpRequest["type"];
46
+ vault: string;
47
+ title: string;
48
+ /** `op://<vault>/<title>` — a pointer, not the value. */
49
+ reference: string;
50
+ /** Non-secret facts about what was minted (key id, webhook id, …). */
51
+ details: string[];
52
+ } | {
53
+ ok: false;
54
+ error: string;
55
+ /** Set when a secret WAS minted but not stored: how to revoke it. */
56
+ revoke?: string;
57
+ };
58
+ /** `<project> - gcp-sa-key - <sa name>`, the n8n credential naming shape. */
59
+ export declare function defaultOpTitle(request: MintToOpRequest): string;
60
+ export declare function mintToOnePassword(options: MintToOpOptions): Promise<MintToOpResult>;
@@ -0,0 +1,230 @@
1
+ import { mkdtemp, rm, writeFile } from "node:fs/promises";
2
+ import { tmpdir } from "node:os";
3
+ import { join } from "node:path";
4
+ import { execFailureDetail, execFileAsync } from "./exec.js";
5
+ import { mintFathomWebhook, } from "./fathom-webhook.js";
6
+ import { mintGcpServiceAccountKey, } from "./gcp-service-account-key.js";
7
+ import { mintGeminiApiKey, } from "./gemini-api-key.js";
8
+ import { opReachable } from "./op-cli.js";
9
+ import { detectPlatformInfo } from "./platform.js";
10
+ const NAME_PATTERN = /^[^\n\r\t]{1,100}$/;
11
+ /** `<project> - gcp-sa-key - <sa name>`, the n8n credential naming shape. */
12
+ export function defaultOpTitle(request) {
13
+ switch (request.type) {
14
+ case "gcp-service-account-key":
15
+ return `${request.project} - gcp-sa-key - ${request.serviceAccountEmail.split("@")[0]}`;
16
+ case "gemini-api-key":
17
+ return `${request.project} - gemini-api-key - ${request.displayName?.trim() || "ia-minted"}`;
18
+ case "fathom-webhook": {
19
+ let host = "webhook";
20
+ try {
21
+ host = new URL(request.destinationUrl).host || host;
22
+ }
23
+ catch {
24
+ // mintFathomWebhook rejects the URL itself, after the preflight.
25
+ }
26
+ return `fathom - webhook-secret - ${host}`;
27
+ }
28
+ }
29
+ }
30
+ export async function mintToOnePassword(options) {
31
+ const vault = options.vault.trim();
32
+ const title = (options.title ?? defaultOpTitle(options.request)).trim();
33
+ if (!NAME_PATTERN.test(vault)) {
34
+ throw new Error("--to-op needs a vault name (one line, at most 100 characters)");
35
+ }
36
+ if (!NAME_PATTERN.test(title)) {
37
+ throw new Error("the 1Password item title must be one line, at most 100 characters");
38
+ }
39
+ const execFileImpl = options.execFileImpl ?? execFileAsync;
40
+ const platform = options.platform ?? detectPlatformInfo();
41
+ const ready = await opPreflight(execFileImpl, platform, vault, title);
42
+ if (ready !== true)
43
+ return { ok: false, error: ready };
44
+ const mints = {
45
+ gcp: mintGcpServiceAccountKey,
46
+ gemini: mintGeminiApiKey,
47
+ fathom: mintFathomWebhook,
48
+ ...options.mints,
49
+ };
50
+ const minted = await mintOnce(options.request, mints);
51
+ if (!minted.ok)
52
+ return { ok: false, error: minted.error };
53
+ const stored = await storeInOp(execFileImpl, vault, title, minted.secret, minted.store);
54
+ if (stored !== true) {
55
+ return {
56
+ ok: false,
57
+ error: `minted, but NOT stored in 1Password (${redact(stored, minted.secret)}). The value was not printed. Revoke it, then retry.`,
58
+ revoke: minted.revoke,
59
+ };
60
+ }
61
+ return {
62
+ ok: true,
63
+ type: options.request.type,
64
+ vault,
65
+ title,
66
+ reference: `op://${vault}/${title}`,
67
+ details: minted.details,
68
+ };
69
+ }
70
+ async function mintOnce(request, mints) {
71
+ switch (request.type) {
72
+ case "gcp-service-account-key": {
73
+ const { type: _type, ...opts } = request;
74
+ const result = await mints.gcp(opts);
75
+ if (!result.ok)
76
+ return result;
77
+ const keyId = privateKeyId(result.keyJson);
78
+ return {
79
+ ok: true,
80
+ secret: result.keyJson,
81
+ store: { kind: "document", fileName: `${result.serviceAccountEmail.split("@")[0]}.json` },
82
+ details: [
83
+ `service account ${result.serviceAccountEmail} in ${result.project}`,
84
+ ...(keyId ? [`key id ${keyId}`] : []),
85
+ ],
86
+ revoke: keyId
87
+ ? `gcloud iam service-accounts keys delete ${keyId} --iam-account=${result.serviceAccountEmail} --project=${result.project}`
88
+ : `gcloud iam service-accounts keys list --iam-account=${result.serviceAccountEmail} --project=${result.project}, then delete the newest key`,
89
+ };
90
+ }
91
+ case "gemini-api-key": {
92
+ const { type: _type, ...opts } = request;
93
+ const result = await mints.gemini(opts);
94
+ if (!result.ok)
95
+ return result;
96
+ return {
97
+ ok: true,
98
+ secret: result.keyString,
99
+ store: { kind: "api-credential" },
100
+ details: [`key ${result.keyName}, restricted to ${result.restrictedTo}`],
101
+ revoke: `gcloud services api-keys delete ${result.keyName}`,
102
+ };
103
+ }
104
+ case "fathom-webhook": {
105
+ const { type: _type, ...opts } = request;
106
+ const result = await mints.fathom(opts);
107
+ if (!result.ok)
108
+ return result;
109
+ return {
110
+ ok: true,
111
+ secret: result.webhookSecret,
112
+ store: { kind: "api-credential" },
113
+ details: [
114
+ `webhook ${result.webhookId} → ${result.destinationUrl}`,
115
+ `triggers: ${result.triggers.join(", ")}`,
116
+ ],
117
+ revoke: `delete webhook ${result.webhookId} in Fathom (Settings → API Access)`,
118
+ };
119
+ }
120
+ }
121
+ }
122
+ /** The key's id is public (it names the key in IAM), unlike the key material. */
123
+ function privateKeyId(keyJson) {
124
+ try {
125
+ const id = JSON.parse(keyJson).private_key_id;
126
+ return typeof id === "string" && /^[0-9a-f]{20,}$/.test(id) ? id : undefined;
127
+ }
128
+ catch {
129
+ return undefined;
130
+ }
131
+ }
132
+ /** op installed + signed in, the vault visible, the title free. Never mints. */
133
+ async function opPreflight(execFileImpl, platform, vault, title) {
134
+ const reachable = await opReachable(execFileImpl, platform);
135
+ if (reachable !== true)
136
+ return `${reachable}. Nothing was minted.`;
137
+ // `item list` returns titles and ids only — never field values.
138
+ let stdout;
139
+ try {
140
+ ({ stdout } = await execFileImpl("op", ["item", "list", "--vault", vault, "--format", "json"]));
141
+ }
142
+ catch (error) {
143
+ return `1Password vault "${vault}" is not visible to your op session (${execFailureDetail(error).detail}). Check the name (CLIENT.md onepassword_vault) and your access, then retry. Nothing was minted.`;
144
+ }
145
+ let titles = [];
146
+ try {
147
+ titles = JSON.parse(stdout || "[]")
148
+ .map((item) => item.title)
149
+ .filter((t) => typeof t === "string");
150
+ }
151
+ catch {
152
+ return "could not read the vault's item list from op (unexpected output). Nothing was minted.";
153
+ }
154
+ if (titles.some((t) => t.toLowerCase() === title.toLowerCase())) {
155
+ return `"${title}" already exists in ${vault} — ia never overwrites an item. Pass a new --op-title, or rotate the old item by hand. Nothing was minted.`;
156
+ }
157
+ return true;
158
+ }
159
+ /**
160
+ * One write through a private temp file. A key JSON becomes a Document (the
161
+ * file a service-account credential is uploaded as); a single string becomes
162
+ * an API Credential item from a JSON template (1Password's documented item
163
+ * template shape: title, category, fields). Returns true, or op's error text.
164
+ */
165
+ async function storeInOp(execFileImpl, vault, title, secret, store) {
166
+ const dir = await mkdtemp(join(tmpdir(), "ia-op-"));
167
+ try {
168
+ if (store.kind === "document") {
169
+ const path = join(dir, store.fileName);
170
+ await writeFile(path, secret, { mode: 0o600 });
171
+ await execFileImpl("op", [
172
+ "document",
173
+ "create",
174
+ path,
175
+ "--vault",
176
+ vault,
177
+ "--title",
178
+ title,
179
+ "--file-name",
180
+ store.fileName,
181
+ ]);
182
+ }
183
+ else {
184
+ const path = join(dir, "item.json");
185
+ const template = {
186
+ title,
187
+ category: "API_CREDENTIAL",
188
+ fields: [
189
+ {
190
+ id: "credential",
191
+ type: "CONCEALED",
192
+ label: "credential",
193
+ value: secret,
194
+ },
195
+ ],
196
+ };
197
+ await writeFile(path, JSON.stringify(template), { mode: 0o600 });
198
+ await execFileImpl("op", ["item", "create", "--vault", vault, "--template", path]);
199
+ }
200
+ return true;
201
+ }
202
+ catch (error) {
203
+ return execFailureDetail(error).detail;
204
+ }
205
+ finally {
206
+ await rm(dir, { recursive: true, force: true });
207
+ }
208
+ }
209
+ /**
210
+ * Belt and braces: op's stderr should never echo the value, but if it did, cut
211
+ * it — the whole value, and for a key JSON every long string inside it (an
212
+ * echo of `private_key` alone is still the key).
213
+ */
214
+ function redact(text, secret) {
215
+ const fragments = [secret];
216
+ try {
217
+ const parsed = JSON.parse(secret);
218
+ for (const value of Object.values(parsed)) {
219
+ if (typeof value === "string" && value.length >= 16)
220
+ fragments.push(value);
221
+ }
222
+ }
223
+ catch {
224
+ // Not JSON: the whole value is the only fragment.
225
+ }
226
+ return fragments
227
+ .filter(Boolean)
228
+ .sort((a, b) => b.length - a.length)
229
+ .reduce((out, fragment) => out.split(fragment).join("[redacted]"), text);
230
+ }
package/dist/pr-open.d.ts CHANGED
@@ -1,7 +1,7 @@
1
1
  import { type ExecFileFn } from "./exec.js";
2
2
  /**
3
3
  * `ia pr open` — push the current branch and open a DRAFT pull request, with
4
- * the three checks that the Slack Merge button made necessary:
4
+ * the checks that the Slack Merge button made necessary:
5
5
  *
6
6
  * 1. The gh account is the workspace's work account (`.github-account` at the
7
7
  * workspace root). A PR under a personal account lands on the wrong identity
@@ -11,6 +11,8 @@ import { type ExecFileFn } from "./exec.js";
11
11
  * same branch was silently lost (6 incidents in 20 days, Oct 2026).
12
12
  * 3. The branch has no OPEN pull request. More commits on an open PR is the
13
13
  * same trap one click later: open a new PR per slice.
14
+ * 4. The branch has at least one commit ahead of the base. An empty branch
15
+ * pushes fine and leaves a dead remote branch behind.
14
16
  *
15
17
  * The PR opens as a draft, so no Slack card (and no Merge button) exists until
16
18
  * someone marks it ready on purpose.
package/dist/pr-open.js CHANGED
@@ -69,6 +69,15 @@ export async function prOpen(options = {}) {
69
69
  throw new Error(`PR #${open.number} from ${branch} is still open (${open.url}). Do not add commits to it: ` +
70
70
  "the Merge button squashes the head as it is. Open a new branch for the next slice.");
71
71
  }
72
+ // 4. The branch has commits of its own. An empty branch pushes fine, then
73
+ // `gh pr create` has nothing to open. Compare with origin/<base> when the
74
+ // checkout has it, else the local base branch.
75
+ const hasRemoteBase = await git("rev-parse", "--verify", "--quiet", `origin/${base}`).then(() => true, () => false);
76
+ const baseRef = hasRemoteBase ? `origin/${base}` : base;
77
+ if (Number(await git("rev-list", "--count", `${baseRef}..HEAD`)) === 0) {
78
+ throw new Error(`${branch} has no commits ahead of ${baseRef}. Commit your changes on this branch first, ` +
79
+ "then re-run `ia pr open`.");
80
+ }
72
81
  const result = {
73
82
  repo,
74
83
  branch,
@@ -1,3 +1,4 @@
1
+ import { type GcpManifestKey } from "./client-manifest.js";
1
2
  /**
2
3
  * Files that must stay byte-identical between clients/client-template/ and
3
4
  * every clients/client-<slug>/ repo — the enforcement chain (the lint script
@@ -49,12 +50,21 @@ export interface TemplateSyncRepoResult {
49
50
  dir: string;
50
51
  files: TemplateSyncFileResult[];
51
52
  inSync: boolean;
53
+ /**
54
+ * CLIENT.md's Google Cloud keys (gcp_project / gcp_account) that are absent
55
+ * or still the placeholder. Report only: CLIENT.md is per-client, so even
56
+ * `--apply` never writes it — a technician fills the keys in that repo.
57
+ * Empty when both are set (or `none`), or when the repo has no CLIENT.md.
58
+ */
59
+ manifestGaps: GcpManifestKey[];
52
60
  }
53
61
  export interface TemplateSyncResult {
54
62
  templateDir: string;
55
63
  files: string[];
56
64
  repos: TemplateSyncRepoResult[];
57
65
  driftedRepoCount: number;
66
+ /** Repos whose CLIENT.md lacks gcp_project / gcp_account (or holds the placeholder). */
67
+ manifestGapRepoCount: number;
58
68
  applied: boolean;
59
69
  }
60
70
  /**
@@ -1,6 +1,7 @@
1
1
  import { existsSync } from "node:fs";
2
2
  import { copyFile, mkdir, readdir, readFile } from "node:fs/promises";
3
3
  import { dirname, join, resolve } from "node:path";
4
+ import { readGcpManifestFromRepo } from "./client-manifest.js";
4
5
  /**
5
6
  * Files that must stay byte-identical between clients/client-template/ and
6
7
  * every clients/client-<slug>/ repo — the enforcement chain (the lint script
@@ -37,6 +38,9 @@ export const TEMPLATE_SYNCED_FILES = [
37
38
  "CADENCE.md",
38
39
  "ci/repo-lint.mjs",
39
40
  "ci/repo-lint.test.mjs",
41
+ // repo-lint imports log-progress (rule 9), so the two always travel together.
42
+ "ci/log-progress.mjs",
43
+ "ci/log-progress.test.mjs",
40
44
  "lefthook.yml",
41
45
  ".github/workflows/repo-lint.yml",
42
46
  ".github/workflows/pr-to-slack.yml",
@@ -89,11 +93,15 @@ export async function templateSync(options) {
89
93
  }
90
94
  fileResults.push({ file: rel, status });
91
95
  }
96
+ const manifest = readGcpManifestFromRepo(dir);
92
97
  repos.push({
93
98
  slug,
94
99
  dir,
95
100
  files: fileResults,
96
101
  inSync: fileResults.every((f) => f.status === "in-sync" || f.status === "fixed"),
102
+ manifestGaps: manifest
103
+ ? [...manifest.missing, ...manifest.unfilled, ...manifest.invalid]
104
+ : [],
97
105
  });
98
106
  }
99
107
  return {
@@ -101,6 +109,7 @@ export async function templateSync(options) {
101
109
  files,
102
110
  repos,
103
111
  driftedRepoCount: repos.filter((r) => !r.inSync).length,
112
+ manifestGapRepoCount: repos.filter((r) => r.manifestGaps.length > 0).length,
104
113
  applied: apply,
105
114
  };
106
115
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@installagent/sdk",
3
- "version": "0.6.0",
3
+ "version": "0.8.0",
4
4
  "description": "Install Agent's shared SDK for internal team operations (client repos, n8n workflows, docs search, and more).",
5
5
  "type": "module",
6
6
  "main": "./dist/index.js",