loopctl-mcp-server 3.13.0 → 3.14.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 +2 -1
- package/index.js +66 -6
- package/lib/chg-ledger-summary.js +69 -0
- package/lib/project-update.js +2 -2
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -277,7 +277,7 @@ Epic 39 Repo Coordination Bus — a lightweight, tenant-isolated channel for age
|
|
|
277
277
|
| Tool | Description |
|
|
278
278
|
|---|---|
|
|
279
279
|
| `report_story` | Reviewer confirms the implementation is done. Transitions implementing -> reported_done. Accepts optional `token_usage` object. Under the LCP-1 §9.3 signed profile, pass the `claim` from `custody_sign_claim`. Refused 409 `chg_root_review_only` for a key descending from an intake source's `chg_root_dispatch_id`. |
|
|
280
|
-
| `review_complete` | Record that a review has been completed for a story. Required before verify. Under the signed profile, pass the `claim` from `custody_sign_claim`. On a story bound to a chg change (loopctl US-47.5), after the existing custody gates: only a key chg-server minted for the review — a strict descendant of the intake source's `chg_root_dispatch_id` — may record it (409 `chg_reviewer_required`, the root key included); `commit_sha` is REQUIRED and must be the sha of a submitted revision of the story's current change (422 `commit_sha_not_bound`); one reviewer dispatch records one verdict (409 `chg_review_already_recorded`). `commit_sha` is ignored on any other story. |
|
|
280
|
+
| `review_complete` | Record that a review has been completed for a story. Required before verify. Under the signed profile, pass the `claim` from `custody_sign_claim`. On a story bound to a chg change (loopctl US-47.5), after the existing custody gates: only a key chg-server minted for the review — a strict descendant of the intake source's `chg_root_dispatch_id` — may record it (409 `chg_reviewer_required`, the root key included); `commit_sha` is REQUIRED and must be the sha of a submitted revision of the story's current change (422 `commit_sha_not_bound`); one reviewer dispatch records one verdict (409 `chg_review_already_recorded`); a key the intake source minted (`review_dispatch`, US-50.3) reviews only the revision it was minted for, while its dispatch is live (409 `chg_review_dispatch_mismatch`). `commit_sha` is ignored on any other story. |
|
|
281
281
|
|
|
282
282
|
### Verification Tools (orchestrator key)
|
|
283
283
|
|
|
@@ -538,6 +538,7 @@ The order to wire it up, the stage machine these tools move a story through, and
|
|
|
538
538
|
| `place_dispatch` | **Place a queued story on a runner** (`POST /api/v1/runners/:runner_id/dispatches`): claims it under a freshly minted custody dispatch and pushes the work. The control-side trigger of the delivery loop. 409 `runner_declines_work` when the machine declares `draining` or `max_sessions` 0 — refused before the mint, so nothing was claimed; a retry carrying a `dispatch_id` loopctl already holds is re-sent anyway, because its claim is already standing. 409 `runner_exhausted` when the machine's subscription (its own, or one it shares an account with) is exhausted — also refused before the mint, and the body carries `usage_exhausted_until`, when it clears on its own. Required: `story_id`, `runner_id` (from `runner_pool`). Optional: `kind` (`implement`, the only kind this tool sends — `triage` is dispatchable on the contract but placement CLAIMS the story, which triage must not do; the server refuses any kind whose agent spec is not a `:build` with 422 `not_placeable_kind`, before anything is minted or claimed), `dispatch_id` (the idempotency key — generated when absent; pass the SAME one to retry rather than start a second session), `base_branch`, `wall_clock_seconds`, `max_turns`, and `branch` — **which you should not send**. Since runner contract 1.14.0 loopctl DERIVES the branch from the story number and an id fragment, behind a prefix the target runner declared it accepts (`branch_prefixes`, visible on `runner_pool`), which is a per-machine fact only the server can read. A branch you name is never rewritten, only judged, and it must satisfy three things: it must be a valid git ref name (422 `invalid_branch_name`, which also refuses a non-string such as `null`), it must start with one of that machine's declared prefixes (422 `branch_not_allowed`), and it must END WITH THIS STORY'S OWN SUFFIX (422 `branch_not_unique`) so that two stories on one repository can never be given one branch — you may choose the prefix, you may not drop the suffix. Nothing is claimed on any of them, and the fix is to drop the field. `base_branch` is judged as a git ref name too (422 `invalid_branch_name`): it reaches git on the runner just as `branch` does. It is NOT story-unique — every dispatch cutting from `master` is the normal case. A retry naming a different `branch` from the one this dispatch was already sent on is 422 `branch_conflict`: the branch is recorded at the first push and re-sent verbatim, because a session may be running on it right now, and a retry naming a different `base_branch` from the recorded one is 422 `base_branch_conflict`, because the merge gate judges against the recorded base. 409 `no_conforming_branch` is the machine's problem rather than the request's: it declares prefixes and none of them can produce a valid branch name carrying the story number and id fragment that keeps two stories off one branch, so nothing was claimed and an operator has to fix `branch_prefixes` on that box — the body echoes the declared prefixes. A retry carrying a `dispatch_id` loopctl already holds is never refused for either prefix reason: its claim is already standing, so the declaration only steers the name. The story object is NOT a parameter: loopctl builds it from its own rows and refuses a caller-supplied one. The story must be `pending` or `contracted` (a pending one is contracted by the placement), its dependencies met, with its stage at `queued`. A retry also moves the claim's deadline to now + its `wall_clock_seconds` + `DISPATCH_LEASE_GRACE_SECONDS` (never earlier than the one already sent), and 409 `dispatch_claim_ended` means the claim that `dispatch_id` was placed under has ended — nothing was pushed or written; place again with a new `dispatch_id`. Requires `LOOPCTL_USER_KEY`. |
|
|
539
539
|
| `story_stage` | **Where a story is in the delivery machine** (`GET /api/v1/stories/:id/stage`): stage, `claim_epoch`, `lock_version`, `attempts`, the runner holding it, and the escalation reason when parked. `stage: null` means the loop has never touched it. This is how you watch a run, and the only way to see why a stage report was refused `stale_stage`. `escalation_reason` is untrusted session text. Required: `story_id`. |
|
|
540
540
|
| `agent_outcomes` | **An agent spec's track record, per version** (`GET /api/v1/agent_specs/:spec_id/outcomes`, loopctl US-48.12): every runner dispatch ends in one outcome row keyed by its spec `{id, version}`, and this summarises one spec's rows recorded in the last `window_days` (default 30, at most 365), newest version first — `runs`, `ended`, `successes` (a build whose work merged, a triage verdict no human overrode, a verify verdict loopctl recorded, a reply draft stored `drafted`, a spec_tuner run whose draft loopctl judged `proposed`), `human_overrides`, `budget_exhausted` (sessions ended `wall_clock_exceeded` / `max_turns_exceeded`), each also as a rate, and `median_elapsed_s` / `median_turns` (null when no run carries one; turns come from the runner's session-end report, runner contract 1.27.0, so a run on an older runner has none). Every figure is from an event loopctl recorded, never session text. Any tenant key reads it (`role: :agent` with the hierarchy): `LOOPCTL_API_KEY` when set, else `LOOPCTL_AGENT_KEY`, else `LOOPCTL_ORCH_KEY`. 400 for a malformed `spec_id` or a `window_days` outside 1..365 (both also refused locally), 401 without a valid key; no role is refused. Required: `spec_id` (`triage`, `implement`, `reply_draft`, `verify`, `spec_tuner`). |
|
|
541
|
+
| `chg_ledger_summary` | **The chg audit questions, answered** (`GET /api/v1/chg_ledger/summary`, loopctl US-50.6): what the `/chg` dashboard shows, computed by the same functions, from the ledger rows the fleet's chg outboxes sent — `gate_outcomes` (per day and kind, counts per verdict), `fallbacks` (checks that ran mode `all`, the rate, the top reasons), `selection` (stats and misses: a chg check that passed on a commit whose gate failed), `phase_times` (hydrate, static, affected, tests, lock_wait), `flaky`, `runner_samples`, `review_outcomes` (merged PRs' findings by severity and disposition, and how many merged without a counted round, totalled over EVERY merged PR in range) and `attention` (changes flagged gap or stale and still flagged: current state, so `since` and `until` do not apply). Lists cap at 50 rows; a panel shed under load is the string `unavailable`. Optional: `repo`, `host` (review outcomes and flagged changes ignore it), `since` (ISO 8601, default 7 days before `until`), `until` (default now). 422 for a malformed timestamp, a `since` not before `until`, or a period over 90 days (all also refused locally); 401 without a valid key; no role is refused. Any tenant key: `LOOPCTL_API_KEY` when set, else `LOOPCTL_AGENT_KEY`, else `LOOPCTL_ORCH_KEY`. |
|
|
541
542
|
| `change_binding_get` | **The chg changes bound to a story** (`GET /api/v1/stories/:id/changes`, loopctl US-47.7): every change a chg `submitted` event bound to the story, OLDEST FIRST so the current one is last, each with `repo`, `change_id`, `current`, `superseded_at`, `submitter_not_claimant`, `inserted_at`, and its APPLIED events in `event_seq` order (`event_seq`, `kind`, `revision`, `sha`, `occurred_at`, `applied_at`; never the event `data` payload). Bounded by the server, bounds in `meta` (`max_bindings`, `max_events_per_change`): the newest of each are kept, so the current binding is always listed, and `binding_count` / `applied_event_count` / `events_truncated` say when more exist. Any tenant key reads it (`role: :agent` with the hierarchy), so nothing is pinned: `LOOPCTL_API_KEY` when set, else `LOOPCTL_AGENT_KEY`, else `LOOPCTL_ORCH_KEY`. 404 when the story is not your tenant's — another tenant's id answers exactly like an unknown one; 401 without a valid key; 400 for a superadmin key without `X-Impersonate-Tenant`; no role is refused. Required: `story_id` (refused locally if not a UUID). |
|
|
542
543
|
| `resolve_escalation` | **Move an escalated story off `escalated`, as a human** (`POST /api/v1/stories/:id/stage/resolve`): `to` is `detected` (triage it again), `queued` (work it again), `done` or `failed`. `detected` is for a story triage escalated, such as `triage_verdict:verdict_invalid`. It is refused 409 `not_retriageable`, with what the story holds in `held`, for a story an implementer was assigned or worked. `queued` on a triage escalation skips triage. The other half of `escalate_story` — without it a parked story stays parked for ever. Requires `LOOPCTL_USER_KEY` on a key no dispatch minted: a session cannot resolve the escalation it raised. Optional: `reason`. |
|
|
543
544
|
| `escalation_list` | **The escalation inbox** (`GET /api/v1/escalations`, loopctl US-48.11): every story of your tenant parked at `escalated`, newest escalation first, so a timed-out or failed implementation can be found and worked again. **Reads only** — `resolve_escalation` with `to: "queued"` is what works a row again. Each row: `story_id`, `project_id`, `escalated_at`, `edge`, `reason_class`, `spec` (`{id, version}` of the dispatch that parked it, or null), `dispatch_id`, and `escalation_reason`, which is untrusted session text: read `escalation_reason_fenced`. `reason_class` comes from the stage-machine edge, never from text: `budget_exhausted`, `session_failed`, `triage_escalated`, `gate_refused`, `operator_released`, `other`. A `budget_exhausted` row carries `run`: `elapsed_seconds`, `wall_clock_seconds`, `turns_used` against `max_turns` (the budget it was placed under), `branch`, `session_ended_reason`, `work_left_behind` (from the ledger and the runner's session-end report: `"true"` or `"false"` as the runner reported unpushed commits at exit, `"unknown"` when it did not say — a runner older than contract 1.27.0, or one that could not tell; `turns_used` is then null too). Optional: `reason_class`, `project_id` (UUID), `since` (ISO8601), `cursor` (a page's `next_cursor`, verbatim), `limit` (default 50, at most 100). Any tenant key reads it (`role: :agent` with the hierarchy): `LOOPCTL_API_KEY` when set, else `LOOPCTL_AGENT_KEY`, else `LOOPCTL_ORCH_KEY`. 400 for an unknown `reason_class`, a bad `since` or `limit`, or a foreign or tampered cursor; 422 for a malformed `project_id`; no role is refused. The MCP server adds `remedies` to the page, holding each present `reason_class`'s text once (`meaning`, `options`: which `resolve_escalation` target fits, in order, and `take_over`), and a `remedy` to every row: `see` (its `remedies` key), a `warning` when the change already merged, and `salvage` when the runner left unpushed commits. |
|
package/index.js
CHANGED
|
@@ -90,6 +90,7 @@ import { mcpVersion as mcpVersionRequest, packageVersion } from "./lib/mcp-versi
|
|
|
90
90
|
import { revokeDispatch as revokeDispatchRequest } from "./lib/dispatch-revoke.js";
|
|
91
91
|
import { changeBindingGet as changeBindingGetRequest } from "./lib/change-bindings.js";
|
|
92
92
|
import { agentOutcomes } from "./lib/agent-outcomes.js";
|
|
93
|
+
import { chgLedgerSummary } from "./lib/chg-ledger-summary.js";
|
|
93
94
|
import {
|
|
94
95
|
clearGithubCredential as clearGithubCredentialRequest,
|
|
95
96
|
githubCredential as githubCredentialRequest,
|
|
@@ -3504,6 +3505,18 @@ async function agentOutcomesRead(args) {
|
|
|
3504
3505
|
);
|
|
3505
3506
|
}
|
|
3506
3507
|
|
|
3508
|
+
// US-50.6: a READ of the chg ledger summary, `role: :agent` with the hierarchy — keyed as
|
|
3509
|
+
// agentOutcomesRead is, LOOPCTL_AGENT_KEY as an OVERRIDE so `resolveKey`'s order holds.
|
|
3510
|
+
async function chgLedgerSummaryRead(args) {
|
|
3511
|
+
const key = process.env.LOOPCTL_AGENT_KEY;
|
|
3512
|
+
|
|
3513
|
+
return toContent(
|
|
3514
|
+
await chgLedgerSummary(args, {
|
|
3515
|
+
apiCall: (method, path, body) => apiCall(method, path, body, key),
|
|
3516
|
+
}),
|
|
3517
|
+
);
|
|
3518
|
+
}
|
|
3519
|
+
|
|
3507
3520
|
async function resolveEscalation(args) {
|
|
3508
3521
|
return toContent(await resolveEscalationRequest(args, deliveryDeps()));
|
|
3509
3522
|
}
|
|
@@ -4303,7 +4316,7 @@ const TOOLS = [
|
|
|
4303
4316
|
{
|
|
4304
4317
|
name: "delete_project",
|
|
4305
4318
|
description:
|
|
4306
|
-
"ARCHIVE a project (DELETE /api/v1/projects/:id sets status to archived; it removes no rows). Its epics, stories and audit entries stay, and an already-archived project is a no-op. The SLUG stays taken: slugs are unique per tenant across archived projects too, resolve_project by that slug still returns the archived project, create_project with it is refused 422, and archiving never releases it, so a new project needs a different one. The one way a slug is freed: update_project renaming
|
|
4319
|
+
"ARCHIVE a project (DELETE /api/v1/projects/:id sets status to archived; it removes no rows). Its epics, stories and audit entries stay, and an already-archived project is a no-op. The SLUG stays taken: slugs are unique per tenant across archived projects too, resolve_project by that slug still returns the archived project, create_project with it is refused 422, and archiving never releases it, so a new project needs a different one. The one way a slug is freed: update_project renaming the project's slug releases the old one. The way back: restore_project for a work project, restore_kb_scope for a kb scope. Sent with LOOPCTL_USER_KEY verbatim when it is set (a global LOOPCTL_API_KEY does not displace it), else with the default key. Refusals: 403 insufficient_role below user role, 403 custody_tier_required on an agent-rooted tenant (the human-anchor gate), 404 for an id not in your tenant.",
|
|
4307
4320
|
inputSchema: {
|
|
4308
4321
|
type: "object",
|
|
4309
4322
|
properties: {
|
|
@@ -4333,7 +4346,7 @@ const TOOLS = [
|
|
|
4333
4346
|
{
|
|
4334
4347
|
name: "update_project",
|
|
4335
4348
|
description:
|
|
4336
|
-
"UPDATE a project's fields (PATCH /api/v1/projects/:id): name, slug, repo_url, description, tech_stack, mission, metadata. Send only what changes; a field left out is left alone, and a call naming none is refused locally.
|
|
4349
|
+
"UPDATE a project's fields (PATCH /api/v1/projects/:id): name, slug, repo_url, description, tech_stack, mission, metadata. Send only what changes; a field left out is left alone, and a call naming none is refused locally. A slug change renames the project's channel (kb scope or work project); when no name is sent and the name equaled the old slug, the name follows. A kb name different from its slug is 422, and a slug another project holds (archived included) is 422. Status is not settable here (archive with delete_project, restore with restore_project). Setting repo_url makes resolve_project({repo_url}) and SessionStart find the project, so it must be the ONLY active project carrying that URL: a second one makes every lookup for the repo 409 ambiguous_resolution fleet-wide. Sent with LOOPCTL_ORCH_KEY verbatim, else LOOPCTL_USER_KEY, else the default key. Refusals: 403 insufficient_role below orchestrator role, 403 custody_tier_required on an agent-rooted tenant (the human-anchor gate), 404 for an id not in your tenant, 422 for an invalid field.",
|
|
4337
4350
|
inputSchema: {
|
|
4338
4351
|
type: "object",
|
|
4339
4352
|
properties: {
|
|
@@ -4342,7 +4355,7 @@ const TOOLS = [
|
|
|
4342
4355
|
slug: {
|
|
4343
4356
|
type: "string",
|
|
4344
4357
|
description:
|
|
4345
|
-
"New slug
|
|
4358
|
+
"New slug (lowercase alphanumerics, hyphens, underscores; 2-63 chars). For a repo channel, the repo basename verbatim, e.g. home_care_billing.",
|
|
4346
4359
|
},
|
|
4347
4360
|
repo_url: { type: "string", description: "Git remote URL, e.g. https://github.com/owner/repo." },
|
|
4348
4361
|
description: { type: "string", description: "New description." },
|
|
@@ -5026,7 +5039,10 @@ const TOOLS = [
|
|
|
5026
5039
|
"chg_root_dispatch_id — else 409 chg_reviewer_required (chg-server's root key is " +
|
|
5027
5040
|
"refused too); commit_sha is REQUIRED and must be the sha of a submitted revision of " +
|
|
5028
5041
|
"the story's current change, else 422 commit_sha_not_bound; and one reviewer dispatch " +
|
|
5029
|
-
"records one verdict, a second is 409 chg_review_already_recorded.
|
|
5042
|
+
"records one verdict, a second is 409 chg_review_already_recorded. A key the intake " +
|
|
5043
|
+
"source minted (review_dispatch, loopctl US-50.3) reviews only the revision it was " +
|
|
5044
|
+
"minted for, and only while its dispatch is live, else 409 " +
|
|
5045
|
+
"chg_review_dispatch_mismatch. On any other story " +
|
|
5030
5046
|
"commit_sha is ignored and not stored. On a PULL-REQUEST-ROUTE story (loopctl " +
|
|
5031
5047
|
"US-48.18) only the key of the story's bound verify@1 dispatch may record the review, " +
|
|
5032
5048
|
"else 409 pr_route_verifier_only — a user key included.",
|
|
@@ -8949,6 +8965,45 @@ const TOOLS = [
|
|
|
8949
8965
|
required: ["spec_id"],
|
|
8950
8966
|
},
|
|
8951
8967
|
},
|
|
8968
|
+
{
|
|
8969
|
+
name: "chg_ledger_summary",
|
|
8970
|
+
description:
|
|
8971
|
+
"THE CHG AUDIT QUESTIONS, ANSWERED (GET /api/v1/chg_ledger/summary, loopctl US-50.6): " +
|
|
8972
|
+
"what the /chg dashboard shows, computed server-side by the same functions, from the " +
|
|
8973
|
+
"ledger rows the fleet's chg outboxes sent. Panels: `gate_outcomes` (per day and kind " +
|
|
8974
|
+
"`chg`/`gate`, counts per verdict), `fallbacks` (checks that ran mode all, the rate, " +
|
|
8975
|
+
"the top reasons), `selection` (stats, plus misses: a chg check that passed on a " +
|
|
8976
|
+
"commit whose gate failed), `phase_times` (hydrate, static, affected, tests, " +
|
|
8977
|
+
"lock_wait: rows, mean and max ms), `flaky`, `runner_samples`, `review_outcomes` " +
|
|
8978
|
+
"(merged PRs' findings by severity and disposition, and how many merged without a " +
|
|
8979
|
+
"counted review round), `attention` (changes flagged gap or stale). Lists are capped " +
|
|
8980
|
+
"at 50 rows. A panel whose read was shed under load is the string `unavailable`; " +
|
|
8981
|
+
"retry later, the others are unaffected.\n\n" +
|
|
8982
|
+
"Filters, all optional: `repo` (owner/name), `host` (a fleet host; review outcomes " +
|
|
8983
|
+
"and flagged changes carry none and ignore it), `since` (ISO 8601, inclusive; default " +
|
|
8984
|
+
"7 days before `until`), `until` (ISO 8601, exclusive; default now). Any key of the " +
|
|
8985
|
+
"tenant may read it (`role: :agent` with the hierarchy), so the key is the usual " +
|
|
8986
|
+
"order with LOOPCTL_AGENT_KEY as this tool's own: LOOPCTL_API_KEY when set, else " +
|
|
8987
|
+
"LOOPCTL_AGENT_KEY, else LOOPCTL_ORCH_KEY. REFUSES: 422 for a timestamp that is not " +
|
|
8988
|
+
"ISO 8601, a `since` not before `until`, or a period over 90 days; 401 for no key or " +
|
|
8989
|
+
"one that does not authenticate; 429 when rate limited. No 403: every key role " +
|
|
8990
|
+
"clears the gate. Those 422 cases are refused locally too (status 0, nothing sent).",
|
|
8991
|
+
inputSchema: {
|
|
8992
|
+
type: "object",
|
|
8993
|
+
properties: {
|
|
8994
|
+
repo: { type: "string", description: "Only this repository, owner/name." },
|
|
8995
|
+
host: { type: "string", description: "Only rows from this fleet host." },
|
|
8996
|
+
since: {
|
|
8997
|
+
type: "string",
|
|
8998
|
+
description: "ISO 8601 start, inclusive. Default 7 days before `until`.",
|
|
8999
|
+
},
|
|
9000
|
+
until: {
|
|
9001
|
+
type: "string",
|
|
9002
|
+
description: "ISO 8601 end, exclusive. Default now. At most 90 days after `since`.",
|
|
9003
|
+
},
|
|
9004
|
+
},
|
|
9005
|
+
},
|
|
9006
|
+
},
|
|
8952
9007
|
{
|
|
8953
9008
|
name: "change_binding_get",
|
|
8954
9009
|
description:
|
|
@@ -9234,11 +9289,14 @@ const TOOLS = [
|
|
|
9234
9289
|
"THEN CONFIGURE GITHUB — the tool stops at the loopctl end and this is the other half. " +
|
|
9235
9290
|
"On the repository: Settings > Webhooks > Add webhook, Payload URL = the `webhook_url` " +
|
|
9236
9291
|
"returned, Content type = application/json, Secret = the contents of `secret_file`, and " +
|
|
9237
|
-
"under 'Let me select individual events' tick ISSUES
|
|
9292
|
+
"under 'Let me select individual events' tick ISSUES and PULL REQUESTS (a merged pull " +
|
|
9293
|
+
"request queues a read of its `## Review findings` section; every other pull-request " +
|
|
9294
|
+
"action is recorded as ignored). The secret is the HMAC key " +
|
|
9238
9295
|
"GitHub signs the RAW body with as `X-Hub-Signature-256`; loopctl verifies it before " +
|
|
9239
9296
|
"trusting a byte. In one command, without the secret ever passing through this " +
|
|
9240
9297
|
"transcript: gh api repos/OWNER/REPO/hooks -f name=web -f config[url]=<webhook_url> -f " +
|
|
9241
|
-
"config[content_type]=json -f config[secret]=\"$(cat <secret_file>)\" -f 'events[]=issues'
|
|
9298
|
+
"config[content_type]=json -f config[secret]=\"$(cat <secret_file>)\" -f 'events[]=issues' " +
|
|
9299
|
+
"-f 'events[]=pull_request'\n\n" +
|
|
9242
9300
|
"EVERY delivery failure afterwards is the SAME 401 `invalid_signature` — an unknown or " +
|
|
9243
9301
|
"revoked source, a suspended tenant, a missing or wrong signature, and a payload whose " +
|
|
9244
9302
|
"`repository.full_name` does not match this source's repository. That is deliberate (a " +
|
|
@@ -10665,6 +10723,8 @@ server.setRequestHandler(CallToolRequestSchema, async (request) => {
|
|
|
10665
10723
|
|
|
10666
10724
|
case "agent_outcomes":
|
|
10667
10725
|
return await agentOutcomesRead(args);
|
|
10726
|
+
case "chg_ledger_summary":
|
|
10727
|
+
return await chgLedgerSummaryRead(args);
|
|
10668
10728
|
|
|
10669
10729
|
case "resolve_escalation":
|
|
10670
10730
|
return await resolveEscalation(args);
|
|
@@ -0,0 +1,69 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* `chg_ledger_summary` (loopctl US-50.6): the chg audit questions the /chg dashboard answers,
|
|
3
|
+
* for a session with no browser — `GET /api/v1/chg_ledger/summary`.
|
|
4
|
+
*
|
|
5
|
+
* Gate outcomes per day, the fallback rate and its reasons, selection quality and misses,
|
|
6
|
+
* time per gate phase, flaky tests, runner samples, merged-PR review outcomes, and changes
|
|
7
|
+
* flagged gap or stale; computed server-side by the same functions the page renders.
|
|
8
|
+
*
|
|
9
|
+
* A READ, `role: :agent` with the hierarchy, so any role's key clears the gate and nothing is
|
|
10
|
+
* pinned: the handler passes LOOPCTL_AGENT_KEY as an override, so `resolveKey`'s order holds
|
|
11
|
+
* (LOOPCTL_API_KEY when set, else LOOPCTL_AGENT_KEY, else LOOPCTL_ORCH_KEY).
|
|
12
|
+
*/
|
|
13
|
+
|
|
14
|
+
export const MAX_PERIOD_DAYS = 90;
|
|
15
|
+
|
|
16
|
+
const DAY_MS = 86_400_000;
|
|
17
|
+
|
|
18
|
+
function refuse(body) {
|
|
19
|
+
return { error: true, status: 0, body };
|
|
20
|
+
}
|
|
21
|
+
|
|
22
|
+
function parseTime(value) {
|
|
23
|
+
if (typeof value !== "string" || value === "") return null;
|
|
24
|
+
const ms = Date.parse(value);
|
|
25
|
+
return Number.isNaN(ms) ? NaN : ms;
|
|
26
|
+
}
|
|
27
|
+
|
|
28
|
+
/** `GET /api/v1/chg_ledger/summary`, with the optional `repo`, `host`, `since`, `until`. */
|
|
29
|
+
export async function chgLedgerSummary(args = {}, { apiCall, now = Date.now } = {}) {
|
|
30
|
+
const { repo, host, since, until } = args;
|
|
31
|
+
|
|
32
|
+
for (const [name, value] of [
|
|
33
|
+
["repo", repo],
|
|
34
|
+
["host", host],
|
|
35
|
+
]) {
|
|
36
|
+
if (value !== undefined && value !== null && typeof value !== "string") {
|
|
37
|
+
return refuse(`\`${name}\` must be a string.`);
|
|
38
|
+
}
|
|
39
|
+
}
|
|
40
|
+
|
|
41
|
+
const sinceMs = parseTime(since);
|
|
42
|
+
const untilMs = parseTime(until);
|
|
43
|
+
|
|
44
|
+
if (Number.isNaN(sinceMs)) return refuse("`since` must be an ISO 8601 timestamp.");
|
|
45
|
+
if (Number.isNaN(untilMs)) return refuse("`until` must be an ISO 8601 timestamp.");
|
|
46
|
+
|
|
47
|
+
// Mirrors the server's defaults only to refuse locally what it would refuse anyway; the
|
|
48
|
+
// server stays the judge.
|
|
49
|
+
const end = untilMs ?? now();
|
|
50
|
+
const start = sinceMs ?? end - 7 * DAY_MS;
|
|
51
|
+
|
|
52
|
+
if (start >= end) return refuse("`since` must be before `until`.");
|
|
53
|
+
if (end - start > MAX_PERIOD_DAYS * DAY_MS) {
|
|
54
|
+
return refuse(`The period may be at most ${MAX_PERIOD_DAYS} days (since to until).`);
|
|
55
|
+
}
|
|
56
|
+
|
|
57
|
+
const qs = new URLSearchParams();
|
|
58
|
+
for (const [name, value] of [
|
|
59
|
+
["repo", repo],
|
|
60
|
+
["host", host],
|
|
61
|
+
["since", since],
|
|
62
|
+
["until", until],
|
|
63
|
+
]) {
|
|
64
|
+
if (typeof value === "string" && value !== "") qs.set(name, value);
|
|
65
|
+
}
|
|
66
|
+
|
|
67
|
+
const query = qs.toString();
|
|
68
|
+
return apiCall("GET", `/api/v1/chg_ledger/summary${query ? `?${query}` : ""}`, null);
|
|
69
|
+
}
|
package/lib/project-update.js
CHANGED
|
@@ -5,8 +5,8 @@
|
|
|
5
5
|
*
|
|
6
6
|
* WHAT THE ENDPOINT ACCEPTS: `name`, `slug`, `repo_url`, `description`, `tech_stack`,
|
|
7
7
|
* `mission`, `metadata`. It drops every nil, so a request naming none is a 200 that changes
|
|
8
|
-
* nothing: refused here.
|
|
9
|
-
* (#1038)
|
|
8
|
+
* nothing: refused here. Any project's `slug` can change, and a name that equaled the old
|
|
9
|
+
* slug follows it (#1038). A body carrying `status` is a 422 (archive
|
|
10
10
|
* and restore have their own routes), so it is never sent. An empty `mission` clears it.
|
|
11
11
|
*
|
|
12
12
|
* KEY: orchestrator role on a human-anchored tenant; index.js injects the orchestrator-pinned
|