@gtheys/pi-flow 0.0.0-stage → 0.2.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 (164) hide show
  1. package/README.md +833 -2
  2. package/adhoc/tracker.ts +360 -0
  3. package/aven/client.ts +996 -0
  4. package/aven/status.ts +395 -0
  5. package/brainstorm/args.ts +24 -0
  6. package/brainstorm/artifact.ts +67 -0
  7. package/brainstorm/paths.ts +43 -0
  8. package/brainstorm/prompt.ts +172 -0
  9. package/brainstorm/refs.ts +41 -0
  10. package/config.schema.json +161 -0
  11. package/config.ts +577 -0
  12. package/feedback/args.ts +21 -0
  13. package/feedback/prompt.ts +177 -0
  14. package/feedback/triage.ts +88 -0
  15. package/flow/agent-role.ts +46 -0
  16. package/flow/answer-wake.ts +212 -0
  17. package/flow/answer.ts +183 -0
  18. package/flow/args.ts +48 -0
  19. package/flow/ask-emitter.ts +331 -0
  20. package/flow/attribution.ts +145 -0
  21. package/flow/aven-resolve-exec.ts +95 -0
  22. package/flow/aven-resolve.ts +80 -0
  23. package/flow/awaiting-approval.ts +32 -0
  24. package/flow/binding-heal.ts +68 -0
  25. package/flow/cost-autopush.ts +162 -0
  26. package/flow/cost-command.ts +122 -0
  27. package/flow/cost-rows-journal.ts +296 -0
  28. package/flow/cost-rows-push.ts +112 -0
  29. package/flow/cost-rows-rows.ts +209 -0
  30. package/flow/cost-rows.ts +228 -0
  31. package/flow/cost.ts +173 -0
  32. package/flow/durable-refs.ts +287 -0
  33. package/flow/effect-gate.ts +137 -0
  34. package/flow/ensure-labels.ts +44 -0
  35. package/flow/frame.ts +172 -0
  36. package/flow/gates.ts +211 -0
  37. package/flow/jira-ref.ts +212 -0
  38. package/flow/label-gate.ts +149 -0
  39. package/flow/land-gate.ts +98 -0
  40. package/flow/lifecycle-policy.ts +162 -0
  41. package/flow/live-wait.ts +52 -0
  42. package/flow/liveness.ts +408 -0
  43. package/flow/loop-deps.ts +210 -0
  44. package/flow/loop-settle.ts +531 -0
  45. package/flow/loop.ts +437 -0
  46. package/flow/orchestrate.ts +45 -0
  47. package/flow/phase-command.ts +287 -0
  48. package/flow/phase-emoji.ts +13 -0
  49. package/flow/phase-prompts.ts +251 -0
  50. package/flow/picker.ts +307 -0
  51. package/flow/push.ts +475 -0
  52. package/flow/reconcile-command.ts +253 -0
  53. package/flow/reconcile-deps.ts +329 -0
  54. package/flow/reconcile.ts +738 -0
  55. package/flow/ref-kind.ts +80 -0
  56. package/flow/resume-picker.ts +222 -0
  57. package/flow/resume.ts +116 -0
  58. package/flow/run-health.ts +252 -0
  59. package/flow/run-liveness.ts +33 -0
  60. package/flow/state-metrics.ts +559 -0
  61. package/flow/status.ts +105 -0
  62. package/flow/step-output.ts +416 -0
  63. package/flow/steps.ts +73 -0
  64. package/flow/terminal-purge.ts +281 -0
  65. package/flow/turn-generation.ts +19 -0
  66. package/flow/v2-emission.ts +381 -0
  67. package/flow/v2-resume.ts +100 -0
  68. package/flow/vocabulary.ts +261 -0
  69. package/flow/widget.ts +448 -0
  70. package/flow/worktree-context.ts +136 -0
  71. package/flow-diagram/assemble.ts +27 -0
  72. package/flow-diagram/command.ts +252 -0
  73. package/flow-diagram/translate.ts +862 -0
  74. package/flow-diagram/vendor/harness-profiler/LICENSE +21 -0
  75. package/flow-diagram/vendor/harness-profiler/PIN.md +64 -0
  76. package/flow-diagram/vendor/harness-profiler/hp.js +960 -0
  77. package/flow-diagram/vendor/harness-profiler/load.ts +66 -0
  78. package/flow-diagram/vendor/harness-profiler/view.html +436 -0
  79. package/gates.ts +20 -0
  80. package/herdr/sync.ts +355 -0
  81. package/herdr/viewer.ts +432 -0
  82. package/implement/args.ts +21 -0
  83. package/implement/prompt.ts +98 -0
  84. package/implement/retry.ts +57 -0
  85. package/implement/routing.ts +31 -0
  86. package/index.ts +3206 -0
  87. package/mode-profile.ts +56 -0
  88. package/package.json +205 -4
  89. package/phase-state.ts +18 -0
  90. package/plan/args.ts +20 -0
  91. package/plan/prompt.ts +251 -0
  92. package/plan/size-check.ts +46 -0
  93. package/plan-tools/helpers.ts +177 -0
  94. package/plan-tools/jira-branch-tool.ts +54 -0
  95. package/plan-tools/jira-branch.ts +109 -0
  96. package/plan-tools/jira-issue.ts +85 -0
  97. package/plan-tools/resolve-feature-path.ts +30 -0
  98. package/plan-tools/resolve-notes-path.ts +37 -0
  99. package/plan-tools/resolve-spec-path.ts +31 -0
  100. package/pr-quality/index.ts +908 -0
  101. package/review/LICENSE +19 -0
  102. package/review/deviation.ts +252 -0
  103. package/review/review.ts +3053 -0
  104. package/review/sem-guidance.d.mts +8 -0
  105. package/review/sem-guidance.mjs +89 -0
  106. package/review/verdict.ts +13 -0
  107. package/run-state.ts +2046 -0
  108. package/run-title.ts +91 -0
  109. package/server/consumer.ts +146 -0
  110. package/server/daemon.ts +1094 -0
  111. package/server/lifecycle.ts +679 -0
  112. package/server/pending.ts +267 -0
  113. package/server/staleness.ts +320 -0
  114. package/server/writer.ts +86 -0
  115. package/shared/diff-base.ts +138 -0
  116. package/shared/flow-base.ts +210 -0
  117. package/shared/sonarqube-utils.ts +415 -0
  118. package/shared/stable-range.ts +102 -0
  119. package/slugify.ts +13 -0
  120. package/sonarqube/sonarqube.ts +821 -0
  121. package/spec-review/approve.ts +91 -0
  122. package/spec-review/args.ts +21 -0
  123. package/spec-review/aven-spec.ts +142 -0
  124. package/spec-review/commands.ts +336 -0
  125. package/spec-review/escape-regexp.ts +7 -0
  126. package/spec-review/open-in-pane.ts +166 -0
  127. package/spec-review/picker.ts +74 -0
  128. package/spec-review/prompt.ts +72 -0
  129. package/spec-review/publish-args.ts +33 -0
  130. package/spec-review/publish.ts +210 -0
  131. package/telemetry/attributes.ts +118 -0
  132. package/telemetry/content.ts +140 -0
  133. package/telemetry/dispatch.ts +521 -0
  134. package/telemetry/exporter.ts +124 -0
  135. package/telemetry/index.ts +776 -0
  136. package/telemetry/loki.ts +224 -0
  137. package/tools/code-review-parse.ts +518 -0
  138. package/tools/code-review.ts +312 -0
  139. package/tools/deviation.ts +737 -0
  140. package/tools/flow-submit.ts +302 -0
  141. package/tools/land.ts +608 -0
  142. package/tools/phase-complete.ts +476 -0
  143. package/tools/result.ts +18 -0
  144. package/tools/review-deps.ts +44 -0
  145. package/tools/run-attempt.ts +312 -0
  146. package/tools/spec-approve.ts +265 -0
  147. package/validate/args.ts +22 -0
  148. package/validate/deviation-gate.ts +229 -0
  149. package/validate/gate-target.ts +371 -0
  150. package/validate/gate.ts +79 -0
  151. package/validate/paths.ts +20 -0
  152. package/validate/personal.ts +104 -0
  153. package/validate/prompt.ts +525 -0
  154. package/validate/review-gate.ts +134 -0
  155. package/validate/subtask-range.ts +113 -0
  156. package/work-mode.ts +19 -0
  157. package/worktree/bootstrap.ts +243 -0
  158. package/worktree/branch.ts +168 -0
  159. package/worktree/herdr.ts +447 -0
  160. package/worktree/index.ts +1447 -0
  161. package/worktree/orphan.ts +384 -0
  162. package/worktree/remove-guards.ts +99 -0
  163. package/worktree/residue.ts +216 -0
  164. package/worktree/sweep.ts +526 -0
@@ -0,0 +1,124 @@
1
+ // AIDEV-NOTE (PMR-R8AG): minimal OTLP/HTTP JSON trace exporter. Hand-rolled
2
+ // on purpose — no OTel SDK dependency, no growing buffers, no retry queue.
3
+ // Fire-and-forget with a short timeout; failures are dropped silently after
4
+ // at most one journal note per process (never a rejected promise into the
5
+ // host). Tempo's OTLP/HTTP receiver accepts this JSON at <endpoint>/v1/traces.
6
+ export interface TelemetrySpan {
7
+ traceId: string
8
+ spanId: string
9
+ parentSpanId?: string
10
+ name: string
11
+ /** OTel span kind: 1 INTERNAL, 2 SERVER, 3 CLIENT. */
12
+ kind: number
13
+ startTimeUnixNano: string
14
+ endTimeUnixNano: string
15
+ attributes: Record<string, string>
16
+ /** 2 = ERROR, 1 = OK, 0 = UNSET. */
17
+ statusCode: number
18
+ statusMessage?: string
19
+ }
20
+
21
+ export interface ExportOutcome {
22
+ ok: boolean
23
+ error?: string
24
+ }
25
+
26
+ export type TelemetryFetch = (
27
+ url: string,
28
+ init: {
29
+ method: string
30
+ headers: Record<string, string>
31
+ body: string
32
+ signal: AbortSignal
33
+ },
34
+ ) => Promise<{ status: number }>
35
+
36
+ function attrValue(value: string): { stringValue: string } {
37
+ return { stringValue: value }
38
+ }
39
+
40
+ /**
41
+ * Build the OTLP export request body (pure). Attribute values ride as
42
+ * strings; numeric gen_ai usage tokens are formatted strings, which OTLP
43
+ * JSON accepts and Tempo indexes fine.
44
+ */
45
+ export function buildOtlpBody(
46
+ resourceAttributes: Record<string, string>,
47
+ spans: readonly TelemetrySpan[],
48
+ ): string {
49
+ const resourceAttrs = Object.keys(resourceAttributes).map((key) => ({
50
+ key,
51
+ value: attrValue(resourceAttributes[key]),
52
+ }))
53
+ const otlpSpans = spans.map((span) => {
54
+ const out: Record<string, unknown> = {
55
+ traceId: span.traceId,
56
+ spanId: span.spanId,
57
+ name: span.name,
58
+ kind: span.kind,
59
+ startTimeUnixNano: span.startTimeUnixNano,
60
+ endTimeUnixNano: span.endTimeUnixNano,
61
+ attributes: Object.keys(span.attributes).map((key) => ({
62
+ key,
63
+ value: attrValue(span.attributes[key]),
64
+ })),
65
+ status: { code: span.statusCode },
66
+ }
67
+ if (span.parentSpanId !== undefined) {
68
+ out.parentSpanId = span.parentSpanId
69
+ }
70
+ if (span.statusMessage !== undefined) {
71
+ out.status = { code: span.statusCode, message: span.statusMessage }
72
+ }
73
+ return out
74
+ })
75
+ return JSON.stringify({
76
+ resourceSpans: [
77
+ {
78
+ resource: { attributes: resourceAttrs },
79
+ scopeSpans: [
80
+ {
81
+ scope: { name: 'pi-flow-telemetry', version: '1.0.0' },
82
+ spans: otlpSpans,
83
+ },
84
+ ],
85
+ },
86
+ ],
87
+ })
88
+ }
89
+
90
+ /**
91
+ * POST one batch of spans. Timeout via AbortSignal (default 2500 ms);
92
+ * any failure maps to {ok:false, error} — the caller decides whether to
93
+ * note it once, then drops it.
94
+ */
95
+ export async function exportSpans(
96
+ endpoint: string,
97
+ headers: Record<string, string>,
98
+ resourceAttributes: Record<string, string>,
99
+ spans: readonly TelemetrySpan[],
100
+ fetchImpl: TelemetryFetch,
101
+ timeoutMs = 2500,
102
+ ): Promise<ExportOutcome> {
103
+ if (spans.length === 0) return { ok: true }
104
+ const controller = new AbortController()
105
+ const timer = setTimeout(() => controller.abort(), timeoutMs)
106
+ try {
107
+ const base = endpoint.replace(/\/+$/, '')
108
+ const response = await fetchImpl(`${base}/v1/traces`, {
109
+ method: 'POST',
110
+ headers: { 'content-type': 'application/json', ...headers },
111
+ body: buildOtlpBody(resourceAttributes, spans),
112
+ signal: controller.signal,
113
+ })
114
+ if (response.status < 200 || response.status >= 300) {
115
+ return { ok: false, error: `OTLP endpoint responded ${response.status}` }
116
+ }
117
+ return { ok: true }
118
+ } catch (err) {
119
+ const message = err instanceof Error ? err.message : `${err}`
120
+ return { ok: false, error: message }
121
+ } finally {
122
+ clearTimeout(timer)
123
+ }
124
+ }