@event4u/agent-config 8.4.0 → 8.4.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.
Files changed (126) hide show
  1. package/.claude-plugin/marketplace.json +1 -1
  2. package/CHANGELOG.md +6 -0
  3. package/dist/agent-src/templates/agents/agent-project-settings.example.yml +1 -1
  4. package/dist/discovery/deprecation-report.md +1 -1
  5. package/dist/discovery/discovery-manifest.json +1 -1
  6. package/dist/discovery/discovery-manifest.json.sha256 +1 -1
  7. package/dist/discovery/discovery-manifest.summary.md +1 -1
  8. package/dist/discovery/orphan-report.md +1 -1
  9. package/dist/discovery/packs.json +1 -1
  10. package/dist/discovery/trust-report.md +1 -1
  11. package/dist/discovery/workspaces.json +1 -1
  12. package/dist/mcp/registry-manifest.json +1 -1
  13. package/package.json +4 -1
  14. package/src/agent-src/README.md +64 -0
  15. package/src/agent-src/scripts/archive_completed_roadmaps.ts +497 -0
  16. package/src/agent-src/scripts/scan-seeder-violations.php +145 -0
  17. package/src/agent-src/scripts/update_roadmap_progress.ts +1087 -0
  18. package/src/agent-src/templates/AGENTS.md +34 -0
  19. package/src/agent-src/templates/scripts/README.md +195 -0
  20. package/src/agent-src/templates/scripts/check_memory.ts +662 -0
  21. package/src/agent-src/templates/scripts/check_memory_proposal.ts +370 -0
  22. package/src/agent-src/templates/scripts/historical-bug-patterns.example.yml +84 -0
  23. package/src/agent-src/templates/scripts/implement_ticket/__main__.ts +27 -0
  24. package/src/agent-src/templates/scripts/memory_hash.ts +355 -0
  25. package/src/agent-src/templates/scripts/memory_lookup.ts +1089 -0
  26. package/src/agent-src/templates/scripts/memory_report.ts +868 -0
  27. package/src/agent-src/templates/scripts/memory_signal.ts +444 -0
  28. package/src/agent-src/templates/scripts/memory_status.ts +215 -0
  29. package/src/agent-src/templates/scripts/ownership-map.example.yml +87 -0
  30. package/src/agent-src/templates/scripts/pr-risk-config.example.yml +76 -0
  31. package/src/agent-src/templates/scripts/pr_review_routing.ts +544 -0
  32. package/src/agent-src/templates/scripts/pr_risk_review.ts +0 -0
  33. package/src/agent-src/templates/scripts/telemetry/aggregator.ts +0 -0
  34. package/src/agent-src/templates/scripts/telemetry/boundary.ts +164 -0
  35. package/src/agent-src/templates/scripts/telemetry/engagement.ts +479 -0
  36. package/src/agent-src/templates/scripts/telemetry/report_renderer.ts +394 -0
  37. package/src/agent-src/templates/scripts/telemetry/settings.ts +210 -0
  38. package/src/agent-src/templates/scripts/telemetry_record.ts +276 -0
  39. package/src/agent-src/templates/scripts/telemetry_report.ts +211 -0
  40. package/src/agent-src/templates/scripts/telemetry_status.ts +333 -0
  41. package/src/agent-src/templates/scripts/tier_usage_report.ts +619 -0
  42. package/src/agent-src/templates/scripts/work_engine/__main__.ts +14 -0
  43. package/src/agent-src/templates/scripts/work_engine/_lib/agent_settings.ts +1261 -0
  44. package/src/agent-src/templates/scripts/work_engine/_lib/user_global_paths.ts +329 -0
  45. package/src/agent-src/templates/scripts/work_engine/cli.ts +206 -0
  46. package/src/agent-src/templates/scripts/work_engine/cli_args.ts +249 -0
  47. package/src/agent-src/templates/scripts/work_engine/delivery_state.ts +225 -0
  48. package/src/agent-src/templates/scripts/work_engine/directives/backend/analyze.ts +125 -0
  49. package/src/agent-src/templates/scripts/work_engine/directives/backend/implement.ts +189 -0
  50. package/src/agent-src/templates/scripts/work_engine/directives/backend/index.ts +94 -0
  51. package/src/agent-src/templates/scripts/work_engine/directives/backend/memory.ts +193 -0
  52. package/src/agent-src/templates/scripts/work_engine/directives/backend/plan.ts +267 -0
  53. package/src/agent-src/templates/scripts/work_engine/directives/backend/refine.ts +518 -0
  54. package/src/agent-src/templates/scripts/work_engine/directives/backend/report.ts +379 -0
  55. package/src/agent-src/templates/scripts/work_engine/directives/backend/test.ts +268 -0
  56. package/src/agent-src/templates/scripts/work_engine/directives/backend/verify.ts +258 -0
  57. package/src/agent-src/templates/scripts/work_engine/directives/index.ts +32 -0
  58. package/src/agent-src/templates/scripts/work_engine/directives/mixed/contract.ts +243 -0
  59. package/src/agent-src/templates/scripts/work_engine/directives/mixed/index.ts +108 -0
  60. package/src/agent-src/templates/scripts/work_engine/directives/mixed/stitch.ts +259 -0
  61. package/src/agent-src/templates/scripts/work_engine/directives/mixed/ui.ts +216 -0
  62. package/src/agent-src/templates/scripts/work_engine/directives/ui/_passthrough.ts +40 -0
  63. package/src/agent-src/templates/scripts/work_engine/directives/ui/app_spec.ts +241 -0
  64. package/src/agent-src/templates/scripts/work_engine/directives/ui/apply.ts +216 -0
  65. package/src/agent-src/templates/scripts/work_engine/directives/ui/audit.ts +506 -0
  66. package/src/agent-src/templates/scripts/work_engine/directives/ui/design.ts +325 -0
  67. package/src/agent-src/templates/scripts/work_engine/directives/ui/index.ts +102 -0
  68. package/src/agent-src/templates/scripts/work_engine/directives/ui/polish.ts +462 -0
  69. package/src/agent-src/templates/scripts/work_engine/directives/ui/review.ts +474 -0
  70. package/src/agent-src/templates/scripts/work_engine/directives/ui/scaffold.ts +352 -0
  71. package/src/agent-src/templates/scripts/work_engine/directives/ui_trivial/_skipped.ts +33 -0
  72. package/src/agent-src/templates/scripts/work_engine/directives/ui_trivial/apply.ts +213 -0
  73. package/src/agent-src/templates/scripts/work_engine/directives/ui_trivial/index.ts +111 -0
  74. package/src/agent-src/templates/scripts/work_engine/directives/ui_trivial/refine.ts +126 -0
  75. package/src/agent-src/templates/scripts/work_engine/directives/ui_trivial/report.ts +112 -0
  76. package/src/agent-src/templates/scripts/work_engine/directives/ui_trivial/test.ts +164 -0
  77. package/src/agent-src/templates/scripts/work_engine/dispatcher.ts +515 -0
  78. package/src/agent-src/templates/scripts/work_engine/emitters.ts +119 -0
  79. package/src/agent-src/templates/scripts/work_engine/errors.ts +24 -0
  80. package/src/agent-src/templates/scripts/work_engine/hook_bootstrap.ts +104 -0
  81. package/src/agent-src/templates/scripts/work_engine/hooks/builtin/_chat_history_base.ts +189 -0
  82. package/src/agent-src/templates/scripts/work_engine/hooks/builtin/chat_history_append.ts +41 -0
  83. package/src/agent-src/templates/scripts/work_engine/hooks/builtin/chat_history_halt_append.ts +89 -0
  84. package/src/agent-src/templates/scripts/work_engine/hooks/builtin/decision_gate.ts +193 -0
  85. package/src/agent-src/templates/scripts/work_engine/hooks/builtin/decision_trace.ts +304 -0
  86. package/src/agent-src/templates/scripts/work_engine/hooks/builtin/directive_set_guard.ts +110 -0
  87. package/src/agent-src/templates/scripts/work_engine/hooks/builtin/halt_surface_audit.ts +118 -0
  88. package/src/agent-src/templates/scripts/work_engine/hooks/builtin/index.ts +17 -0
  89. package/src/agent-src/templates/scripts/work_engine/hooks/builtin/memory_visibility.ts +161 -0
  90. package/src/agent-src/templates/scripts/work_engine/hooks/builtin/state_shape_validation.ts +45 -0
  91. package/src/agent-src/templates/scripts/work_engine/hooks/builtin/trace.ts +134 -0
  92. package/src/agent-src/templates/scripts/work_engine/hooks/context.ts +94 -0
  93. package/src/agent-src/templates/scripts/work_engine/hooks/events.ts +58 -0
  94. package/src/agent-src/templates/scripts/work_engine/hooks/exceptions.ts +85 -0
  95. package/src/agent-src/templates/scripts/work_engine/hooks/index.ts +27 -0
  96. package/src/agent-src/templates/scripts/work_engine/hooks/registry.ts +66 -0
  97. package/src/agent-src/templates/scripts/work_engine/hooks/runner.ts +90 -0
  98. package/src/agent-src/templates/scripts/work_engine/hooks/settings.ts +260 -0
  99. package/src/agent-src/templates/scripts/work_engine/input_builders.ts +260 -0
  100. package/src/agent-src/templates/scripts/work_engine/intent/classify.ts +466 -0
  101. package/src/agent-src/templates/scripts/work_engine/migration/v0_to_v1.ts +531 -0
  102. package/src/agent-src/templates/scripts/work_engine/orchestration.ts +366 -0
  103. package/src/agent-src/templates/scripts/work_engine/persona_policy.ts +97 -0
  104. package/src/agent-src/templates/scripts/work_engine/resolvers/diff.ts +135 -0
  105. package/src/agent-src/templates/scripts/work_engine/resolvers/file.ts +175 -0
  106. package/src/agent-src/templates/scripts/work_engine/resolvers/prompt.ts +115 -0
  107. package/src/agent-src/templates/scripts/work_engine/scoring/confidence.ts +415 -0
  108. package/src/agent-src/templates/scripts/work_engine/scoring/decision_engine.ts +466 -0
  109. package/src/agent-src/templates/scripts/work_engine/scoring/decision_trace.ts +298 -0
  110. package/src/agent-src/templates/scripts/work_engine/scoring/memory_visibility.ts +444 -0
  111. package/src/agent-src/templates/scripts/work_engine/stack/detect.ts +252 -0
  112. package/src/agent-src/templates/scripts/work_engine/stack/runner.ts +745 -0
  113. package/src/agent-src/templates/scripts/work_engine/state.ts +1151 -0
  114. package/src/agent-src/templates/scripts/work_engine/state_io.ts +413 -0
  115. package/src/install/atomic.ts +111 -0
  116. package/src/install/conflict.ts +226 -0
  117. package/src/install/detect.ts +280 -0
  118. package/src/install/paths.ts +90 -0
  119. package/src/install/plan.ts +205 -0
  120. package/src/install/preflight.ts +210 -0
  121. package/src/install/selectedTools.ts +52 -0
  122. package/src/install/toolDetection.ts +120 -0
  123. package/src/install/txlog.ts +161 -0
  124. package/src/install/types.ts +175 -0
  125. package/src/install/wizard-plan.ts +216 -0
  126. package/src/scripts/prepack-check.mjs +108 -5
@@ -0,0 +1,298 @@
1
+ /**
2
+ * Confidence-band + risk-class heuristics for decision-trace v1.
3
+ *
4
+ * TypeScript twin of `work_engine/scoring/decision_trace.py` (ADR-200 py2ts
5
+ * Phase 1 — work_engine scoring subpackage). Public API names stay snake_case
6
+ * to mirror the Python module 1:1 (per ADR-200 — Python style is part of the
7
+ * contract).
8
+ *
9
+ * These heuristics back the JSON envelope emitted by
10
+ * `work_engine.hooks.builtin.DecisionTraceHook`. They live here
11
+ * (under `scoring/`) so the rules and the hook share a single source
12
+ * of truth, and so unit tests can exercise the heuristics without
13
+ * spinning up a dispatcher.
14
+ *
15
+ * Confidence-band heuristic (per
16
+ * `docs/contracts/decision-trace-v1.md`):
17
+ *
18
+ * - `high` — `memory.hits >= 2` AND
19
+ * `verify.first_try_passes == verify.claims` AND no ambiguity flag.
20
+ * - `medium` — `memory.hits >= 1` OR `verify.first_try_passes >= 1`.
21
+ * - `low` — otherwise.
22
+ *
23
+ * Edge case: `verify.claims == 0` is **not** `high` by default; it
24
+ * folds into `medium` if at least one memory hit landed, `low`
25
+ * otherwise.
26
+ *
27
+ * Risk-class heuristic: maximum risk across the files the phase
28
+ * touched. With no file-ownership matrix wired in yet, the
29
+ * implementation defaults to `low` and exposes a `files` argument
30
+ * so a future hook can pass concrete paths. If the phase touched any
31
+ * files at all the heuristic returns `medium` so reviewers stay
32
+ * nudged toward a closer look until the matrix lands.
33
+ */
34
+
35
+ /** Arbitrary JSON-ish value, mirroring the Python `Any` fields. */
36
+ export type Any = unknown;
37
+
38
+ export const BAND_HIGH = 'high';
39
+ export const BAND_MEDIUM = 'medium';
40
+ export const BAND_LOW = 'low';
41
+
42
+ export const RISK_HIGH = 'high';
43
+ export const RISK_MEDIUM = 'medium';
44
+ export const RISK_LOW = 'low';
45
+
46
+ /** Return `high` / `medium` / `low` per the v1 heuristic. */
47
+ export function derive_confidence_band(args: {
48
+ memory_hits: number;
49
+ verify_claims: number;
50
+ verify_first_try_passes: number;
51
+ ambiguity_flag: boolean;
52
+ }): string {
53
+ const { memory_hits, verify_claims, verify_first_try_passes, ambiguity_flag } = args;
54
+ if (
55
+ memory_hits >= 2 &&
56
+ verify_claims > 0 &&
57
+ verify_first_try_passes === verify_claims &&
58
+ !ambiguity_flag
59
+ ) {
60
+ return BAND_HIGH;
61
+ }
62
+ if (memory_hits >= 1 || verify_first_try_passes >= 1) {
63
+ return BAND_MEDIUM;
64
+ }
65
+ return BAND_LOW;
66
+ }
67
+
68
+ /**
69
+ * Return the trace-level risk class.
70
+ *
71
+ * `changes` is the `delivery.changes` slice — a list of dicts in
72
+ * the canonical engine shape, or `null` for pure planning phases.
73
+ * Until the file-ownership matrix is wired in, "any change touched"
74
+ * maps to `medium`; "no change" maps to `low`. `high` is
75
+ * reserved for the future ownership-matrix lookup.
76
+ *
77
+ * Mirrors the Python truthiness check `if not changes:` — empty list,
78
+ * empty string, `0`, `null`, `undefined`, and `false` all count as falsy.
79
+ * Non-iterable truthy values fall through to `RISK_LOW` exactly as the
80
+ * Python `isinstance(changes, Iterable)` guard does.
81
+ */
82
+ export function derive_risk_class(changes: Any): string {
83
+ if (!_pyTruthy(changes)) {
84
+ return RISK_LOW;
85
+ }
86
+ if (_isIterable(changes)) {
87
+ // `sum(1 for _ in changes)` — count the elements. Strings are
88
+ // iterable in Python (each char is one element); JS strings are not
89
+ // iterated by the `for...of` below the same way for our purposes, so
90
+ // mirror Python: a non-empty string counts as `count > 0`.
91
+ let count = 0;
92
+ if (typeof changes === 'string') {
93
+ count = _pyLen(changes);
94
+ } else {
95
+ for (const _ of changes as Iterable<unknown>) {
96
+ void _;
97
+ count += 1;
98
+ }
99
+ }
100
+ return count > 0 ? RISK_MEDIUM : RISK_LOW;
101
+ }
102
+ return RISK_LOW;
103
+ }
104
+
105
+ /**
106
+ * Reduce `state.memory` into the trace-envelope `memory` slice.
107
+ *
108
+ * The engine stores memory entries as dicts with at least an `id`
109
+ * or `rule_id` key plus arbitrary per-entry payload. The trace
110
+ * only carries ids — bodies stay behind the privacy floor.
111
+ */
112
+ export function summarise_memory(
113
+ memory: Any,
114
+ args: { limit?: number } = {},
115
+ ): Record<string, Any> {
116
+ const limit = args.limit ?? 32;
117
+ if (!_pyTruthy(memory)) {
118
+ return { asks: 0, hits: 0, ids: [] };
119
+ }
120
+ const ids: string[] = [];
121
+ let asks = 0;
122
+ let hits = 0;
123
+ for (const entry of memory as Iterable<unknown>) {
124
+ if (!_isPlainDict(entry)) {
125
+ continue;
126
+ }
127
+ const e = entry as Record<string, unknown>;
128
+ // `int(entry.get("asks", 1) or 0) or 1` — Python: default 1 when key
129
+ // absent; coerce to int; `or 0` turns a falsy value into 0; outer
130
+ // `or 1` turns a resulting 0 into 1. Net: the increment is always >= 1.
131
+ asks += _pyInt(_pyOr(_get(e, 'asks', 1), 0)) || 1;
132
+ // `entry.get("hit", True)` — default True when absent.
133
+ if (_pyTruthy('hit' in e ? e['hit'] : true)) {
134
+ hits += 1;
135
+ const entry_id = _pyOr(_get(e, 'id', undefined), _get(e, 'rule_id', undefined));
136
+ if (_pyTruthy(entry_id) && ids.length < limit) {
137
+ ids.push(_pyStr(entry_id));
138
+ }
139
+ }
140
+ }
141
+ return { asks, hits, ids };
142
+ }
143
+
144
+ /**
145
+ * Reduce `state.verify` into the trace-envelope `verify` slice.
146
+ *
147
+ * `verify` may be `null` (no verify run yet), a dict carrying
148
+ * `claims` / `first_try_passes`, or a list of attempt records.
149
+ * Anything else collapses to zeros.
150
+ */
151
+ export function summarise_verify(verify: Any): Record<string, number> {
152
+ if (verify === null || verify === undefined) {
153
+ return { claims: 0, first_try_passes: 0 };
154
+ }
155
+ if (_isPlainDict(verify)) {
156
+ const v = verify as Record<string, unknown>;
157
+ const claims = _pyInt(_pyOr(_get(v, 'claims', 0), 0));
158
+ const passes = _pyInt(_pyOr(_get(v, 'first_try_passes', 0), 0));
159
+ return { claims, first_try_passes: passes };
160
+ }
161
+ if (Array.isArray(verify)) {
162
+ const claims = verify.length;
163
+ let passes = 0;
164
+ for (const entry of verify) {
165
+ if (_isPlainDict(entry) && _pyTruthy((entry as Record<string, unknown>)['first_try_pass'])) {
166
+ passes += 1;
167
+ }
168
+ }
169
+ return { claims, first_try_passes: passes };
170
+ }
171
+ return { claims: 0, first_try_passes: 0 };
172
+ }
173
+
174
+ // ── Python-parity primitives ────────────────────────────────────────────
175
+
176
+ /** `dict.get(key, default)` for a plain object. */
177
+ function _get(obj: Record<string, unknown>, key: string, dflt: unknown): unknown {
178
+ return key in obj ? obj[key] : dflt;
179
+ }
180
+
181
+ /** Python `a or b` — returns `a` when truthy, else `b`. */
182
+ function _pyOr(a: unknown, b: unknown): unknown {
183
+ return _pyTruthy(a) ? a : b;
184
+ }
185
+
186
+ /**
187
+ * Python `bool(x)` truthiness: `None`/`undefined`, `False`, `0`, `0.0`,
188
+ * `""`, empty list/tuple/dict/set are falsy; everything else truthy.
189
+ */
190
+ function _pyTruthy(value: unknown): boolean {
191
+ if (value === null || value === undefined || value === false) {
192
+ return false;
193
+ }
194
+ if (value === true) {
195
+ return true;
196
+ }
197
+ if (typeof value === 'number') {
198
+ return value !== 0;
199
+ }
200
+ if (typeof value === 'string') {
201
+ return value.length > 0;
202
+ }
203
+ if (Array.isArray(value)) {
204
+ return value.length > 0;
205
+ }
206
+ if (value instanceof Map || value instanceof Set) {
207
+ return value.size > 0;
208
+ }
209
+ if (typeof value === 'object') {
210
+ return Object.keys(value as Record<string, unknown>).length > 0;
211
+ }
212
+ return true;
213
+ }
214
+
215
+ /**
216
+ * Python `int(x)` for the value kinds these heuristics see — booleans
217
+ * (`True` → 1, `False` → 0), numbers (truncate toward zero), and numeric
218
+ * strings. Non-coercible values raise like CPython would; in practice the
219
+ * callers only pass the dict-derived scalars above.
220
+ */
221
+ function _pyInt(value: unknown): number {
222
+ if (value === true) {
223
+ return 1;
224
+ }
225
+ if (value === false) {
226
+ return 0;
227
+ }
228
+ if (typeof value === 'number') {
229
+ return Math.trunc(value);
230
+ }
231
+ if (typeof value === 'string') {
232
+ const trimmed = value.trim();
233
+ const n = Number(trimmed);
234
+ if (trimmed !== '' && Number.isFinite(n)) {
235
+ return Math.trunc(n);
236
+ }
237
+ }
238
+ throw new Error(`invalid literal for int(): ${String(value)}`);
239
+ }
240
+
241
+ /** Python `str(x)` for the scalar shapes returned by `id` / `rule_id`. */
242
+ function _pyStr(value: unknown): string {
243
+ if (value === null || value === undefined) {
244
+ return 'None';
245
+ }
246
+ if (value === true) {
247
+ return 'True';
248
+ }
249
+ if (value === false) {
250
+ return 'False';
251
+ }
252
+ return String(value);
253
+ }
254
+
255
+ /** Python `len(x)` for a string — code-point count, not UTF-16 unit count. */
256
+ function _pyLen(s: string): number {
257
+ let n = 0;
258
+ for (const _ of s) {
259
+ void _;
260
+ n += 1;
261
+ }
262
+ return n;
263
+ }
264
+
265
+ /**
266
+ * Python `isinstance(x, dict)` — only a plain object (not array, not null).
267
+ * Mirrors the source's `isinstance(entry, dict)` guards.
268
+ */
269
+ function _isPlainDict(value: unknown): boolean {
270
+ return (
271
+ typeof value === 'object' &&
272
+ value !== null &&
273
+ !Array.isArray(value)
274
+ );
275
+ }
276
+
277
+ /**
278
+ * Python `isinstance(x, Iterable)` for the shapes `derive_risk_class` can
279
+ * see after the `if not changes:` guard: lists, strings, sets, maps, and
280
+ * generic iterables expose `Symbol.iterator`; plain dicts are iterable in
281
+ * Python (over keys) so an object also counts.
282
+ */
283
+ function _isIterable(value: unknown): boolean {
284
+ if (value === null || value === undefined) {
285
+ return false;
286
+ }
287
+ if (typeof value === 'string' || Array.isArray(value)) {
288
+ return true;
289
+ }
290
+ if (typeof value === 'object') {
291
+ if (typeof (value as { [Symbol.iterator]?: unknown })[Symbol.iterator] === 'function') {
292
+ return true;
293
+ }
294
+ // Plain dict: iterable over its keys in Python.
295
+ return true;
296
+ }
297
+ return false;
298
+ }