UNPKG

@hasna/projects

Version:

High-level project management CLI, MCP server, SDK, and AI SDK agent loop for coding agents

114 lines • 6.13 kB
/** * The channel-validity rule, split out of `project-channel.ts` so the write-time * guard can be reached from a storage layer. * * `project-channel.ts` imports the SQLite registry module (ensure reads the * project row and records an audit event there), so a store that must not pull * `bun:sqlite` in — the PostgreSQL `projects-serve` store — cannot import it. * Nothing in this module touches a database: it is the channel-name normalizer, * the conversations CLI probe and the guard over a `conversations_channel` * value. `project-channel.ts` re-exports every symbol here, so existing * importers keep importing from the same place. */ import type { WorkspaceIntegrations } from "../types/workspace.js"; export declare const PROJECT_CHANNEL_INTEGRATION_KEY = "conversations_channel"; export interface ConversationsRunResult { ok: boolean; stdout: string; stderr: string; } export type ConversationsChannelRunner = (args: string[]) => ConversationsRunResult; export declare function normalizeProjectChannelName(value: string): string; export declare const CONVERSATIONS_CLI_TIMEOUT_MS = 15000; export declare function conversationsCliRunner(binary?: string): ConversationsChannelRunner; /** * A synchronous read-only probe of whether one conversations channel exists. * * Doctor and link surfaces use this to validate the channel a project ADVERTISES * through `integrations.conversations_channel` against the real conversations * app. Verdicts are deliberately tri-state: only a channel observed in a * successfully listed channel set is "missing"; anything that prevented the * listing (no CLI, auth, a parse failure) is "unknown" and never a false error. */ export type ProjectChannelExistenceVerdict = "exists" | "missing" | "unknown"; export interface ProjectChannelExistenceResult { verdict: ProjectChannelExistenceVerdict; /** Why an "unknown" verdict was reached (CLI failure, parse failure). */ detail?: string; } export type ProjectChannelExistenceProbe = (channel: string) => ProjectChannelExistenceResult; /** The channel-list surface the CLI prints as a bare JSON array on stdout (compact.ts). */ export declare function conversationsChannelListResult(result: ConversationsRunResult): { ok: true; names: string[]; } | { ok: false; detail: string; }; /** Exact (normalized) membership of one channel in a channel-name set. */ export declare function conversationsChannelExistence(names: readonly string[], channel: string): { verdict: "exists"; } | { verdict: "missing"; }; /** * An existence probe built from any {@link ConversationsChannelRunner}. The * channel listing is fetched once and cached for the lifetime of the probe, so * a multi-project doctor run performs one listing, not one per project. */ export declare function conversationsChannelProbe(runner: ConversationsChannelRunner): ProjectChannelExistenceProbe; export declare function conversationsCliChannelProbe(binary?: string): ProjectChannelExistenceProbe; /** * Whether doctor/link surfaces should validate advertised conversations * channels against the conversations app on this box. Off in tests (a probe * would spawn a CLI that is not there); on by default where the conversations * CLI is expected (the fleet). Set HASNA_PROJECTS_CHANNEL_VERIFY (or * PROJECTS_CHANNEL_VERIFY) to force on/off. */ export declare function shouldProbeConversationsChannel(envValue?: Record<string, string | undefined>): boolean; /** * The probe a write-side channel guard uses when the caller supplies none. * `undefined` when this box cannot reach the conversations app (tests, or * `HASNA_PROJECTS_CHANNEL_VERIFY=0`) — an unverifiable write is never refused, * see {@link assertProjectChannelWritable}. */ export declare function projectChannelWriteProbe(envValue?: Record<string, string | undefined>): ProjectChannelExistenceProbe | undefined; /** * The channel name a write would newly pin, or `null` when the write leaves * `integrations.conversations_channel` alone (absent on both sides, or * byte-equal to what the record already held — a full-integrations write that * merely carries the existing value forward is not a new claim). */ export declare function changedProjectChannel(next: WorkspaceIntegrations | undefined, previous: WorkspaceIntegrations | undefined): string | null; /** * Refuse a write that would pin `integrations.conversations_channel` at a name * the conversations app has no channel for (BUG-0063). * * The registry stores the channel as a free-form name and nothing validated it, * so a renamed project kept pointing at its old name — `employee-contracts` * still carrying `employee-contract-closing`. That name resolved as an agent DM * handle and not as a channel, so the project-channel post fell through to the * DM lane (nobody watching the project channel ever saw it) or failed closed * with HTTP 400 "Channel ... does not exist, so this message was not sent." * * Only a positive `missing` verdict refuses the write. An unavailable probe * (`probe` undefined, e.g. tests, or a box with no conversations CLI) or an * `unknown` verdict passes through: this guard must never invent a failure * from an answer it could not obtain — the same discipline the workspace * doctor follows when it reports "not verified" instead of a fabricated * error. */ export declare function assertProjectChannelWritable(channel: string | null | undefined, options?: { probe?: ProjectChannelExistenceProbe; }): void; /** * The write-time guard for an integration mutation: checks the channel only * when this write actually sets or changes it, so a full-integrations write * that carries an existing (already-broken) value forward still succeeds and * the repair stays a deliberate, separate act. */ export declare function assertProjectChannelIntegrationWritable(next: WorkspaceIntegrations | undefined, previous: WorkspaceIntegrations | undefined, options?: { probe?: ProjectChannelExistenceProbe; env?: Record<string, string | undefined>; }): void; //# sourceMappingURL=project-channel-guard.d.ts.map