@sifr-dev/loom 0.0.0-stage → 1.0.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 (64) hide show
  1. package/CHANGELOG.md +112 -0
  2. package/LICENSE +21 -0
  3. package/README.ar.md +253 -0
  4. package/README.md +262 -2
  5. package/dist/browser.js +2717 -0
  6. package/dist/cli.js +15 -0
  7. package/dist/index.js +4854 -0
  8. package/dist/types/args.d.ts +14 -0
  9. package/dist/types/base64.d.ts +9 -0
  10. package/dist/types/browser.d.ts +57 -0
  11. package/dist/types/canonical.d.ts +20 -0
  12. package/dist/types/cli.d.ts +12 -0
  13. package/dist/types/commands/context.d.ts +30 -0
  14. package/dist/types/commands/diff.d.ts +18 -0
  15. package/dist/types/commands/doctor.d.ts +19 -0
  16. package/dist/types/commands/export.d.ts +30 -0
  17. package/dist/types/commands/migrate.d.ts +9 -0
  18. package/dist/types/commands/serve.d.ts +18 -0
  19. package/dist/types/commands/snapshot.d.ts +15 -0
  20. package/dist/types/commands/sync.d.ts +17 -0
  21. package/dist/types/commands/verify.d.ts +9 -0
  22. package/dist/types/commands/watch.d.ts +25 -0
  23. package/dist/types/compute.d.ts +49 -0
  24. package/dist/types/concurrency.d.ts +31 -0
  25. package/dist/types/config.d.ts +132 -0
  26. package/dist/types/diff.d.ts +57 -0
  27. package/dist/types/digest.d.ts +11 -0
  28. package/dist/types/entities.d.ts +27 -0
  29. package/dist/types/errors.d.ts +37 -0
  30. package/dist/types/fs.d.ts +23 -0
  31. package/dist/types/github/cache.d.ts +44 -0
  32. package/dist/types/github/client.d.ts +91 -0
  33. package/dist/types/github/collect.d.ts +36 -0
  34. package/dist/types/github/discovery.d.ts +39 -0
  35. package/dist/types/github/fixture.d.ts +26 -0
  36. package/dist/types/github/guard.d.ts +14 -0
  37. package/dist/types/github/memory-cache.d.ts +34 -0
  38. package/dist/types/index.d.ts +44 -0
  39. package/dist/types/log.d.ts +16 -0
  40. package/dist/types/metrics.d.ts +21 -0
  41. package/dist/types/migrate.d.ts +24 -0
  42. package/dist/types/pipeline.d.ts +73 -0
  43. package/dist/types/queue.d.ts +33 -0
  44. package/dist/types/sdk.d.ts +165 -0
  45. package/dist/types/secrets.d.ts +28 -0
  46. package/dist/types/serve-handler.d.ts +46 -0
  47. package/dist/types/sha256.d.ts +13 -0
  48. package/dist/types/site-module.d.ts +23 -0
  49. package/dist/types/site.d.ts +135 -0
  50. package/dist/types/snapshot.d.ts +16 -0
  51. package/dist/types/store.d.ts +119 -0
  52. package/dist/types/triggers.d.ts +67 -0
  53. package/dist/types/types.d.ts +176 -0
  54. package/dist/types/version.d.ts +7 -0
  55. package/dist/types/webhook/delivery.d.ts +45 -0
  56. package/dist/types/webhook/receiver.d.ts +46 -0
  57. package/dist/types/webhook/signature.d.ts +43 -0
  58. package/docs/CONFIGURATION.md +213 -0
  59. package/docs/DEPLOYMENT.md +316 -0
  60. package/docs/SDK.md +351 -0
  61. package/docs/SITE_CONTRACT.md +318 -0
  62. package/docs/VERIFICATION.md +130 -0
  63. package/package.json +83 -4
  64. package/schema/site@1.json +188 -0
@@ -0,0 +1,14 @@
1
+ export type FlagKind = "string" | "number" | "boolean";
2
+ export type FlagSpec = Record<string, FlagKind>;
3
+ export type FlagValue = string | number | boolean;
4
+ export type ParsedArgs = {
5
+ command: string | null;
6
+ positionals: string[];
7
+ flags: Record<string, FlagValue>;
8
+ };
9
+ export declare const COMMON_FLAGS: FlagSpec;
10
+ /** Small, strict flag parser. Unknown flags are usage errors, never ignored. */
11
+ export declare function parseArgs(argv: readonly string[], spec: FlagSpec): ParsedArgs;
12
+ export declare function stringFlag(flags: Record<string, FlagValue>, name: string): string | null;
13
+ export declare function numberFlag(flags: Record<string, FlagValue>, name: string): number | null;
14
+ export declare function booleanFlag(flags: Record<string, FlagValue>, name: string): boolean;
@@ -0,0 +1,9 @@
1
+ /**
2
+ * Base64 decoding without a `Buffer` global.
3
+ *
4
+ * GitHub returns README content as base64. The collector decodes a bounded
5
+ * prefix of it, and the collector is part of the browser-safe data path, so the
6
+ * decoder uses `atob` plus `TextDecoder` instead of Node's `Buffer`.
7
+ */
8
+ /** Decode a base64 string to UTF-8 text. Invalid input throws. */
9
+ export declare function decodeBase64(value: string): string;
@@ -0,0 +1,57 @@
1
+ /**
2
+ * `@sifr-dev/loom/browser` - the environment-free half of the SDK.
3
+ *
4
+ * Everything reachable from this module works with nothing but `fetch`,
5
+ * `TextEncoder`, `atob`, and standard JavaScript: no `node:` builtins, no
6
+ * filesystem, no Bun global. A website can read public GitHub state and derive
7
+ * the `loom/site@1` record in the page, a worker, or a serverless function.
8
+ *
9
+ * import { collectSite } from "@sifr-dev/loom/browser";
10
+ * const record = await collectSite({ repos: ["Sifr-Dev/Loom"] });
11
+ * render(record.projects);
12
+ *
13
+ * Persistence (`SnapshotStore`), triggers, webhooks, and the CLI live in the
14
+ * package root and need a Bun or Node runtime.
15
+ */
16
+ import type { LoomConfig } from "./config.js";
17
+ import { type SourceOptions } from "./compute.js";
18
+ import { type SiteRecord } from "./site.js";
19
+ export { CONFIG_SCHEMA, DEFAULT_CONFIG, isRepoGlob, isRepoName, parseConfig, repoGlobMatches, repoKey, } from "./config.js";
20
+ export type { CollectConfig, DiscoveryConfig, LoomConfig, ServeConfig, TriggerConfig, WatchConfig, WebhookConfig, } from "./config.js";
21
+ export { canonicalBytes, canonicalize, sortKeysDeep } from "./canonical.js";
22
+ export type { JsonPrimitive, JsonValue } from "./canonical.js";
23
+ export { DIGEST_PREFIX, digestHex, digestOf, isDigest, shortDigest } from "./digest.js";
24
+ export { sha256Hex } from "./sha256.js";
25
+ export { decodeBase64 } from "./base64.js";
26
+ export { GitHubClient, nextLink, parseRateLimit } from "./github/client.js";
27
+ export type { ClientStats, FetchLike, GetAllResult, GetOptions, GetResult, GitHubClientOptions, RateLimit, } from "./github/client.js";
28
+ export { MemoryCache } from "./github/memory-cache.js";
29
+ export type { CacheEntry, ResponseCache } from "./github/memory-cache.js";
30
+ export { createFixtureTransport } from "./github/fixture.js";
31
+ export type { FixtureFile, FixtureTransport } from "./github/fixture.js";
32
+ export { discoverRepositories } from "./github/discovery.js";
33
+ export type { DiscoveryOptions, DiscoveryResult, DiscoverySkipReason } from "./github/discovery.js";
34
+ export { buildSnapshot, normalizeSnapshot } from "./snapshot.js";
35
+ export { describeEvent, diffSnapshots, resolveRepoAlias } from "./diff.js";
36
+ export type { DiffEvent, DiffEventKind, DiffOptions, DiffResult, DiffSummary } from "./diff.js";
37
+ export { computeSnapshot, ownerAliasesOf } from "./compute.js";
38
+ export type { ComputedSnapshot, Logger, RecordedSource, SourceOptions } from "./compute.js";
39
+ export { buildSiteRecord, SITE_SCHEMA, siteDigest, siteProject } from "./site.js";
40
+ export type { SiteBranch, SiteCi, SiteComment, SiteHead, SiteProject, SiteReadme, SiteRecord, SiteRelease, SiteWorkflow, } from "./site.js";
41
+ export { renderSiteModule, siteModuleDigest } from "./site-module.js";
42
+ export type { CuratedEntry, CuratedValue, SiteModuleOptions } from "./site-module.js";
43
+ export { EXIT, LoomError } from "./errors.js";
44
+ export type { ExitCode, LoomErrorCode } from "./errors.js";
45
+ export { SNAPSHOT_SCHEMA, snapshotStats } from "./types.js";
46
+ export type { BranchSnapshot, CiSnapshot, CommitCommentSnapshot, HeadSnapshot, IssueCommentSnapshot, ReadmeSnapshot, ReleaseSnapshot, RepoSnapshot, Snapshot, SnapshotError, SnapshotPayload, SnapshotSource, SnapshotStats, WorkflowSnapshot, } from "./types.js";
47
+ export { VERSION } from "./version.js";
48
+ export type CollectSiteOptions = Omit<SourceOptions, "config">;
49
+ /**
50
+ * Read public GitHub state and return the `loom/site@1` record in one call.
51
+ *
52
+ * `config` may be a validated `LoomConfig` or a plain object such as the
53
+ * contents of `loom.config.json`; a plain object is validated with the same
54
+ * rules the CLI uses. Pass `fetch` to route through a proxy or a recorded
55
+ * transport, and `token` to raise the anonymous rate limit.
56
+ */
57
+ export declare function collectSite(config: LoomConfig | Record<string, unknown>, options?: CollectSiteOptions): Promise<SiteRecord>;
@@ -0,0 +1,20 @@
1
+ /**
2
+ * Canonical JSON: one byte sequence per logical value.
3
+ *
4
+ * Every digest Loom publishes is taken over this encoding, so two runs that
5
+ * observe the same GitHub state produce the same snapshot id regardless of key
6
+ * insertion order, file system order, or how the payload was assembled.
7
+ */
8
+ export type JsonPrimitive = null | boolean | number | string;
9
+ export type JsonValue = JsonPrimitive | JsonValue[] | {
10
+ readonly [key: string]: JsonValue;
11
+ };
12
+ export declare class CanonicalJsonError extends Error {
13
+ name: string;
14
+ }
15
+ /** Serialise a JSON value with object keys sorted by code unit. */
16
+ export declare function canonicalize(value: unknown): string;
17
+ /** UTF-8 bytes of {@link canonicalize}. */
18
+ export declare function canonicalBytes(value: unknown): Uint8Array;
19
+ /** Recursively sort object keys, returning a new value. Arrays keep their order. */
20
+ export declare function sortKeysDeep<T>(value: T): T;
@@ -0,0 +1,12 @@
1
+ #!/usr/bin/env bun
2
+ import { type FlagSpec } from "./args.js";
3
+ import { type CliContext } from "./commands/context.js";
4
+ import { VERSION } from "./version.js";
5
+ export { VERSION };
6
+ type Command = {
7
+ summary: string;
8
+ spec: FlagSpec;
9
+ run: (ctx: CliContext, flags: Record<string, string | number | boolean>) => Promise<number>;
10
+ };
11
+ export declare const COMMANDS: Record<string, Command>;
12
+ export declare function runCli(argv: readonly string[], overrides?: Partial<CliContext>): Promise<number>;
@@ -0,0 +1,30 @@
1
+ import { type FlagValue } from "../args.js";
2
+ import { type LoomConfig } from "../config.js";
3
+ import { LoomError } from "../errors.js";
4
+ import { SnapshotStore } from "../store.js";
5
+ import type { Logger } from "../pipeline.js";
6
+ export type CliContext = {
7
+ cwd: string;
8
+ env: Record<string, string | undefined>;
9
+ stdout: (line: string) => void;
10
+ stderr: (line: string) => void;
11
+ };
12
+ export declare const defaultContext: () => CliContext;
13
+ export declare function out(ctx: CliContext, line?: string): void;
14
+ export declare function err(ctx: CliContext, line: string): void;
15
+ export declare function flag(flags: Record<string, FlagValue>, name: string): string | null;
16
+ export declare function isSet(flags: Record<string, FlagValue>, name: string): boolean;
17
+ export declare function number(flags: Record<string, FlagValue>, name: string): number | null;
18
+ export declare function loggerFor(ctx: CliContext, flags: Record<string, FlagValue>): Logger | undefined;
19
+ export declare function configFrom(ctx: CliContext, flags: Record<string, FlagValue>): Promise<{
20
+ config: LoomConfig;
21
+ path: string | null;
22
+ }>;
23
+ export declare function storeFrom(ctx: CliContext, flags: Record<string, FlagValue>, config: LoomConfig, options?: {
24
+ create?: boolean;
25
+ }): Promise<SnapshotStore>;
26
+ export declare function fixtureFrom(ctx: CliContext, flags: Record<string, FlagValue>): string | null;
27
+ export declare function tokenFrom(ctx: CliContext, flags: Record<string, FlagValue>): string | null;
28
+ /** Print a failure once, in text or JSON, and return the process exit code. */
29
+ export declare function reportFailure(ctx: CliContext, error: unknown, json: boolean): number;
30
+ export declare function asLoomError(error: unknown): LoomError;
@@ -0,0 +1,18 @@
1
+ import type { SnapshotStore } from "../store.js";
2
+ import { type Snapshot } from "../types.js";
3
+ import type { FlagValue } from "../args.js";
4
+ import { type CliContext } from "./context.js";
5
+ export declare const DIFF_FLAGS: {
6
+ readonly config: "string";
7
+ readonly store: "string";
8
+ readonly fixture: "string";
9
+ readonly "token-env": "string";
10
+ readonly from: "string";
11
+ readonly to: "string";
12
+ readonly json: "boolean";
13
+ readonly quiet: "boolean";
14
+ readonly help: "boolean";
15
+ };
16
+ /** Read a snapshot by reference: `HEAD`, a digest, or `file:<path>`. */
17
+ export declare function loadSnapshotRef(store: SnapshotStore, reference: string, cwd: string): Promise<Snapshot>;
18
+ export declare function runDiffCommand(ctx: CliContext, flags: Record<string, FlagValue>): Promise<number>;
@@ -0,0 +1,19 @@
1
+ import type { FlagValue } from "../args.js";
2
+ import { type CliContext } from "./context.js";
3
+ export declare const DOCTOR_FLAGS: {
4
+ readonly config: "string";
5
+ readonly store: "string";
6
+ readonly "token-env": "string";
7
+ readonly fix: "boolean";
8
+ readonly json: "boolean";
9
+ readonly quiet: "boolean";
10
+ readonly "log-format": "string";
11
+ readonly help: "boolean";
12
+ };
13
+ /**
14
+ * Offline, actionable diagnostics. `doctor` never contacts GitHub; it reports
15
+ * what a deployment would fail on and what merely deserves attention. With
16
+ * `--fix` it quarantines corrupt caches and removes crash debris, never a
17
+ * content-addressed object.
18
+ */
19
+ export declare function runDoctorCommand(ctx: CliContext, flags: Record<string, FlagValue>): Promise<number>;
@@ -0,0 +1,30 @@
1
+ import type { FlagValue } from "../args.js";
2
+ import { type CliContext } from "./context.js";
3
+ export declare const EXPORT_FLAGS: {
4
+ readonly config: "string";
5
+ readonly store: "string";
6
+ readonly fixture: "string";
7
+ readonly "token-env": "string";
8
+ readonly source: "string";
9
+ readonly out: "string";
10
+ /** `json` (default, the loom/site@1 wire record) or `ts` (typed module). */
11
+ readonly format: "string";
12
+ /** Optional curated-enrichment JSON keyed by project id, for `--format ts`. */
13
+ readonly curated: "string";
14
+ /** Import specifier written into a `--format ts` module. */
15
+ readonly package: "string";
16
+ readonly check: "boolean";
17
+ readonly json: "boolean";
18
+ readonly quiet: "boolean";
19
+ readonly "log-format": "string";
20
+ readonly help: "boolean";
21
+ };
22
+ /**
23
+ * Emit the deterministic site-consumer record (`loom/site@1`).
24
+ *
25
+ * Default source is the committed snapshot (`head`), so a deploy job can export
26
+ * without touching GitHub. `--source remote` recomputes from GitHub/fixture
27
+ * without committing anything. `--check` exits 7 when the file on disk differs
28
+ * from the current snapshot, which is the CI signal that a redeploy is due.
29
+ */
30
+ export declare function runExportCommand(ctx: CliContext, flags: Record<string, FlagValue>): Promise<number>;
@@ -0,0 +1,9 @@
1
+ import type { FlagValue } from "../args.js";
2
+ import { type CliContext } from "./context.js";
3
+ export declare const MIGRATE_FLAGS: {
4
+ readonly config: "string";
5
+ readonly store: "string";
6
+ readonly json: "boolean";
7
+ readonly help: "boolean";
8
+ };
9
+ export declare function runMigrateCommand(ctx: CliContext, flags: Record<string, FlagValue>): Promise<number>;
@@ -0,0 +1,18 @@
1
+ import type { FlagValue } from "../args.js";
2
+ import { type CliContext } from "./context.js";
3
+ export declare const SERVE_FLAGS: {
4
+ readonly config: "string";
5
+ readonly store: "string";
6
+ readonly fixture: "string";
7
+ readonly "token-env": "string";
8
+ readonly port: "number";
9
+ readonly host: "string";
10
+ readonly "secret-env": "string";
11
+ readonly "poll-interval": "number";
12
+ readonly "queue-depth": "number";
13
+ readonly "shutdown-timeout": "number";
14
+ readonly quiet: "boolean";
15
+ readonly "log-format": "string";
16
+ readonly help: "boolean";
17
+ };
18
+ export declare function runServeCommand(ctx: CliContext, flags: Record<string, FlagValue>): Promise<number>;
@@ -0,0 +1,15 @@
1
+ import type { FlagValue } from "../args.js";
2
+ import { type CliContext } from "./context.js";
3
+ export declare const SNAPSHOT_FLAGS: {
4
+ readonly config: "string";
5
+ readonly store: "string";
6
+ readonly fixture: "string";
7
+ readonly "token-env": "string";
8
+ readonly out: "string";
9
+ readonly write: "boolean";
10
+ readonly json: "boolean";
11
+ readonly quiet: "boolean";
12
+ readonly help: "boolean";
13
+ };
14
+ /** Read the source and print or write the snapshot without committing it. */
15
+ export declare function runSnapshotCommand(ctx: CliContext, flags: Record<string, FlagValue>): Promise<number>;
@@ -0,0 +1,17 @@
1
+ import { type CliContext } from "./context.js";
2
+ import type { FlagValue } from "../args.js";
3
+ export declare const SYNC_FLAGS: {
4
+ readonly config: "string";
5
+ readonly store: "string";
6
+ readonly fixture: "string";
7
+ readonly "token-env": "string";
8
+ readonly concurrency: "number";
9
+ readonly "dry-run": "boolean";
10
+ readonly dispatch: "boolean";
11
+ readonly json: "boolean";
12
+ readonly quiet: "boolean";
13
+ readonly "tolerate-errors": "boolean";
14
+ readonly "log-format": "string";
15
+ readonly help: "boolean";
16
+ };
17
+ export declare function runSyncCommand(ctx: CliContext, flags: Record<string, FlagValue>): Promise<number>;
@@ -0,0 +1,9 @@
1
+ import type { FlagValue } from "../args.js";
2
+ import { type CliContext } from "./context.js";
3
+ export declare const VERIFY_FLAGS: {
4
+ readonly config: "string";
5
+ readonly store: "string";
6
+ readonly json: "boolean";
7
+ readonly help: "boolean";
8
+ };
9
+ export declare function runVerifyCommand(ctx: CliContext, flags: Record<string, FlagValue>): Promise<number>;
@@ -0,0 +1,25 @@
1
+ import type { FlagValue } from "../args.js";
2
+ import { type CliContext } from "./context.js";
3
+ export declare const WATCH_FLAGS: {
4
+ readonly config: "string";
5
+ readonly store: "string";
6
+ readonly fixture: "string";
7
+ readonly "token-env": "string";
8
+ readonly concurrency: "number";
9
+ readonly "dry-run": "boolean";
10
+ readonly dispatch: "boolean";
11
+ readonly json: "boolean";
12
+ readonly quiet: "boolean";
13
+ readonly "tolerate-errors": "boolean";
14
+ readonly "log-format": "string";
15
+ readonly help: "boolean";
16
+ readonly interval: "number";
17
+ readonly once: "boolean";
18
+ readonly "max-cycles": "number";
19
+ };
20
+ /**
21
+ * Poll the source on an interval. Conditional requests make an unchanged cycle
22
+ * cheap: GitHub answers 304 and the snapshot id stays the same, so no commit and
23
+ * no trigger happens. SIGINT/SIGTERM finish the current cycle, then exit 0.
24
+ */
25
+ export declare function runWatchCommand(ctx: CliContext, flags: Record<string, FlagValue>): Promise<number>;
@@ -0,0 +1,49 @@
1
+ /**
2
+ * Reading public state without a store.
3
+ *
4
+ * `computeSnapshot` is the read half of a sync: discovery, conditional
5
+ * collection, normalisation, and the content address. It never touches the
6
+ * filesystem and never imports a Node builtin, so the same function runs in a
7
+ * worker, in a browser page, and in the CLI. `pipeline.ts` adds the store,
8
+ * outbox, and trigger dispatch around it.
9
+ */
10
+ import type { LoomConfig } from "./config.js";
11
+ import { GitHubClient, type FetchLike } from "./github/client.js";
12
+ import { type ResponseCache } from "./github/memory-cache.js";
13
+ import type { FixtureTransport } from "./github/fixture.js";
14
+ import type { Snapshot, SnapshotPayload, SnapshotStats } from "./types.js";
15
+ export type Logger = (message: string, detail?: Record<string, unknown>) => void;
16
+ /** Owner aliases recorded in a snapshot source, as a lookup table. */
17
+ export declare function ownerAliasesOf(snapshot: Snapshot): Record<string, string>;
18
+ /** A recorded transport and the base URL its routes were recorded against. */
19
+ export type RecordedSource = {
20
+ transport: FixtureTransport;
21
+ baseUrl: string;
22
+ };
23
+ export type SourceOptions = {
24
+ config: LoomConfig;
25
+ /** Recorded responses; when set, no network is used. */
26
+ fixture?: RecordedSource | null;
27
+ token?: string | null;
28
+ cache?: ResponseCache | null;
29
+ fetch?: FetchLike;
30
+ sleep?: (ms: number) => Promise<void>;
31
+ now?: () => number;
32
+ logger?: Logger;
33
+ tolerateErrors?: boolean;
34
+ /** Previous payload for partial-failure retention. */
35
+ previous?: SnapshotPayload | null;
36
+ /** Repository fan-out bound. */
37
+ concurrency?: number;
38
+ signal?: AbortSignal;
39
+ };
40
+ export type ComputedSnapshot = {
41
+ snapshot: Snapshot;
42
+ payload: SnapshotPayload;
43
+ client: GitHubClient;
44
+ fixture: FixtureTransport | null;
45
+ cache: ResponseCache;
46
+ stats: SnapshotStats;
47
+ };
48
+ /** Read the configured source into a normalised, content-addressed snapshot. */
49
+ export declare function computeSnapshot(options: SourceOptions): Promise<ComputedSnapshot>;
@@ -0,0 +1,31 @@
1
+ /**
2
+ * Small concurrency primitives.
3
+ *
4
+ * Loom talks to one origin (GitHub) whose limits are per-token, not per-socket.
5
+ * Every fan-out therefore passes through a bound and every job can be
6
+ * cancelled. The helpers keep result order stable so a concurrent collection
7
+ * still normalises to the same content address as a sequential one.
8
+ */
9
+ export declare class CancelledError extends Error {
10
+ name: string;
11
+ constructor(message?: string);
12
+ }
13
+ /** Throw a cancellation error when the caller's signal has fired. */
14
+ export declare function throwIfAborted(signal: AbortSignal | undefined): void;
15
+ /** A signal that fires when either input fires, without leaking listeners. */
16
+ export declare function combineSignals(signals: readonly (AbortSignal | undefined)[]): AbortSignal | undefined;
17
+ export type SettledResult<T> = {
18
+ ok: true;
19
+ value: T;
20
+ } | {
21
+ ok: false;
22
+ error: unknown;
23
+ };
24
+ /**
25
+ * Run `worker` over `items` with at most `limit` in flight, preserving input
26
+ * order. Failures are returned, not thrown, so one bad repository cannot abort
27
+ * the rest of a tolerated collection. Cancellation rejects the whole pool.
28
+ */
29
+ export declare function mapLimitSettled<T, R>(items: readonly T[], limit: number, worker: (item: T, index: number) => Promise<R>, signal?: AbortSignal): Promise<SettledResult<R>[]>;
30
+ /** Like {@link mapLimitSettled}, but rejects on the first failure. */
31
+ export declare function mapLimit<T, R>(items: readonly T[], limit: number, worker: (item: T, index: number) => Promise<R>, signal?: AbortSignal): Promise<R[]>;
@@ -0,0 +1,132 @@
1
+ export declare const CONFIG_SCHEMA = "loom/config@1";
2
+ export type TriggerConfig = {
3
+ kind: "vercel";
4
+ urlEnv: string;
5
+ } | {
6
+ kind: "github-dispatch";
7
+ repo: string;
8
+ eventType: string;
9
+ tokenEnv: string;
10
+ } | {
11
+ kind: "webhook";
12
+ urlEnv: string;
13
+ secretEnv: string | null;
14
+ };
15
+ export type WebhookConfig = {
16
+ /** HTTP path served by `loom serve`. */
17
+ path: string;
18
+ /** Name of the environment variable holding the HMAC secret. Never the secret. */
19
+ secretEnv: string;
20
+ /** Seconds of clock skew accepted in signed-timestamp mode. */
21
+ toleranceSeconds: number;
22
+ /** Rejected requests above this many bytes. */
23
+ maxBodyBytes: number;
24
+ };
25
+ export type WatchConfig = {
26
+ intervalSeconds: number;
27
+ };
28
+ export type ServeConfig = {
29
+ /** Reconciliation poll interval; 0 disables polling and relies on webhooks. */
30
+ pollIntervalSeconds: number;
31
+ /** Maximum webhook syncs waiting behind the active one. */
32
+ queueDepth: number;
33
+ /** Graceful drain deadline on SIGTERM/SIGINT. */
34
+ shutdownTimeoutSeconds: number;
35
+ /** Hard deadline for one queued sync, so a wedged request cannot block the queue. */
36
+ syncTimeoutSeconds: number;
37
+ };
38
+ /**
39
+ * Automatic public-repository discovery for one or more owners. Discovery is
40
+ * deliberately a policy, not a crawler: only public repositories are eligible,
41
+ * archived/fork entries are excluded unless explicitly allowed, and include/
42
+ * exclude globs make the selected set reviewable and deterministic.
43
+ */
44
+ export type DiscoveryConfig = {
45
+ /** GitHub user or organization logins (not repository names). */
46
+ owners: string[];
47
+ /** `owner/name` globs; when non-empty, a repository must match one. */
48
+ include: string[];
49
+ /** `owner/name` globs; a match always wins over include and defaults. */
50
+ exclude: string[];
51
+ includeArchived: boolean;
52
+ includeForks: boolean;
53
+ };
54
+ /**
55
+ * Opt-in enrichment sources. Each one is bounded, so a high-activity repository
56
+ * cannot make the snapshot (or the generated website module) grow without
57
+ * limit. The default is metadata + languages + releases + latest commit; these
58
+ * add README state, branch heads, comment history, and workflows/CI.
59
+ */
60
+ export type CollectConfig = {
61
+ /** README metadata plus a bounded plain-text excerpt. */
62
+ readme: boolean;
63
+ readmeExcerptChars: number;
64
+ /** Branch heads for the default branch and `extraBranches`. */
65
+ branches: boolean;
66
+ branchLimit: number;
67
+ /** Branch names to track in addition to each repository's default branch. */
68
+ extraBranches: string[];
69
+ /** Commit comments, newest first. */
70
+ commitComments: boolean;
71
+ commitCommentLimit: number;
72
+ /** Repository-wide issue/PR comments, newest first. */
73
+ issueComments: boolean;
74
+ issueCommentLimit: number;
75
+ /** Workflow definitions and the latest CI run on the default branch. */
76
+ workflows: boolean;
77
+ workflowLimit: number;
78
+ ciRuns: number;
79
+ };
80
+ export type LoomConfig = {
81
+ schema: typeof CONFIG_SCHEMA;
82
+ /** Explicit public repositories, `owner/name`. May be empty with discovery. */
83
+ repos: string[];
84
+ /** Branches whose pushes are considered deploy-relevant. */
85
+ branches: string[];
86
+ /** How many releases per repository to include. */
87
+ releases: number;
88
+ includeLatestCommit: boolean;
89
+ /** Old repository id -> new repository id, for renames. */
90
+ aliases: Record<string, string>;
91
+ /**
92
+ * Old GitHub owner login -> current owner login. Applied before repository
93
+ * aliases so an account rename canonicalises every repository under it.
94
+ */
95
+ ownerAliases: Record<string, string>;
96
+ /** Automatic public-owner discovery. */
97
+ discovery: DiscoveryConfig;
98
+ /** Opt-in enrichment sources; every one is bounded. */
99
+ collect: CollectConfig;
100
+ store: string;
101
+ githubBaseUrl: string;
102
+ triggers: TriggerConfig[];
103
+ webhook: WebhookConfig;
104
+ watch: WatchConfig;
105
+ serve: ServeConfig;
106
+ };
107
+ export declare const DEFAULT_CONFIG: LoomConfig;
108
+ /** Validates `owner/name` and rejects path tricks. */
109
+ export declare function isRepoName(value: string): boolean;
110
+ /** Validates a discovery include/exclude glob such as `Sifr-Dev/*`. */
111
+ export declare function isRepoGlob(value: string): boolean;
112
+ /** Case-insensitive `*`/`?` glob over `owner/name`. Deterministic by construction. */
113
+ export declare function repoGlobMatches(pattern: string, repo: string): boolean;
114
+ /** Normalises `owner/name` for case-insensitive comparison (GitHub names are case-insensitive). */
115
+ export declare function repoKey(value: string): string;
116
+ /** Follow an owner-alias chain, stopping on cycles or after eight hops. */
117
+ export declare function resolveOwnerAlias(owner: string, aliases: Record<string, string>): string;
118
+ /** Split `owner/name`, returning `null` when it is not a repository name. */
119
+ export declare function splitRepoName(fullName: string): {
120
+ owner: string;
121
+ name: string;
122
+ } | null;
123
+ /** Apply owner aliases to the owner part, preserving the repository name. */
124
+ export declare function canonicalRepoKey(fullName: string, ownerAliases: Record<string, string>): string;
125
+ /** Display-cased form of `canonicalRepoKey`, using the alias target's casing. */
126
+ export declare function canonicalRepoDisplay(fullName: string, ownerAliases: Record<string, string>): string;
127
+ /** Aliases that form a cycle, for `loom doctor`. Empty when the table is sound. */
128
+ export declare function aliasCycles(aliases: Record<string, string>): string[][];
129
+ /** Parse configuration, filling defaults and validating every field. */
130
+ export declare function parseConfig(raw: unknown): LoomConfig;
131
+ /** Load and validate a config file. A missing file yields defaults. */
132
+ export declare function loadConfig(path: string | null): Promise<LoomConfig>;
@@ -0,0 +1,57 @@
1
+ import { type EntityKind } from "./entities.js";
2
+ import type { Snapshot } from "./types.js";
3
+ export declare const DIFF_SCHEMA = "loom/diff@1";
4
+ export type DiffEventKind = "added" | "updated" | "removed";
5
+ export type DiffEvent = {
6
+ id: string;
7
+ kind: DiffEventKind;
8
+ entity: EntityKind;
9
+ repo: string;
10
+ /** Top-level field names that changed; empty for added and removed. */
11
+ fields: string[];
12
+ /** Set when the entity id changed because the repository was renamed. */
13
+ previousId?: string;
14
+ fingerprint: string | null;
15
+ previousFingerprint: string | null;
16
+ };
17
+ export type DiffSummary = {
18
+ added: number;
19
+ updated: number;
20
+ removed: number;
21
+ renamed: number;
22
+ total: number;
23
+ };
24
+ export type DiffResult = {
25
+ schema: typeof DIFF_SCHEMA;
26
+ from: string | null;
27
+ to: string;
28
+ changed: boolean;
29
+ summary: DiffSummary;
30
+ renames: {
31
+ from: string;
32
+ to: string;
33
+ }[];
34
+ events: DiffEvent[];
35
+ };
36
+ export type DiffOptions = {
37
+ /** Old repository id -> new repository id. Keys are compared case-insensitively. */
38
+ aliases?: Record<string, string>;
39
+ /** Old owner login -> current owner login, applied before `aliases`. */
40
+ ownerAliases?: Record<string, string>;
41
+ };
42
+ /**
43
+ * Follow an alias chain, stopping on cycles. Owner aliases are applied first,
44
+ * so a repository under a renamed account reaches its canonical owner before
45
+ * any repository-level alias is consulted.
46
+ */
47
+ export declare function resolveRepoAlias(repo: string, aliases: Record<string, string>, ownerAliases?: Record<string, string>): string;
48
+ /**
49
+ * Rewrite an entity id through the alias table. A release keeps its tag while
50
+ * its repository part is renamed, so `release:old@v1` becomes `release:new@v1`.
51
+ * Every id kind that carries an `@` discriminator is rewritten the same way.
52
+ */
53
+ export declare function rewriteEntityId(id: string, aliases: Record<string, string>, ownerAliases?: Record<string, string>): string;
54
+ /** Diff two snapshots into added / updated / removed events with stable ids. */
55
+ export declare function diffSnapshots(from: Snapshot | null, to: Snapshot, options?: DiffOptions): DiffResult;
56
+ /** One-line description used by the CLI and by trigger payloads. */
57
+ export declare function describeEvent(event: DiffEvent): string;
@@ -0,0 +1,11 @@
1
+ import { sha256Hex } from "./sha256.js";
2
+ export { sha256Hex };
3
+ export declare const DIGEST_PREFIX = "sha256:";
4
+ /** Content address of a JSON value: `sha256:<hex>` over canonical JSON. */
5
+ export declare function digestOf(value: unknown): string;
6
+ export declare function isDigest(value: string): boolean;
7
+ export declare function assertDigest(value: string): string;
8
+ /** The hex part of a digest, used as a file name. */
9
+ export declare function digestHex(digest: string): string;
10
+ /** Short, human-facing form: `sha256:ab12cd34`. */
11
+ export declare function shortDigest(digest: string, length?: number): string;
@@ -0,0 +1,27 @@
1
+ import type { RepoSnapshot, SnapshotPayload } from "./types.js";
2
+ export type EntityKind = "repo" | "release" | "head" | "readme" | "branch" | "commit-comment" | "issue-comment" | "workflow" | "ci";
3
+ export type Entity = {
4
+ /** Stable id across snapshots: `repo:owner/name`, `release:owner/name@tag`, `head:owner/name`. */
5
+ id: string;
6
+ kind: EntityKind;
7
+ /** Repository id the entity belongs to. */
8
+ repo: string;
9
+ /** Content address of `fields`, so updates are detectable without field-level bookkeeping. */
10
+ fingerprint: string;
11
+ fields: Record<string, unknown>;
12
+ };
13
+ /** Repository metadata without the nested entities that diff separately. */
14
+ export declare function repoFields(repo: RepoSnapshot): Record<string, unknown>;
15
+ export declare function repoEntityId(repo: string): string;
16
+ export declare function releaseEntityId(repo: string, tag: string): string;
17
+ export declare function headEntityId(repo: string): string;
18
+ export declare function readmeEntityId(repo: string): string;
19
+ export declare function branchEntityId(repo: string, branch: string): string;
20
+ export declare function commitCommentEntityId(repo: string, id: number | string): string;
21
+ export declare function issueCommentEntityId(repo: string, id: number | string): string;
22
+ export declare function workflowEntityId(repo: string, id: number | string): string;
23
+ export declare function ciEntityId(repo: string): string;
24
+ export declare function entityKindOf(id: string): EntityKind | null;
25
+ export declare function repoOfEntityId(id: string): string | null;
26
+ /** Flatten a payload into its addressable entities. */
27
+ export declare function entitiesFromSnapshot(payload: SnapshotPayload): Map<string, Entity>;