@pikku/core 0.12.98 → 0.12.99

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 (37) hide show
  1. package/CHANGELOG.md +51 -0
  2. package/dist/services/http-personas.d.ts +10 -4
  3. package/dist/services/index.d.ts +1 -0
  4. package/dist/services/index.js +1 -0
  5. package/dist/services/persona-actor-secret.d.ts +38 -0
  6. package/dist/services/persona-actor-secret.js +39 -0
  7. package/dist/services/persona-sign-in.d.ts +11 -1
  8. package/dist/services/persona-sign-in.js +10 -1
  9. package/dist/services/typed-secret-service.js +4 -1
  10. package/dist/wirings/agent-scorer/agent-scorer.d.ts +14 -0
  11. package/dist/wirings/gateway/gateway.types.d.ts +13 -0
  12. package/dist/wirings/persona/index.d.ts +2 -1
  13. package/dist/wirings/persona/index.js +1 -0
  14. package/dist/wirings/secret/secret.types.d.ts +8 -0
  15. package/knowledge/decisions/internals/a-virtual-user-cadence-is-a-row-not-a-timer.md +1 -1
  16. package/knowledge/decisions/internals/a-virtual-user-run-is-not-a-workflow-but-it-needs-a-trigger.md +65 -0
  17. package/knowledge/decisions/internals/index.md +1 -1
  18. package/knowledge/decisions/security/actor-sign-in-only-works-for-actor-flagged-users.md +19 -15
  19. package/knowledge/decisions/security/an-actor-credential-is-derived-per-persona.md +41 -0
  20. package/knowledge/decisions/security/index.md +2 -1
  21. package/package.json +4 -4
  22. package/src/public-surface.json +12 -0
  23. package/src/services/http-personas-converse.test.ts +3 -3
  24. package/src/services/http-personas.test.ts +13 -5
  25. package/src/services/http-personas.ts +10 -3
  26. package/src/services/index.ts +8 -0
  27. package/src/services/persona-actor-secret.test.ts +68 -0
  28. package/src/services/persona-actor-secret.ts +70 -0
  29. package/src/services/persona-sign-in.ts +20 -2
  30. package/src/services/typed-secret-service.test.ts +26 -1
  31. package/src/services/typed-secret-service.ts +4 -1
  32. package/src/wirings/agent-scorer/agent-scorer.ts +14 -0
  33. package/src/wirings/gateway/gateway.types.ts +20 -1
  34. package/src/wirings/persona/index.ts +9 -0
  35. package/src/wirings/secret/secret.types.ts +8 -0
  36. package/tsconfig.tsbuildinfo +1 -1
  37. package/knowledge/decisions/internals/a-virtual-user-run-is-not-a-workflow-and-not-a-queued-job.md +0 -53
package/CHANGELOG.md CHANGED
@@ -1,3 +1,54 @@
1
+ ## 0.12.99
2
+
3
+ ### Patch Changes
4
+
5
+ - ee9da9e: Reading an optional secret that is not set no longer makes `hasSecret` report it as set. `TypedSecretService` caches `undefined` to remember the absence, and the cache probe read that as a value.
6
+ - 7a15c9c: An actor credential is one persona's, not everyone's
7
+
8
+ `SCENARIO_ACTOR_SECRET` was a skeleton key. Anyone holding it could post any
9
+ `actor: true` address to `/auth/sign-in/actor` and get that persona's session —
10
+ including the `admin` persona, which provisioning grants real admin. The browser
11
+ switcher held it too, baked into the dev bundle as `VITE_SCENARIO_ACTOR_SECRET`,
12
+ so "the reviewer can sign in as each kind of user" and "the reviewer's bundle is
13
+ entitled to every persona" were the same fact.
14
+
15
+ It is now a root that credentials derive from, never one that is presented:
16
+
17
+ ```ts
18
+ deriveActorSecret(root, email) // HKDF-expanded HMAC-SHA256 over the address
19
+ ```
20
+
21
+ The endpoint re-derives the expected value for whichever address is signing in
22
+ and compares, so nothing is stored or looked up, a credential minted for one
23
+ persona is refused for every other, and rotating the root invalidates all of
24
+ them at once. The root itself is no longer a valid credential, and a root under
25
+ 32 characters refuses the endpoint rather than deriving weak credentials from
26
+ it — the server log says why, the client is not told.
27
+
28
+ What that buys, in the places that used to need the whole key:
29
+
30
+ - **`pikku dev`** mints one credential per declared persona into
31
+ `VITE_DEV_ACTOR_SECRETS` and no longer writes `VITE_SCENARIO_ACTOR_SECRET` at
32
+ all. The root stays on the server.
33
+ - **`pikku persona secret <id>`** mints them for anything else, and a run given
34
+ `PIKKU_PERSONA_SECRETS=id=secret,…` can sign in as those personas and no
35
+ others — asking for one outside the list throws naming the persona instead of
36
+ falling back to the root.
37
+
38
+ `useDevActors()` and `<DevActorSwitcher />` take `secrets` (one per address)
39
+ where they took `secret`, and an actor with no credential is no longer offered
40
+ rather than rendering a row that 401s. `HttpPersonasConfig.secret` and the
41
+ Playwright provider's `secret` additionally accept a resolver, which is how a
42
+ partially-credentialled run is expressed.
43
+
44
+ - ee9da9e: the surface gate measures the surface it actually ships
45
+
46
+ The doc-quality gate went in with ceilings of 112, 823 and 10 beside a surface
47
+ that measured 160, 1210 and 15, so it never passed on any build. Re-baselined to
48
+ the real measurements, and the key-documentation floor earned its way from 76%
49
+ to 79% by documenting what a caller has to put in `defineSecret`, the gateway
50
+ message shapes, and the scorer and judge configs.
51
+
1
52
  ## 0.12.98
2
53
 
3
54
  ### Patch Changes
@@ -1,6 +1,6 @@
1
1
  import type { ScenarioPersona, ResolvedPersona, ScenarioPersonas, ScenarioInvokeOptions, ScenarioHttpResponse } from './personas-service.js';
2
2
  import type { ConverseOptions, ActorFlowVerdict } from '../wirings/actor-flow/actor-flow.types.js';
3
- import { type OperatorSignInOptions } from './persona-sign-in.js';
3
+ import { type ActorSecretResolver, type OperatorSignInOptions } from './persona-sign-in.js';
4
4
  export interface HttpPersonasConfig {
5
5
  /**
6
6
  * Base API URL of the target app, INCLUDING the HTTP prefix — e.g.
@@ -10,13 +10,19 @@ export interface HttpPersonasConfig {
10
10
  */
11
11
  apiUrl: string;
12
12
  /**
13
- * The impersonation secret. Sign-in only ever works for user rows flagged
14
- * `actor: true` knowing the secret never impersonates real users.
13
+ * The ROOT actor secret, from which each persona's own credential is derived
14
+ * and bound to their address. Sign-in only ever works for user rows flagged
15
+ * `actor: true`, and a derived credential only ever works for the one address
16
+ * it was derived for.
17
+ *
18
+ * Pass an {@link ActorSecretResolver} instead to drive personas whose
19
+ * credentials were minted elsewhere — a caller entitled to one persona then
20
+ * never holds the root.
15
21
  *
16
22
  * The local-development credential. A deployed stage has none, and passes
17
23
  * {@link HttpPersonasConfig.operator} instead.
18
24
  */
19
- secret?: string;
25
+ secret?: string | ActorSecretResolver;
20
26
  /**
21
27
  * Fabric operator credentials, for signing personas into a DEPLOYED stage.
22
28
  *
@@ -23,6 +23,7 @@ export type { JWTService } from './jwt-service.js';
23
23
  export type { EmailService, SendEmailInput, SendEmailResult, SendHTMLEmailInput, SendTemplateEmailInput, SendTextEmailInput, } from './email-service.js';
24
24
  export { renderEmail, type EmailAssets, type EmailTemplateAssets, type EmailTemplateHashes, type RenderEmailRequest, type RenderedEmailResult, } from './email-template.js';
25
25
  export { DEFAULT_WEBHOOK_RETRIES, PIKKU_OUTGOING_WEBHOOK_QUEUE_NAME, WebhookService, type SendWebhookInput, type SendWebhookResult, type WebhookAttemptResult, type WebhookDeliveryRecord, type WebhookDeliveryWithAttempts, type WebhookJobData, type WebhookServiceConfig, } from './webhook-service.js';
26
+ export { ACTOR_ROOT_SECRET_MIN_LENGTH, ACTOR_SECRET_INFO, ACTOR_SECRET_NAME, actorSecretSubject, deriveActorSecret, verifyActorSecret, } from './persona-actor-secret.js';
26
27
  export type { Logger } from './logger.js';
27
28
  export type { SecretService, SecretValues } from './secret-service.js';
28
29
  export type { VariablesService } from './variables-service.js';
@@ -19,6 +19,7 @@ export { LocalGatewayService } from './local-gateway-service.js';
19
19
  export { FileScenarioRunStore, scenarioArtifactContentType, scenarioRunSummary, } from './file-scenario-run-store.js';
20
20
  export { renderEmail, } from './email-template.js';
21
21
  export { DEFAULT_WEBHOOK_RETRIES, PIKKU_OUTGOING_WEBHOOK_QUEUE_NAME, WebhookService, } from './webhook-service.js';
22
+ export { ACTOR_ROOT_SECRET_MIN_LENGTH, ACTOR_SECRET_INFO, ACTOR_SECRET_NAME, actorSecretSubject, deriveActorSecret, verifyActorSecret, } from './persona-actor-secret.js';
22
23
  export { SchedulerService } from './scheduler-service.js';
23
24
  export { TypedCredentialService } from './typed-credential-service.js';
24
25
  export { NoopAuditService, createInvocationAudit } from './audit-service.js';
@@ -0,0 +1,38 @@
1
+ /** The name the root secret is held under, used only in error messages. */
2
+ export declare const ACTOR_SECRET_NAME = "SCENARIO_ACTOR_SECRET";
3
+ /**
4
+ * Namespaces the derivation so the same root secret used for anything else
5
+ * produces different values. See knowledge/crypto.md.
6
+ */
7
+ export declare const ACTOR_SECRET_INFO = "pikku:actor-sign-in";
8
+ /** The root must be strong: every persona's credential is derived from it. */
9
+ export declare const ACTOR_ROOT_SECRET_MIN_LENGTH = 32;
10
+ /**
11
+ * What the derivation is bound to. Lowercased because the sign-in endpoint
12
+ * looks the user up by lowercased address, and a credential that verified
13
+ * against a different string than the row it opens is a credential for nothing.
14
+ */
15
+ export declare const actorSecretSubject: (email: string) => string;
16
+ /**
17
+ * One persona's actor credential: `HMAC-SHA256(root, email)`, base64url.
18
+ *
19
+ * The root secret is not itself a valid credential and never travels: what a
20
+ * scenario run, a CI job or a virtual user is handed is the derived value for
21
+ * the one address it is entitled to. Presenting it for any other address fails,
22
+ * so a leaked credential is worth exactly one synthetic account rather than the
23
+ * whole actor population.
24
+ *
25
+ * Deterministic, so nothing is stored and nothing is provisioned — the target
26
+ * re-derives the expected value from the address being signed in as. Rotating
27
+ * the root invalidates every derived credential at once, which is the property
28
+ * a per-persona secret table would have to implement by hand.
29
+ */
30
+ export declare const deriveActorSecret: (rootSecret: string, email: string) => Promise<string>;
31
+ /**
32
+ * Whether `presented` is the credential for `email` under `rootSecret`.
33
+ *
34
+ * False — never throws — for a malformed, truncated or mismatched value, and
35
+ * the comparison is WebCrypto's own HMAC verify, so it does not exit early on
36
+ * the first differing byte.
37
+ */
38
+ export declare const verifyActorSecret: (rootSecret: string, email: string, presented: string) => Promise<boolean>;
@@ -0,0 +1,39 @@
1
+ import { MIN_KEY_MATERIAL_LENGTH, signWithKeyMaterial, verifyWithKeyMaterial, } from '../crypto-utils.js';
2
+ /** The name the root secret is held under, used only in error messages. */
3
+ export const ACTOR_SECRET_NAME = 'SCENARIO_ACTOR_SECRET';
4
+ /**
5
+ * Namespaces the derivation so the same root secret used for anything else
6
+ * produces different values. See knowledge/crypto.md.
7
+ */
8
+ export const ACTOR_SECRET_INFO = 'pikku:actor-sign-in';
9
+ /** The root must be strong: every persona's credential is derived from it. */
10
+ export const ACTOR_ROOT_SECRET_MIN_LENGTH = MIN_KEY_MATERIAL_LENGTH;
11
+ /**
12
+ * What the derivation is bound to. Lowercased because the sign-in endpoint
13
+ * looks the user up by lowercased address, and a credential that verified
14
+ * against a different string than the row it opens is a credential for nothing.
15
+ */
16
+ export const actorSecretSubject = (email) => email.trim().toLowerCase();
17
+ /**
18
+ * One persona's actor credential: `HMAC-SHA256(root, email)`, base64url.
19
+ *
20
+ * The root secret is not itself a valid credential and never travels: what a
21
+ * scenario run, a CI job or a virtual user is handed is the derived value for
22
+ * the one address it is entitled to. Presenting it for any other address fails,
23
+ * so a leaked credential is worth exactly one synthetic account rather than the
24
+ * whole actor population.
25
+ *
26
+ * Deterministic, so nothing is stored and nothing is provisioned — the target
27
+ * re-derives the expected value from the address being signed in as. Rotating
28
+ * the root invalidates every derived credential at once, which is the property
29
+ * a per-persona secret table would have to implement by hand.
30
+ */
31
+ export const deriveActorSecret = async (rootSecret, email) => signWithKeyMaterial(ACTOR_SECRET_NAME, rootSecret, ACTOR_SECRET_INFO, actorSecretSubject(email));
32
+ /**
33
+ * Whether `presented` is the credential for `email` under `rootSecret`.
34
+ *
35
+ * False — never throws — for a malformed, truncated or mismatched value, and
36
+ * the comparison is WebCrypto's own HMAC verify, so it does not exit early on
37
+ * the first differing byte.
38
+ */
39
+ export const verifyActorSecret = async (rootSecret, email, presented) => verifyWithKeyMaterial(ACTOR_SECRET_NAME, rootSecret, ACTOR_SECRET_INFO, actorSecretSubject(email), presented);
@@ -26,6 +26,11 @@ export interface PersonaSignIn {
26
26
  /** Headers every request after `login` must carry. */
27
27
  headers(): Record<string, string>;
28
28
  }
29
+ /**
30
+ * Yields the credential for one persona, for a caller that holds that persona's
31
+ * derived secret and not the root it came from.
32
+ */
33
+ export type ActorSecretResolver = (persona: ResolvedPersona) => string | Promise<string>;
29
34
  /**
30
35
  * Sign a persona in through the Better Auth actor plugin — the local-development
31
36
  * path.
@@ -34,12 +39,17 @@ export interface PersonaSignIn {
34
39
  * for it. Passwordless by design and refused for any row not carrying that flag,
35
40
  * so the secret can never reach a real user's account; the plugin still declines
36
41
  * to serve the endpoint at all outside `pikku dev`.
42
+ *
43
+ * What is presented is the persona's own credential, derived from the root and
44
+ * bound to their address. A run driving many personas holds the root and
45
+ * derives as it goes; a run entitled to one persona is handed that one value
46
+ * through a resolver and can sign in as nobody else.
37
47
  */
38
48
  export declare class ActorSignIn implements PersonaSignIn {
39
49
  private readonly apiUrl;
40
50
  private readonly secret;
41
51
  private readonly signInPath;
42
- constructor(apiUrl: string, secret: string, signInPath: string);
52
+ constructor(apiUrl: string, secret: string | ActorSecretResolver, signInPath: string);
43
53
  login(jar: ScenarioCookieJar, persona: ResolvedPersona): Promise<void>;
44
54
  headers(): Record<string, string>;
45
55
  }
@@ -1,3 +1,4 @@
1
+ import { deriveActorSecret } from './persona-actor-secret.js';
1
2
  /**
2
3
  * The header `resolveImpersonatedSession` reads the target user id from.
3
4
  *
@@ -18,6 +19,11 @@ const failed = async (what, personaId, res) => {
18
19
  * for it. Passwordless by design and refused for any row not carrying that flag,
19
20
  * so the secret can never reach a real user's account; the plugin still declines
20
21
  * to serve the endpoint at all outside `pikku dev`.
22
+ *
23
+ * What is presented is the persona's own credential, derived from the root and
24
+ * bound to their address. A run driving many personas holds the root and
25
+ * derives as it goes; a run entitled to one persona is handed that one value
26
+ * through a resolver and can sign in as nobody else.
21
27
  */
22
28
  export class ActorSignIn {
23
29
  apiUrl;
@@ -29,13 +35,16 @@ export class ActorSignIn {
29
35
  this.signInPath = signInPath;
30
36
  }
31
37
  async login(jar, persona) {
38
+ const secret = typeof this.secret === 'function'
39
+ ? await this.secret(persona)
40
+ : await deriveActorSecret(this.secret, persona.email);
32
41
  const res = await jar.fetch(`${this.apiUrl}${this.signInPath}`, {
33
42
  method: 'POST',
34
43
  headers: { 'content-type': 'application/json' },
35
44
  body: JSON.stringify({
36
45
  email: persona.email,
37
46
  name: persona.name,
38
- secret: this.secret,
47
+ secret,
39
48
  }),
40
49
  });
41
50
  if (!res.ok) {
@@ -21,8 +21,11 @@ export class TypedSecretService {
21
21
  return value;
22
22
  }
23
23
  async hasSecret(key) {
24
+ // `undefined` is cached for an optional secret that resolved absent, so a
25
+ // cache hit means "already looked", not "there is a value". Reporting true
26
+ // for it would let a read of an optional secret assert its own presence.
24
27
  if (this.cache.has(key)) {
25
- return true;
28
+ return this.cache.get(key) !== undefined;
26
29
  }
27
30
  return this.secrets.hasSecret(key);
28
31
  }
@@ -6,7 +6,9 @@ import type { JudgeToolCallDisclosure, PikkuAgentScorer, ScorerInput, ScorerOutp
6
6
  * @example snippet: agentScorer
7
7
  */
8
8
  export declare const pikkuAgentScorer: <Services = any>(config: {
9
+ /** Identifies the scorer in results and in the Console. Unique per project. */
9
10
  name: string;
11
+ /** What this scorer grades, in one line, for whoever reads the score later. */
10
12
  description: string;
11
13
  /** 0..1 fraction of live runs to grade. Defaults to all of them. */
12
14
  sampleRate?: number;
@@ -15,6 +17,10 @@ export declare const pikkuAgentScorer: <Services = any>(config: {
15
17
  * traffic has no answer key, so the runtime never samples it.
16
18
  */
17
19
  requiresReference?: boolean;
20
+ /**
21
+ * The grade itself: read the finished run and return `{ score, reason }`.
22
+ * Runs in-process, so it may use your own services.
23
+ */
18
24
  score: (input: ScorerInput, services: Services) => ScorerOutput | Promise<ScorerOutput>;
19
25
  }) => PikkuAgentScorer<Services>;
20
26
  /**
@@ -28,7 +34,9 @@ export declare const pikkuAgentScorer: <Services = any>(config: {
28
34
  * @example snippet: agentJudge
29
35
  */
30
36
  export declare const pikkuAgentJudge: <Services = any>(config: {
37
+ /** Identifies the judge in results and in the Console. Unique per project. */
31
38
  name: string;
39
+ /** What this judge grades, in one line, for whoever reads the score later. */
32
40
  description: string;
33
41
  /** 0..1 fraction of live runs to grade. Defaults to all of them. */
34
42
  sampleRate?: number;
@@ -37,7 +45,9 @@ export declare const pikkuAgentJudge: <Services = any>(config: {
37
45
  * traffic has no answer key, so the runtime never samples it.
38
46
  */
39
47
  requiresReference?: boolean;
48
+ /** The model that grades, e.g. `'claude-sonnet-4-5'`. Not the model under test. */
40
49
  model: string;
50
+ /** The rubric: what a good answer looks like, phrased as the goal it should meet. */
41
51
  goal: string;
42
52
  /**
43
53
  * How much of the run's trajectory to disclose to the judge. Defaults to
@@ -45,5 +55,9 @@ export declare const pikkuAgentJudge: <Services = any>(config: {
45
55
  * sending a third-party model the rows the tools returned.
46
56
  */
47
57
  toolCalls?: JudgeToolCallDisclosure;
58
+ /**
59
+ * Replaces the generated rubric prompt outright, for framing `goal` cannot
60
+ * express. The `{ score, reason }` response is still forced.
61
+ */
48
62
  prompt?: (input: ScorerInput) => string;
49
63
  }) => PikkuAgentScorer<Services>;
@@ -16,9 +16,13 @@ export interface GatewayAttachment {
16
16
  export interface GatewayInboundMessage {
17
17
  /** Platform-specific: a phone number, a Slack user id, and so on. */
18
18
  senderId: string;
19
+ /** What they said, as plain text, with the provider's markup stripped. */
19
20
  text: string;
21
+ /** The provider's own event, untouched, for anything this shape drops. */
20
22
  raw: unknown;
23
+ /** Files and media that came with the message. */
21
24
  attachments?: GatewayAttachment[];
25
+ /** Anything else the adapter wants to carry through to the wiring. */
22
26
  metadata?: Record<string, unknown>;
23
27
  }
24
28
  /**
@@ -26,8 +30,11 @@ export interface GatewayInboundMessage {
26
30
  * own rich content.
27
31
  */
28
32
  export interface GatewayOutboundMessage {
33
+ /** The reply as plain text. Every provider can render this. */
29
34
  text?: string;
35
+ /** The provider's own rich payload, e.g. Slack blocks. Passed through as-is. */
30
36
  richContent?: Record<string, unknown>;
37
+ /** Files and media to send alongside. */
31
38
  attachments?: GatewayAttachment[];
32
39
  }
33
40
  /**
@@ -35,9 +42,12 @@ export interface GatewayOutboundMessage {
35
42
  * provider expects back, or not.
36
43
  */
37
44
  export type WebhookVerificationResult = {
45
+ /** True when the request really came from the provider. */
38
46
  verified: true;
47
+ /** What to echo back, e.g. Meta's hub.challenge. */
39
48
  response: unknown;
40
49
  } | {
50
+ /** False when the signature or challenge did not check out. */
41
51
  verified: false;
42
52
  };
43
53
  /**
@@ -45,12 +55,15 @@ export type WebhookVerificationResult = {
45
55
  * message, send one back, and open and close the connection.
46
56
  */
47
57
  export interface GatewayAdapter {
58
+ /** Identifies the gateway in wirings and logs, e.g. `'slack'`. */
48
59
  name: string;
49
60
  /** Return null to ignore the event, e.g. a delivery receipt. */
50
61
  parse(data: unknown): GatewayInboundMessage | null;
62
+ /** Deliver a reply back to the sender the message came from. */
51
63
  send(senderId: string, message: GatewayOutboundMessage): Promise<void>;
52
64
  /** Called by GatewayService.start(); must call onMessage per incoming event. */
53
65
  init(onMessage: (data: unknown) => Promise<void>): Promise<void>;
66
+ /** Called by GatewayService.stop(); release the connection init() opened. */
54
67
  close(): Promise<void>;
55
68
  /** Receives the GET query params, or the POST body when called from the POST handler. */
56
69
  verifyWebhook?(data: unknown, request?: PikkuHTTPRequest): WebhookVerificationResult | Promise<WebhookVerificationResult>;
@@ -18,5 +18,6 @@ export type { CorePersona, CorePersonas, PersonaAccountMeta, PersonaDefinitions,
18
18
  * Lambda deploy would load outright.
19
19
  */
20
20
  export { HttpPersona, createHttpPersonas, type HttpPersonasConfig, } from '../../services/http-personas.js';
21
- export { ActorSignIn, OperatorSignIn, establishOperatorSession, IMPERSONATE_USER_ID_HEADER, type PersonaSignIn, type OperatorSignInOptions, type OperatorSessionResult, } from '../../services/persona-sign-in.js';
21
+ export { ActorSignIn, OperatorSignIn, establishOperatorSession, IMPERSONATE_USER_ID_HEADER, type ActorSecretResolver, type PersonaSignIn, type OperatorSignInOptions, type OperatorSessionResult, } from '../../services/persona-sign-in.js';
22
+ export { ACTOR_ROOT_SECRET_MIN_LENGTH, ACTOR_SECRET_INFO, ACTOR_SECRET_NAME, actorSecretSubject, deriveActorSecret, verifyActorSecret, } from '../../services/persona-actor-secret.js';
22
23
  export { postScenarioJson, readScenarioHttpResponse, } from '../../services/personas-service.js';
@@ -15,4 +15,5 @@ export { APP_SCOPE_ROOT, appScopeId, buildAppScopeDefinition, } from './persona-
15
15
  */
16
16
  export { HttpPersona, createHttpPersonas, } from '../../services/http-personas.js';
17
17
  export { ActorSignIn, OperatorSignIn, establishOperatorSession, IMPERSONATE_USER_ID_HEADER, } from '../../services/persona-sign-in.js';
18
+ export { ACTOR_ROOT_SECRET_MIN_LENGTH, ACTOR_SECRET_INFO, ACTOR_SECRET_NAME, actorSecretSubject, deriveActorSecret, verifyActorSecret, } from '../../services/persona-actor-secret.js';
18
19
  export { postScenarioJson, readScenarioHttpResponse, } from '../../services/personas-service.js';
@@ -1,8 +1,16 @@
1
1
  export type CoreSecret<T = unknown> = {
2
+ /** The key code reads it by: `secrets.getSecret('NAME')`. SCREAMING_SNAKE_CASE. */
2
3
  name: string;
4
+ /** How the secret is labelled wherever a person is asked to supply it. */
3
5
  displayName: string;
6
+ /** What this secret is for, shown beside the field someone has to fill in. */
4
7
  description?: string;
8
+ /** The id under the backing store, which is where the value actually lives. */
5
9
  secretId: string;
10
+ /**
11
+ * The shape of the value, as a schema. This is what types `getSecret`'s
12
+ * result — pass the schema itself, not an instance of it.
13
+ */
6
14
  schema: T;
7
15
  /** Required by default: this says absence is a supported state, and `getSecret` resolves `undefined` rather than throwing. */
8
16
  optional?: boolean;
@@ -52,7 +52,7 @@ instances:
52
52
  different one, and every finding it produces is unreproducible.
53
53
  - **A run still `running` after `STALE_RUN_AFTER_MS` is failed and the persona
54
54
  runs again.** This is where the stranded-record cost of
55
- [a virtual user run being neither a workflow nor a queued job](a-virtual-user-run-is-not-a-workflow-and-not-a-queued-job.md)
55
+ [a virtual user run not being a workflow](a-virtual-user-run-is-not-a-workflow-but-it-needs-a-trigger.md)
56
56
  gets paid: without it, one restart mid-run would block that persona's schedule
57
57
  permanently.
58
58
 
@@ -0,0 +1,65 @@
1
+ ---
2
+ type: decision
3
+ title: A virtual user run is not a workflow, but it needs a trigger
4
+ description: runVirtualUser writes its record and dispatches the run onto a queue at one attempt — an exploratory run has nothing to replay, but a deployment that puts each function in its own unit has nothing to fire it either
5
+ tags: virtual-user, storage, deploy
6
+ ---
7
+
8
+ # A virtual user run is not a workflow, but it needs a trigger
9
+
10
+ `runVirtualUser` — the RPC `scaffold.virtualUser` generates — does three things
11
+ in order: writes a `VirtualUserRunStore` record, dispatches
12
+ `executeVirtualUserRun`, and returns the `runId`. The request never waits for
13
+ the run; a run takes minutes and survives neither a rollout nor a proxy timeout.
14
+
15
+ **A workflow** is still the wrong shape, for the reason it always was. Its value
16
+ is that a run can be resumed at the step it died on, and that the same input
17
+ reaches the same step. A virtual user is the opposite by construction — it is an
18
+ LLM deciding what to try next, so no two attempts take the same steps, and there
19
+ is no step to resume _to_. Recording a run as a workflow puts entries in the
20
+ workflow store that can never be replayed, and gives every operator reading that
21
+ store a row that lies about what it is. The seed makes a run _reproducible_ —
22
+ run it again and it explores the same way — which is a different property from
23
+ resumable, and one the record already carries.
24
+
25
+ **A queue was rejected once, on durability, and that was the wrong question.**
26
+ The original reasoning weighed a broker dependency against a retry nobody wants,
27
+ and concluded the in-process dispatch was enough. It is enough in one process.
28
+ It is not a dispatch at all under a deployment that puts each function in its own
29
+ unit: there is no in-process promise to leave running, and `executeVirtualUserRun`
30
+ — sessionless, unexposed, wired to nothing — is not a function any unit can be
31
+ reached at. The RPC resolves to nothing, the rejection is swallowed by the
32
+ `catch` that exists to stop it taking the process down, and the run parks at
33
+ `running` with zero steps and no error anywhere. That is what a fabric stage did.
34
+
35
+ So the queue is not bought for durability. It is bought because **a trigger is
36
+ what makes a function deployable**: `wireQueueWorker` puts `executeVirtualUserRun`
37
+ in the manifest, which gives it a unit and gives the platform somewhere to
38
+ deliver to. The job is dispatched at `attempts: 1`, because a redelivery is a
39
+ second different outing writing into a record that already has an outcome — the
40
+ retry the queue offers is precisely the part that stays unused.
41
+
42
+ A project with no queue service keeps the in-process dispatch. That is not a
43
+ fallback that hides a failure: a project without a broker runs in one process,
44
+ where an unawaited promise is a real dispatch and the only correct one.
45
+
46
+ The record remains the run's only trace, and that is what `VirtualUserRunStore`
47
+ exists for. It is also why `fail()` is a method rather than an absence: a run
48
+ that crashed and a run that found nothing are different answers, and a record
49
+ left at `running` is neither.
50
+
51
+ The cost is smaller than it was but has not gone: **a restart mid-run strands a
52
+ record at `running` with nothing left to finish it**, since nothing retries. A
53
+ run older than its budget window and still `running` is dead, not working — a
54
+ read-side rule. A stranded run is started again, with its seed if the caller
55
+ wants the same exploration.
56
+
57
+ Where that rule is actually applied is
58
+ [the schedule tick](a-virtual-user-cadence-is-a-row-not-a-timer.md), which has
59
+ to: a record stuck at `running` would otherwise block its persona's cadence
60
+ forever.
61
+
62
+ **What this rules out:** dispatching the run through `startWorkflow`; awaiting
63
+ the engine inside the request; retrying a run that failed; storing the operator
64
+ token on the record rather than on the dispatch; and inferring `status` from
65
+ `finishedAt` being unset, which cannot separate a crash from a run still going.
@@ -17,7 +17,7 @@ caller is entitled to assume.
17
17
  - [A secret that fails to decrypt fails the whole read](a-secret-that-fails-to-decrypt-fails-the-whole-read.md) — getSecrets throws naming the key and its key_version rather than omitting the row, because a silent omission surfaces as an unrelated failure much later
18
18
  - [A virtual user decides whether to trust its notes once per turn, by one roll](a-virtual-user-decides-whether-to-trust-memory-once-per-turn.md) — The difference between the stale, newcomer and auditor dispositions is expressed as a single probability rather than as prose in each prompt
19
19
  - [A virtual user cadence is a row, not a timer](a-virtual-user-cadence-is-a-row-not-a-timer.md) — how often a persona runs is stored as a due time per persona and acted on by a tick the project schedules — pikku never starts a timer, and a run never reschedules itself
20
- - [A virtual user run is not a workflow and not a queued job](a-virtual-user-run-is-not-a-workflow-and-not-a-queued-job.md) — runVirtualUser writes its record, dispatches the run without awaiting it, and returns the id because an exploratory run has nothing to replay and the record already carries what a queue would be holding
20
+ - [A virtual user run is not a workflow, but it needs a trigger](a-virtual-user-run-is-not-a-workflow-but-it-needs-a-trigger.md) — runVirtualUser writes its record and dispatches the run onto a queue at one attempt — an exploratory run has nothing to replay, but a deployment that puts each function in its own unit has nothing to fire it either
21
21
  - [A wall-clock threshold is a load test in disguise](a-wall-clock-threshold-is-a-load-test-in-disguise.md) — The KEK derivation test asserted a fixed 50ms budget for work that took 10ms, which went red about one run in five once the suite was large enough to compete for the machine
22
22
  - [A workflow's wire is built from the run record, not from the RPC service](a-workflow-wire-is-built-from-the-run-not-from-the-rpc-service.md) — The RPC service exposes no wire, so every rpcService.wire read was undefined; the run record is the only thing that carries the caller across a step boundary
23
23
  - [An actor conversation starts from a seeded kickoff message](actor-flow-conversations-seed-a-hidden-kickoff-message.md) — The actor's first turn needs a non-empty message list because providers reject an empty prompt; the seed is an instruction and stays out of the transcript
@@ -1,27 +1,31 @@
1
1
  ---
2
2
  type: decision
3
3
  title: Actor sign-in only works for actor-flagged users
4
- description: The scenario actor secret mints sessions for user rows flagged actor and nothing else, so holding it never impersonates a real user
4
+ description: An actor credential mints sessions for user rows flagged actor and nothing else, so holding one never impersonates a real user
5
5
  tags: services
6
6
  ---
7
7
 
8
8
  # Actor sign-in only works for actor-flagged users
9
9
 
10
- `HttpScenarioActorsConfig.secret`
11
- (`packages/core/src/services/http-scenario-actors.ts`) is a shared impersonation
12
- secret: `HttpScenarioActor.login` POSTs `{ email, name, secret }` to
10
+ `HttpPersonasConfig.secret` (`packages/core/src/services/http-personas.ts`) is
11
+ what `ActorSignIn.login` presents: it POSTs `{ email, name, secret }` to
13
12
  `/auth/sign-in/actor` and gets back a session. That looks like a master key, and
14
- it deliberately is not one.
13
+ it deliberately is not one — for two independent reasons.
15
14
 
16
- The Better Auth actor plugin on the other end upserts and signs in only user rows
17
- flagged `actor: true`. Presenting the secret with a real customer's email does not
18
- mint that customer's session — it is refused. The `actor` flag also flows into the
19
- minted session, so audits and analytics can tell scenario traffic from human
20
- traffic after the fact. The blast radius of a leaked actor secret is therefore the
21
- synthetic actor population, not the user table.
15
+ The first is the flag. The Better Auth actor plugin on the other end upserts and
16
+ signs in only user rows flagged `actor: true`. Presenting a credential with a
17
+ real customer's email does not mint that customer's session — it is refused. The
18
+ `actor` flag also flows into the minted session, so audits and analytics can tell
19
+ scenario traffic from human traffic after the fact.
20
+
21
+ The second is that a credential is not shared. What is presented is derived from
22
+ the root `SCENARIO_ACTOR_SECRET` and the address it signs in as — see
23
+ [an actor credential is derived per persona](an-actor-credential-is-derived-per-persona.md) —
24
+ so the blast radius of a leaked credential is one synthetic account, not the
25
+ synthetic actor population.
22
26
 
23
27
  **What this rules out:** widening the sign-in endpoint to accept any email "so
24
- scenarios can test as a real user", and treating the actor secret as equivalent to
25
- a session-signing key. It also rules out dropping the `actor` flag from the minted
26
- session — the audit trail's ability to separate synthetic from real activity
27
- depends on it.
28
+ scenarios can test as a real user", and treating an actor credential as
29
+ equivalent to a session-signing key. It also rules out dropping the `actor` flag
30
+ from the minted session — the audit trail's ability to separate synthetic from
31
+ real activity depends on it.
@@ -0,0 +1,41 @@
1
+ ---
2
+ type: decision
3
+ title: An actor credential is derived per persona
4
+ description: What a caller presents to the actor endpoint is HKDF-derived from the root secret and the address it signs in as, so one credential opens one persona
5
+ tags: services
6
+ ---
7
+
8
+ # An actor credential is derived per persona
9
+
10
+ `SCENARIO_ACTOR_SECRET` is a root, not a password. What a caller presents to
11
+ `/auth/sign-in/actor` is `deriveActorSecret(root, email)`
12
+ (`packages/core/src/services/persona-actor-secret.ts`) — an HKDF-expanded
13
+ HMAC-SHA256 over the lowercased address, on the same key-material primitives
14
+ everything else in core signs with. The endpoint does not store or look anything
15
+ up: it re-derives the expected value for whichever address is being signed in as
16
+ and compares. A credential minted for one persona is refused for every other.
17
+
18
+ The root itself is not accepted as a credential, and a root shorter than 32
19
+ characters refuses the endpoint outright rather than deriving weak credentials
20
+ from it. The server-side warning names the problem; what the client is told does
21
+ not.
22
+
23
+ Derivation rather than a per-persona secrets table because there is then nothing
24
+ to store, provision, or keep in sync — the target already holds the root, and
25
+ rotating it invalidates every credential at once.
26
+
27
+ This is what lets a holder be handed less than everything:
28
+
29
+ - The browser switcher gets `VITE_DEV_ACTOR_SECRETS`, one credential per
30
+ declared persona. The root stays on the dev server, so a bundle can no longer
31
+ hold the thing that is entitled to every persona.
32
+ - A run can be given `PIKKU_PERSONA_SECRETS` (`id=secret,…`, minted with
33
+ `pikku persona secret`) instead of the root, and then it can sign in as those
34
+ personas and no others. Asking for one outside the list throws naming the
35
+ persona rather than falling back to the root.
36
+
37
+ **What this rules out:** accepting the root as a credential at the endpoint,
38
+ putting the root in any client bundle, and comparing a presented credential
39
+ against a stored one. It also rules out per-persona secrets that are generated
40
+ randomly and written down — the derivation is the reason there is nothing to
41
+ provision.
@@ -19,7 +19,8 @@ A rule about who may do what, and which way it fails when it is unsure.
19
19
  - [A workflow run is read and approved by its owner](a-workflow-run-is-read-and-approved-by-its-owner.md) — A run started through a session records that user and only that user may read it or answer its approval gates; a run with no recorded owner has no ownership to enforce
20
20
  - [An actor's missing approval decision defaults to denied](actor-flow-missing-approval-decisions-default-to-denied.md) — Every pending tool call gets an explicit decision; an id the persona LLM omitted is denied, so a dropped field can never read as consent
21
21
  - [Actor sign-in is proven by Set-Cookie, not a non-empty jar](actor-sign-in-is-proven-by-set-cookie-not-a-non-empty-jar.md) — HttpScenarioActor tracks its own signedIn flag and requires the sign-in response itself to set a cookie, because a populated jar proves nothing
22
- - [Actor sign-in only works for actor-flagged users](actor-sign-in-only-works-for-actor-flagged-users.md) — The scenario actor secret mints sessions for user rows flagged actor and nothing else, so holding it never impersonates a real user
22
+ - [Actor sign-in only works for actor-flagged users](actor-sign-in-only-works-for-actor-flagged-users.md) — An actor credential mints sessions for user rows flagged actor and nothing else, so holding one never impersonates a real user
23
+ - [An actor credential is derived per persona](an-actor-credential-is-derived-per-persona.md) — What a caller presents to the actor endpoint is HKDF-derived from the root secret and the address it signs in as, so one credential opens one persona
23
24
  - [Addon auth and tags only tighten, and resolve where the function runs](addon-auth-and-tags-only-tighten.md) — wireAddon auth and tags are applied in runPikkuFunc like scopes, but auth:false is ignored and tags resolve against the consuming app's tag groups rather than the addon package's
24
25
  - [Addon auth and tag gates apply wherever the function runs, including inside the addon](addon-config-gates-apply-only-at-the-namespaced-rpc-boundary.md) — wireAddon's auth and tags moved from the namespaced RPC boundary into runPikkuFunc, so they also apply to direct wirings and to bare intra-addon calls
25
26
  - [Addon scopes are resolved where the function runs](addon-scopes-are-resolved-where-the-function-runs.md) — wireAddon scopes are merged inside runPikkuFunc rather than at namespace resolution, because most wirings reach an addon function without ever resolving a namespace
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@pikku/core",
3
- "version": "0.12.98",
3
+ "version": "0.12.99",
4
4
  "description": "The Pikku runtime — functions, wirings, services, middleware and types",
5
5
  "author": "yasser.fadl@gmail.com",
6
6
  "license": "MIT",
@@ -18,12 +18,12 @@
18
18
  },
19
19
  "sideEffects": [
20
20
  "./dist/errors/errors.js",
21
- "./dist/wirings/rpc/rpc-runner.js",
22
21
  "./dist/wirings/addon/remote-addon-auth.js",
22
+ "./dist/wirings/rpc/rpc-runner.js",
23
+ "./dist/wirings/workflow/pikku-scenario-service.js",
23
24
  "./dist/wirings/workflow/workflow-approval-policy.js",
24
25
  "./dist/wirings/workflow/workflow-errors.js",
25
- "./dist/wirings/workflow/workflow-run-ownership.js",
26
- "./dist/wirings/workflow/pikku-scenario-service.js"
26
+ "./dist/wirings/workflow/workflow-run-ownership.js"
27
27
  ],
28
28
  "exports": {
29
29
  ".": "./dist/bootstrap-compat/root.js",