@pikku/inspector 0.12.56 → 0.12.59

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 (45) hide show
  1. package/CHANGELOG.md +185 -0
  2. package/dist/add/add-ai-agent.js +25 -0
  3. package/dist/add/add-ai-scorer.d.ts +2 -0
  4. package/dist/add/add-ai-scorer.js +61 -0
  5. package/dist/add/add-wire-addon.js +26 -0
  6. package/dist/add/scenario-instrumentation.d.ts +6 -1
  7. package/dist/add/scenario-instrumentation.js +6 -0
  8. package/dist/error-codes.d.ts +2 -0
  9. package/dist/error-codes.js +3 -0
  10. package/dist/inspector.js +7 -3
  11. package/dist/types.d.ts +24 -0
  12. package/dist/utils/filter-inspector-state.js +8 -0
  13. package/dist/utils/post-process.d.ts +13 -3
  14. package/dist/utils/post-process.js +51 -21
  15. package/dist/utils/serialize-inspector-state.d.ts +11 -0
  16. package/dist/utils/serialize-inspector-state.js +8 -0
  17. package/dist/utils/workflow/dsl/extract-dsl-workflow.js +13 -4
  18. package/dist/utils/workflow/dsl/patterns.d.ts +2 -1
  19. package/dist/utils/workflow/dsl/patterns.js +8 -5
  20. package/dist/utils/workflow/graph/workflow-graph.types.d.ts +2 -1
  21. package/dist/visit.js +2 -0
  22. package/package.json +3 -3
  23. package/src/add/add-ai-agent.ts +35 -0
  24. package/src/add/add-ai-scorer.test.ts +197 -0
  25. package/src/add/add-ai-scorer.ts +83 -0
  26. package/src/add/add-functions.ts +1 -1
  27. package/src/add/add-scenario-step.test.ts +21 -1
  28. package/src/add/add-wire-addon.test.ts +74 -0
  29. package/src/add/add-wire-addon.ts +22 -0
  30. package/src/add/scenario-instrumentation.ts +6 -0
  31. package/src/error-codes.ts +4 -0
  32. package/src/inspector.ts +7 -3
  33. package/src/types.ts +21 -0
  34. package/src/utils/filter-inspector-state.ts +8 -0
  35. package/src/utils/post-process.test.ts +138 -0
  36. package/src/utils/post-process.ts +69 -22
  37. package/src/utils/serialize-inspector-state.ts +16 -0
  38. package/src/utils/workflow/dsl/extract-approval-policy.test.ts +68 -0
  39. package/src/utils/workflow/dsl/extract-dsl-workflow.ts +13 -5
  40. package/src/utils/workflow/dsl/patterns.ts +8 -5
  41. package/src/utils/workflow/graph/workflow-graph.types.ts +1 -1
  42. package/src/visit.ts +2 -0
  43. package/tsconfig.tsbuildinfo +1 -1
  44. package/src/utils/secret-brokers.test.ts +0 -53
  45. package/src/utils/secret-brokers.ts +0 -11
package/CHANGELOG.md CHANGED
@@ -1,3 +1,188 @@
1
+ ## 0.12.59
2
+
3
+ ### Patch Changes
4
+
5
+ - 02c4fe5: fix(core,inspector): let a host grant an addon secrets it could not declare
6
+
7
+ Scoping an addon's `SecretService` to its `declaredSecrets` left generic addons
8
+ with nothing readable: `declaredSecrets` is derived from the addon package's own
9
+ source, but the secrets an addon like `@pikku/addon-graph` reads are named by the
10
+ consuming app's workflow nodes at runtime. Every authenticated `graph:httpRequest`
11
+ threw.
12
+
13
+ `wireAddon` now takes `secretGrants: string[]` and `credentialGrants: string[]`,
14
+ completing the grant family alongside `secretOverrides` (grant + rename) and
15
+ `globalSecrets` (grant everything, with a reason). Grants name the secret as the
16
+ addon reads it, since the scope check runs before the override map renames it —
17
+ which is also why an override's key grants and its value does not.
18
+
19
+ A grant naming a secret the project does not declare is an `INVALID_VALUE`
20
+ critical at codegen, resolved through the override map before lookup.
21
+
22
+ - 438b776: Move the scenario and feature surface off `@pikku/core/workflow` and onto
23
+ `@pikku/core/scenario`. Scenarios extend workflows, so the production workflow
24
+ wiring no longer names a scenario module in its import graph. Feature and
25
+ scenario types are declared in their own `scenario.types.ts` rather than in
26
+ `workflow.types.ts`. Import `requireActor`, `requireScenarioEnv`, `pollUntil`,
27
+ `createCookieJar`, `addFeature`, `ScenarioHttpResponse` and the rest from
28
+ `@pikku/core/scenario`; `HttpPersonasConfig` now comes from
29
+ `@pikku/core/persona` rather than `@pikku/core/services`.
30
+ - ad63f47: feat(cli): warn before codegen when a linked dependency splits a package's type identity
31
+
32
+ `pikku all` now runs the split-type-identity check as a preflight, beside the
33
+ existing `@pikku/core` one, and warns with `PKU719` naming each package, both
34
+ versions and both paths.
35
+
36
+ It has to run _before_ the work rather than after it fails. The failure it
37
+ explains is a V8 heap OOM, which aborts the process — `process.on('exit')`,
38
+ `uncaughtException` and `finally` never run, so nothing printed after the fact is
39
+ ever seen. By the time there is a symptom, the only thing that can help is
40
+ already on screen above it. Without this the user sees a codegen step that dies
41
+ of memory pressure with no indication that two copies of one package are the
42
+ reason, and the obvious next move is to raise `--max-old-space-size`, which
43
+ hides it further.
44
+
45
+ Warns rather than throws: a skewed linked dependency is a strong signal, not a
46
+ certainty, and refusing to build on a heuristic would break working setups.
47
+ `PIKKU_SKIP_TYPE_IDENTITY_CHECK=1` silences it, matching
48
+ `PIKKU_ALLOW_DUPLICATE_CORE`. It also swallows its own errors — it runs on every
49
+ codegen, so it must never be the reason a build stops.
50
+
51
+ - Updated dependencies [02c4fe5]
52
+ - Updated dependencies [438b776]
53
+ - Updated dependencies [438b776]
54
+ - @pikku/core@0.12.83
55
+
56
+ ## 0.12.58
57
+
58
+ ### Patch Changes
59
+
60
+ - 3ad2131: Name models by what they are for, and switch them all in one place
61
+
62
+ A `models` table in pikku.config.json maps an alias to a provider-qualified
63
+ model, so a declaration can say `model: 'cheap'` and the project repoints every
64
+ use of that tier at once instead of editing each agent. A model containing `/`
65
+ is still concrete and used exactly as written, which is how an agent that needs
66
+ one specific model pins it — aliases are opt-in.
67
+
68
+ The table is baked into codegen rather than read at runtime, so it applies to
69
+ deployed units and not just local runs, and `pikku dev`/`pikku serve` take
70
+ `--model cheap:openai/gpt-5-nano` to repoint a tier for one run without editing
71
+ the config.
72
+
73
+ Because the inspector already holds every agent's model literal, a bare name
74
+ with no matching alias now fails the build (PKU146) naming the aliases that do
75
+ exist, rather than reaching a provider as an unknown model.
76
+
77
+ Aliases resolve for every modality, not just agents: image, speech,
78
+ transcription, embedding and reranking all reach a provider through the same
79
+ point in the Vercel runner.
80
+
81
+ - b930dca: Remove the `secretBroker` escape hatch and scope addon secrets and credentials
82
+
83
+ `secretBroker` let three named console functions receive the real `SecretService`,
84
+ against the rule that a function never sees one. It is gone: the inspector allowlist,
85
+ the `FunctionRuntimeMeta` flag, the runner branches, and the `WiredSecretBrokerServices`
86
+ type. Console secret administration moved into the console addon, where a
87
+ `SecretAdminService` holds the `SecretService` and the functions hold none.
88
+
89
+ Addons are now scoped rather than trusted. The CLI emits each package's declared secret
90
+ keys, and the host wraps the `SecretService` in a `ScopedSecretService` and the
91
+ `CredentialService` in a new `ScopedCredentialService` before the addon's service factory
92
+ runs — so an addon reads only what it declared, cannot write secrets, and cannot enumerate
93
+ the app's users. `wireAddon({ globalSecrets, globalCredentials })` waives this, taking the
94
+ reason as its value; only the consuming app can grant it, and the deploy manifest reports
95
+ every grant under `unscopedSecretAddons` / `unscopedCredentialAddons`.
96
+
97
+ - 8978fbd: feat(workflow): let an approval gate declare who may answer it
98
+
99
+ `workflow.approval()` gains `approvers` (`'any' | 'owner' | 'not-initiator'`)
100
+ and `approverScope`, so a gate can require four-eyes sign-off, restrict itself
101
+ to the run's initiator, or require the decider to hold a named scope.
102
+
103
+ Both are enforced when the workflow replays the gate — the same place, and for
104
+ the same reason, the decision payload is validated: the policy is a value on
105
+ the workflow, and a decision can be recorded before the run has ever reached
106
+ the gate. A decision that fails the policy is discarded and the gate stays
107
+ closed. Where the run has already published its policy, the check also runs at
108
+ submission time so the caller gets a 403 rather than silence.
109
+
110
+ An answer is now recorded where it can be answered for later. The settled
111
+ decision carries `decidedBy` and `decidedAt` in its `ApprovalOutcome`, so who
112
+ signed reaches `workflowStep.result` and `workflowStepHistory` rather than
113
+ living only in mutable run state. Every answer — accepted, refused at the door,
114
+ or cleared on replay — is also written to the audit sink as
115
+ `workflow.approval.decided`, which outlives the run: `deleteRun` cascades to
116
+ steps and history, and a refused attempt never reaches a step at all. Projects
117
+ with no audit service wired are unaffected.
118
+
119
+ **This loosens the default.** `approveStep` previously refused anyone but the
120
+ run's initiator, unconditionally. A gate that declares no `approvers` now
121
+ accepts a decision from anyone the approve entrypoint admits — restore the old
122
+ behaviour per-gate with `approvers: 'owner'`, or gate the approve route with
123
+ `auth`/`permissions`. Ownership still governs _reads_ of a run unchanged.
124
+
125
+ - Updated dependencies [063f43a]
126
+ - Updated dependencies [ce66bf8]
127
+ - Updated dependencies [d0307a8]
128
+ - Updated dependencies [ce66bf8]
129
+ - Updated dependencies [3ad2131]
130
+ - Updated dependencies [b930dca]
131
+ - Updated dependencies [b95e77d]
132
+ - Updated dependencies [fd9d834]
133
+ - Updated dependencies [8978fbd]
134
+ - @pikku/core@0.12.82
135
+
136
+ ## 0.12.57
137
+
138
+ ### Patch Changes
139
+
140
+ - e110c55: Wire `pikkuAIScorer` / `pikkuAIJudge` through the inspector and codegen, and let an agent name the scorers that grade it.
141
+
142
+ The inspector reads a scorer's lane off which constructor was called rather than
143
+ off a field, so the two lanes cannot disagree with the code that produced them,
144
+ and refuses a scorer with no name or description — the meta is the only thing
145
+ that names it at runtime. An agent naming a scorer that was never declared is a
146
+ build error (`PKU155`) rather than an agent that quietly grades nothing forever.
147
+
148
+ Codegen emits a `ScorerName` union, so `scorers` on an agent is checked against
149
+ the scorers the project actually declares, plus the scorer wirings and meta.
150
+ `pikku validate` now also flags a scorer declared outside a `*.scorer.ts` file,
151
+ for the same reason scenarios have to live in files named for them: a rubric
152
+ buried in an agent definition is one nobody reviews as a rubric.
153
+
154
+ - e110c55: Add `scenario.expectScore` — grade a finished agent run with a declared scorer and assert on it.
155
+
156
+ An agent's answer cannot be matched against a fixed string, so a scenario grades
157
+ it instead. `expectScore(step, runId, scorer, { atLeast, atMost, reference })`
158
+ runs one declared scorer against the run the scenario just triggered and fails
159
+ with the reason the judge gave. The default bound is `atLeast: 0.5`, so an
160
+ unqualified assertion still fails a run graded zero.
161
+
162
+ Grading goes over the new `pikkuScenarioGradeRun` instrumentation RPC, which the
163
+ dev server registers alongside the coverage and stub RPCs — so it exists only in
164
+ processes that should have it, and never in a deployed bundle. It grades from
165
+ the snapshot the runtime already took when the run finished, which is what makes
166
+ a scenario's grade the same measurement production's sampler makes rather than
167
+ an approximation of it: a run's prompt, answer and tool calls are spread across
168
+ a thread's messages, where the boundary of one run is not recoverable.
169
+
170
+ Two things differ deliberately from live scoring. The sample rate is ignored — a
171
+ scorer grading 1% of traffic still grades every scenario run — and the grade is
172
+ returned rather than recorded, so a test's score never lands among the
173
+ production figures. `reference` supplies the answer key a `requiresReference`
174
+ judge grades against, which is the only way such a judge is reachable at all.
175
+
176
+ - Updated dependencies [e110c55]
177
+ - Updated dependencies [e110c55]
178
+ - Updated dependencies [e110c55]
179
+ - Updated dependencies [acc8077]
180
+ - Updated dependencies [905f737]
181
+ - Updated dependencies [3cc6428]
182
+ - Updated dependencies [c524adf]
183
+ - Updated dependencies [e110c55]
184
+ - @pikku/core@0.12.81
185
+
1
186
  ## 0.12.56
2
187
 
3
188
  ### Patch Changes
@@ -217,6 +217,29 @@ function resolveIdentifierToAgentName(identifier, checker) {
217
217
  }
218
218
  return null;
219
219
  }
220
+ /**
221
+ * The scorers an agent asks to be graded by, which are plain names rather than
222
+ * references: a scorer is resolved out of the registry at grading time, not
223
+ * imported by the agent, so nothing here has a declaration to chase.
224
+ */
225
+ function resolveScorerNames(obj, agentName, logger) {
226
+ const property = obj.properties.find((p) => ts.isPropertyAssignment(p) &&
227
+ ts.isIdentifier(p.name) &&
228
+ p.name.text === 'scorers');
229
+ if (!property || !ts.isPropertyAssignment(property))
230
+ return null;
231
+ if (!ts.isArrayLiteralExpression(property.initializer))
232
+ return null;
233
+ const names = [];
234
+ for (const element of property.initializer.elements) {
235
+ if (!ts.isStringLiteral(element)) {
236
+ logger.critical(ErrorCode.INVALID_VALUE, `AI agent '${agentName}' lists a scorer that is not an inline string: \`${element.getText()}\`. A scorer is named, not imported, so the name has to be readable from source.`);
237
+ continue;
238
+ }
239
+ names.push(element.text);
240
+ }
241
+ return names.length > 0 ? names : null;
242
+ }
220
243
  export const addAIAgent = (logger, node, checker, state, options) => {
221
244
  if (!ts.isCallExpression(node)) {
222
245
  return;
@@ -244,6 +267,7 @@ export const addAIAgent = (logger, node, checker, state, options) => {
244
267
  const maxStepsValue = getPropertyValue(obj, 'maxSteps');
245
268
  const temperatureValue = getPropertyValue(obj, 'temperature');
246
269
  const toolChoiceValue = getPropertyValue(obj, 'toolChoice');
270
+ const scorersValue = resolveScorerNames(obj, nameValue || '', logger);
247
271
  const toolsValue = resolveToolReferences(obj, checker, nameValue || '', logger);
248
272
  if (toolsValue) {
249
273
  for (const toolName of toolsValue) {
@@ -389,6 +413,7 @@ export const addAIAgent = (logger, node, checker, state, options) => {
389
413
  ...(toolsValue !== null && { tools: toolsValue }),
390
414
  ...(agentsValue !== null && { agents: agentsValue }),
391
415
  ...(workflowsValue !== null && { workflows: workflowsValue }),
416
+ ...(scorersValue !== null && { scorers: scorersValue }),
392
417
  tags,
393
418
  inputSchema,
394
419
  outputSchema,
@@ -0,0 +1,2 @@
1
+ import type { AddWiring } from '../types.js';
2
+ export declare const addAIScorer: AddWiring;
@@ -0,0 +1,61 @@
1
+ import * as ts from 'typescript';
2
+ import { getPropertyValue } from '../utils/get-property-value.js';
3
+ import { extractFunctionName } from '../utils/extract-function-name.js';
4
+ import { ErrorCode } from '../error-codes.js';
5
+ /**
6
+ * `pikkuAIScorer` grades in code and `pikkuAIJudge` grades with a model, which
7
+ * is the whole difference between the two lanes — so the lane is read off which
8
+ * constructor was called rather than from a field an author could contradict.
9
+ */
10
+ const LANES = {
11
+ pikkuAIScorer: 'fast',
12
+ pikkuAIJudge: 'slow',
13
+ };
14
+ export const addAIScorer = (logger, node, checker, state) => {
15
+ if (!ts.isCallExpression(node))
16
+ return;
17
+ const expression = node.expression;
18
+ if (!ts.isIdentifier(expression))
19
+ return;
20
+ const lane = LANES[expression.text];
21
+ if (!lane)
22
+ return;
23
+ const firstArg = node.arguments[0];
24
+ if (!firstArg || !ts.isObjectLiteralExpression(firstArg))
25
+ return;
26
+ const obj = firstArg;
27
+ const { exportedName } = extractFunctionName(node, checker, state.rootDir);
28
+ const nameValue = getPropertyValue(obj, 'name');
29
+ if (!nameValue) {
30
+ logger.critical(ErrorCode.MISSING_NAME, "AI scorer is missing the required 'name' property.");
31
+ return;
32
+ }
33
+ const description = getPropertyValue(obj, 'description');
34
+ if (!description) {
35
+ logger.critical(ErrorCode.MISSING_DESCRIPTION, `AI scorer '${nameValue}' is missing the required 'description' property.`);
36
+ return;
37
+ }
38
+ const sampleRateValue = getPropertyValue(obj, 'sampleRate');
39
+ if (sampleRateValue !== null &&
40
+ (sampleRateValue < 0 || sampleRateValue > 1)) {
41
+ logger.critical(ErrorCode.INVALID_VALUE, `AI scorer '${nameValue}' has a sampleRate of ${sampleRateValue} — it is the fraction of live runs to grade, so it must be between 0 and 1.`);
42
+ return;
43
+ }
44
+ const requiresReference = getPropertyValue(obj, 'requiresReference') ?? false;
45
+ const scorerKey = exportedName || nameValue;
46
+ if (exportedName) {
47
+ state.scorers.files.set(scorerKey, {
48
+ path: node.getSourceFile().fileName,
49
+ exportedName,
50
+ });
51
+ }
52
+ state.scorers.scorersMeta[scorerKey] = {
53
+ name: nameValue,
54
+ description,
55
+ lane,
56
+ sampleRate: sampleRateValue ?? 1,
57
+ requiresReference,
58
+ sourceFile: node.getSourceFile().fileName,
59
+ exportedName: exportedName || undefined,
60
+ };
61
+ };
@@ -53,6 +53,10 @@ export function addWireAddon(node, state, logger) {
53
53
  let secretOverrides;
54
54
  let variableOverrides;
55
55
  let credentialOverrides;
56
+ let secretGrants;
57
+ let credentialGrants;
58
+ let globalSecrets;
59
+ let globalCredentials;
56
60
  for (const prop of firstArg.properties) {
57
61
  if (!ts.isPropertyAssignment(prop) || !ts.isIdentifier(prop.name))
58
62
  continue;
@@ -94,6 +98,24 @@ export function addWireAddon(node, state, logger) {
94
98
  ts.isObjectLiteralExpression(prop.initializer)) {
95
99
  credentialOverrides = parseStringRecord(prop.initializer);
96
100
  }
101
+ else if (key === 'secretGrants') {
102
+ secretGrants = parseStringArray(prop.initializer);
103
+ }
104
+ else if (key === 'credentialGrants') {
105
+ credentialGrants = parseStringArray(prop.initializer);
106
+ }
107
+ else if (key === 'globalSecrets') {
108
+ // The grant is real at runtime whatever the reason evaluates to, so a
109
+ // non-literal is recorded as its source text rather than dropped.
110
+ globalSecrets = ts.isStringLiteral(prop.initializer)
111
+ ? prop.initializer.text
112
+ : prop.initializer.getText();
113
+ }
114
+ else if (key === 'globalCredentials') {
115
+ globalCredentials = ts.isStringLiteral(prop.initializer)
116
+ ? prop.initializer.text
117
+ : prop.initializer.getText();
118
+ }
97
119
  }
98
120
  if (!name || !pkg)
99
121
  return;
@@ -108,6 +130,10 @@ export function addWireAddon(node, state, logger) {
108
130
  secretOverrides,
109
131
  variableOverrides,
110
132
  credentialOverrides,
133
+ secretGrants,
134
+ credentialGrants,
135
+ globalSecrets,
136
+ globalCredentials,
111
137
  });
112
138
  state.rpc.usedAddons.add(name);
113
139
  state.rpc.wireAddonFiles.add(node.getSourceFile().fileName);
@@ -13,8 +13,13 @@
13
13
  * `pikku dev` registers the implementations itself. Ignoring by name (rather
14
14
  * than deleting the scaffold and requiring every project to regenerate) is what
15
15
  * keeps an existing project's checked-in `scenarios.gen.ts` from deploying.
16
+ *
17
+ * `pikkuScenarioGradeRun` was never scaffolded — it arrived after the split —
18
+ * but it belongs here for the same reason: grading a run on demand, ignoring the
19
+ * sample rate that governs live traffic, is a thing you do to a development
20
+ * server, and the name is reserved so an application cannot claim it.
16
21
  */
17
- export declare const SCENARIO_INSTRUMENTATION_FUNCTIONS: readonly ["pikkuScenarioTakeLiveCoverage", "pikkuScenarioResetLiveCoverage", "pikkuScenarioResetStubs", "pikkuScenarioGetStubCalls"];
22
+ export declare const SCENARIO_INSTRUMENTATION_FUNCTIONS: readonly ["pikkuScenarioTakeLiveCoverage", "pikkuScenarioResetLiveCoverage", "pikkuScenarioResetStubs", "pikkuScenarioGetStubCalls", "pikkuScenarioGradeRun"];
18
23
  export type ScenarioInstrumentationFunction = (typeof SCENARIO_INSTRUMENTATION_FUNCTIONS)[number];
19
24
  /**
20
25
  * True for a scenario instrumentation function, by name. Versioned ids
@@ -13,12 +13,18 @@
13
13
  * `pikku dev` registers the implementations itself. Ignoring by name (rather
14
14
  * than deleting the scaffold and requiring every project to regenerate) is what
15
15
  * keeps an existing project's checked-in `scenarios.gen.ts` from deploying.
16
+ *
17
+ * `pikkuScenarioGradeRun` was never scaffolded — it arrived after the split —
18
+ * but it belongs here for the same reason: grading a run on demand, ignoring the
19
+ * sample rate that governs live traffic, is a thing you do to a development
20
+ * server, and the name is reserved so an application cannot claim it.
16
21
  */
17
22
  export const SCENARIO_INSTRUMENTATION_FUNCTIONS = [
18
23
  'pikkuScenarioTakeLiveCoverage',
19
24
  'pikkuScenarioResetLiveCoverage',
20
25
  'pikkuScenarioResetStubs',
21
26
  'pikkuScenarioGetStubCalls',
27
+ 'pikkuScenarioGradeRun',
22
28
  ];
23
29
  const names = new Set(SCENARIO_INSTRUMENTATION_FUNCTIONS);
24
30
  /**
@@ -62,12 +62,14 @@ export declare enum ErrorCode {
62
62
  AGENT_TOOL_UNKNOWN_NAMESPACE = "PKU152",
63
63
  AGENT_TOOL_NOT_FOUND = "PKU153",
64
64
  AGENT_TOOL_MISSING_DESCRIPTION = "PKU154",
65
+ AGENT_SCORER_NOT_FOUND = "PKU155",
65
66
  SCHEMA_AND_WIRING_COLOCATED = "PKU490",
66
67
  SERVICES_NOT_DESTRUCTURED = "PKU410",
67
68
  WIRES_NOT_DESTRUCTURED = "PKU411",
68
69
  FUNCTION_DYNAMIC_IMPORT = "PKU498",
69
70
  DUPLICATE_CORE_VERSION = "PKU717",
70
71
  CORE_VERSION_SKEW = "PKU718",
72
+ SPLIT_TYPE_IDENTITY = "PKU719",
71
73
  PII_IN_OUTPUT = "PKU910",
72
74
  ADDON_WIRING_NOT_ALLOWED = "PKU920",
73
75
  ADDON_CONTRACT_HANDLERS_NOT_ALLOWED = "PKU921",
@@ -79,6 +79,8 @@ export var ErrorCode;
79
79
  ErrorCode["AGENT_TOOL_UNKNOWN_NAMESPACE"] = "PKU152";
80
80
  ErrorCode["AGENT_TOOL_NOT_FOUND"] = "PKU153";
81
81
  ErrorCode["AGENT_TOOL_MISSING_DESCRIPTION"] = "PKU154";
82
+ // Agent scorer reference errors
83
+ ErrorCode["AGENT_SCORER_NOT_FOUND"] = "PKU155";
82
84
  // File structure errors
83
85
  ErrorCode["SCHEMA_AND_WIRING_COLOCATED"] = "PKU490";
84
86
  // Optimization diagnostics
@@ -88,6 +90,7 @@ export var ErrorCode;
88
90
  // Dependency integrity errors
89
91
  ErrorCode["DUPLICATE_CORE_VERSION"] = "PKU717";
90
92
  ErrorCode["CORE_VERSION_SKEW"] = "PKU718";
93
+ ErrorCode["SPLIT_TYPE_IDENTITY"] = "PKU719";
91
94
  // Data classification errors
92
95
  ErrorCode["PII_IN_OUTPUT"] = "PKU910";
93
96
  // Addon authoring errors
package/dist/inspector.js CHANGED
@@ -6,7 +6,7 @@ import { TypesMap } from './types-map.js';
6
6
  import { getFilesAndMethods } from './utils/get-files-and-methods.js';
7
7
  import { findCommonAncestor } from './utils/find-root-dir.js';
8
8
  import { createNestedProjectFilter } from './utils/nested-project-filter.js';
9
- import { aggregateRequiredServices, stampAuthHandlerServices, validateAgentModels, validateAgentToolReferences, validateSecretOverrides, validateVariableOverrides, validateCredentialOverrides, validateRemoteAddonDependencies, validateRemoteAddonAuth, validateScopeReferences, validateSystemRoleScopes, validatePersonaRoles, computeResolvedIOTypes, computeMiddlewareGroupsMeta, computePermissionsGroupsMeta, computeRequiredSchemas, computeSecretBrokers, validateNoSecretAliasServices, validateSecretUsage, computeDiagnostics, validateSchemaReferences, validateSchemaWiringSeparation, validateScenarioServices, validateScenarioSteps, validateWorkflowGraphAddons, } from './utils/post-process.js';
9
+ import { aggregateRequiredServices, stampAuthHandlerServices, validateAgentModels, validateAgentToolReferences, validateAgentScorerReferences, validateSecretOverrides, validateVariableOverrides, validateCredentialOverrides, validateRemoteAddonDependencies, validateRemoteAddonAuth, validateScopeReferences, validateSystemRoleScopes, validatePersonaRoles, computeResolvedIOTypes, computeMiddlewareGroupsMeta, computePermissionsGroupsMeta, computeRequiredSchemas, validateNoSecretAliasServices, validateSecretUsage, computeDiagnostics, validateSchemaReferences, validateSchemaWiringSeparation, validateScenarioServices, validateScenarioSteps, validateWorkflowGraphAddons, } from './utils/post-process.js';
10
10
  import { validateExposedFunctionsGated } from './utils/validate-exposed-functions-gated.js';
11
11
  import { validateTagsResolveToMiddleware } from './utils/validate-tags-resolve-to-middleware.js';
12
12
  import { annotateHttpRouteAuth } from './utils/annotate-http-route-auth.js';
@@ -116,6 +116,10 @@ export function getInitialInspectorState(rootDir) {
116
116
  agentsMeta: {},
117
117
  files: new Map(),
118
118
  },
119
+ scorers: {
120
+ scorersMeta: {},
121
+ files: new Map(),
122
+ },
119
123
  cli: {
120
124
  meta: {
121
125
  programs: {},
@@ -366,7 +370,6 @@ export const inspect = async (logger, routeFiles, options = {}) => {
366
370
  computeResolvedIOTypes(state);
367
371
  computeMiddlewareGroupsMeta(state);
368
372
  computePermissionsGroupsMeta(state);
369
- computeSecretBrokers(state);
370
373
  validateNoSecretAliasServices(logger, checker, state);
371
374
  validateSecretUsage(logger, state);
372
375
  computeDiagnostics(state);
@@ -384,8 +387,9 @@ export const inspect = async (logger, routeFiles, options = {}) => {
384
387
  if (options.openAPI) {
385
388
  state.openAPISpec = await generateOpenAPISpec(logger, state.functions.meta, state.http.meta, state.schemas, options.openAPI.additionalInfo, pikkuState(null, 'misc', 'errors'));
386
389
  }
387
- validateAgentModels(logger, state);
390
+ validateAgentModels(logger, state, options.modelAliases);
388
391
  validateAgentToolReferences(logger, state, options);
392
+ validateAgentScorerReferences(logger, state);
389
393
  validateSecretOverrides(logger, state);
390
394
  validateVariableOverrides(logger, state);
391
395
  validateCredentialOverrides(logger, state);
package/dist/types.d.ts CHANGED
@@ -9,6 +9,7 @@ import type { QueueWorkersMeta } from '@pikku/core/queue';
9
9
  import type { WorkflowsMeta } from '@pikku/core/workflow';
10
10
  import type { MCPResourceMeta, MCPToolMeta, MCPPromptMeta } from '@pikku/core/mcp';
11
11
  import type { AIAgentMeta } from '@pikku/core/ai-agent';
12
+ import type { ScorerMeta } from '@pikku/core/ai-scorer';
12
13
  import type { CLIMeta } from '@pikku/core/cli';
13
14
  import type { CLICommandMeta } from '@pikku/core/cli';
14
15
  import type { NodesMeta } from '@pikku/core/node';
@@ -229,6 +230,8 @@ export type InspectorOptions = Partial<{
229
230
  * tool's own name, so this is a quality gate rather than a correctness one.
230
231
  */
231
232
  strictMeta: boolean;
233
+ /** The `models` table from pikku.config.json, alias -> `provider/model`. */
234
+ modelAliases: Record<string, string>;
232
235
  sourceFile: ts.SourceFile;
233
236
  /**
234
237
  * The project's tsconfig, read for its path mappings only. The inspector's
@@ -518,6 +521,20 @@ export interface InspectorState {
518
521
  secretOverrides?: Record<string, string>;
519
522
  variableOverrides?: Record<string, string>;
520
523
  credentialOverrides?: Record<string, string>;
524
+ /** Secrets the app lends this instance, named as the addon reads them. */
525
+ secretGrants?: string[];
526
+ /** Credentials the app lends this instance, named as the addon reads them. */
527
+ credentialGrants?: string[];
528
+ /**
529
+ * The app's stated reason for handing this instance the whole
530
+ * `SecretService` instead of one scoped to its declared secrets.
531
+ */
532
+ globalSecrets?: string;
533
+ /**
534
+ * The app's stated reason for handing this instance the whole
535
+ * `CredentialService` instead of one scoped to its declared credentials.
536
+ */
537
+ globalCredentials?: string;
521
538
  }>;
522
539
  wireAddonFiles: Set<string>;
523
540
  };
@@ -534,6 +551,13 @@ export interface InspectorState {
534
551
  exportedName: string;
535
552
  }>;
536
553
  };
554
+ scorers: {
555
+ scorersMeta: ScorerMeta;
556
+ files: Map<string, {
557
+ path: string;
558
+ exportedName: string;
559
+ }>;
560
+ };
537
561
  cli: {
538
562
  meta: CLIMeta;
539
563
  files: Set<string>;
@@ -328,6 +328,14 @@ export function filterInspectorState(state, filters, logger) {
328
328
  agentsMeta: JSON.parse(JSON.stringify(state.agents?.agentsMeta ?? {})),
329
329
  files: new Map(),
330
330
  },
331
+ // Scorers carry through every filter. They are named by the agents that
332
+ // survive it, and a deployment that quietly stopped grading would look
333
+ // exactly like one whose scorers all returned nothing.
334
+ scorers: {
335
+ ...state.scorers,
336
+ scorersMeta: JSON.parse(JSON.stringify(state.scorers?.scorersMeta ?? {})),
337
+ files: new Map(state.scorers?.files ?? []),
338
+ },
331
339
  rpc: {
332
340
  ...state.rpc,
333
341
  internalMeta: { ...state.rpc.internalMeta }, // Clone to avoid mutating original
@@ -65,7 +65,11 @@ export declare function computeRequiredSchemas(state: InspectorState, options: I
65
65
  * `--fail-on-error` without failing a dev server over a function nobody calls.
66
66
  */
67
67
  export declare function validateSchemaReferences(logger: InspectorLogger, state: InspectorState): void;
68
- export declare function validateAgentModels(logger: InspectorLogger, state: InspectorState | Omit<InspectorState, 'typesLookup'>): void;
68
+ /**
69
+ * A model is either concrete (`provider/model`) or an alias, which must appear
70
+ * in the `models` table from pikku.config.json.
71
+ */
72
+ export declare function validateAgentModels(logger: InspectorLogger, state: InspectorState | Omit<InspectorState, 'typesLookup'>, modelAliases?: Record<string, string>): void;
69
73
  /**
70
74
  * Scenarios are pure stories of remote RPCs (same rule as client-side CLI
71
75
  * renderers): the func may only destructure logger/config — everything else
@@ -111,8 +115,6 @@ export declare function validateWorkflowGraphAddons(logger: InspectorLogger, sta
111
115
  * because the pikku state metadata doesn't exist in the CLI context.
112
116
  */
113
117
  export declare function validateSchemaWiringSeparation(logger: InspectorLogger, state: InspectorState): void;
114
- /** Marks the functions that keep the full `SecretService`. */
115
- export declare function computeSecretBrokers(state: InspectorState): void;
116
118
  /**
117
119
  * Refuses a singleton service that is a `SecretService` under another name.
118
120
  *
@@ -156,6 +158,14 @@ export declare function validateScopeReferences(logger: InspectorLogger, state:
156
158
  * a title labels a tool in a UI, it does not tell a model when to reach for it.
157
159
  */
158
160
  export declare function validateAgentToolReferences(logger: InspectorLogger, state: InspectorState | Omit<InspectorState, 'typesLookup'>, options?: InspectorOptions): void;
161
+ /**
162
+ * Validates that every scorer an agent asks to be graded by exists.
163
+ *
164
+ * The runtime warns and skips an unresolvable name rather than failing a run
165
+ * that has already answered the user — which means a typo would otherwise cost
166
+ * nothing visible and simply grade nothing, forever.
167
+ */
168
+ export declare function validateAgentScorerReferences(logger: InspectorLogger, state: InspectorState | Omit<InspectorState, 'typesLookup'>): void;
159
169
  /**
160
170
  * Validates that every scope granted by a system role is declared via
161
171
  * `defineScope`. Runs after all visitors, so declaration order does not matter.