@phren/cli
Version:
Knowledge layer for AI agents - CLI, MCP server, and data layer
216 lines (215 loc) • 8.57 kB
TypeScript
import { z } from "zod";
import { type Json } from "./protocol.js";
/** A forge issue link, `domain/owner/name#N` (for example
* `github.com/alaarab/phren#42`), at most 300 characters. The number is a safe
* integer, so a link always names one issue. */
export declare function parseIssueLink(text: string): {
repo: string;
number: number;
} | undefined;
export declare const inboxTargetSchema: z.ZodUnion<readonly [z.ZodObject<{
server: z.ZodString;
workspace: z.ZodString;
tab: z.ZodString;
pane: z.ZodString;
source: z.ZodEnum<{
claude: "claude";
codex: "codex";
copilot: "copilot";
opencode: "opencode";
phren: "phren";
}>;
session: z.ZodUnion<readonly [z.ZodString, z.ZodString]>;
}, z.core.$strip>, z.ZodObject<{
server: z.ZodString;
workspace: z.ZodString;
tab: z.ZodString;
pane: z.ZodString;
source: z.ZodEnum<{
claude: "claude";
codex: "codex";
copilot: "copilot";
opencode: "opencode";
phren: "phren";
}>;
starting: z.ZodLiteral<true>;
startingToken: z.ZodString;
}, z.core.$strip>]>;
declare const itemSchema: z.ZodObject<{
id: z.ZodString;
kind: z.ZodEnum<{
blocked: "blocked";
manual: "manual";
"needs-you": "needs-you";
}>;
title: z.ZodString;
createdAt: z.ZodString;
updatedAt: z.ZodString;
state: z.ZodEnum<{
open: "open";
resolved: "resolved";
}>;
resolvedAt: z.ZodOptional<z.ZodString>;
resolution: z.ZodOptional<z.ZodString>;
project: z.ZodOptional<z.ZodString>;
computer: z.ZodOptional<z.ZodString>;
target: z.ZodOptional<z.ZodUnion<readonly [z.ZodObject<{
server: z.ZodString;
workspace: z.ZodString;
tab: z.ZodString;
pane: z.ZodString;
source: z.ZodEnum<{
claude: "claude";
codex: "codex";
copilot: "copilot";
opencode: "opencode";
phren: "phren";
}>;
session: z.ZodUnion<readonly [z.ZodString, z.ZodString]>;
}, z.core.$strip>, z.ZodObject<{
server: z.ZodString;
workspace: z.ZodString;
tab: z.ZodString;
pane: z.ZodString;
source: z.ZodEnum<{
claude: "claude";
codex: "codex";
copilot: "copilot";
opencode: "opencode";
phren: "phren";
}>;
starting: z.ZodLiteral<true>;
startingToken: z.ZodString;
}, z.core.$strip>]>>;
dispatch: z.ZodOptional<z.ZodString>;
actionId: z.ZodOptional<z.ZodString>;
source: z.ZodOptional<z.ZodString>;
live: z.ZodOptional<z.ZodBoolean>;
command: z.ZodOptional<z.ZodString>;
pr: z.ZodOptional<z.ZodString>;
key: z.ZodOptional<z.ZodString>;
}, z.core.$strict>;
export type InboxItem = z.infer<typeof itemSchema>;
/** An open manual row nothing is stopped on closes itself after this long with
* no change and no repeated add. A row that blocks work never expires. */
export declare const INBOX_EXPIRE_MS: number;
export declare const INBOX_EXPIRED = "expired: nothing happened in 14 days";
/** The internal tick snapshot: the public open row plus whether this is the
* row's first open, which a reword or a same-id reopen must not reset. */
export type InboxTickItem = InboxItem & {
firstOpen: boolean;
blocks?: boolean;
};
export declare const ownerInboxSchema: z.ZodObject<{
action: z.ZodDefault<z.ZodEnum<{
add: "add";
list: "list";
resolve: "resolve";
}>>;
title: z.ZodOptional<z.ZodString>;
project: z.ZodOptional<z.ZodString>;
id: z.ZodOptional<z.ZodString>;
resolution: z.ZodOptional<z.ZodString>;
ifUpdatedAt: z.ZodOptional<z.ZodString>;
includeResolved: z.ZodOptional<z.ZodBoolean>;
computer: z.ZodOptional<z.ZodString>;
command: z.ZodOptional<z.ZodString>;
pr: z.ZodOptional<z.ZodString>;
issue: z.ZodOptional<z.ZodString>;
key: z.ZodOptional<z.ZodString>;
blocks: z.ZodOptional<z.ZodBoolean>;
rules: z.ZodOptional<z.ZodBoolean>;
issues: z.ZodOptional<z.ZodBoolean>;
}, z.core.$strict>;
export interface InboxSource {
source: string;
kind: "needs-you" | "blocked";
title: string;
project?: string;
computer?: string;
target?: z.infer<typeof inboxTargetSchema>;
dispatch?: string;
actionId?: string;
}
export interface InboxSnapshot {
sources: InboxSource[];
unavailableDispatches?: string[];
}
/** Use a separate shell for multiline commands so `&&` cannot suppress their errexit. */
export declare function pasteCommand(item: {
id: string;
command: string;
updatedAt: string;
}, inboxComputer?: string): string;
/** How a reader without the structured `issue` field learns the link. */
export declare function issueSuffix(issue: string): string;
/** A stored title split into its plain text and the issue link it carries. */
export declare function issueInTitle(title: string): {
title: string;
issue?: string;
};
/** The item title bound: `itemSchema`'s `title.max` and the phone contract. */
export declare const INBOX_TITLE_LIMIT = 500;
/** How long a plain title may be beside this link. */
export declare function titleBudget(issue: string): number;
/** The stored title: the plain title plus its link, exactly. Never trimmed,
* because two different titles would then store identically and a re-add would
* not advance `updatedAt` (which a stale close and a reopen rely on). A caller
* adding a link checks `titleBudget` first and refuses a title that does not
* fit; idempotent, so a title already carrying the link is not decorated twice. */
export declare function inboxIssueTitle(item: {
title: string;
issue?: string;
}): string;
/** The APNs alert body, which `push.ts` cuts at 500 UTF-8 bytes: trim by bytes
* with the link's own bytes reserved, so a long title never loses the link.
* This trims a notification only, never a stored row. */
export declare function pushIssueTitle(item: {
title: string;
issue?: string;
}): string;
/**
* One inbox row as a reader receives it. The stored row carries the link only
* in its title, which every older strict Hook and phone schema accepts. A
* reader that asks for it (`issues`) gets the link as a field and the plain
* title instead; everyone else gets the row as stored.
*/
export declare function inboxWire(item: Json, issues?: boolean): Json;
/** Reconcile automatic work against current sources; manual work is owner-owned.
* The first reconciliation also migrates old stale/duplicate automatic rows. */
export declare class OwnerInbox {
private readonly sources;
private readonly file;
private readonly done?;
private pending;
/** `done` reports the open manual items whose linked action happened (item
* id → resolution), so a list can resolve them without the owner. */
constructor(sources?: () => Promise<InboxSource[] | InboxSnapshot>, file?: string, done?: ((items: InboxItem[]) => Promise<Map<string, string>>) | undefined);
private get reopenedFile();
private get metaFile();
/** Called under the Inbox lock. An unreadable sidecar is no sidecar: a row
* then counts as not blocking, which only ever makes the Inbox quieter. */
private readMeta;
/** Bounded by the open manual rows: a closed row keeps nothing. */
private writeMeta;
private readReopened;
private recordReopens;
/** Called under the Inbox lock, including while migrating a previous build's
* inline reopen marker or `issue` key. */
private read;
private withStoreLock;
run(input: unknown): Promise<Json>;
/** A signed phone decision on one row, guarded by the exact revision the
* phone read. Resolve means handled; dismiss removes the row from this
* Hook's shared list. Both are final in v1. Check and write under the same
* lock an ordinary read takes, so a concurrent tick cannot resurrect it. */
close(id: string, ifUpdatedAt: string, decision: "resolve" | "dismiss"): Promise<InboxItem>;
/** Check durable visibility immediately before a send, without reconciling
* sources or holding the store lock during provider I/O. */
isOpenForPush(id: string): Promise<boolean>;
/** Reconcile and return the open snapshot a push sweep may alert about.
* `firstOpen` is carried separately from the public list so a reword or a
* same-id reopen can never look like a first creation. */
tick(): Promise<InboxTickItem[]>;
}
export {};