@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.
- package/README.md +833 -2
- package/adhoc/tracker.ts +360 -0
- package/aven/client.ts +996 -0
- package/aven/status.ts +395 -0
- package/brainstorm/args.ts +24 -0
- package/brainstorm/artifact.ts +67 -0
- package/brainstorm/paths.ts +43 -0
- package/brainstorm/prompt.ts +172 -0
- package/brainstorm/refs.ts +41 -0
- package/config.schema.json +161 -0
- package/config.ts +577 -0
- package/feedback/args.ts +21 -0
- package/feedback/prompt.ts +177 -0
- package/feedback/triage.ts +88 -0
- package/flow/agent-role.ts +46 -0
- package/flow/answer-wake.ts +212 -0
- package/flow/answer.ts +183 -0
- package/flow/args.ts +48 -0
- package/flow/ask-emitter.ts +331 -0
- package/flow/attribution.ts +145 -0
- package/flow/aven-resolve-exec.ts +95 -0
- package/flow/aven-resolve.ts +80 -0
- package/flow/awaiting-approval.ts +32 -0
- package/flow/binding-heal.ts +68 -0
- package/flow/cost-autopush.ts +162 -0
- package/flow/cost-command.ts +122 -0
- package/flow/cost-rows-journal.ts +296 -0
- package/flow/cost-rows-push.ts +112 -0
- package/flow/cost-rows-rows.ts +209 -0
- package/flow/cost-rows.ts +228 -0
- package/flow/cost.ts +173 -0
- package/flow/durable-refs.ts +287 -0
- package/flow/effect-gate.ts +137 -0
- package/flow/ensure-labels.ts +44 -0
- package/flow/frame.ts +172 -0
- package/flow/gates.ts +211 -0
- package/flow/jira-ref.ts +212 -0
- package/flow/label-gate.ts +149 -0
- package/flow/land-gate.ts +98 -0
- package/flow/lifecycle-policy.ts +162 -0
- package/flow/live-wait.ts +52 -0
- package/flow/liveness.ts +408 -0
- package/flow/loop-deps.ts +210 -0
- package/flow/loop-settle.ts +531 -0
- package/flow/loop.ts +437 -0
- package/flow/orchestrate.ts +45 -0
- package/flow/phase-command.ts +287 -0
- package/flow/phase-emoji.ts +13 -0
- package/flow/phase-prompts.ts +251 -0
- package/flow/picker.ts +307 -0
- package/flow/push.ts +475 -0
- package/flow/reconcile-command.ts +253 -0
- package/flow/reconcile-deps.ts +329 -0
- package/flow/reconcile.ts +738 -0
- package/flow/ref-kind.ts +80 -0
- package/flow/resume-picker.ts +222 -0
- package/flow/resume.ts +116 -0
- package/flow/run-health.ts +252 -0
- package/flow/run-liveness.ts +33 -0
- package/flow/state-metrics.ts +559 -0
- package/flow/status.ts +105 -0
- package/flow/step-output.ts +416 -0
- package/flow/steps.ts +73 -0
- package/flow/terminal-purge.ts +281 -0
- package/flow/turn-generation.ts +19 -0
- package/flow/v2-emission.ts +381 -0
- package/flow/v2-resume.ts +100 -0
- package/flow/vocabulary.ts +261 -0
- package/flow/widget.ts +448 -0
- package/flow/worktree-context.ts +136 -0
- package/flow-diagram/assemble.ts +27 -0
- package/flow-diagram/command.ts +252 -0
- package/flow-diagram/translate.ts +862 -0
- package/flow-diagram/vendor/harness-profiler/LICENSE +21 -0
- package/flow-diagram/vendor/harness-profiler/PIN.md +64 -0
- package/flow-diagram/vendor/harness-profiler/hp.js +960 -0
- package/flow-diagram/vendor/harness-profiler/load.ts +66 -0
- package/flow-diagram/vendor/harness-profiler/view.html +436 -0
- package/gates.ts +20 -0
- package/herdr/sync.ts +355 -0
- package/herdr/viewer.ts +432 -0
- package/implement/args.ts +21 -0
- package/implement/prompt.ts +98 -0
- package/implement/retry.ts +57 -0
- package/implement/routing.ts +31 -0
- package/index.ts +3206 -0
- package/mode-profile.ts +56 -0
- package/package.json +205 -4
- package/phase-state.ts +18 -0
- package/plan/args.ts +20 -0
- package/plan/prompt.ts +251 -0
- package/plan/size-check.ts +46 -0
- package/plan-tools/helpers.ts +177 -0
- package/plan-tools/jira-branch-tool.ts +54 -0
- package/plan-tools/jira-branch.ts +109 -0
- package/plan-tools/jira-issue.ts +85 -0
- package/plan-tools/resolve-feature-path.ts +30 -0
- package/plan-tools/resolve-notes-path.ts +37 -0
- package/plan-tools/resolve-spec-path.ts +31 -0
- package/pr-quality/index.ts +908 -0
- package/review/LICENSE +19 -0
- package/review/deviation.ts +252 -0
- package/review/review.ts +3053 -0
- package/review/sem-guidance.d.mts +8 -0
- package/review/sem-guidance.mjs +89 -0
- package/review/verdict.ts +13 -0
- package/run-state.ts +2046 -0
- package/run-title.ts +91 -0
- package/server/consumer.ts +146 -0
- package/server/daemon.ts +1094 -0
- package/server/lifecycle.ts +679 -0
- package/server/pending.ts +267 -0
- package/server/staleness.ts +320 -0
- package/server/writer.ts +86 -0
- package/shared/diff-base.ts +138 -0
- package/shared/flow-base.ts +210 -0
- package/shared/sonarqube-utils.ts +415 -0
- package/shared/stable-range.ts +102 -0
- package/slugify.ts +13 -0
- package/sonarqube/sonarqube.ts +821 -0
- package/spec-review/approve.ts +91 -0
- package/spec-review/args.ts +21 -0
- package/spec-review/aven-spec.ts +142 -0
- package/spec-review/commands.ts +336 -0
- package/spec-review/escape-regexp.ts +7 -0
- package/spec-review/open-in-pane.ts +166 -0
- package/spec-review/picker.ts +74 -0
- package/spec-review/prompt.ts +72 -0
- package/spec-review/publish-args.ts +33 -0
- package/spec-review/publish.ts +210 -0
- package/telemetry/attributes.ts +118 -0
- package/telemetry/content.ts +140 -0
- package/telemetry/dispatch.ts +521 -0
- package/telemetry/exporter.ts +124 -0
- package/telemetry/index.ts +776 -0
- package/telemetry/loki.ts +224 -0
- package/tools/code-review-parse.ts +518 -0
- package/tools/code-review.ts +312 -0
- package/tools/deviation.ts +737 -0
- package/tools/flow-submit.ts +302 -0
- package/tools/land.ts +608 -0
- package/tools/phase-complete.ts +476 -0
- package/tools/result.ts +18 -0
- package/tools/review-deps.ts +44 -0
- package/tools/run-attempt.ts +312 -0
- package/tools/spec-approve.ts +265 -0
- package/validate/args.ts +22 -0
- package/validate/deviation-gate.ts +229 -0
- package/validate/gate-target.ts +371 -0
- package/validate/gate.ts +79 -0
- package/validate/paths.ts +20 -0
- package/validate/personal.ts +104 -0
- package/validate/prompt.ts +525 -0
- package/validate/review-gate.ts +134 -0
- package/validate/subtask-range.ts +113 -0
- package/work-mode.ts +19 -0
- package/worktree/bootstrap.ts +243 -0
- package/worktree/branch.ts +168 -0
- package/worktree/herdr.ts +447 -0
- package/worktree/index.ts +1447 -0
- package/worktree/orphan.ts +384 -0
- package/worktree/remove-guards.ts +99 -0
- package/worktree/residue.ts +216 -0
- package/worktree/sweep.ts +526 -0
|
@@ -0,0 +1,224 @@
|
|
|
1
|
+
// AIDEV-NOTE (PMR-ZV9Y 4.2): minimal Loki log-push client. Mirrors
|
|
2
|
+
// telemetry/exporter.ts (PMR-R8AG) on purpose — hand-rolled JSON POST, no
|
|
3
|
+
// collector dependency, no growing buffers, no retry queue. Fire-and-forget
|
|
4
|
+
// with a short AbortSignal timeout; failures are dropped silently after AT
|
|
5
|
+
// MOST ONE journal note per process (never a rejected promise into the host),
|
|
6
|
+
// and the once-per-process guard is the caller-owned `state` object (a
|
|
7
|
+
// per-LokiPusher singleton threaded through subtask 4.3's fan-out). Loki's
|
|
8
|
+
// push receiver accepts this JSON at <endpoint>/loki/api/v1/push.
|
|
9
|
+
//
|
|
10
|
+
// LABEL HYGIENE (ISC-A-1): the Loki stream carries ONLY the closed v2 enum set
|
|
11
|
+
// plus identity (job, flow_ref, mode, phase, state, reason, wait_kind, kind).
|
|
12
|
+
// Free text — note prose, halt reasons, deviation text — lives in the JSON
|
|
13
|
+
// `line` only, NEVER a label. buildLokiStream is the fixed label-builder so a
|
|
14
|
+
// caller structurally cannot inject an arbitrary label, and it drops
|
|
15
|
+
// empty/absent values so a reasonless state never emits `reason=""`.
|
|
16
|
+
//
|
|
17
|
+
// SESSION-SIDE ONLY: like the OTLP path, this pushes from the live session
|
|
18
|
+
// (subtask 4.3 wires the journal-writer fan-out that calls it). The daemon
|
|
19
|
+
// never pushes Loki — see the AIDEV-NOTE on the `telemetry.loki` block in
|
|
20
|
+
// config.ts (single strict reader).
|
|
21
|
+
|
|
22
|
+
import type { FlowReason, FlowState, WaitKind } from '../flow/vocabulary.ts'
|
|
23
|
+
import type { FlowPhase } from '../run-state.ts'
|
|
24
|
+
|
|
25
|
+
/** Closed Loki label set: job (fixed) + identity + v2 enums. No free text. */
|
|
26
|
+
export interface LokiLabels {
|
|
27
|
+
flow_ref?: string
|
|
28
|
+
mode?: string
|
|
29
|
+
phase?: FlowPhase
|
|
30
|
+
state?: FlowState
|
|
31
|
+
reason?: FlowReason | ''
|
|
32
|
+
wait_kind?: WaitKind
|
|
33
|
+
kind?: string
|
|
34
|
+
}
|
|
35
|
+
|
|
36
|
+
/** Resolved Loki push settings; null (caller) = disabled, push zero events. */
|
|
37
|
+
export interface LokiSettings {
|
|
38
|
+
endpoint: string
|
|
39
|
+
headers?: Record<string, string>
|
|
40
|
+
}
|
|
41
|
+
|
|
42
|
+
export interface LokiOutcome {
|
|
43
|
+
ok: boolean
|
|
44
|
+
error?: string
|
|
45
|
+
}
|
|
46
|
+
|
|
47
|
+
/**
|
|
48
|
+
* At-most-one-note-per-process guard (ISC-A-5). Held by the caller and shared
|
|
49
|
+
* across every push in a process; pushLokiEvent flips `noted` on first failure
|
|
50
|
+
* so later failures are silent. Mirrors the OTLP path's `state.noted`.
|
|
51
|
+
*/
|
|
52
|
+
export interface LokiNoteState {
|
|
53
|
+
noted: boolean
|
|
54
|
+
}
|
|
55
|
+
|
|
56
|
+
/** Pusher dependencies, injected so tests run without a live endpoint (D2). */
|
|
57
|
+
export interface LokiPushDeps {
|
|
58
|
+
fetchImpl: LokiFetch
|
|
59
|
+
/** Wall-clock fallback (ms epoch) when the event carries no parseable `at`. */
|
|
60
|
+
now: () => number
|
|
61
|
+
/** Shared per-process once-guard; the caller owns and threads it (4.3). */
|
|
62
|
+
state: LokiNoteState
|
|
63
|
+
/** Journal-note hook, invoked at most once per process on first failure. */
|
|
64
|
+
onNote: (error: string) => void
|
|
65
|
+
timeoutMs?: number
|
|
66
|
+
}
|
|
67
|
+
|
|
68
|
+
/** Injectable fetch seam: returns at least the HTTP status. */
|
|
69
|
+
export type LokiFetch = (
|
|
70
|
+
url: string,
|
|
71
|
+
init: {
|
|
72
|
+
method: string
|
|
73
|
+
headers: Record<string, string>
|
|
74
|
+
body: string
|
|
75
|
+
signal: AbortSignal
|
|
76
|
+
},
|
|
77
|
+
) => Promise<{ status: number }>
|
|
78
|
+
|
|
79
|
+
/** Fixed Loki job label — every pi-flow stream is `{job="pi-flow"}`. */
|
|
80
|
+
export const LOKI_JOB = 'pi-flow'
|
|
81
|
+
|
|
82
|
+
/** Loki push endpoint path (D2): the config stores only the base URL. */
|
|
83
|
+
export const LOKI_PUSH_PATH = '/loki/api/v1/push'
|
|
84
|
+
|
|
85
|
+
/** Default push timeout in ms — same posture as the OTLP exporter. */
|
|
86
|
+
export const LOKI_TIMEOUT_MS = 2500
|
|
87
|
+
|
|
88
|
+
/** The closed label keys that may ride a Loki stream, in a stable order. */
|
|
89
|
+
const LOKI_LABEL_KEYS = [
|
|
90
|
+
'flow_ref',
|
|
91
|
+
'mode',
|
|
92
|
+
'phase',
|
|
93
|
+
'state',
|
|
94
|
+
'reason',
|
|
95
|
+
'wait_kind',
|
|
96
|
+
'kind',
|
|
97
|
+
] as const satisfies readonly (keyof LokiLabels)[]
|
|
98
|
+
|
|
99
|
+
/**
|
|
100
|
+
* Build the fixed label map: `job` always, then each closed-set key present
|
|
101
|
+
* AND non-empty. Unknown keys are never copied (the key list is the guard) and
|
|
102
|
+
* an empty value (e.g. reasonless state's `reason: ''`) is dropped so it
|
|
103
|
+
* cannot inflate cardinality.
|
|
104
|
+
*/
|
|
105
|
+
export function buildLokiStream(labels: LokiLabels): Record<string, string> {
|
|
106
|
+
const stream: Record<string, string> = { job: LOKI_JOB }
|
|
107
|
+
for (const key of LOKI_LABEL_KEYS) {
|
|
108
|
+
const value = labels[key]
|
|
109
|
+
if (typeof value === 'string' && value.length > 0) stream[key] = value
|
|
110
|
+
}
|
|
111
|
+
return stream
|
|
112
|
+
}
|
|
113
|
+
|
|
114
|
+
/**
|
|
115
|
+
* Build the Loki push request body (pure): one stream, one entry. `timestampNs`
|
|
116
|
+
* is an epoch-nanoseconds STRING — see lokiTimestampNs.
|
|
117
|
+
*/
|
|
118
|
+
export function buildLokiPushBody(
|
|
119
|
+
labels: LokiLabels,
|
|
120
|
+
line: string,
|
|
121
|
+
timestampNs: string,
|
|
122
|
+
): string {
|
|
123
|
+
return JSON.stringify({
|
|
124
|
+
streams: [
|
|
125
|
+
{ stream: buildLokiStream(labels), values: [[timestampNs, line]] },
|
|
126
|
+
],
|
|
127
|
+
})
|
|
128
|
+
}
|
|
129
|
+
|
|
130
|
+
/**
|
|
131
|
+
* Epoch-nanoseconds STRING for the Loki entry. Derives from the event's own
|
|
132
|
+
* `at` (ISO-8601) when it parses, else the caller's `now()` fallback — this
|
|
133
|
+
* keeps the Loki entry timestamp aligned with the journal event time even
|
|
134
|
+
* when a push is retried or delayed within the session. Nanoseconds EXCEED
|
|
135
|
+
* Number.MAX_SAFE_INTEGER at current epoch (~1.7e18), so the value is built by
|
|
136
|
+
* appending the six nano digits to the integer millisecond epoch rather than
|
|
137
|
+
* `ms * 1_000_000` (which would silently truncate low-order digits to float).
|
|
138
|
+
*/
|
|
139
|
+
export function lokiTimestampNs(at: string | undefined, nowMs: number): string {
|
|
140
|
+
const eventMs = at === undefined ? Number.NaN : Date.parse(at)
|
|
141
|
+
const ms = Number.isNaN(eventMs) ? nowMs : eventMs
|
|
142
|
+
return `${Math.trunc(ms)}000000`
|
|
143
|
+
}
|
|
144
|
+
|
|
145
|
+
/** Pull the event's ISO `at` off a JSON line so pushLokiEvent can timestamp it. */
|
|
146
|
+
function eventAt(line: string): string | undefined {
|
|
147
|
+
let parsed: unknown
|
|
148
|
+
try {
|
|
149
|
+
parsed = JSON.parse(line)
|
|
150
|
+
} catch {
|
|
151
|
+
return undefined
|
|
152
|
+
}
|
|
153
|
+
if (parsed === null || typeof parsed !== 'object') return undefined
|
|
154
|
+
const at = (parsed as Record<string, unknown>).at
|
|
155
|
+
return typeof at === 'string' ? at : undefined
|
|
156
|
+
}
|
|
157
|
+
|
|
158
|
+
/**
|
|
159
|
+
* POST one event. Timeout via AbortSignal (default LOKI_TIMEOUT_MS); any
|
|
160
|
+
* failure (throw, abort, non-2xx) maps to {ok:false, error} — the caller
|
|
161
|
+
* decides whether to note it once, then drops it. Never throws.
|
|
162
|
+
*/
|
|
163
|
+
export async function pushLoki(
|
|
164
|
+
endpoint: string,
|
|
165
|
+
headers: Record<string, string>,
|
|
166
|
+
labels: LokiLabels,
|
|
167
|
+
line: string,
|
|
168
|
+
timestampNs: string,
|
|
169
|
+
fetchImpl: LokiFetch,
|
|
170
|
+
timeoutMs = LOKI_TIMEOUT_MS,
|
|
171
|
+
): Promise<LokiOutcome> {
|
|
172
|
+
try {
|
|
173
|
+
const base = endpoint.replace(/\/+$/, '')
|
|
174
|
+
const response = await fetchImpl(`${base}${LOKI_PUSH_PATH}`, {
|
|
175
|
+
method: 'POST',
|
|
176
|
+
headers: { 'content-type': 'application/json', ...headers },
|
|
177
|
+
body: buildLokiPushBody(labels, line, timestampNs),
|
|
178
|
+
// AbortSignal.timeout is unref'd — a dead endpoint never pins the loop.
|
|
179
|
+
signal: AbortSignal.timeout(timeoutMs),
|
|
180
|
+
})
|
|
181
|
+
if (response.status < 200 || response.status >= 300) {
|
|
182
|
+
return { ok: false, error: `Loki endpoint responded ${response.status}` }
|
|
183
|
+
}
|
|
184
|
+
return { ok: true }
|
|
185
|
+
} catch (err) {
|
|
186
|
+
const message = err instanceof Error ? err.message : `${err}`
|
|
187
|
+
return { ok: false, error: message }
|
|
188
|
+
}
|
|
189
|
+
}
|
|
190
|
+
|
|
191
|
+
/**
|
|
192
|
+
* Fire-and-forget push (the 4.3 fan-out seam). `settings === null` or an empty
|
|
193
|
+
* endpoint → disabled, ZERO fetch calls and no note. Otherwise: void the POST
|
|
194
|
+
* promise (no-throw contract — the flow loop must never await or crash on it)
|
|
195
|
+
* and route any failure through `state`, so the FIRST failure in the process
|
|
196
|
+
* calls `onNote` once and every later one is silent.
|
|
197
|
+
*
|
|
198
|
+
* The entry timestamp comes from the line's own `at` when parseable, else the
|
|
199
|
+
* caller's `now()` — see lokiTimestampNs.
|
|
200
|
+
*/
|
|
201
|
+
export function pushLokiEvent(
|
|
202
|
+
settings: LokiSettings | null,
|
|
203
|
+
labels: LokiLabels,
|
|
204
|
+
line: string,
|
|
205
|
+
deps: LokiPushDeps,
|
|
206
|
+
): void {
|
|
207
|
+
if (settings === null) return
|
|
208
|
+
if (settings.endpoint.length === 0) return
|
|
209
|
+
const timestampNs = lokiTimestampNs(eventAt(line), deps.now())
|
|
210
|
+
void pushLoki(
|
|
211
|
+
settings.endpoint,
|
|
212
|
+
settings.headers ?? {},
|
|
213
|
+
labels,
|
|
214
|
+
line,
|
|
215
|
+
timestampNs,
|
|
216
|
+
deps.fetchImpl,
|
|
217
|
+
deps.timeoutMs ?? LOKI_TIMEOUT_MS,
|
|
218
|
+
).then((outcome) => {
|
|
219
|
+
if (outcome.ok) return
|
|
220
|
+
if (deps.state.noted) return
|
|
221
|
+
deps.state.noted = true
|
|
222
|
+
deps.onNote(outcome.error ?? 'loki push failed')
|
|
223
|
+
})
|
|
224
|
+
}
|