@mastra/code-sdk 0.0.0-agent-tags-alpha-20261125185303
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/LICENSE.md +32 -0
- package/README.md +284 -0
- package/dist/acp/agent.d.ts +48 -0
- package/dist/acp/agent.js +414 -0
- package/dist/acp/errors.d.ts +3 -0
- package/dist/acp/errors.js +11 -0
- package/dist/acp/event-mapper.d.ts +28 -0
- package/dist/acp/event-mapper.js +274 -0
- package/dist/acp/index.d.ts +9 -0
- package/dist/acp/index.js +21 -0
- package/dist/acp/runtime.d.ts +5 -0
- package/dist/acp/runtime.js +91 -0
- package/dist/acp/server.d.ts +4 -0
- package/dist/acp/server.js +35 -0
- package/dist/acp/skills.d.ts +6 -0
- package/dist/acp/skills.js +30 -0
- package/dist/acp.d.ts +2 -0
- package/dist/acp.js +1 -0
- package/dist/agent-connections/messaging-processor.d.ts +17 -0
- package/dist/agent-connections/messaging-processor.js +131 -0
- package/dist/agent-connections/ownership.d.ts +24 -0
- package/dist/agent-connections/ownership.js +96 -0
- package/dist/agent-connections/registry.d.ts +20 -0
- package/dist/agent-connections/registry.js +167 -0
- package/dist/agent-connections/session-advertisement.d.ts +27 -0
- package/dist/agent-connections/session-advertisement.js +86 -0
- package/dist/agent-connections/signal-provider.d.ts +141 -0
- package/dist/agent-connections/signal-provider.js +35 -0
- package/dist/agent-connections/state-processor.d.ts +23 -0
- package/dist/agent-connections/state-processor.js +270 -0
- package/dist/agent-connections/thread-state.d.ts +41 -0
- package/dist/agent-connections/thread-state.js +157 -0
- package/dist/agent-connections/tools.d.ts +133 -0
- package/dist/agent-connections/tools.js +616 -0
- package/dist/agent-connections/types.d.ts +99 -0
- package/dist/agent-connections/types.js +4 -0
- package/dist/agent-connections/untrusted-text.d.ts +5 -0
- package/dist/agent-connections/untrusted-text.js +19 -0
- package/dist/agents/background-completion-events.d.ts +16 -0
- package/dist/agents/background-completion-events.js +16 -0
- package/dist/agents/background-completion.d.ts +22 -0
- package/dist/agents/background-completion.js +73 -0
- package/dist/agents/context-audit.d.ts +84 -0
- package/dist/agents/context-audit.js +115 -0
- package/dist/agents/credential-resolver.d.ts +74 -0
- package/dist/agents/credential-resolver.js +142 -0
- package/dist/agents/custom-provider-source.d.ts +35 -0
- package/dist/agents/custom-provider-source.js +22 -0
- package/dist/agents/fastembed-subprocess.d.ts +52 -0
- package/dist/agents/fastembed-subprocess.js +282 -0
- package/dist/agents/instructions.d.ts +42 -0
- package/dist/agents/instructions.js +69 -0
- package/dist/agents/mastracode-gateway.d.ts +85 -0
- package/dist/agents/mastracode-gateway.js +500 -0
- package/dist/agents/memory.d.ts +36 -0
- package/dist/agents/memory.js +248 -0
- package/dist/agents/model.d.ts +158 -0
- package/dist/agents/model.js +382 -0
- package/dist/agents/modes/build.d.ts +12 -0
- package/dist/agents/modes/build.js +33 -0
- package/dist/agents/modes/explore.d.ts +10 -0
- package/dist/agents/modes/explore.js +25 -0
- package/dist/agents/modes/plan.d.ts +8 -0
- package/dist/agents/modes/plan.js +43 -0
- package/dist/agents/prompts/agent-instructions.d.ts +122 -0
- package/dist/agents/prompts/agent-instructions.js +617 -0
- package/dist/agents/prompts/build.d.ts +12 -0
- package/dist/agents/prompts/build.js +73 -0
- package/dist/agents/prompts/fast.d.ts +5 -0
- package/dist/agents/prompts/fast.js +23 -0
- package/dist/agents/prompts/index.d.ts +61 -0
- package/dist/agents/prompts/index.js +141 -0
- package/dist/agents/prompts/model.d.ts +5 -0
- package/dist/agents/prompts/model.js +20 -0
- package/dist/agents/prompts/plan.d.ts +11 -0
- package/dist/agents/prompts/plan.js +132 -0
- package/dist/agents/prompts/tool-guidance.d.ts +18 -0
- package/dist/agents/prompts/tool-guidance.js +158 -0
- package/dist/agents/sandbox-filesystem.d.ts +232 -0
- package/dist/agents/sandbox-filesystem.js +851 -0
- package/dist/agents/subagents/execute.d.ts +3 -0
- package/dist/agents/subagents/execute.js +24 -0
- package/dist/agents/subagents/explore.d.ts +3 -0
- package/dist/agents/subagents/explore.js +15 -0
- package/dist/agents/subagents/index.d.ts +6 -0
- package/dist/agents/subagents/index.js +15 -0
- package/dist/agents/subagents/plan.d.ts +3 -0
- package/dist/agents/subagents/plan.js +15 -0
- package/dist/agents/thread-caveman-state.d.ts +17 -0
- package/dist/agents/thread-caveman-state.js +104 -0
- package/dist/agents/tool-availability.d.ts +17 -0
- package/dist/agents/tool-availability.js +134 -0
- package/dist/agents/tools.d.ts +37 -0
- package/dist/agents/tools.js +154 -0
- package/dist/agents/workflow-builder-agent.d.ts +2 -0
- package/dist/agents/workflow-builder-agent.js +79 -0
- package/dist/agents/workspace.d.ts +35 -0
- package/dist/agents/workspace.js +207 -0
- package/dist/analytics.d.ts +18 -0
- package/dist/analytics.js +159 -0
- package/dist/auth/account-rotation-processor.d.ts +210 -0
- package/dist/auth/account-rotation-processor.js +662 -0
- package/dist/auth/account-routing-context.d.ts +17 -0
- package/dist/auth/account-routing-context.js +38 -0
- package/dist/auth/authorization-input.d.ts +16 -0
- package/dist/auth/authorization-input.js +39 -0
- package/dist/auth/device-code.d.ts +93 -0
- package/dist/auth/device-code.js +126 -0
- package/dist/auth/index.d.ts +13 -0
- package/dist/auth/index.js +9 -0
- package/dist/auth/pkce.d.ts +13 -0
- package/dist/auth/pkce.js +29 -0
- package/dist/auth/provider-auth-error.d.ts +24 -0
- package/dist/auth/provider-auth-error.js +44 -0
- package/dist/auth/providers/anthropic.d.ts +40 -0
- package/dist/auth/providers/anthropic.js +117 -0
- package/dist/auth/providers/github-copilot.d.ts +154 -0
- package/dist/auth/providers/github-copilot.js +359 -0
- package/dist/auth/providers/kimi-coding.d.ts +38 -0
- package/dist/auth/providers/kimi-coding.js +225 -0
- package/dist/auth/providers/openai-codex.d.ts +141 -0
- package/dist/auth/providers/openai-codex.js +531 -0
- package/dist/auth/providers/xai.d.ts +64 -0
- package/dist/auth/providers/xai.js +223 -0
- package/dist/auth/storage.d.ts +222 -0
- package/dist/auth/storage.js +805 -0
- package/dist/auth/types.d.ts +164 -0
- package/dist/auth/types.js +1 -0
- package/dist/clipboard/index.d.ts +26 -0
- package/dist/clipboard/index.js +224 -0
- package/dist/constants.d.ts +29 -0
- package/dist/constants.js +34 -0
- package/dist/error-classification.d.ts +10 -0
- package/dist/error-classification.js +19 -0
- package/dist/evals/context-builder.d.ts +41 -0
- package/dist/evals/context-builder.js +156 -0
- package/dist/evals/index.d.ts +4 -0
- package/dist/evals/index.js +5 -0
- package/dist/evals/scorers/classify-command.d.ts +30 -0
- package/dist/evals/scorers/classify-command.js +61 -0
- package/dist/evals/scorers/efficiency.d.ts +44 -0
- package/dist/evals/scorers/efficiency.js +256 -0
- package/dist/evals/scorers/extract-tools.d.ts +25 -0
- package/dist/evals/scorers/extract-tools.js +57 -0
- package/dist/evals/scorers/index.d.ts +3 -0
- package/dist/evals/scorers/index.js +3 -0
- package/dist/evals/scorers/outcome.d.ts +49 -0
- package/dist/evals/scorers/outcome.js +360 -0
- package/dist/experimental-agent.d.ts +19 -0
- package/dist/experimental-agent.js +45 -0
- package/dist/factory/client.d.ts +44 -0
- package/dist/factory/client.js +110 -0
- package/dist/factory/remote-controller.d.ts +34 -0
- package/dist/factory/remote-controller.js +40 -0
- package/dist/factory/remote-session.d.ts +210 -0
- package/dist/factory/remote-session.js +415 -0
- package/dist/goal-manager.d.ts +114 -0
- package/dist/goal-manager.js +351 -0
- package/dist/goal-signal.d.ts +14 -0
- package/dist/goal-signal.js +14 -0
- package/dist/headless/cli.d.ts +55 -0
- package/dist/headless/cli.js +261 -0
- package/dist/headless/flags.d.ts +33 -0
- package/dist/headless/flags.js +207 -0
- package/dist/headless/format.d.ts +41 -0
- package/dist/headless/format.js +94 -0
- package/dist/headless/index.d.ts +25 -0
- package/dist/headless/index.js +6 -0
- package/dist/headless/policy.d.ts +17 -0
- package/dist/headless/policy.js +39 -0
- package/dist/headless/run-mc.d.ts +7 -0
- package/dist/headless/run-mc.js +438 -0
- package/dist/headless/types.d.ts +175 -0
- package/dist/headless/types.js +16 -0
- package/dist/hooks/config.d.ts +11 -0
- package/dist/hooks/config.js +77 -0
- package/dist/hooks/executor.d.ts +13 -0
- package/dist/hooks/executor.js +128 -0
- package/dist/hooks/index.d.ts +6 -0
- package/dist/hooks/index.js +5 -0
- package/dist/hooks/manager.d.ts +75 -0
- package/dist/hooks/manager.js +289 -0
- package/dist/hooks/types.d.ts +180 -0
- package/dist/hooks/types.js +5 -0
- package/dist/index.d.ts +537 -0
- package/dist/index.js +1399 -0
- package/dist/ipc/ipc-reporter.d.ts +14 -0
- package/dist/ipc/ipc-reporter.js +18 -0
- package/dist/knowledge-inspector.d.ts +139 -0
- package/dist/knowledge-inspector.js +533 -0
- package/dist/knowledge-scope-id.d.ts +7 -0
- package/dist/knowledge-scope-id.js +10 -0
- package/dist/knowledge-scope.d.ts +41 -0
- package/dist/knowledge-scope.js +85 -0
- package/dist/lsp/client.d.ts +56 -0
- package/dist/lsp/client.js +248 -0
- package/dist/lsp/index.d.ts +4 -0
- package/dist/lsp/index.js +4 -0
- package/dist/lsp/language.d.ts +9 -0
- package/dist/lsp/language.js +41 -0
- package/dist/lsp/manager.d.ts +34 -0
- package/dist/lsp/manager.js +79 -0
- package/dist/lsp/server.d.ts +27 -0
- package/dist/lsp/server.js +158 -0
- package/dist/lsp/workspace.d.ts +9 -0
- package/dist/lsp/workspace.js +52 -0
- package/dist/mcp/config.d.ts +77 -0
- package/dist/mcp/config.js +313 -0
- package/dist/mcp/index.d.ts +6 -0
- package/dist/mcp/index.js +3 -0
- package/dist/mcp/manager.d.ts +104 -0
- package/dist/mcp/manager.js +693 -0
- package/dist/mcp/state.d.ts +35 -0
- package/dist/mcp/state.js +94 -0
- package/dist/mcp/types.d.ts +139 -0
- package/dist/mcp/types.js +1 -0
- package/dist/onboarding/custom-packs.d.ts +7 -0
- package/dist/onboarding/custom-packs.js +17 -0
- package/dist/onboarding/custom-providers.d.ts +4 -0
- package/dist/onboarding/custom-providers.js +27 -0
- package/dist/onboarding/index.d.ts +5 -0
- package/dist/onboarding/index.js +3 -0
- package/dist/onboarding/om-settings.d.ts +47 -0
- package/dist/onboarding/om-settings.js +80 -0
- package/dist/onboarding/pack-activation.d.ts +43 -0
- package/dist/onboarding/pack-activation.js +105 -0
- package/dist/onboarding/packs.d.ts +106 -0
- package/dist/onboarding/packs.js +283 -0
- package/dist/onboarding/settings.d.ts +563 -0
- package/dist/onboarding/settings.js +1110 -0
- package/dist/permissions.d.ts +55 -0
- package/dist/permissions.js +139 -0
- package/dist/platform/index.d.ts +74 -0
- package/dist/platform/index.js +199 -0
- package/dist/plugin.d.ts +156 -0
- package/dist/plugin.js +27 -0
- package/dist/plugins/dependencies.d.ts +9 -0
- package/dist/plugins/dependencies.js +84 -0
- package/dist/plugins/install.d.ts +21 -0
- package/dist/plugins/install.js +187 -0
- package/dist/plugins/loader.d.ts +25 -0
- package/dist/plugins/loader.js +264 -0
- package/dist/plugins/manager.d.ts +115 -0
- package/dist/plugins/manager.js +507 -0
- package/dist/plugins/manifest.d.ts +14 -0
- package/dist/plugins/manifest.js +47 -0
- package/dist/plugins/package-link.d.ts +3 -0
- package/dist/plugins/package-link.js +58 -0
- package/dist/plugins/paths.d.ts +10 -0
- package/dist/plugins/paths.js +22 -0
- package/dist/plugins/registry.d.ts +8 -0
- package/dist/plugins/registry.js +109 -0
- package/dist/plugins/scaffold.d.ts +10 -0
- package/dist/plugins/scaffold.js +115 -0
- package/dist/plugins/signal-lane.d.ts +59 -0
- package/dist/plugins/signal-lane.js +163 -0
- package/dist/plugins/types.d.ts +95 -0
- package/dist/plugins/types.js +1 -0
- package/dist/process-memory-diagnostics.d.ts +136 -0
- package/dist/process-memory-diagnostics.js +497 -0
- package/dist/processors/plan-rejection-abort.d.ts +16 -0
- package/dist/processors/plan-rejection-abort.js +62 -0
- package/dist/providers/amazon-bedrock-gateway.d.ts +47 -0
- package/dist/providers/amazon-bedrock-gateway.js +142 -0
- package/dist/providers/amazon-bedrock.d.ts +28 -0
- package/dist/providers/amazon-bedrock.js +99 -0
- package/dist/providers/anthropic-prompt-cache.d.ts +19 -0
- package/dist/providers/anthropic-prompt-cache.js +8 -0
- package/dist/providers/anthropic-thinking.d.ts +5 -0
- package/dist/providers/anthropic-thinking.js +22 -0
- package/dist/providers/claude-max.d.ts +67 -0
- package/dist/providers/claude-max.js +232 -0
- package/dist/providers/github-copilot-gateway.d.ts +35 -0
- package/dist/providers/github-copilot-gateway.js +58 -0
- package/dist/providers/github-copilot.d.ts +60 -0
- package/dist/providers/github-copilot.js +320 -0
- package/dist/providers/google-thinking.d.ts +31 -0
- package/dist/providers/google-thinking.js +64 -0
- package/dist/providers/google-vertex-gateway.d.ts +23 -0
- package/dist/providers/google-vertex-gateway.js +49 -0
- package/dist/providers/google-vertex.d.ts +6 -0
- package/dist/providers/google-vertex.js +51 -0
- package/dist/providers/kimi-coding.d.ts +14 -0
- package/dist/providers/kimi-coding.js +80 -0
- package/dist/providers/model-ids.d.ts +53 -0
- package/dist/providers/model-ids.js +132 -0
- package/dist/providers/openai-codex.d.ts +114 -0
- package/dist/providers/openai-codex.js +427 -0
- package/dist/providers/provider-thinking.d.ts +23 -0
- package/dist/providers/provider-thinking.js +61 -0
- package/dist/providers/thinking-request.d.ts +14 -0
- package/dist/providers/thinking-request.js +87 -0
- package/dist/providers/xai.d.ts +33 -0
- package/dist/providers/xai.js +72 -0
- package/dist/schedules/index.d.ts +10 -0
- package/dist/schedules/index.js +6 -0
- package/dist/schedules/interval.d.ts +49 -0
- package/dist/schedules/interval.js +212 -0
- package/dist/schedules/prompt.d.ts +36 -0
- package/dist/schedules/prompt.js +36 -0
- package/dist/schedules/run-script.d.ts +8 -0
- package/dist/schedules/run-script.js +80 -0
- package/dist/schedules/scheduler.d.ts +101 -0
- package/dist/schedules/scheduler.js +167 -0
- package/dist/schedules/tools.d.ts +57 -0
- package/dist/schedules/tools.js +217 -0
- package/dist/schema.d.ts +499 -0
- package/dist/schema.js +131 -0
- package/dist/theme-palette.d.ts +17 -0
- package/dist/theme-palette.js +18 -0
- package/dist/thinking-catalog.d.ts +4 -0
- package/dist/thinking-catalog.js +13 -0
- package/dist/thinking.d.ts +37 -0
- package/dist/thinking.js +134 -0
- package/dist/tool-names.d.ts +77 -0
- package/dist/tool-names.js +53 -0
- package/dist/tools/index.d.ts +6 -0
- package/dist/tools/index.js +3 -0
- package/dist/tools/request-sandbox-access.d.ts +6 -0
- package/dist/tools/request-sandbox-access.js +80 -0
- package/dist/tools/utils.d.ts +20 -0
- package/dist/tools/utils.js +31 -0
- package/dist/tools/web-search.d.ts +116 -0
- package/dist/tools/web-search.js +158 -0
- package/dist/tools/workflows/create-workflow.d.ts +7 -0
- package/dist/tools/workflows/create-workflow.js +82 -0
- package/dist/tools/workflows/delete-workflow.d.ts +7 -0
- package/dist/tools/workflows/delete-workflow.js +18 -0
- package/dist/tools/workflows/ephemeral-memory.d.ts +28 -0
- package/dist/tools/workflows/ephemeral-memory.js +41 -0
- package/dist/tools/workflows/extract-json-schema.d.ts +12 -0
- package/dist/tools/workflows/extract-json-schema.js +19 -0
- package/dist/tools/workflows/get-workflow.d.ts +11 -0
- package/dist/tools/workflows/get-workflow.js +31 -0
- package/dist/tools/workflows/list-available-agents.d.ts +8 -0
- package/dist/tools/workflows/list-available-agents.js +29 -0
- package/dist/tools/workflows/list-available-classifiers.d.ts +19 -0
- package/dist/tools/workflows/list-available-classifiers.js +53 -0
- package/dist/tools/workflows/list-available-tools.d.ts +9 -0
- package/dist/tools/workflows/list-available-tools.js +37 -0
- package/dist/tools/workflows/list-available-workflows.d.ts +9 -0
- package/dist/tools/workflows/list-available-workflows.js +29 -0
- package/dist/tools/workflows/list-workflows.d.ts +9 -0
- package/dist/tools/workflows/list-workflows.js +30 -0
- package/dist/tools/workflows/run-workflow.d.ts +9 -0
- package/dist/tools/workflows/run-workflow.js +49 -0
- package/dist/tools/workflows/save-workflow.d.ts +1125 -0
- package/dist/tools/workflows/save-workflow.js +25 -0
- package/dist/tools/workflows/tool-ids.d.ts +16 -0
- package/dist/tools/workflows/tool-ids.js +17 -0
- package/dist/utils/binaries.d.ts +7 -0
- package/dist/utils/binaries.js +97 -0
- package/dist/utils/debug-log.d.ts +12 -0
- package/dist/utils/debug-log.js +56 -0
- package/dist/utils/discarding-scores-storage.d.ts +33 -0
- package/dist/utils/discarding-scores-storage.js +51 -0
- package/dist/utils/errors.d.ts +36 -0
- package/dist/utils/errors.js +215 -0
- package/dist/utils/gateway-sync.d.ts +26 -0
- package/dist/utils/gateway-sync.js +58 -0
- package/dist/utils/local-observability.d.ts +19 -0
- package/dist/utils/local-observability.js +54 -0
- package/dist/utils/maintenance-lock.d.ts +42 -0
- package/dist/utils/maintenance-lock.js +196 -0
- package/dist/utils/notification-dispatch.d.ts +74 -0
- package/dist/utils/notification-dispatch.js +128 -0
- package/dist/utils/open-url.d.ts +10 -0
- package/dist/utils/open-url.js +27 -0
- package/dist/utils/path-security.d.ts +2 -0
- package/dist/utils/path-security.js +7 -0
- package/dist/utils/plan-diff.d.ts +25 -0
- package/dist/utils/plan-diff.js +59 -0
- package/dist/utils/plans.d.ts +61 -0
- package/dist/utils/plans.js +120 -0
- package/dist/utils/project.d.ts +160 -0
- package/dist/utils/project.js +361 -0
- package/dist/utils/prune-cli.d.ts +24 -0
- package/dist/utils/prune-cli.js +124 -0
- package/dist/utils/signals-pubsub.d.ts +103 -0
- package/dist/utils/signals-pubsub.js +409 -0
- package/dist/utils/slash-command-loader.d.ts +52 -0
- package/dist/utils/slash-command-loader.js +139 -0
- package/dist/utils/slash-command-processor.d.ts +14 -0
- package/dist/utils/slash-command-processor.js +106 -0
- package/dist/utils/stdin-pipe.d.ts +33 -0
- package/dist/utils/stdin-pipe.js +93 -0
- package/dist/utils/storage-factory.d.ts +50 -0
- package/dist/utils/storage-factory.js +118 -0
- package/dist/utils/storage-maintenance.d.ts +121 -0
- package/dist/utils/storage-maintenance.js +352 -0
- package/dist/utils/thread-lock.d.ts +26 -0
- package/dist/utils/thread-lock.js +109 -0
- package/dist/utils/token-estimator.d.ts +3 -0
- package/dist/utils/token-estimator.js +19 -0
- package/dist/utils/update-check.d.ts +151 -0
- package/dist/utils/update-check.js +430 -0
- package/dist/utils/wake-session.d.ts +44 -0
- package/dist/utils/wake-session.js +83 -0
- package/dist/voice/stt-registry.d.ts +67 -0
- package/dist/voice/stt-registry.js +144 -0
- package/dist/voice/transcribe.d.ts +10 -0
- package/dist/voice/transcribe.js +75 -0
- package/dist/workflows/register-primitives.d.ts +52 -0
- package/dist/workflows/register-primitives.js +40 -0
- package/dist/workflows/service.d.ts +64 -0
- package/dist/workflows/service.js +50 -0
- package/package.json +117 -0
|
@@ -0,0 +1,114 @@
|
|
|
1
|
+
import type { AgentController, Session } from '@mastra/core/agent-controller';
|
|
2
|
+
export interface GoalManagerState<TState extends Record<string, unknown> = Record<string, unknown>> {
|
|
3
|
+
controller: AgentController<TState>;
|
|
4
|
+
session: Session<TState>;
|
|
5
|
+
}
|
|
6
|
+
export type GoalStatus = 'active' | 'paused' | 'done';
|
|
7
|
+
/**
|
|
8
|
+
* TUI-facing view of a goal. Derived from the durable {@link GoalObjectiveRecord}
|
|
9
|
+
* plus the effective judge/max-runs settings, with display-only timer fields and
|
|
10
|
+
* a stable `id` used to match plan-started goals.
|
|
11
|
+
*/
|
|
12
|
+
export interface GoalState {
|
|
13
|
+
id: string;
|
|
14
|
+
objective: string;
|
|
15
|
+
status: GoalStatus;
|
|
16
|
+
turnsUsed: number;
|
|
17
|
+
maxTurns: number;
|
|
18
|
+
judgeModelId: string;
|
|
19
|
+
startedAt: string;
|
|
20
|
+
activeStartedAt?: string;
|
|
21
|
+
activeDurationMs?: number;
|
|
22
|
+
/** Why the goal paused (judge failure, budget exhaustion, ...). Only set while paused. */
|
|
23
|
+
pausedReason?: string;
|
|
24
|
+
}
|
|
25
|
+
export declare const DEFAULT_MAX_TURNS = 50;
|
|
26
|
+
export declare class GoalManager {
|
|
27
|
+
/** Synchronous in-memory view of the active objective record (source of truth is ThreadState). */
|
|
28
|
+
private record;
|
|
29
|
+
private threadId;
|
|
30
|
+
private agentId;
|
|
31
|
+
private persistGoalOnNextThreadCreate;
|
|
32
|
+
/**
|
|
33
|
+
* Set by {@link clear} to the thread the goal was cleared on: the next save
|
|
34
|
+
* with an empty mirror on that same thread deletes the goal. A goal hydrated
|
|
35
|
+
* from legacy metadata has no known thread, so its clear applies to whichever
|
|
36
|
+
* thread the next save runs on (the pre-existing behaviour).
|
|
37
|
+
*/
|
|
38
|
+
private pendingDelete;
|
|
39
|
+
getGoal(): GoalState | null;
|
|
40
|
+
isActive(): boolean;
|
|
41
|
+
persistOnNextThreadCreate(): void;
|
|
42
|
+
consumePersistOnNextThreadCreate(): boolean;
|
|
43
|
+
/**
|
|
44
|
+
* Set a new objective. Persists to ThreadState via `agent.setObjective` and
|
|
45
|
+
* updates the in-memory view. Only the provided settings are persisted into
|
|
46
|
+
* the record; unset ones fall back to the agent's `goal` config at read time.
|
|
47
|
+
*/
|
|
48
|
+
setGoal(state: GoalManagerState, objective: string, judgeModelId: string, maxTurns?: number): Promise<GoalState | null>;
|
|
49
|
+
/**
|
|
50
|
+
* Update the judge model / max-runs defaults. Persists into the active record
|
|
51
|
+
* (so the override is remembered in thread state) when a goal is set.
|
|
52
|
+
*/
|
|
53
|
+
updateJudgeDefaults(state: GoalManagerState, judgeModelId: string, maxTurns: number): Promise<GoalState | null>;
|
|
54
|
+
pause(reason?: string): GoalState | null;
|
|
55
|
+
resume(): GoalState | null;
|
|
56
|
+
markDone(): void;
|
|
57
|
+
clear(): void;
|
|
58
|
+
/**
|
|
59
|
+
* Sync the latest objective record from ThreadState into the in-memory view.
|
|
60
|
+
* Called from the `goal` stream-chunk handler after each evaluation.
|
|
61
|
+
*/
|
|
62
|
+
applyEvaluation(update: {
|
|
63
|
+
runsUsed: number;
|
|
64
|
+
status: GoalStatus;
|
|
65
|
+
pausedReason?: string;
|
|
66
|
+
}): GoalState | null;
|
|
67
|
+
/**
|
|
68
|
+
* Persist the active objective to ThreadState via the agent. The objective
|
|
69
|
+
* record is the source of truth; the legacy thread-metadata key is cleared on
|
|
70
|
+
* a save that actually wrote, so stale state from older sessions cannot
|
|
71
|
+
* shadow the record — and a save that wrote nothing leaves it alone.
|
|
72
|
+
*
|
|
73
|
+
* An empty in-memory mirror means "I have nothing *loaded*", which is not the
|
|
74
|
+
* same statement as "there is nothing": the mirror is also emptied by storage
|
|
75
|
+
* failures and thread switches. So a save with an empty mirror deletes the
|
|
76
|
+
* goal (durable record and legacy key) only right after an explicit
|
|
77
|
+
* {@link clear} on the same thread (or any thread, for a legacy-hydrated goal
|
|
78
|
+
* whose thread is unknown), and is a complete no-op otherwise.
|
|
79
|
+
*/
|
|
80
|
+
saveToThread(state: GoalManagerState): Promise<void>;
|
|
81
|
+
/**
|
|
82
|
+
* Remove the objective from the thread, whatever the in-memory mirror holds.
|
|
83
|
+
*
|
|
84
|
+
* The durable record needs an agent and a thread; the legacy thread-metadata
|
|
85
|
+
* key does not, so it is wiped either way — unlike {@link saveToThread}, which
|
|
86
|
+
* writes nothing with an empty mirror unless {@link clear} ran. That asymmetry is deliberate: a
|
|
87
|
+
* pre-migration goal must not resurface from the legacy key after a clear.
|
|
88
|
+
* Like the save, this is best-effort: a failed durable delete also skips the
|
|
89
|
+
* legacy wipe. A pending {@link clear} stays pending until both writes
|
|
90
|
+
* succeed, so a later save retries it; loading the thread retries it once
|
|
91
|
+
* and then drops it. Resolves to whether the delete landed.
|
|
92
|
+
*/
|
|
93
|
+
deleteFromThread(state: GoalManagerState): Promise<boolean>;
|
|
94
|
+
/**
|
|
95
|
+
* Load the objective from ThreadState (called on thread switch). Falls back to
|
|
96
|
+
* the legacy thread-metadata goal for threads created before this migration.
|
|
97
|
+
*
|
|
98
|
+
* A clear whose delete failed is retried here when it targeted this thread and
|
|
99
|
+
* the stored goal is the one that was cleared; otherwise the stored goal loads,
|
|
100
|
+
* so the mirror never hides a goal core is still judging. Resolves to whether
|
|
101
|
+
* that retried delete landed.
|
|
102
|
+
*/
|
|
103
|
+
loadFromThread(state: GoalManagerState, isCurrent?: () => boolean): Promise<boolean>;
|
|
104
|
+
/**
|
|
105
|
+
* Legacy entry point retained for thread-switch call sites that only have the
|
|
106
|
+
* thread metadata available. Hydrates from a previously-persisted GoalState.
|
|
107
|
+
*/
|
|
108
|
+
loadFromThreadMetadata(metadata: Record<string, unknown> | undefined): void;
|
|
109
|
+
private getAgent;
|
|
110
|
+
/** Resolve effective judge model + max runs (record value → settings default). */
|
|
111
|
+
private effectiveSettings;
|
|
112
|
+
private localRecord;
|
|
113
|
+
}
|
|
114
|
+
//# sourceMappingURL=goal-manager.d.ts.map
|
|
@@ -0,0 +1,351 @@
|
|
|
1
|
+
import { loadSettings } from "./onboarding/settings.js";
|
|
2
|
+
import { getGoalActivityDurationMs } from "@mastra/core/agent";
|
|
3
|
+
// src/goal-manager.ts
|
|
4
|
+
/**
|
|
5
|
+
* GoalManager — persistent cross-turn goals, backed by the Agent's native goal
|
|
6
|
+
* mechanism.
|
|
7
|
+
*
|
|
8
|
+
* The objective lives in the durable `threadState` `'goal'` slot (via
|
|
9
|
+
* `agent.setObjective`/`getObjective`/`clearObjective`/`updateObjectiveOptions`)
|
|
10
|
+
* and is judged in-loop by the core goal step. This manager is a thin adapter:
|
|
11
|
+
* it keeps a synchronous in-memory view of the current objective for the TUI
|
|
12
|
+
* (status line, modal, keyboard shortcuts) and delegates persistence to the
|
|
13
|
+
* agent. There is no standalone judge agent and no between-turn re-invocation —
|
|
14
|
+
* the core goal step drives continuation and surfaces progress via `goal` stream
|
|
15
|
+
* chunks.
|
|
16
|
+
*/
|
|
17
|
+
const DEFAULT_MAX_TURNS = 50;
|
|
18
|
+
const THREAD_GOAL_KEY = "goal";
|
|
19
|
+
function normalizeActiveDurationMs(value) {
|
|
20
|
+
return value !== void 0 && Number.isFinite(value) && value >= 0 ? value : 0;
|
|
21
|
+
}
|
|
22
|
+
var GoalManager = class {
|
|
23
|
+
/** Synchronous in-memory view of the active objective record (source of truth is ThreadState). */
|
|
24
|
+
record = null;
|
|
25
|
+
threadId;
|
|
26
|
+
agentId;
|
|
27
|
+
persistGoalOnNextThreadCreate = false;
|
|
28
|
+
/**
|
|
29
|
+
* Set by {@link clear} to the thread the goal was cleared on: the next save
|
|
30
|
+
* with an empty mirror on that same thread deletes the goal. A goal hydrated
|
|
31
|
+
* from legacy metadata has no known thread, so its clear applies to whichever
|
|
32
|
+
* thread the next save runs on (the pre-existing behaviour).
|
|
33
|
+
*/
|
|
34
|
+
pendingDelete = null;
|
|
35
|
+
getGoal() {
|
|
36
|
+
if (!this.record) return null;
|
|
37
|
+
const { judgeModelId, maxTurns } = this.effectiveSettings(this.record);
|
|
38
|
+
return {
|
|
39
|
+
id: this.record.id,
|
|
40
|
+
objective: this.record.objective,
|
|
41
|
+
status: this.record.status,
|
|
42
|
+
turnsUsed: this.record.runsUsed,
|
|
43
|
+
maxTurns,
|
|
44
|
+
judgeModelId,
|
|
45
|
+
startedAt: new Date(this.record.startedAt).toISOString(),
|
|
46
|
+
...this.record.pausedReason ? { pausedReason: this.record.pausedReason } : {},
|
|
47
|
+
activeDurationMs: this.agentId && this.threadId ? getGoalActivityDurationMs({
|
|
48
|
+
agentId: this.agentId,
|
|
49
|
+
threadId: this.threadId,
|
|
50
|
+
objectiveId: this.record.id,
|
|
51
|
+
activeDurationMs: this.record.activeDurationMs
|
|
52
|
+
}) : normalizeActiveDurationMs(this.record.activeDurationMs)
|
|
53
|
+
};
|
|
54
|
+
}
|
|
55
|
+
isActive() {
|
|
56
|
+
return this.record?.status === "active";
|
|
57
|
+
}
|
|
58
|
+
persistOnNextThreadCreate() {
|
|
59
|
+
this.persistGoalOnNextThreadCreate = true;
|
|
60
|
+
}
|
|
61
|
+
consumePersistOnNextThreadCreate() {
|
|
62
|
+
if (!this.persistGoalOnNextThreadCreate) return false;
|
|
63
|
+
this.persistGoalOnNextThreadCreate = false;
|
|
64
|
+
return true;
|
|
65
|
+
}
|
|
66
|
+
/**
|
|
67
|
+
* Set a new objective. Persists to ThreadState via `agent.setObjective` and
|
|
68
|
+
* updates the in-memory view. Only the provided settings are persisted into
|
|
69
|
+
* the record; unset ones fall back to the agent's `goal` config at read time.
|
|
70
|
+
*/
|
|
71
|
+
async setGoal(state, objective, judgeModelId, maxTurns = 50) {
|
|
72
|
+
const threadId = state.session.thread.getId();
|
|
73
|
+
const agent = this.getAgent(state);
|
|
74
|
+
const now = Date.now();
|
|
75
|
+
const id = globalThis.crypto.randomUUID();
|
|
76
|
+
this.pendingDelete = null;
|
|
77
|
+
this.threadId = threadId ?? void 0;
|
|
78
|
+
this.agentId = agent?.id;
|
|
79
|
+
if (agent && threadId) {
|
|
80
|
+
const persisted = await agent.setObjective(objective, {
|
|
81
|
+
id,
|
|
82
|
+
threadId,
|
|
83
|
+
resourceId: state.session.identity.getResourceId(),
|
|
84
|
+
...judgeModelId ? { judgeModelId } : {},
|
|
85
|
+
maxRuns: maxTurns
|
|
86
|
+
});
|
|
87
|
+
this.record = persisted ? {
|
|
88
|
+
...persisted,
|
|
89
|
+
id: persisted.id ?? id
|
|
90
|
+
} : this.localRecord(objective, judgeModelId, maxTurns, now, id);
|
|
91
|
+
} else this.record = this.localRecord(objective, judgeModelId, maxTurns, now, id);
|
|
92
|
+
return this.getGoal();
|
|
93
|
+
}
|
|
94
|
+
/**
|
|
95
|
+
* Update the judge model / max-runs defaults. Persists into the active record
|
|
96
|
+
* (so the override is remembered in thread state) when a goal is set.
|
|
97
|
+
*/
|
|
98
|
+
async updateJudgeDefaults(state, judgeModelId, maxTurns) {
|
|
99
|
+
if (!this.record) return null;
|
|
100
|
+
const threadId = state.session.thread.getId();
|
|
101
|
+
const agent = this.getAgent(state);
|
|
102
|
+
if (agent && threadId) {
|
|
103
|
+
const updated = await agent.updateObjectiveOptions({
|
|
104
|
+
threadId,
|
|
105
|
+
...judgeModelId ? { judgeModelId } : {},
|
|
106
|
+
maxRuns: maxTurns
|
|
107
|
+
});
|
|
108
|
+
if (updated) this.record = {
|
|
109
|
+
...updated,
|
|
110
|
+
id: this.record.id
|
|
111
|
+
};
|
|
112
|
+
} else this.record = {
|
|
113
|
+
...this.record,
|
|
114
|
+
...judgeModelId ? { judgeModelId } : {},
|
|
115
|
+
maxRuns: maxTurns,
|
|
116
|
+
updatedAt: Date.now()
|
|
117
|
+
};
|
|
118
|
+
return this.getGoal();
|
|
119
|
+
}
|
|
120
|
+
pause(reason) {
|
|
121
|
+
if (this.record && this.record.status === "active") this.record = {
|
|
122
|
+
...this.record,
|
|
123
|
+
status: "paused",
|
|
124
|
+
pausedReason: reason,
|
|
125
|
+
updatedAt: Date.now()
|
|
126
|
+
};
|
|
127
|
+
return this.getGoal();
|
|
128
|
+
}
|
|
129
|
+
resume() {
|
|
130
|
+
if (this.record && this.record.status === "paused") this.record = {
|
|
131
|
+
...this.record,
|
|
132
|
+
status: "active",
|
|
133
|
+
pausedReason: void 0,
|
|
134
|
+
updatedAt: Date.now()
|
|
135
|
+
};
|
|
136
|
+
return this.getGoal();
|
|
137
|
+
}
|
|
138
|
+
markDone() {
|
|
139
|
+
if (this.record) this.record = {
|
|
140
|
+
...this.record,
|
|
141
|
+
status: "done",
|
|
142
|
+
pausedReason: void 0,
|
|
143
|
+
updatedAt: Date.now()
|
|
144
|
+
};
|
|
145
|
+
}
|
|
146
|
+
clear() {
|
|
147
|
+
this.pendingDelete = {
|
|
148
|
+
threadId: this.threadId,
|
|
149
|
+
goalId: this.record?.id
|
|
150
|
+
};
|
|
151
|
+
this.record = null;
|
|
152
|
+
this.threadId = void 0;
|
|
153
|
+
this.agentId = void 0;
|
|
154
|
+
this.persistGoalOnNextThreadCreate = false;
|
|
155
|
+
}
|
|
156
|
+
/**
|
|
157
|
+
* Sync the latest objective record from ThreadState into the in-memory view.
|
|
158
|
+
* Called from the `goal` stream-chunk handler after each evaluation.
|
|
159
|
+
*/
|
|
160
|
+
applyEvaluation(update) {
|
|
161
|
+
if (!this.record) return null;
|
|
162
|
+
const pausedReason = update.status === "paused" ? update.pausedReason ?? (this.record.status === "paused" ? this.record.pausedReason : void 0) : void 0;
|
|
163
|
+
this.record = {
|
|
164
|
+
...this.record,
|
|
165
|
+
runsUsed: update.runsUsed,
|
|
166
|
+
status: update.status,
|
|
167
|
+
pausedReason,
|
|
168
|
+
updatedAt: Date.now()
|
|
169
|
+
};
|
|
170
|
+
return this.getGoal();
|
|
171
|
+
}
|
|
172
|
+
/**
|
|
173
|
+
* Persist the active objective to ThreadState via the agent. The objective
|
|
174
|
+
* record is the source of truth; the legacy thread-metadata key is cleared on
|
|
175
|
+
* a save that actually wrote, so stale state from older sessions cannot
|
|
176
|
+
* shadow the record — and a save that wrote nothing leaves it alone.
|
|
177
|
+
*
|
|
178
|
+
* An empty in-memory mirror means "I have nothing *loaded*", which is not the
|
|
179
|
+
* same statement as "there is nothing": the mirror is also emptied by storage
|
|
180
|
+
* failures and thread switches. So a save with an empty mirror deletes the
|
|
181
|
+
* goal (durable record and legacy key) only right after an explicit
|
|
182
|
+
* {@link clear} on the same thread (or any thread, for a legacy-hydrated goal
|
|
183
|
+
* whose thread is unknown), and is a complete no-op otherwise.
|
|
184
|
+
*/
|
|
185
|
+
async saveToThread(state) {
|
|
186
|
+
const threadId = state.session.thread.getId();
|
|
187
|
+
const agent = this.getAgent(state);
|
|
188
|
+
if (!this.record && this.pendingDelete) {
|
|
189
|
+
const clearedThreadId = this.pendingDelete.threadId;
|
|
190
|
+
if (clearedThreadId === void 0 || clearedThreadId === threadId) await this.deleteFromThread(state);
|
|
191
|
+
return;
|
|
192
|
+
}
|
|
193
|
+
try {
|
|
194
|
+
if (agent && threadId) {
|
|
195
|
+
if (this.record) {
|
|
196
|
+
if (!await agent.updateObjectiveOptions({
|
|
197
|
+
threadId,
|
|
198
|
+
status: this.record.status,
|
|
199
|
+
...this.record.pausedReason ? { pausedReason: this.record.pausedReason } : {},
|
|
200
|
+
...this.record.judgeModelId ? { judgeModelId: this.record.judgeModelId } : {},
|
|
201
|
+
...this.record.maxRuns !== void 0 ? { maxRuns: this.record.maxRuns } : {}
|
|
202
|
+
})) {
|
|
203
|
+
const desiredStatus = this.record.status;
|
|
204
|
+
if (!await agent.setObjective(this.record.objective, {
|
|
205
|
+
id: this.record.id,
|
|
206
|
+
threadId,
|
|
207
|
+
resourceId: state.session.identity.getResourceId(),
|
|
208
|
+
activeDurationMs: normalizeActiveDurationMs(this.record.activeDurationMs),
|
|
209
|
+
...this.record.judgeModelId ? { judgeModelId: this.record.judgeModelId } : {},
|
|
210
|
+
...this.record.maxRuns !== void 0 ? { maxRuns: this.record.maxRuns } : {}
|
|
211
|
+
})) return;
|
|
212
|
+
if (desiredStatus !== "active") await agent.updateObjectiveOptions({
|
|
213
|
+
threadId,
|
|
214
|
+
status: desiredStatus,
|
|
215
|
+
...this.record.pausedReason ? { pausedReason: this.record.pausedReason } : {}
|
|
216
|
+
});
|
|
217
|
+
}
|
|
218
|
+
await state.session.thread.setSetting({
|
|
219
|
+
key: THREAD_GOAL_KEY,
|
|
220
|
+
value: void 0
|
|
221
|
+
});
|
|
222
|
+
}
|
|
223
|
+
}
|
|
224
|
+
} catch {}
|
|
225
|
+
}
|
|
226
|
+
/**
|
|
227
|
+
* Remove the objective from the thread, whatever the in-memory mirror holds.
|
|
228
|
+
*
|
|
229
|
+
* The durable record needs an agent and a thread; the legacy thread-metadata
|
|
230
|
+
* key does not, so it is wiped either way — unlike {@link saveToThread}, which
|
|
231
|
+
* writes nothing with an empty mirror unless {@link clear} ran. That asymmetry is deliberate: a
|
|
232
|
+
* pre-migration goal must not resurface from the legacy key after a clear.
|
|
233
|
+
* Like the save, this is best-effort: a failed durable delete also skips the
|
|
234
|
+
* legacy wipe. A pending {@link clear} stays pending until both writes
|
|
235
|
+
* succeed, so a later save retries it; loading the thread retries it once
|
|
236
|
+
* and then drops it. Resolves to whether the delete landed.
|
|
237
|
+
*/
|
|
238
|
+
async deleteFromThread(state) {
|
|
239
|
+
const threadId = state.session.thread.getId();
|
|
240
|
+
const agent = this.getAgent(state);
|
|
241
|
+
try {
|
|
242
|
+
if (agent && threadId) await agent.clearObjective({ threadId });
|
|
243
|
+
await state.session.thread.setSetting({
|
|
244
|
+
key: THREAD_GOAL_KEY,
|
|
245
|
+
value: void 0
|
|
246
|
+
});
|
|
247
|
+
this.pendingDelete = null;
|
|
248
|
+
return true;
|
|
249
|
+
} catch {
|
|
250
|
+
if (threadId) this.pendingDelete = {
|
|
251
|
+
threadId,
|
|
252
|
+
goalId: this.pendingDelete?.goalId
|
|
253
|
+
};
|
|
254
|
+
return false;
|
|
255
|
+
}
|
|
256
|
+
}
|
|
257
|
+
/**
|
|
258
|
+
* Load the objective from ThreadState (called on thread switch). Falls back to
|
|
259
|
+
* the legacy thread-metadata goal for threads created before this migration.
|
|
260
|
+
*
|
|
261
|
+
* A clear whose delete failed is retried here when it targeted this thread and
|
|
262
|
+
* the stored goal is the one that was cleared; otherwise the stored goal loads,
|
|
263
|
+
* so the mirror never hides a goal core is still judging. Resolves to whether
|
|
264
|
+
* that retried delete landed.
|
|
265
|
+
*/
|
|
266
|
+
async loadFromThread(state, isCurrent = () => true) {
|
|
267
|
+
const pending = this.pendingDelete;
|
|
268
|
+
const threadId = state.session.thread.getId();
|
|
269
|
+
const agent = this.getAgent(state);
|
|
270
|
+
let nextRecord = null;
|
|
271
|
+
let storedId;
|
|
272
|
+
if (agent && threadId) try {
|
|
273
|
+
const record = await agent.getObjective({ threadId });
|
|
274
|
+
if (record) {
|
|
275
|
+
storedId = record.id;
|
|
276
|
+
nextRecord = {
|
|
277
|
+
...record,
|
|
278
|
+
id: record.id ?? globalThis.crypto.randomUUID(),
|
|
279
|
+
activeDurationMs: normalizeActiveDurationMs(record.activeDurationMs)
|
|
280
|
+
};
|
|
281
|
+
}
|
|
282
|
+
} catch {}
|
|
283
|
+
if (!isCurrent()) return false;
|
|
284
|
+
if (pending && this.pendingDelete !== pending) return false;
|
|
285
|
+
let retriedDelete = false;
|
|
286
|
+
if (pending?.goalId && pending.threadId === threadId && storedId === pending.goalId) {
|
|
287
|
+
retriedDelete = await this.deleteFromThread(state);
|
|
288
|
+
if (retriedDelete) nextRecord = null;
|
|
289
|
+
if (!isCurrent()) return false;
|
|
290
|
+
}
|
|
291
|
+
this.persistGoalOnNextThreadCreate = false;
|
|
292
|
+
this.pendingDelete = null;
|
|
293
|
+
this.threadId = threadId ?? void 0;
|
|
294
|
+
this.agentId = agent?.id;
|
|
295
|
+
this.record = nextRecord;
|
|
296
|
+
return retriedDelete;
|
|
297
|
+
}
|
|
298
|
+
/**
|
|
299
|
+
* Legacy entry point retained for thread-switch call sites that only have the
|
|
300
|
+
* thread metadata available. Hydrates from a previously-persisted GoalState.
|
|
301
|
+
*/
|
|
302
|
+
loadFromThreadMetadata(metadata) {
|
|
303
|
+
const saved = metadata?.[THREAD_GOAL_KEY];
|
|
304
|
+
this.persistGoalOnNextThreadCreate = false;
|
|
305
|
+
this.pendingDelete = null;
|
|
306
|
+
this.threadId = void 0;
|
|
307
|
+
this.agentId = void 0;
|
|
308
|
+
if (saved && saved.objective && saved.status) this.record = {
|
|
309
|
+
objective: saved.objective,
|
|
310
|
+
status: saved.status,
|
|
311
|
+
runsUsed: saved.turnsUsed ?? 0,
|
|
312
|
+
activeDurationMs: normalizeActiveDurationMs(saved.activeDurationMs),
|
|
313
|
+
maxRuns: saved.maxTurns ?? 50,
|
|
314
|
+
judgeModelId: saved.judgeModelId ?? "",
|
|
315
|
+
...saved.pausedReason ? { pausedReason: saved.pausedReason } : {},
|
|
316
|
+
startedAt: saved.startedAt ? Date.parse(saved.startedAt) || Date.now() : Date.now(),
|
|
317
|
+
updatedAt: Date.now(),
|
|
318
|
+
id: saved.id ?? globalThis.crypto.randomUUID()
|
|
319
|
+
};
|
|
320
|
+
else this.record = null;
|
|
321
|
+
}
|
|
322
|
+
getAgent(state) {
|
|
323
|
+
try {
|
|
324
|
+
return state.controller.getCurrentAgent(state.session);
|
|
325
|
+
} catch {
|
|
326
|
+
return;
|
|
327
|
+
}
|
|
328
|
+
}
|
|
329
|
+
/** Resolve effective judge model + max runs (record value → settings default). */
|
|
330
|
+
effectiveSettings(record) {
|
|
331
|
+
const settings = loadSettings();
|
|
332
|
+
return {
|
|
333
|
+
judgeModelId: record.judgeModelId ?? settings.models.goalJudgeModel ?? "",
|
|
334
|
+
maxTurns: record.maxRuns ?? settings.models.goalMaxTurns ?? 50
|
|
335
|
+
};
|
|
336
|
+
}
|
|
337
|
+
localRecord(objective, judgeModelId, maxTurns, now, id) {
|
|
338
|
+
return {
|
|
339
|
+
objective,
|
|
340
|
+
status: "active",
|
|
341
|
+
runsUsed: 0,
|
|
342
|
+
activeDurationMs: 0,
|
|
343
|
+
maxRuns: maxTurns,
|
|
344
|
+
...judgeModelId ? { judgeModelId } : {},
|
|
345
|
+
startedAt: now,
|
|
346
|
+
updatedAt: now,
|
|
347
|
+
id
|
|
348
|
+
};
|
|
349
|
+
}
|
|
350
|
+
};
|
|
351
|
+
export { DEFAULT_MAX_TURNS, GoalManager };
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
import type { GoalState } from './goal-manager.js';
|
|
2
|
+
export declare function createGoalReminderSignal(goal: GoalState): {
|
|
3
|
+
type: 'system-reminder';
|
|
4
|
+
contents: string;
|
|
5
|
+
attributes: {
|
|
6
|
+
type: string;
|
|
7
|
+
};
|
|
8
|
+
metadata: {
|
|
9
|
+
goalId: string;
|
|
10
|
+
goalMaxTurns: number;
|
|
11
|
+
judgeModelId: string;
|
|
12
|
+
};
|
|
13
|
+
};
|
|
14
|
+
//# sourceMappingURL=goal-signal.d.ts.map
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
// src/goal-signal.ts
|
|
2
|
+
function createGoalReminderSignal(goal) {
|
|
3
|
+
return {
|
|
4
|
+
type: "system-reminder",
|
|
5
|
+
contents: goal.objective,
|
|
6
|
+
attributes: { type: "goal" },
|
|
7
|
+
metadata: {
|
|
8
|
+
goalId: goal.id,
|
|
9
|
+
goalMaxTurns: goal.maxTurns,
|
|
10
|
+
judgeModelId: goal.judgeModelId
|
|
11
|
+
}
|
|
12
|
+
};
|
|
13
|
+
}
|
|
14
|
+
export { createGoalReminderSignal };
|
|
@@ -0,0 +1,55 @@
|
|
|
1
|
+
import type { Writable } from 'node:stream';
|
|
2
|
+
import type { PermissionMode, RunMode, ThinkingLevel } from './types.js';
|
|
3
|
+
/** Consolidated output mode (replaces the old `--format` + `--output-format`). */
|
|
4
|
+
export type OutputMode = 'human' | 'json' | 'jsonl';
|
|
5
|
+
export interface HeadlessArgs {
|
|
6
|
+
prompt?: string;
|
|
7
|
+
/** Timeout in seconds (CLI surface); converted to ms before `runMC`. */
|
|
8
|
+
timeout?: number;
|
|
9
|
+
output: OutputMode;
|
|
10
|
+
continue_: boolean;
|
|
11
|
+
model?: string;
|
|
12
|
+
pack?: string;
|
|
13
|
+
mode?: RunMode;
|
|
14
|
+
thinkingLevel?: ThinkingLevel;
|
|
15
|
+
settings?: string;
|
|
16
|
+
thread?: string;
|
|
17
|
+
title?: string;
|
|
18
|
+
cloneThread: boolean;
|
|
19
|
+
resourceId?: string;
|
|
20
|
+
/** Max agentic turns before the run aborts with exit code 1. */
|
|
21
|
+
maxTurns?: number;
|
|
22
|
+
/** Named permission mode resolving to a built-in policy. Defaults to `auto`. */
|
|
23
|
+
permissionMode?: PermissionMode;
|
|
24
|
+
}
|
|
25
|
+
/**
|
|
26
|
+
* Returns true if `argv` selects headless mode. This must agree with what
|
|
27
|
+
* {@link parseHeadlessArgs} (and `runMCCli`) accept as a prompt: `--prompt`/`-p`
|
|
28
|
+
* or a bare positional prompt (e.g. `mastracode "Fix the bug"`). Note that a
|
|
29
|
+
* prompt piped via stdin without a flag is handled separately by the caller.
|
|
30
|
+
*/
|
|
31
|
+
export declare function hasHeadlessFlag(argv: string[]): boolean;
|
|
32
|
+
/**
|
|
33
|
+
* Parse CLI arguments for headless mode. The flag table in `flags.ts` is the
|
|
34
|
+
* single source of truth: each flag carries its own coercion/validation, so this
|
|
35
|
+
* function just walks {@link FLAGS} and assembles the typed {@link HeadlessArgs}.
|
|
36
|
+
*/
|
|
37
|
+
export declare function parseHeadlessArgs(argv: string[]): HeadlessArgs;
|
|
38
|
+
export declare function printHeadlessUsage(): void;
|
|
39
|
+
/**
|
|
40
|
+
* Wait until everything written to `stream` has been handed to the OS, since
|
|
41
|
+
* `process.exit()` drops writes a pipe has not accepted yet. Resolves `false`
|
|
42
|
+
* if the stream fails or closes first; never rejects or hangs on a gone reader.
|
|
43
|
+
*/
|
|
44
|
+
export declare function flushWritable(stream: Writable): Promise<boolean>;
|
|
45
|
+
/**
|
|
46
|
+
* Headless CLI entry point: parse arguments, read stdin, initialize MastraCode,
|
|
47
|
+
* run via `runMC`, render output, and exit with the mapped code.
|
|
48
|
+
*/
|
|
49
|
+
export declare function runMCCli(predrainedInput?: string | null, options?: {
|
|
50
|
+
coAuthor?: {
|
|
51
|
+
name?: string;
|
|
52
|
+
email?: string;
|
|
53
|
+
};
|
|
54
|
+
}): Promise<never>;
|
|
55
|
+
//# sourceMappingURL=cli.d.ts.map
|