agent-shim 0.0.0 → 7.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 (44) hide show
  1. package/LICENSE +201 -0
  2. package/README.md +233 -0
  3. package/dist/cli.cjs +69549 -0
  4. package/dist/index.cjs +3620 -0
  5. package/dist/index.mjs +3545 -0
  6. package/dist/types/cliError.d.ts +27 -0
  7. package/dist/types/config/classify.d.ts +49 -0
  8. package/dist/types/config/load.d.ts +42 -0
  9. package/dist/types/config/schema.d.ts +746 -0
  10. package/dist/types/config/store.d.ts +46 -0
  11. package/dist/types/frontdoor/capability.d.ts +19 -0
  12. package/dist/types/frontdoor/connect.d.ts +179 -0
  13. package/dist/types/frontdoor/ensure.d.ts +34 -0
  14. package/dist/types/frontdoor/probe.d.ts +13 -0
  15. package/dist/types/frontdoor/state.d.ts +50 -0
  16. package/dist/types/frontdoor/supervisor.d.ts +48 -0
  17. package/dist/types/frontdoor/x509.d.ts +11 -0
  18. package/dist/types/headroom/ensure.d.ts +31 -0
  19. package/dist/types/headroom/settings.d.ts +13 -0
  20. package/dist/types/headroom/source.d.ts +8 -0
  21. package/dist/types/headroom/state.d.ts +77 -0
  22. package/dist/types/headroom/supervisor.d.ts +107 -0
  23. package/dist/types/index.d.ts +21 -0
  24. package/dist/types/launcher/farm.d.ts +165 -0
  25. package/dist/types/launcher/guard.d.ts +57 -0
  26. package/dist/types/launcher/lock.d.ts +41 -0
  27. package/dist/types/launcher/ports.d.ts +135 -0
  28. package/dist/types/legacy.d.ts +24 -0
  29. package/dist/types/paths.d.ts +79 -0
  30. package/dist/types/resolve/conditions.d.ts +37 -0
  31. package/dist/types/resolve/decide.d.ts +45 -0
  32. package/dist/types/resolve/extends.d.ts +41 -0
  33. package/dist/types/resolve/flatten.d.ts +13 -0
  34. package/dist/types/resolve/match.d.ts +58 -0
  35. package/dist/types/resolve/pipeline.d.ts +30 -0
  36. package/dist/types/resolve/plan.d.ts +57 -0
  37. package/dist/types/resolve/projects.d.ts +61 -0
  38. package/dist/types/resolve/reconcile.d.ts +80 -0
  39. package/dist/types/resolve/types.d.ts +159 -0
  40. package/dist/types/resolve/walk.d.ts +85 -0
  41. package/dist/types/usage/account.d.ts +20 -0
  42. package/dist/types/usage/read.d.ts +70 -0
  43. package/dist/types/usage/schema.d.ts +318 -0
  44. package/package.json +91 -2
@@ -0,0 +1,27 @@
1
+ /** Exit status for every expected failure that is not a usage error: a missing identity, an invalid config file, a refused launch. */
2
+ export declare const EXIT_FAILURE = 1;
3
+ /** Exit status for a usage error: an unknown command or option, a malformed flag value, or required input missing with no terminal to prompt on. */
4
+ export declare const EXIT_USAGE = 2;
5
+ /**
6
+ * Base class for every error this CLI throws to represent an expected, user-facing failure: bad input, a missing identity/profile/rule, a malformed config file. `reportFatalError` prints this class as `agent-shim: <message>` with no stack trace and exits with `exitCode`; anything that does not extend it is an unexpected bug, reported by message alone unless `AGENT_SHIM_DEBUG` asks for the stack.
7
+ */
8
+ export declare abstract class CliError extends Error {
9
+ /** The process exit status this failure maps to. `EXIT_FAILURE` unless a subclass says otherwise. */
10
+ readonly exitCode: number;
11
+ }
12
+ /** A usage error: the command line itself is wrong or incomplete. Exits `EXIT_USAGE`. */
13
+ export declare class UsageError extends CliError {
14
+ readonly exitCode: number;
15
+ constructor(message: string);
16
+ }
17
+ /**
18
+ * Raised when a command needs input it would prompt for on a terminal, but standard input is not one. Names the option (or argument) that supplies the input non-interactively, so a script's failure says exactly what to add.
19
+ */
20
+ export declare class MissingInputError extends UsageError {
21
+ readonly option: string;
22
+ constructor(option: string, what: string);
23
+ }
24
+ /** Raised when the user cancels an interactive prompt that a command cannot continue without. */
25
+ export declare class PromptCancelledError extends CliError {
26
+ constructor();
27
+ }
@@ -0,0 +1,49 @@
1
+ import { type CategoryClassification, type CategoryClassificationOverlay, type CategoryName } from "./schema";
2
+ import type { LayoutPaths } from "../paths";
3
+ /** Which map a classification pattern came from. A `local` pattern is an answer the user gave to an "unclassified entry" prompt; a `default` pattern is shipped with the tool. */
4
+ type ClassificationSource = "default" | "local";
5
+ /** One compiled classification pattern: which category it assigns, where it came from, and how specific it is. */
6
+ export interface ClassificationPattern {
7
+ readonly pattern: string;
8
+ readonly category: CategoryName;
9
+ readonly source: ClassificationSource;
10
+ /** True when the pattern contains no glob metacharacter, so it can only ever match one literal name. */
11
+ readonly isExact: boolean;
12
+ /** Position of the pattern within its own category list, used only as the final deterministic tie-break. */
13
+ readonly ordinal: number;
14
+ readonly matches: (name: string) => boolean;
15
+ }
16
+ /** The outcome of classifying a set of real top-level `~/.claude` entry names. */
17
+ export interface ClassifyResult {
18
+ /** Every input name mapped to its category, or to null when nothing in either map recognises it. */
19
+ readonly classification: ReadonlyMap<string, CategoryName | null>;
20
+ /** The input names that nothing recognised, in input order. These are the names `agent-shim configure` prompts about. */
21
+ readonly unclassified: readonly string[];
22
+ /** For each classified name, the pattern that decided it — used by `agent-shim check` to explain a classification. */
23
+ readonly decidedBy: ReadonlyMap<string, ClassificationPattern>;
24
+ }
25
+ /** True when `pattern` contains no glob metacharacter, so it matches exactly one literal name. */
26
+ export declare function isExactPattern(pattern: string): boolean;
27
+ /** Compiles a shipped classification map plus an optional local overlay into one flat, ranked pattern list. */
28
+ export declare function compileClassificationPatterns(defaults: CategoryClassification, overlay?: CategoryClassificationOverlay): ClassificationPattern[];
29
+ /** The classification input every real call site needs: the shipped defaults plus this user's own local overlay, when one exists. */
30
+ export interface LoadedClassification {
31
+ readonly defaults: CategoryClassification;
32
+ readonly overlay?: CategoryClassificationOverlay;
33
+ }
34
+ /**
35
+ * Loads the classification input `classifyEntries` needs — the shipped `categories.default.json`, plus `categories.local.json` when the user has answered at least one "unclassified entry" prompt.
36
+ *
37
+ * Real-wired convenience over reading and validating the two files. Every command that classifies anything (`cli.ts`'s farm runtime, `check`, `configure`, `identity resolve-conflicts`) was independently repeating this exact pair of `readJson`/`.parse()` calls before this existed; centralising it here means the four command files stay thin call sites rather than each holding its own copy of a validation step that never varies between them.
38
+ */
39
+ export declare function loadClassification(paths: LayoutPaths): LoadedClassification;
40
+ /**
41
+ * Classifies a list of real top-level `~/.claude` entry names against the shipped category map plus an optional local overlay.
42
+ *
43
+ * An unrecognised name maps to `null` rather than being silently assumed safe or silently dropped: the resolver treats it as not-shared and reports it, and `agent-shim configure` prompts for an answer that is then written to the local overlay.
44
+ */
45
+ export declare function classifyEntries(names: readonly string[], options: {
46
+ defaults: CategoryClassification;
47
+ overlay?: CategoryClassificationOverlay;
48
+ }): ClassifyResult;
49
+ export {};
@@ -0,0 +1,42 @@
1
+ import { type PublicExplorerSync } from "cosmiconfig";
2
+ import type { z } from "zod";
3
+ import { CliError } from "../cliError";
4
+ /**
5
+ * A configuration file that has been read, parsed, and validated.
6
+ *
7
+ * `entryOrder` and `ruleEntryOrders` capture each `entries` object's own key insertion order as an explicit ordinal array, taken from the *raw* parsed value before Zod ever sees it. This is not paranoia about JSON key ordering: `schema.parse()` returns a fresh deep clone, and relying on key order implicitly surviving that clone would make the resolver's same-layer source-order tie-break depend on an implementation detail of a third-party library. Capturing it explicitly at load time makes it data.
8
+ */
9
+ export interface LoadedFile<T> {
10
+ readonly filepath: string;
11
+ readonly config: T;
12
+ /** Key insertion order of the file's own top-level `entries` object; empty when the file has none. */
13
+ readonly entryOrder: readonly string[];
14
+ /** For a directory-rules file: the key insertion order of each rule's `entries` object, indexed the same as `rules[]`. Empty for every other file shape. */
15
+ readonly ruleEntryOrders: readonly (readonly string[])[];
16
+ }
17
+ /**
18
+ * Builds the cosmiconfig explorer used for every read.
19
+ *
20
+ * Only `load(filepath)` is ever called on it — never `search()`. `search()` stops at the first config file found while walking upward, and this design needs the exact opposite: every ancestor collected, shallowest-first. `src/resolve/walk.ts` does its own directory walk and this module loads each level it visits, so cosmiconfig contributes its format flexibility (JSON, YAML, JS) without its traversal semantics.
21
+ */
22
+ export declare function createExplorer(moduleName?: string): PublicExplorerSync;
23
+ /** Reads the key insertion order of `value.entries`, when `value` is an object carrying an `entries` object. */
24
+ export declare function captureEntryOrder(value: unknown): readonly string[];
25
+ /** Reads the per-rule key insertion order of a directory-rules file's `rules[].entries` objects. */
26
+ export declare function captureRuleEntryOrders(value: unknown): readonly (readonly string[])[];
27
+ /** Raised when a config file exists but fails Zod validation, so the caller can report the offending path alongside the issue list. */
28
+ export declare class ConfigValidationError extends CliError {
29
+ readonly filepath: string;
30
+ readonly issues: readonly z.core.$ZodIssue[];
31
+ constructor(filepath: string, issues: readonly z.core.$ZodIssue[]);
32
+ }
33
+ /** Injected reader for a single config file, so tests never touch a real filesystem. Returns undefined when the file does not exist. */
34
+ export type ConfigFileReader = (filepath: string) => unknown;
35
+ /** A cosmiconfig-backed reader: loads and parses one file by path, returning undefined when it is missing or empty. */
36
+ export declare function cosmiconfigReader(explorer?: Readonly<PublicExplorerSync>): ConfigFileReader;
37
+ /**
38
+ * Loads one config file by exact path, validates it against `schema`, and captures its entries key order.
39
+ *
40
+ * Returns undefined when the file does not exist or is empty. Throws ConfigValidationError when it exists but does not validate — a malformed config is never silently ignored or half-applied.
41
+ */
42
+ export declare function loadConfigFile<S extends z.ZodType>(filepath: string, schema: S, read?: ConfigFileReader): LoadedFile<z.infer<S>> | undefined;