ambit-ts 0.1.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 (96) hide show
  1. package/CHANGELOG.md +64 -0
  2. package/LICENSE +21 -0
  3. package/README.md +403 -0
  4. package/dist/checker/authority.d.ts +13 -0
  5. package/dist/checker/authority.js +87 -0
  6. package/dist/checker/backend/legacy-ts.d.ts +26 -0
  7. package/dist/checker/backend/legacy-ts.js +1936 -0
  8. package/dist/checker/config.d.ts +84 -0
  9. package/dist/checker/config.js +391 -0
  10. package/dist/checker/coverage.d.ts +78 -0
  11. package/dist/checker/coverage.js +84 -0
  12. package/dist/checker/diagnose.d.ts +89 -0
  13. package/dist/checker/diagnose.js +734 -0
  14. package/dist/checker/index.d.ts +8 -0
  15. package/dist/checker/index.js +8 -0
  16. package/dist/checker/init.d.ts +38 -0
  17. package/dist/checker/init.js +205 -0
  18. package/dist/checker/propagate.d.ts +69 -0
  19. package/dist/checker/propagate.js +259 -0
  20. package/dist/checker/summarize.d.ts +27 -0
  21. package/dist/checker/summarize.js +411 -0
  22. package/dist/cli/analyze.d.ts +33 -0
  23. package/dist/cli/analyze.js +98 -0
  24. package/dist/cli/approvals.d.ts +28 -0
  25. package/dist/cli/approvals.js +55 -0
  26. package/dist/cli/diff.d.ts +66 -0
  27. package/dist/cli/diff.js +235 -0
  28. package/dist/cli/github.d.ts +33 -0
  29. package/dist/cli/github.js +41 -0
  30. package/dist/cli/main.d.ts +8 -0
  31. package/dist/cli/main.js +385 -0
  32. package/dist/cli/worktree.d.ts +75 -0
  33. package/dist/cli/worktree.js +154 -0
  34. package/dist/config.d.ts +12 -0
  35. package/dist/config.js +10 -0
  36. package/dist/core/approvals.d.ts +82 -0
  37. package/dist/core/approvals.js +0 -0
  38. package/dist/core/authority-diff.d.ts +98 -0
  39. package/dist/core/authority-diff.js +209 -0
  40. package/dist/core/authority.d.ts +109 -0
  41. package/dist/core/authority.js +50 -0
  42. package/dist/core/backend.d.ts +355 -0
  43. package/dist/core/backend.js +1 -0
  44. package/dist/core/budget.d.ts +61 -0
  45. package/dist/core/budget.js +95 -0
  46. package/dist/core/capability.d.ts +53 -0
  47. package/dist/core/capability.js +117 -0
  48. package/dist/core/config.d.ts +59 -0
  49. package/dist/core/config.js +10 -0
  50. package/dist/core/diagnostic.d.ts +126 -0
  51. package/dist/core/diagnostic.js +13 -0
  52. package/dist/core/effects.d.ts +39 -0
  53. package/dist/core/effects.js +72 -0
  54. package/dist/core/index.d.ts +13 -0
  55. package/dist/core/index.js +13 -0
  56. package/dist/core/location.d.ts +15 -0
  57. package/dist/core/location.js +1 -0
  58. package/dist/core/sql.d.ts +22 -0
  59. package/dist/core/sql.js +38 -0
  60. package/dist/core/summary.d.ts +240 -0
  61. package/dist/core/summary.js +8 -0
  62. package/dist/core/symbol-id.d.ts +25 -0
  63. package/dist/core/symbol-id.js +23 -0
  64. package/dist/index.d.ts +14 -0
  65. package/dist/index.js +14 -0
  66. package/dist/runtime/child-process.d.ts +29 -0
  67. package/dist/runtime/child-process.js +124 -0
  68. package/dist/runtime/context.d.ts +37 -0
  69. package/dist/runtime/context.js +8 -0
  70. package/dist/runtime/enforce.d.ts +52 -0
  71. package/dist/runtime/enforce.js +95 -0
  72. package/dist/runtime/fs.d.ts +46 -0
  73. package/dist/runtime/fs.js +188 -0
  74. package/dist/runtime/hono.d.ts +55 -0
  75. package/dist/runtime/hono.js +68 -0
  76. package/dist/runtime/index.d.ts +71 -0
  77. package/dist/runtime/index.js +126 -0
  78. package/dist/runtime/next.d.ts +95 -0
  79. package/dist/runtime/next.js +60 -0
  80. package/dist/runtime/pg.d.ts +48 -0
  81. package/dist/runtime/pg.js +122 -0
  82. package/dist/stubs/constructors.d.ts +34 -0
  83. package/dist/stubs/constructors.js +111 -0
  84. package/dist/stubs/data-clients.d.ts +9 -0
  85. package/dist/stubs/data-clients.js +109 -0
  86. package/dist/stubs/http-capabilities.d.ts +15 -0
  87. package/dist/stubs/http-capabilities.js +70 -0
  88. package/dist/stubs/mutating-builtins.d.ts +1 -0
  89. package/dist/stubs/mutating-builtins.js +48 -0
  90. package/dist/stubs/node-builtins.d.ts +2 -0
  91. package/dist/stubs/node-builtins.js +77 -0
  92. package/dist/stubs/pure-builtins.d.ts +1 -0
  93. package/dist/stubs/pure-builtins.js +89 -0
  94. package/docs/diagnostics/README.md +519 -0
  95. package/docs/limitations.md +712 -0
  96. package/package.json +89 -0
@@ -0,0 +1,89 @@
1
+ import type { ContractOperation, Diagnostic, DiagnosticEngine, KnownEffect, RuntimeWrapper, SymbolId, UncarriedContract } from "../core/index.ts";
2
+ import type { PropagatedFunction } from "./propagate.ts";
3
+ /**
4
+ * Compare declared vs. observed effects for every declared function and
5
+ * produce diagnostics (DESIGN.md §5.1). Undeclared functions
6
+ * (`declared.kind === "none"`) are not diagnosed here — see §4.2/§4.3:
7
+ * undeclared is a coverage concern, not a propagation input.
8
+ *
9
+ * `engine` identifies the backend that produced `state` (DESIGN.md §3.4) and
10
+ * is attached to every diagnostic emitted.
11
+ */
12
+ export declare function diagnose(state: ReadonlyMap<SymbolId, PropagatedFunction>, engine: DiagnosticEngine): readonly Diagnostic[];
13
+ /**
14
+ * A contract tag written on a function-like node the backend does not extract
15
+ * (DESIGN.md §4.1 permits `@effects` on any function or method, but only an
16
+ * extracted node has a `SymbolId` to hang one on). Reported rather than
17
+ * dropped, on the same principle as AMB-E002: a declaration that silently does
18
+ * nothing looks like a guarantee and is not one.
19
+ */
20
+ export declare function diagnoseUncarriedContracts(uncarried: readonly UncarriedContract[], engine: DiagnosticEngine): readonly Diagnostic[];
21
+ /**
22
+ * JSDoc and `ambit.config.ts` declare the same tag for one symbol and the two
23
+ * do not agree (DESIGN.md §4.1: "If a symbol has both JSDoc and config,
24
+ * JSDoc wins and the difference is warned about").
25
+ *
26
+ * A warning, not an error: JSDoc winning is the specified behaviour, so the
27
+ * run is doing the right thing — but a config entry that is being ignored is
28
+ * a declaration the author believes is in force and is not, which is the same
29
+ * failure AMB-E003 exists to prevent. `--strict` does not promote it: the
30
+ * disagreement is between two declarations, not an unverified path.
31
+ *
32
+ * No fix is offered. Which side is wrong is the author's decision — deleting
33
+ * the config entry and rewriting the JSDoc are opposite intentions, and §5.3
34
+ * forbids inventing a candidate to fill the slot.
35
+ */
36
+ export declare function diagnoseContractDivergence(state: ReadonlyMap<SymbolId, PropagatedFunction>, configPath: string, engine: DiagnosticEngine): readonly Diagnostic[];
37
+ /**
38
+ * An exact `contracts` key that named no extracted symbol (DESIGN.md §4.1).
39
+ *
40
+ * Same principle as AMB-E003: a declaration that silently applies to nothing
41
+ * reads as a guarantee and is not one. Only *exact* keys are reported — a
42
+ * glob covering a directory this run did not check matches nothing for a
43
+ * reason that is not a mistake, and reporting it would make `ambit check
44
+ * src/domain` noisy in proportion to how much of the project it skipped.
45
+ *
46
+ * A warning rather than an error, and not promoted by `--strict`: the key may
47
+ * name a file outside the directory being checked, which is a normal thing
48
+ * for one config to do.
49
+ */
50
+ export declare function diagnoseUnmatchedConfigKeys(keys: readonly string[], configPath: string, configSource: string, engine: DiagnosticEngine): readonly Diagnostic[];
51
+ /**
52
+ * DESIGN.md §4.4: a literal spec on a `withAmbit(spec, handler)` or
53
+ * `ambitHandler(spec, handler, decode)` naming a handler in the same file *is*
54
+ * that handler's `@capabilities` / `@budget` (`summarize.ts`'s
55
+ * `specContracts`). Writing the tag too stays legal, and this is what stops it
56
+ * from being free: an agent adding `db:write:users` to one of them — or
57
+ * widening `timeMs` in one of them — expanded authority silently.
58
+ *
59
+ * Where the spec is *not* the declaration — a list built at runtime, a budget
60
+ * that is not an object literal, a handler from another module — there is
61
+ * nothing to compare and nothing was declared by the spec either. That is
62
+ * `AMB-W004`, and its message says so: the handler's own JSDoc is then the
63
+ * only declaration there is.
64
+ *
65
+ * This compares the two **as source**, half by half: the capability set
66
+ * (`AMB-E010`) and the budget (`AMB-E011`) are fixed by the source
67
+ * independently, so one may be comparable when the other is not. §12's
68
+ * "Mapping contracts to handlers" — matching a contract to a handler after a
69
+ * build
70
+ * strips the comments, or after a bundler moves it — stays open, and a half
71
+ * this comparison cannot reach is reported (`AMB-W004`) rather than passed
72
+ * over.
73
+ */
74
+ export declare function diagnoseRuntimeWrappers(wrappers: readonly RuntimeWrapper[], state: ReadonlyMap<SymbolId, PropagatedFunction>, engine: DiagnosticEngine): readonly Diagnostic[];
75
+ /**
76
+ * The call site inside `ownerId` that performs `effect` — the `fetch(...)` line
77
+ * rather than the enclosing function's declaration line.
78
+ *
79
+ * Only a stub call answers: it is the layer that knows an operation's name and
80
+ * its effects. A `state_write` that came from an assignment or a mutating
81
+ * method has no operation to name, and an effect that reached `ownerId`
82
+ * through its own `@effects` declaration alone has no site inside it — both
83
+ * return `undefined` rather than a guess (DESIGN.md §5.2).
84
+ *
85
+ * The first matching site in source order is reported when a function performs
86
+ * the same effect more than once: one site is enough to send the reader to the
87
+ * right place, and picking the first is stable across re-analysis.
88
+ */
89
+ export declare function operationSite(effect: KnownEffect, ownerId: SymbolId, state: ReadonlyMap<SymbolId, PropagatedFunction>): ContractOperation | undefined;