@adhd/backlog 0.0.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/CHANGELOG.md ADDED
@@ -0,0 +1 @@
1
+ ## Unreleased
package/README.md ADDED
@@ -0,0 +1,67 @@
1
+ # @adhd/backlog
2
+
3
+ A structured, queryable, multi-agent-safe **graph store** for backlog items (bugs,
4
+ debt, features, investigations, plans) — a replacement for ad-hoc `BACKLOG.md`
5
+ editing that stays compatible with the existing markdown convention this repo
6
+ already uses.
7
+
8
+ Built on `@adhd/sox-graph-store` (bi-temporal nodes/edges over SQLite) and mounted
9
+ live via `@adhd/apigen-core-client` (no code generation — `extract()` →
10
+ `composeSchemas()` → `plugin.run()`).
11
+
12
+ See `SPEC.md` (functional spec: personas, data model, status vocabulary,
13
+ operation surface) and `DESIGN.md` (technical design: graph mapping, claim
14
+ protocol, env/apigen wiring) in this package for the full contract.
15
+
16
+ ```bash
17
+ pnpm add @adhd/backlog
18
+ ```
19
+
20
+ ## Usage
21
+
22
+ ```ts
23
+ import { createItem, listItems, claimItem, transitionStatus } from '@adhd/backlog';
24
+ import { buildBacklogEnv } from '@adhd/backlog';
25
+ import { openGraphBacklogStore } from '@adhd/backlog';
26
+
27
+ const env = buildBacklogEnv();
28
+ env.ensureDirs();
29
+ const store = openGraphBacklogStore(env.files.db);
30
+ const ctx = { store, env };
31
+
32
+ const { item } = await createItem(ctx, {
33
+ family: 'BUG-EXAMPLE',
34
+ title: 'Example bug',
35
+ body: 'Something is broken.',
36
+ repo: 'PseudoSky/adhd',
37
+ });
38
+
39
+ await claimItem(ctx, item.repo, item.humanId, 'implementer:abc123');
40
+ await transitionStatus(ctx, item.repo, item.humanId, 'FIXED', {
41
+ by: 'implementer:abc123',
42
+ citations: [{ file: 'entrypoint/backlog/src/client.ts' }],
43
+ });
44
+
45
+ const open = await listItems(ctx, { repo: item.repo, status: 'open' });
46
+ ```
47
+
48
+ ## Running as a live server (no codegen)
49
+
50
+ ```ts
51
+ import { startBacklogServer } from '@adhd/backlog';
52
+
53
+ const abort = new AbortController();
54
+ await startBacklogServer({ transport: 'both', port: 3400, signal: abort.signal });
55
+ ```
56
+
57
+ - `POST /backlog/createItem`, `GET /backlog/getItem`, ... — every `client.ts`
58
+ export, mounted live via `@adhd/apigen-plugin-api-fastify`.
59
+ - Every export is also available as an MCP tool via `@adhd/apigen-plugin-mcp`
60
+ (stdio transport by default).
61
+
62
+ ## Scope
63
+
64
+ Resolved via `@adhd/environment` (see `env.ts`): `global` (default —
65
+ `~/.adhd/backlog/<namespace>/data/backlog.db`, spans every repo on the
66
+ machine), `project` (`<projectRoot>/.adhd/backlog/<namespace>/data/backlog.db`,
67
+ one repo), or `system`. See `SPEC.md` §3 for the full resolution order.
package/client.d.ts ADDED
@@ -0,0 +1,72 @@
1
+ import { GraphBacklogStore } from './store/graph-backlog-store.js';
2
+ import { BacklogConfig } from './env.js';
3
+ import { ArchiveOpts, ArchiveResult, AuditTrailResult, BacklogFilter, BacklogItem, BacklogStats, BacklogStatus, ClaimOpts, ClaimResult, Citation, CreateItemInput, CreateItemResult, DependencyGraph, ImportMarkdownInput, ImportResult, Priority, ReleaseResult, StatsScope, TopoOrderResult, TransitionOpts, UpdateItemInput } from './model.js';
4
+ import { Environment } from '@adhd/environment';
5
+
6
+ /** The one type apigen special-cases via the `ctx-name-only` invariant. */
7
+ export interface BacklogCtx {
8
+ store: GraphBacklogStore;
9
+ env: Environment<BacklogConfig>;
10
+ }
11
+ /**
12
+ * Dedupe-scans (FTS + symbol/path/errorText metadata match) before writing.
13
+ * Allocates humanId as family + next number within (repo, family) unless
14
+ * idOverride is given.
15
+ */
16
+ export declare function createItem(ctx: BacklogCtx, input: CreateItemInput): Promise<CreateItemResult>;
17
+ /** repo is required — humanId alone is not globally unique. */
18
+ export declare function getItem(ctx: BacklogCtx, repo: string, humanId: string): Promise<BacklogItem | null>;
19
+ export declare function updateItem(ctx: BacklogCtx, repo: string, humanId: string, patch: UpdateItemInput): Promise<BacklogItem>;
20
+ export declare function listItems(ctx: BacklogCtx, filter?: BacklogFilter): Promise<BacklogItem[]>;
21
+ /** Invalidates the node (bi-temporal — never a hard delete). */
22
+ export declare function softDeleteItem(ctx: BacklogCtx, repo: string, humanId: string, reason: string): Promise<void>;
23
+ export declare function stats(ctx: BacklogCtx, scope?: StatsScope): Promise<BacklogStats>;
24
+ /** Open + prioritized, most-severe first. */
25
+ export declare function spotlight(ctx: BacklogCtx, scope?: StatsScope, limit?: number): Promise<BacklogItem[]>;
26
+ /** Open items whose every DEPENDS_ON target is a terminal status AND which are not currently claimed. */
27
+ export declare function readyItems(ctx: BacklogCtx, scope?: StatsScope): Promise<BacklogItem[]>;
28
+ /** The DEPENDS_ON set of `humanId` that is NOT yet terminal. */
29
+ export declare function blockers(ctx: BacklogCtx, repo: string, humanId: string): Promise<BacklogItem[]>;
30
+ export declare function dependencyGraph(ctx: BacklogCtx, scope?: StatsScope): Promise<DependencyGraph>;
31
+ export declare function topoOrder(ctx: BacklogCtx, scope?: StatsScope): Promise<TopoOrderResult>;
32
+ /** Items whose claim lease is older than maxAgeMin with no renewal — candidates for --force reclaim. */
33
+ export declare function staleClaims(ctx: BacklogCtx, maxAgeMin: number, scope?: StatsScope): Promise<BacklogItem[]>;
34
+ export declare function claimItem(ctx: BacklogCtx, repo: string, humanId: string, by: string, opts?: ClaimOpts): Promise<ClaimResult>;
35
+ /** Same-claimant renewal — always succeeds (bumps claimedAt), no contention check. */
36
+ export declare function renewClaim(ctx: BacklogCtx, repo: string, humanId: string, by: string): Promise<ClaimResult>;
37
+ export declare function releaseClaim(ctx: BacklogCtx, repo: string, humanId: string, by: string, opts?: {
38
+ force?: boolean;
39
+ }): Promise<ReleaseResult>;
40
+ /** Durable ownership (planner decision) — distinct from the ephemeral claim lease. */
41
+ export declare function assignItem(ctx: BacklogCtx, repo: string, humanId: string, to: string, by: string): Promise<BacklogItem>;
42
+ /** transitionStatus(id, 'IN_PROGRESS', ...) + an implicit claimItem(id, by) — a no-op claim-wise if already held by `by`. */
43
+ export declare function startWork(ctx: BacklogCtx, repo: string, humanId: string, by: string): Promise<BacklogItem>;
44
+ export declare function transitionStatus(ctx: BacklogCtx, repo: string, humanId: string, status: BacklogStatus, opts: TransitionOpts): Promise<BacklogItem>;
45
+ export declare function addCitation(ctx: BacklogCtx, repo: string, humanId: string, citation: Citation): Promise<BacklogItem>;
46
+ export declare function appendNote(ctx: BacklogCtx, repo: string, humanId: string, by: string, text: string): Promise<BacklogItem>;
47
+ /** Sugar for transitionStatus into any terminal status. */
48
+ export declare function resolveItem(ctx: BacklogCtx, repo: string, humanId: string, status: BacklogStatus, opts: TransitionOpts): Promise<BacklogItem>;
49
+ /**
50
+ * Renders terminal items to CHANGELOG.md-formatted markdown and marks them
51
+ * archived (metadata.archivedAt set) so renderToMarkdown's default view
52
+ * excludes them — the graph node itself is NEVER deleted.
53
+ */
54
+ export declare function archiveResolved(ctx: BacklogCtx, scope: StatsScope, opts?: ArchiveOpts): Promise<ArchiveResult>;
55
+ export declare function addDependency(ctx: BacklogCtx, repo: string, humanId: string, dependsOnHumanId: string): Promise<void>;
56
+ export declare function removeDependency(ctx: BacklogCtx, repo: string, humanId: string, dependsOnHumanId: string): Promise<void>;
57
+ export declare function linkRelated(ctx: BacklogCtx, repo: string, humanIdA: string, humanIdB: string): Promise<void>;
58
+ /** Mints a new item, links new SUPERSEDES old, invalidates old with reason. */
59
+ export declare function supersedeItem(ctx: BacklogCtx, repo: string, oldHumanId: string, newInput: CreateItemInput, reason: string): Promise<BacklogItem>;
60
+ /** Creates N children linked child PART_OF parent. Parent is left open. */
61
+ export declare function splitItem(ctx: BacklogCtx, repo: string, parentHumanId: string, children: CreateItemInput[]): Promise<BacklogItem[]>;
62
+ /** SAME_AS(drop -> keep), invalidates drop with an auto-generated reason. */
63
+ export declare function mergeItems(ctx: BacklogCtx, repo: string, keepHumanId: string, dropHumanId: string, reason: string): Promise<BacklogItem>;
64
+ export declare function setPriority(ctx: BacklogCtx, repo: string, humanId: string, priority: Priority): Promise<BacklogItem>;
65
+ /** MEMBER_OF edge to a plan node (auto-created if the plan slug hasn't been seen before). */
66
+ export declare function attachToPlan(ctx: BacklogCtx, repo: string, humanId: string, planSlug: string): Promise<void>;
67
+ export declare function importFromMarkdown(ctx: BacklogCtx, input: ImportMarkdownInput): Promise<ImportResult>;
68
+ /** Excludes archived items (SPEC.md §5.4 archiveResolved) — see markdown.ts's renderItemsToMarkdown doc comment. */
69
+ export declare function renderToMarkdown(ctx: BacklogCtx, filter?: BacklogFilter): Promise<string>;
70
+ export declare function exportJson(ctx: BacklogCtx, filter?: BacklogFilter): Promise<BacklogItem[]>;
71
+ /** Bi-temporal history + supersession chain. */
72
+ export declare function auditTrail(ctx: BacklogCtx, repo: string, humanId: string): Promise<AuditTrailResult>;
package/env.d.ts ADDED
@@ -0,0 +1,36 @@
1
+ import { EnvironmentSpec, Scope } from '@adhd/environment-base-spec';
2
+ import { Environment } from '@adhd/environment';
3
+
4
+ export interface BacklogConfig {
5
+ readonly db: {
6
+ readonly path: string | undefined;
7
+ };
8
+ readonly logging: {
9
+ readonly level: string;
10
+ };
11
+ }
12
+ export declare const backlogEnvironmentSpec: EnvironmentSpec<BacklogConfig>;
13
+ /**
14
+ * Resolves scope per SPEC.md §3 (highest precedence first): explicit option →
15
+ * `ADHD_BACKLOG_SCOPE` → generic `ADHD_ENV_SCOPE` → default `'global'`.
16
+ */
17
+ export declare function resolveBacklogScope(explicit?: Scope): Scope;
18
+ /**
19
+ * Options accepted by `buildBacklogEnv`, beyond scope — `adhdRoot`/`cwd`/
20
+ * `instanceId` exist purely for test isolation (constructing an `Environment`
21
+ * rooted at a temp directory instead of the real machine's `~/.adhd`), mirror
22
+ * `EnvironmentOptions`'s own test-isolation fields.
23
+ */
24
+ export interface BuildBacklogEnvOptions {
25
+ scope?: Scope;
26
+ adhdRoot?: string;
27
+ cwd?: string;
28
+ instanceId?: string;
29
+ }
30
+ export declare function buildBacklogEnv(options?: BuildBacklogEnvOptions): Environment<BacklogConfig>;
31
+ /**
32
+ * DESIGN.md §4.4 — the recommended (not enforced) claimant identity shape:
33
+ * `${agentName}:${instanceId}`. Exposed as a plain helper, never baked into
34
+ * `claimItem` itself.
35
+ */
36
+ export declare function suggestClaimantIdentity(agentName: string, instanceId: string): string;
package/index.d.ts ADDED
@@ -0,0 +1,11 @@
1
+ export { addCitation, addDependency, appendNote, archiveResolved, assignItem, attachToPlan, auditTrail, blockers, claimItem, createItem, dependencyGraph, exportJson, getItem, importFromMarkdown, linkRelated, listItems, mergeItems, readyItems, releaseClaim, removeDependency, renderToMarkdown, renewClaim, resolveItem, setPriority, softDeleteItem, spotlight, splitItem, staleClaims, startWork, stats, supersedeItem, topoOrder, transitionStatus, updateItem, } from './client.js';
2
+ export type { BacklogCtx } from './client.js';
3
+ export { startBacklogServer, buildBacklogApigenPackage } from './server.js';
4
+ export type { StartOpts } from './server.js';
5
+ export { buildBacklogEnv, resolveBacklogScope, suggestClaimantIdentity, backlogEnvironmentSpec } from './env.js';
6
+ export type { BacklogConfig, BuildBacklogEnvOptions } from './env.js';
7
+ export { openGraphBacklogStore, closeGraphBacklogStore } from './store/graph-backlog-store.js';
8
+ export type { GraphBacklogStore } from './store/graph-backlog-store.js';
9
+ export { buildChangelogSection, classifyStatus, detectPriority, detectStatus, normalizeLegacyStatus, parseBacklogMarkdown, renderItemsToMarkdown, toImportItems, } from './markdown.js';
10
+ export type { ParsedImportItem, ParsedMarkdownItem } from './markdown.js';
11
+ export * from './model.js';