@mastra/factory 0.25.0-alpha.4 → 0.25.0-alpha.6
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +3 -1
- package/dist/auth.js +1 -2
- package/dist/boards/define-board.js +1 -2
- package/dist/boards/index.js +1 -2
- package/dist/boards/registry.js +1 -2
- package/dist/boards/relocate.js +1 -2
- package/dist/boards/review.js +1 -2
- package/dist/boards/semantics.js +1 -2
- package/dist/boards/transition-policy.js +1 -2
- package/dist/boards/work-tool-rules.js +1 -2
- package/dist/boards/work-transition-policy.js +1 -2
- package/dist/boards/work.js +1 -2
- package/dist/default-thinking-level.d.ts +3 -0
- package/dist/default-thinking-level.d.ts.map +1 -0
- package/dist/default-thinking-level.js +5 -0
- package/dist/default-thinking-level.js.map +1 -0
- package/dist/environment/build-runner.js +1 -2
- package/dist/environment/build-schedule.js +1 -2
- package/dist/environment/build-workflow.js +1 -2
- package/dist/environment/build.js +1 -2
- package/dist/environment/heads.js +1 -2
- package/dist/factory.d.ts +4 -2
- package/dist/factory.d.ts.map +1 -1
- package/dist/factory.js +62 -21
- package/dist/factory.js.map +1 -1
- package/dist/feed-events.js +1 -2
- package/dist/index.js +2 -2
- package/dist/integrations/channel-thread-announcements.d.ts +8 -0
- package/dist/integrations/channel-thread-announcements.d.ts.map +1 -0
- package/dist/integrations/channel-thread-announcements.js +16 -0
- package/dist/integrations/channel-thread-announcements.js.map +1 -0
- package/dist/integrations/github/acceptance-labels.js +1 -2
- package/dist/integrations/github/app-identity.js +1 -2
- package/dist/integrations/github/commits.js +1 -2
- package/dist/integrations/github/config.js +1 -2
- package/dist/integrations/github/default-rules.js +2 -3
- package/dist/integrations/github/integration.js +3 -4
- package/dist/integrations/github/issue-reconciler.js +1 -2
- package/dist/integrations/github/pat.js +1 -2
- package/dist/integrations/github/provenance.d.ts.map +1 -1
- package/dist/integrations/github/provenance.js +2 -5
- package/dist/integrations/github/provenance.js.map +1 -1
- package/dist/integrations/github/reconcile-worker.js +1 -2
- package/dist/integrations/github/reconciliation-config.js +1 -2
- package/dist/integrations/github/routes.js +4 -5
- package/dist/integrations/github/rules.d.ts.map +1 -1
- package/dist/integrations/github/rules.js +14 -3
- package/dist/integrations/github/rules.js.map +1 -1
- package/dist/integrations/github/sandbox-release.js +1 -2
- package/dist/integrations/github/sandbox.js +1 -2
- package/dist/integrations/github/session-subscriptions.js +1 -2
- package/dist/integrations/github/settle-or-abort.js +1 -2
- package/dist/integrations/github/stale-reviews.js +1 -2
- package/dist/integrations/github/subscriptions.js +1 -2
- package/dist/integrations/github/token-refresh.js +1 -2
- package/dist/integrations/github/webhook.d.ts.map +1 -1
- package/dist/integrations/github/webhook.js +17 -3
- package/dist/integrations/github/webhook.js.map +1 -1
- package/dist/integrations/gitlab/agent-tools.js +1 -2
- package/dist/integrations/gitlab/api.js +1 -2
- package/dist/integrations/gitlab/default-rules.js +1 -2
- package/dist/integrations/gitlab/integration.d.ts +4 -0
- package/dist/integrations/gitlab/integration.d.ts.map +1 -1
- package/dist/integrations/gitlab/integration.js +12 -4
- package/dist/integrations/gitlab/integration.js.map +1 -1
- package/dist/integrations/gitlab/issue-reconciler.js +1 -2
- package/dist/integrations/gitlab/merge-request-reconciler.js +1 -2
- package/dist/integrations/gitlab/reconciler.js +1 -2
- package/dist/integrations/gitlab/reconciliation-config.js +1 -2
- package/dist/integrations/gitlab/routes.d.ts +6 -0
- package/dist/integrations/gitlab/routes.d.ts.map +1 -1
- package/dist/integrations/gitlab/routes.js +154 -3
- package/dist/integrations/gitlab/routes.js.map +1 -1
- package/dist/integrations/gitlab/rules.d.ts.map +1 -1
- package/dist/integrations/gitlab/rules.js +5 -3
- package/dist/integrations/gitlab/rules.js.map +1 -1
- package/dist/integrations/gitlab/session-subscriptions.js +1 -2
- package/dist/integrations/gitlab/subscriptions.js +1 -2
- package/dist/integrations/gitlab/version-control.js +1 -2
- package/dist/integrations/gitlab/webhook-dispatch.js +1 -2
- package/dist/integrations/gitlab/webhook.js +1 -2
- package/dist/integrations/incidentio/agent-tools.js +1 -2
- package/dist/integrations/incidentio/api.js +1 -2
- package/dist/integrations/incidentio/claim.js +1 -2
- package/dist/integrations/incidentio/default-rules.js +1 -2
- package/dist/integrations/incidentio/intake.js +1 -2
- package/dist/integrations/incidentio/integration.js +1 -2
- package/dist/integrations/incidentio/issue-reconciler.js +1 -2
- package/dist/integrations/incidentio/reconciliation-config.js +1 -2
- package/dist/integrations/incidentio/routes.js +1 -2
- package/dist/integrations/incidentio/rules.js +1 -2
- package/dist/integrations/issue-reconcile-worker.js +1 -2
- package/dist/integrations/issue-reconciler.js +1 -2
- package/dist/integrations/jira/adf.js +1 -2
- package/dist/integrations/jira/agent-tools.js +1 -2
- package/dist/integrations/jira/api.d.ts +1 -1
- package/dist/integrations/jira/api.d.ts.map +1 -1
- package/dist/integrations/jira/api.js +2 -3
- package/dist/integrations/jira/api.js.map +1 -1
- package/dist/integrations/jira/claim.js +1 -2
- package/dist/integrations/jira/default-rules.js +1 -2
- package/dist/integrations/jira/integration.d.ts +3 -1
- package/dist/integrations/jira/integration.d.ts.map +1 -1
- package/dist/integrations/jira/integration.js +18 -4
- package/dist/integrations/jira/integration.js.map +1 -1
- package/dist/integrations/jira/issue-reconciler.js +1 -2
- package/dist/integrations/jira/reconciliation-config.js +1 -2
- package/dist/integrations/jira/routes.js +1 -2
- package/dist/integrations/jira/rules.js +1 -2
- package/dist/integrations/linear/agent-tools.d.ts +1 -1
- package/dist/integrations/linear/agent-tools.d.ts.map +1 -1
- package/dist/integrations/linear/agent-tools.js +5 -5
- package/dist/integrations/linear/agent-tools.js.map +1 -1
- package/dist/integrations/linear/claim.js +1 -2
- package/dist/integrations/linear/default-rules.js +1 -2
- package/dist/integrations/linear/integration.d.ts +2 -0
- package/dist/integrations/linear/integration.d.ts.map +1 -1
- package/dist/integrations/linear/integration.js +2 -2
- package/dist/integrations/linear/integration.js.map +1 -1
- package/dist/integrations/linear/issue-reconciler.js +1 -2
- package/dist/integrations/linear/reconciliation-config.js +1 -2
- package/dist/integrations/linear/routes.js +1 -2
- package/dist/integrations/linear/rules.js +1 -2
- package/dist/integrations/platform/api-client.js +1 -2
- package/dist/integrations/platform/connect/routes.js +1 -2
- package/dist/integrations/platform/github/event-worker.js +6 -2
- package/dist/integrations/platform/github/event-worker.js.map +1 -1
- package/dist/integrations/platform/github/integration.js +1 -2
- package/dist/integrations/platform/gitlab/event-worker.js +1 -2
- package/dist/integrations/platform/gitlab/integration.js +1 -2
- package/dist/integrations/platform/incidentio/integration.js +1 -2
- package/dist/integrations/platform/jira/agent-tools.js +1 -2
- package/dist/integrations/platform/jira/integration.js +1 -2
- package/dist/integrations/platform/jira/routes.js +1 -2
- package/dist/integrations/platform/linear/event-worker.js +1 -2
- package/dist/integrations/platform/linear/integration.d.ts.map +1 -1
- package/dist/integrations/platform/linear/integration.js +2 -2
- package/dist/integrations/platform/linear/integration.js.map +1 -1
- package/dist/integrations/pull-request-head.d.ts +1 -0
- package/dist/integrations/pull-request-head.d.ts.map +1 -1
- package/dist/integrations/pull-request-head.js +3 -3
- package/dist/integrations/pull-request-head.js.map +1 -1
- package/dist/integrations/reconciliation-config.js +1 -2
- package/dist/integrations/slack/channel-reply-processor.d.ts +1 -0
- package/dist/integrations/slack/channel-reply-processor.d.ts.map +1 -1
- package/dist/integrations/slack/channel-reply-processor.js +16 -6
- package/dist/integrations/slack/channel-reply-processor.js.map +1 -1
- package/dist/integrations/slack/channel-session-link-processor.d.ts +1 -0
- package/dist/integrations/slack/channel-session-link-processor.d.ts.map +1 -1
- package/dist/integrations/slack/channel-session-link-processor.js +2 -3
- package/dist/integrations/slack/channel-session-link-processor.js.map +1 -1
- package/dist/integrations/slack/connect-route.js +1 -2
- package/dist/integrations/slack/emoji-shortcodes.generated.js +1 -2
- package/dist/integrations/slack/emoji.js +1 -2
- package/dist/integrations/slack/feed-publisher.js +1 -2
- package/dist/integrations/slack/integration.d.ts +5 -0
- package/dist/integrations/slack/integration.d.ts.map +1 -1
- package/dist/integrations/slack/integration.js +13 -2
- package/dist/integrations/slack/integration.js.map +1 -1
- package/dist/integrations/slack/reply-reminder-processor.js +1 -2
- package/dist/integrations/slack/reply-tool.d.ts.map +1 -1
- package/dist/integrations/slack/reply-tool.js +4 -13
- package/dist/integrations/slack/reply-tool.js.map +1 -1
- package/dist/integrations/slack/run-error-card.d.ts +3 -0
- package/dist/integrations/slack/run-error-card.d.ts.map +1 -0
- package/dist/integrations/slack/run-error-card.js +44 -0
- package/dist/integrations/slack/run-error-card.js.map +1 -0
- package/dist/integrations/slack/share-file-tool.js +1 -2
- package/dist/integrations/slack/slack.d.ts.map +1 -1
- package/dist/integrations/slack/slack.js +7 -4
- package/dist/integrations/slack/slack.js.map +1 -1
- package/dist/integrations/subscription-session.js +1 -2
- package/dist/integrations/workos/integration.js +1 -2
- package/dist/mcp/disconnect.js +1 -2
- package/dist/mcp/events.js +2 -3
- package/dist/mcp/routes.js +1 -2
- package/dist/packages/_internals/workspace/dist/index.js +1 -2
- package/dist/packages/_internals/workspace/dist/index.js.map +1 -1
- package/dist/platform-auth-host.js +1 -2
- package/dist/provider-display-name.js +1 -2
- package/dist/review-verdict.d.ts +1 -0
- package/dist/review-verdict.d.ts.map +1 -1
- package/dist/review-verdict.js +9 -3
- package/dist/review-verdict.js.map +1 -1
- package/dist/routes/attention-activity.js +1 -2
- package/dist/routes/attention-parked.js +1 -2
- package/dist/routes/attention-proposed.js +1 -2
- package/dist/routes/attention-providers.js +1 -2
- package/dist/routes/attention.js +1 -2
- package/dist/routes/automation-runs.js +1 -2
- package/dist/routes/config.d.ts +7 -0
- package/dist/routes/config.d.ts.map +1 -1
- package/dist/routes/config.js +29 -3
- package/dist/routes/config.js.map +1 -1
- package/dist/routes/contracts.js +1 -2
- package/dist/routes/custom-provider-source.js +1 -2
- package/dist/routes/fs.js +1 -2
- package/dist/routes/intake.js +6 -4
- package/dist/routes/intake.js.map +1 -1
- package/dist/routes/knowledge.js +1 -2
- package/dist/routes/oauth.js +1 -2
- package/dist/routes/projects.js +1 -2
- package/dist/routes/provider-credentials.js +1 -2
- package/dist/routes/route.js +1 -2
- package/dist/routes/session-access.js +1 -2
- package/dist/routes/skills.js +1 -2
- package/dist/routes/source-control-sessions.js +5 -6
- package/dist/routes/source-control-settings.js +1 -2
- package/dist/routes/surface.js +3 -4
- package/dist/routes/surface.js.map +1 -1
- package/dist/routes/telemetry.js +1 -2
- package/dist/routes/tenant-credentials.js +1 -2
- package/dist/routes/work-items.js +2 -3
- package/dist/rules/binding-context.js +1 -2
- package/dist/rules/decision-applicability.js +1 -2
- package/dist/rules/dispatch-errors.js +1 -2
- package/dist/rules/dispatcher.d.ts.map +1 -1
- package/dist/rules/dispatcher.js +9 -3
- package/dist/rules/dispatcher.js.map +1 -1
- package/dist/rules/event-rules.js +1 -2
- package/dist/rules/processor.js +1 -2
- package/dist/rules/resolve.js +1 -2
- package/dist/rules/review-source-tool.js +1 -2
- package/dist/rules/start-coordinator.js +1 -2
- package/dist/rules/terminal-cleanup.js +1 -2
- package/dist/rules/tools.js +1 -2
- package/dist/rules/transition-service.js +1 -2
- package/dist/rules/types.d.ts +4 -1
- package/dist/rules/types.d.ts.map +1 -1
- package/dist/rules/types.js +1 -2
- package/dist/rules/types.js.map +1 -1
- package/dist/rules/validation.js +1 -2
- package/dist/run-error.d.ts +13 -0
- package/dist/run-error.d.ts.map +1 -0
- package/dist/run-error.js +81 -0
- package/dist/run-error.js.map +1 -0
- package/dist/sandbox/callback-factory-sandbox.js +1 -2
- package/dist/sandbox/git-ref.js +1 -2
- package/dist/sandbox/local-factory-sandbox.d.ts +12 -4
- package/dist/sandbox/local-factory-sandbox.d.ts.map +1 -1
- package/dist/sandbox/local-factory-sandbox.js +32 -7
- package/dist/sandbox/local-factory-sandbox.js.map +1 -1
- package/dist/sandbox/materialization.js +1 -2
- package/dist/sandbox/session-retirement.js +1 -2
- package/dist/sandbox/session-sandbox.js +1 -2
- package/dist/sandbox/workdir.js +1 -2
- package/dist/secret-encryption.js +1 -2
- package/dist/server-error.js +1 -2
- package/dist/session/credential-policy.js +1 -2
- package/dist/session/default-model-hydration.js +1 -2
- package/dist/session/environment-repositories.js +1 -2
- package/dist/session/environment-state-processor.d.ts +0 -1
- package/dist/session/environment-state-processor.d.ts.map +1 -1
- package/dist/session/environment-state-processor.js +2 -3
- package/dist/session/environment-state-processor.js.map +1 -1
- package/dist/session/factory-session.js +1 -2
- package/dist/session/filesystem-capture.js +2 -3
- package/dist/session/filesystem-capture.js.map +1 -1
- package/dist/session/first-exec-capture.js +2 -3
- package/dist/session/first-exec-capture.js.map +1 -1
- package/dist/session/first-message-capture.js +1 -2
- package/dist/session/live-sessions.js +1 -2
- package/dist/session/memory-settings-hydration.js +1 -2
- package/dist/session/org-seed.js +1 -2
- package/dist/session/reply-credential-processor.js +1 -2
- package/dist/session/resource-migration.js +1 -2
- package/dist/session/run-audit.js +1 -2
- package/dist/session/session-threads.js +1 -2
- package/dist/session/session-title.js +1 -2
- package/dist/session/shell-commands.js +1 -2
- package/dist/session/source-control-tools.js +2 -3
- package/dist/session/thinking-default.d.ts +1 -1
- package/dist/session/thinking-default.d.ts.map +1 -1
- package/dist/session/thinking-default.js +11 -13
- package/dist/session/thinking-default.js.map +1 -1
- package/dist/session/thread-session-stamp.js +1 -2
- package/dist/session/thread-title-mirror.js +1 -2
- package/dist/session/thread-title-mirror.js.map +1 -1
- package/dist/session/work-item-repository.js +1 -2
- package/dist/session-owner-signal.js +1 -2
- package/dist/skills/catalog.js +1 -2
- package/dist/skills/service.js +1 -2
- package/dist/spa-static.js +1 -2
- package/dist/state-signing.js +1 -2
- package/dist/storage/domains/audit/actions.js +1 -2
- package/dist/storage/domains/audit/actors.js +1 -2
- package/dist/storage/domains/audit/agent-audit.js +1 -2
- package/dist/storage/domains/audit/base.js +1 -2
- package/dist/storage/domains/audit/domain.js +1 -2
- package/dist/storage/domains/audit/wire.js +1 -2
- package/dist/storage/domains/channel-identity/base.js +1 -2
- package/dist/storage/domains/comments/activity.js +1 -2
- package/dist/storage/domains/comments/actor.js +1 -2
- package/dist/storage/domains/comments/base.js +1 -2
- package/dist/storage/domains/comments/domain.js +1 -2
- package/dist/storage/domains/comments/feed-context.js +1 -2
- package/dist/storage/domains/comments/parse.js +1 -2
- package/dist/storage/domains/comments/routes.js +1 -2
- package/dist/storage/domains/comments/schema.js +1 -2
- package/dist/storage/domains/comments/wire.js +1 -2
- package/dist/storage/domains/credentials/base.d.ts +4 -1
- package/dist/storage/domains/credentials/base.d.ts.map +1 -1
- package/dist/storage/domains/credentials/base.js +40 -44
- package/dist/storage/domains/credentials/base.js.map +1 -1
- package/dist/storage/domains/custom-providers/base.js +1 -2
- package/dist/storage/domains/filesystem/base.js +1 -2
- package/dist/storage/domains/intake/base.d.ts +5 -0
- package/dist/storage/domains/intake/base.d.ts.map +1 -1
- package/dist/storage/domains/intake/base.js +10 -2
- package/dist/storage/domains/intake/base.js.map +1 -1
- package/dist/storage/domains/integrations/base.js +1 -2
- package/dist/storage/domains/memory-settings/base.js +1 -2
- package/dist/storage/domains/model-defaults/base.js +1 -2
- package/dist/storage/domains/projects/base.d.ts +0 -1
- package/dist/storage/domains/projects/base.d.ts.map +1 -1
- package/dist/storage/domains/projects/base.js +5 -6
- package/dist/storage/domains/projects/base.js.map +1 -1
- package/dist/storage/domains/queue-health/base.js +1 -2
- package/dist/storage/domains/source-control/base.js +1 -2
- package/dist/storage/domains/source-control/inmemory.js +1 -2
- package/dist/storage/domains/work-items/base.js +1 -2
- package/dist/storage/domains/work-items/board-version.js +1 -2
- package/dist/storage/domains/work-items/metrics.js +1 -2
- package/dist/telemetry-types.js +1 -2
- package/dist/telemetry.js +1 -2
- package/dist/timing.js +1 -2
- package/dist/tools/annotations.js +1 -2
- package/dist/tools/approval-tools.js +1 -2
- package/dist/tools/deliver.js +2 -3
- package/dist/tools/index.js +1 -2
- package/dist/tools/messaging-tools.js +1 -2
- package/dist/tools/permissions.js +1 -2
- package/dist/tools/read-tools.js +1 -2
- package/dist/tools/reports.js +1 -2
- package/dist/tools/run-watch.d.ts +0 -2
- package/dist/tools/run-watch.d.ts.map +1 -1
- package/dist/tools/run-watch.js +4 -44
- package/dist/tools/run-watch.js.map +1 -1
- package/dist/tools/sandbox-tools.js +1 -2
- package/dist/tools/scope.js +2 -3
- package/dist/tools/session-tools.js +1 -2
- package/dist/tools/sessions-state-processor.js +1 -2
- package/dist/tools/side-sessions.js +1 -2
- package/dist/tools/work-item-tools.js +1 -2
- package/dist/work-item-branch.js +1 -2
- package/dist/work-item-branch.js.map +1 -1
- package/dist/work-items/create-work-item.js +1 -2
- package/dist/work-items/decision-actions.js +1 -2
- package/dist/workspace.d.ts.map +1 -1
- package/dist/workspace.js +1 -3
- package/dist/workspace.js.map +1 -1
- package/factory-skills/factory-gitlab-review/SKILL.md +1 -1
- package/factory-skills/factory-plan/SKILL.md +1 -1
- package/factory-skills/factory-rereview/SKILL.md +14 -3
- package/factory-skills/factory-review/SKILL.md +14 -3
- package/factory-skills/factory-self-review/SKILL.md +1 -1
- package/factory-skills/factory-triage/SKILL.md +52 -29
- package/package.json +19 -17
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
|
|
1
|
+
// src/sandbox/materialization.ts
|
|
2
2
|
/**
|
|
3
3
|
* Narrow a sandbox to one that can run commands, or fail saying which
|
|
4
4
|
* capability is missing.
|
|
@@ -12,7 +12,6 @@ function requireExec(sandbox) {
|
|
|
12
12
|
if (typeof sandbox.executeCommand !== "function") throw new Error(`Sandbox provider '${sandbox.provider}' does not support executeCommand, which is required to run git and filesystem operations in a session.`);
|
|
13
13
|
return sandbox;
|
|
14
14
|
}
|
|
15
|
-
//#endregion
|
|
16
15
|
export { requireExec };
|
|
17
16
|
|
|
18
17
|
//# sourceMappingURL=materialization.js.map
|
|
@@ -3,7 +3,7 @@ import { requireExec } from "./materialization.js";
|
|
|
3
3
|
import { clearFailedSetupCommands, evictSessionSandbox, peekSessionSandbox } from "./session-sandbox.js";
|
|
4
4
|
import { peekSessionEnvironmentTeardown } from "../session/environment-state-processor.js";
|
|
5
5
|
import { destroyDetachedSessionSandbox, releaseSessionSandbox } from "../integrations/github/sandbox-release.js";
|
|
6
|
-
|
|
6
|
+
// src/sandbox/session-retirement.ts
|
|
7
7
|
const DEFAULT_DESTROY_TIMEOUT_MS = 3e4;
|
|
8
8
|
/**
|
|
9
9
|
* A provider error meaning the VM is already gone: 410, or a 404 the proxy
|
|
@@ -322,7 +322,6 @@ var SessionRetirementCoordinator = class {
|
|
|
322
322
|
}
|
|
323
323
|
}
|
|
324
324
|
};
|
|
325
|
-
//#endregion
|
|
326
325
|
export { SessionRetirementCoordinator };
|
|
327
326
|
|
|
328
327
|
//# sourceMappingURL=session-retirement.js.map
|
|
@@ -2,7 +2,7 @@ import { timedPhase } from "../timing.js";
|
|
|
2
2
|
import { SETUP_FAILED_MARKER_PATH, SETUP_MARKER_PATH, WORKSPACE_SETUP_MARKER_PATH, repoSetupMarkerPath, setupMarkerContent } from "../packages/_internals/workspace/dist/index.js";
|
|
3
3
|
import { deriveLocalWorkdir, deriveRemoteRepoDir, repoDirUnder, repositoryDirectoryName } from "./workdir.js";
|
|
4
4
|
import path from "path";
|
|
5
|
-
|
|
5
|
+
// src/sandbox/session-sandbox.ts
|
|
6
6
|
const sessionSandboxes = /* @__PURE__ */ new Map();
|
|
7
7
|
/** The layout of a memoized session, `undefined` until its workdir resolved. */
|
|
8
8
|
function sessionLayout(entry) {
|
|
@@ -246,7 +246,6 @@ function createEnvironmentSetupHook(run, sessionId, repoFullName, environment) {
|
|
|
246
246
|
});
|
|
247
247
|
};
|
|
248
248
|
}
|
|
249
|
-
//#endregion
|
|
250
249
|
export { __clearSessionSandboxesForTests, clearFailedSetupCommands, createEnvironmentSetupHook, createSessionSetupHook, evictSessionSandbox, getSessionSandbox, hasFailedSetupCommand, peekSessionSandbox, recordFailedSetupCommand, resolveSessionWorkdir, sessionLayout };
|
|
251
250
|
|
|
252
251
|
//# sourceMappingURL=session-sandbox.js.map
|
package/dist/sandbox/workdir.js
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import * as path$1 from "path";
|
|
2
|
-
|
|
2
|
+
// src/sandbox/workdir.ts
|
|
3
3
|
/**
|
|
4
4
|
* Session workdir derivation. Workdirs are never persisted or trusted from
|
|
5
5
|
* storage or client input — the stale-workdir class of production bugs came
|
|
@@ -58,7 +58,6 @@ function resolveContainedLocalWorkdir(root, ...segments) {
|
|
|
58
58
|
if (resolved !== resolvedRoot && resolved.startsWith(`${resolvedRoot}${path$1.sep}`)) return resolved;
|
|
59
59
|
throw new Error(`Refusing to use local sandbox path outside configured root: ${resolved}`);
|
|
60
60
|
}
|
|
61
|
-
//#endregion
|
|
62
61
|
export { deriveLocalWorkdir, deriveRemoteRepoDir, repoDirUnder, repositoryDirectoryName, resolveContainedLocalWorkdir, sanitizeSegment };
|
|
63
62
|
|
|
64
63
|
//# sourceMappingURL=workdir.js.map
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { createCipheriv, createDecipheriv } from "crypto";
|
|
2
|
-
|
|
2
|
+
// src/secret-encryption.ts
|
|
3
3
|
const ENVELOPE_PREFIX = "mastra:factory-secret:v1:";
|
|
4
4
|
const ALGORITHM = "aes-256-gcm";
|
|
5
5
|
const IV_BYTES = 12;
|
|
@@ -141,7 +141,6 @@ function createPlaintextFactorySecretEncryption() {
|
|
|
141
141
|
}
|
|
142
142
|
};
|
|
143
143
|
}
|
|
144
|
-
//#endregion
|
|
145
144
|
export { createFactorySecretEncryption, createPlaintextFactorySecretEncryption };
|
|
146
145
|
|
|
147
146
|
//# sourceMappingURL=secret-encryption.js.map
|
package/dist/server-error.js
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { HTTPException } from "hono/http-exception";
|
|
2
|
-
|
|
2
|
+
// src/server-error.ts
|
|
3
3
|
/** Handle a route error: log full detail server-side, return structured JSON. */
|
|
4
4
|
function handleServerError(err, c) {
|
|
5
5
|
if (err instanceof HTTPException) return c.json({ error: err.message }, err.status);
|
|
@@ -10,7 +10,6 @@ function handleServerError(err, c) {
|
|
|
10
10
|
message: err instanceof Error ? err.message : String(err)
|
|
11
11
|
}, 500);
|
|
12
12
|
}
|
|
13
|
-
//#endregion
|
|
14
13
|
export { handleServerError };
|
|
15
14
|
|
|
16
15
|
//# sourceMappingURL=server-error.js.map
|
|
@@ -2,7 +2,7 @@ import { tenantOrgId } from "../routes/provider-credentials.js";
|
|
|
2
2
|
import { effectiveModelScope } from "../storage/domains/projects/base.js";
|
|
3
3
|
import { UUID_PATTERN } from "../routes/contracts.js";
|
|
4
4
|
import { resolveAuthenticatedCredentialTenant } from "@mastra/code-sdk/agents/credential-resolver";
|
|
5
|
-
|
|
5
|
+
// src/session/credential-policy.ts
|
|
6
6
|
const FACTORY_PROJECT_ID = new RegExp(UUID_PATTERN);
|
|
7
7
|
/** Resolve billing authority from authenticated identity and durable bindings, never session state. */
|
|
8
8
|
async function resolveFactoryCredentialTenant(requestContext, deps) {
|
|
@@ -60,7 +60,6 @@ async function routedPersonalDefaults(tenant, modelDefaults) {
|
|
|
60
60
|
userId: tenant.userId
|
|
61
61
|
});
|
|
62
62
|
}
|
|
63
|
-
//#endregion
|
|
64
63
|
export { resolveFactoryCredentialTenant, resolveFactoryModelPolicy, routedPersonalDefaults };
|
|
65
64
|
|
|
66
65
|
//# sourceMappingURL=credential-policy.js.map
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { primeTenantCredentialsForTenant, resolveTenantProviderDefaultModel } from "../routes/tenant-credentials.js";
|
|
2
2
|
import { effectiveModelScope } from "../storage/domains/projects/base.js";
|
|
3
|
-
|
|
3
|
+
// src/session/default-model-hydration.ts
|
|
4
4
|
async function applyDefaultModel(session, modelId) {
|
|
5
5
|
await session.model.switch(modelId);
|
|
6
6
|
for (const agentType of [
|
|
@@ -86,7 +86,6 @@ async function hydrateSessionDefaultModel(session, { sourceControl, projects, wo
|
|
|
86
86
|
console.warn("[Factory default-model hydration] Unable to apply the scoped default model.", error);
|
|
87
87
|
}
|
|
88
88
|
}
|
|
89
|
-
//#endregion
|
|
90
89
|
export { hydrateSessionDefaultModel };
|
|
91
90
|
|
|
92
91
|
//# sourceMappingURL=default-model-hydration.js.map
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
|
|
1
|
+
// src/session/environment-repositories.ts
|
|
2
2
|
/**
|
|
3
3
|
* The `inEnvironment` links of a factory in position order, resolved to their
|
|
4
4
|
* repository and connection rows, for the integration the handle belongs to.
|
|
@@ -83,7 +83,6 @@ function findEnvironmentRepository(repositories, slug) {
|
|
|
83
83
|
function environmentSlugs(repositories) {
|
|
84
84
|
return repositories.map((candidate) => candidate.repository.slug);
|
|
85
85
|
}
|
|
86
|
-
//#endregion
|
|
87
86
|
export { environmentSlugs, findEnvironmentRepository, resolveEnvironmentRepositories, resolveSessionRepositories };
|
|
88
87
|
|
|
89
88
|
//# sourceMappingURL=environment-repositories.js.map
|
|
@@ -8,7 +8,6 @@ export interface SessionEnvironmentRepositoryState {
|
|
|
8
8
|
/** The branch the checkout ended on after boot; `null` when it stays detached. */
|
|
9
9
|
branch: string | null;
|
|
10
10
|
defaultBranch: string;
|
|
11
|
-
position: number;
|
|
12
11
|
/** `ok` ran or was already set up, `failed` exited non-zero, `skipped` has no setup command. */
|
|
13
12
|
setupStatus: EnvironmentRepositorySetupStatus;
|
|
14
13
|
/** The change request this session opened in the repository, once it has. */
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"environment-state-processor.d.ts","sourceRoot":"","sources":["../../src/session/environment-state-processor.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,sBAAsB,EAAE,wBAAwB,EAAE,SAAS,EAAE,MAAM,yBAAyB,CAAC;AAK3G,MAAM,MAAM,gCAAgC,GAAG,IAAI,GAAG,QAAQ,GAAG,SAAS,CAAC;AAE3E,4GAA4G;AAC5G,MAAM,WAAW,iCAAiC;IAChD,IAAI,EAAE,MAAM,CAAC;IACb,mEAAmE;IACnE,GAAG,EAAE,MAAM,CAAC;IACZ,kFAAkF;IAClF,MAAM,EAAE,MAAM,GAAG,IAAI,CAAC;IACtB,aAAa,EAAE,MAAM,CAAC;IACtB,
|
|
1
|
+
{"version":3,"file":"environment-state-processor.d.ts","sourceRoot":"","sources":["../../src/session/environment-state-processor.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,sBAAsB,EAAE,wBAAwB,EAAE,SAAS,EAAE,MAAM,yBAAyB,CAAC;AAK3G,MAAM,MAAM,gCAAgC,GAAG,IAAI,GAAG,QAAQ,GAAG,SAAS,CAAC;AAE3E,4GAA4G;AAC5G,MAAM,WAAW,iCAAiC;IAChD,IAAI,EAAE,MAAM,CAAC;IACb,mEAAmE;IACnE,GAAG,EAAE,MAAM,CAAC;IACZ,kFAAkF;IAClF,MAAM,EAAE,MAAM,GAAG,IAAI,CAAC;IACtB,aAAa,EAAE,MAAM,CAAC;IACtB,gGAAgG;IAChG,WAAW,EAAE,gCAAgC,CAAC;IAC9C,6EAA6E;IAC7E,gBAAgB,CAAC,EAAE,MAAM,CAAC;CAC3B;AAED,MAAM,WAAW,uBAAuB;IACtC,wFAAwF;IACxF,gBAAgB,EAAE,MAAM,CAAC;IACzB,YAAY,EAAE,iCAAiC,EAAE,CAAC;IAClD,+FAA+F;IAC/F,IAAI,CAAC,EAAE,MAAM,CAAC;CACf;AAQD,2GAA2G;AAC3G,MAAM,WAAW,0BAA0B;IACzC,IAAI,EAAE,MAAM,CAAC;IACb,GAAG,EAAE,MAAM,CAAC;IACZ,OAAO,EAAE,MAAM,CAAC;CACjB;AAED,wBAAgB,wBAAwB,CACtC,SAAS,EAAE,MAAM,EACjB,KAAK,EAAE,uBAAuB,EAC9B,QAAQ,GAAE,0BAA0B,EAAO,GAC1C,IAAI,CAEN;AAED;;;;;GAKG;AACH,wBAAgB,kCAAkC,CAChD,SAAS,EAAE,MAAM,EACjB,IAAI,EAAE,MAAM,EACZ,KAAK,EAAE;IAAE,MAAM,CAAC,EAAE,MAAM,CAAC;IAAC,gBAAgB,CAAC,EAAE,MAAM,CAAA;CAAE,GACpD,IAAI,CAaN;AAED,wGAAwG;AACxG,wBAAgB,yBAAyB,CAAC,SAAS,EAAE,MAAM,EAAE,IAAI,EAAE,MAAM,GAAG,IAAI,GAAG,IAAI,CAKtF;AAED,wBAAgB,uBAAuB,CAAC,SAAS,EAAE,MAAM,GAAG,IAAI,CAE/D;AAED,wBAAgB,sBAAsB,CAAC,SAAS,EAAE,MAAM,GAAG,uBAAuB,GAAG,SAAS,CAE7F;AAED,sEAAsE;AACtE,wBAAgB,8BAA8B,CAAC,SAAS,EAAE,MAAM,GAAG,0BAA0B,EAAE,CAE9F;AAED,wBAAgB,kCAAkC,IAAI,IAAI,CAEzD;AAmBD;;;;;GAKG;AACH,qBAAa,gCAAiC,YAAW,SAAS,CAAC,qBAAqB,CAAC;IACvF,QAAQ,CAAC,EAAE,yBAAY;IACvB,QAAQ,CAAC,OAAO,yBAAY;IAEtB,kBAAkB,CAAC,IAAI,EAAE,sBAAsB,GAAG,OAAO,CAAC,wBAAwB,CAAC;CAiC1F"}
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { createHash } from "crypto";
|
|
2
|
-
|
|
2
|
+
// src/session/environment-state-processor.ts
|
|
3
3
|
const STATE_ID = "factory-environment";
|
|
4
4
|
const environments = /* @__PURE__ */ new Map();
|
|
5
5
|
function recordSessionEnvironment(sessionId, state, teardown = []) {
|
|
@@ -81,7 +81,7 @@ var FactoryEnvironmentStateProcessor = class {
|
|
|
81
81
|
if (!state) return;
|
|
82
82
|
const cacheKey = environmentCacheKey(state);
|
|
83
83
|
if (Boolean(args.lastSnapshot) && args.contextWindow.hasSnapshot && (args.tracking?.currentCacheKey ?? args.lastSnapshot?.metadata?.state?.cacheKey) === cacheKey) return;
|
|
84
|
-
const lines = state.repositories.map((repo) => `${
|
|
84
|
+
const lines = state.repositories.map((repo, index) => `${index + 1}. ${escapeText(repo.slug)} at ${escapeText(repo.dir)} on ${escapeText(repo.branch ?? "(detached)")} (default ${escapeText(repo.defaultBranch)}, setup ${repo.setupStatus})` + (repo.changeRequestUrl ? `, change request ${escapeText(repo.changeRequestUrl)}` : ""));
|
|
85
85
|
const only = state.repositories.length === 1 ? state.repositories[0] : void 0;
|
|
86
86
|
const contents = (only ? `Factory environment: 1 repository, ${escapeText(only.slug)} at ${escapeText(only.dir)}, your working directory.\n` : `Factory environment: ${state.repositories.length} repositories under ${escapeText(state.workingDirectory)}, your working directory.\n`) + lines.join("\n") + (only ? "" : "\nRun git and project commands inside the repository directory they belong to.") + (state.note ? `\n${escapeText(state.note)}` : "");
|
|
87
87
|
return {
|
|
@@ -99,7 +99,6 @@ var FactoryEnvironmentStateProcessor = class {
|
|
|
99
99
|
};
|
|
100
100
|
}
|
|
101
101
|
};
|
|
102
|
-
//#endregion
|
|
103
102
|
export { FactoryEnvironmentStateProcessor, __clearSessionEnvironmentsForTests, clearSessionEnvironment, peekSessionEnvironment, peekSessionEnvironmentTeardown, recordSessionEnvironment, setSessionEnvironmentNote, updateSessionEnvironmentRepository };
|
|
104
103
|
|
|
105
104
|
//# sourceMappingURL=environment-state-processor.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"environment-state-processor.js","names":[],"sources":["../../src/session/environment-state-processor.ts"],"sourcesContent":["import { createHash } from 'node:crypto';\nimport type { ComputeStateSignalArgs, ComputeStateSignalResult, Processor } from '@mastra/core/processors';\nimport type { RequestContext } from '@mastra/core/request-context';\n\nconst STATE_ID = 'factory-environment';\n\nexport type EnvironmentRepositorySetupStatus = 'ok' | 'failed' | 'skipped';\n\n/** One repository of the booted environment as the agent is told about it: never a token or a clone URL. */\nexport interface SessionEnvironmentRepositoryState {\n slug: string;\n /** Absolute directory of the checkout under the workspace root. */\n dir: string;\n /** The branch the checkout ended on after boot; `null` when it stays detached. */\n branch: string | null;\n defaultBranch: string;\n
|
|
1
|
+
{"version":3,"file":"environment-state-processor.js","names":[],"sources":["../../src/session/environment-state-processor.ts"],"sourcesContent":["import { createHash } from 'node:crypto';\nimport type { ComputeStateSignalArgs, ComputeStateSignalResult, Processor } from '@mastra/core/processors';\nimport type { RequestContext } from '@mastra/core/request-context';\n\nconst STATE_ID = 'factory-environment';\n\nexport type EnvironmentRepositorySetupStatus = 'ok' | 'failed' | 'skipped';\n\n/** One repository of the booted environment as the agent is told about it: never a token or a clone URL. */\nexport interface SessionEnvironmentRepositoryState {\n slug: string;\n /** Absolute directory of the checkout under the workspace root. */\n dir: string;\n /** The branch the checkout ended on after boot; `null` when it stays detached. */\n branch: string | null;\n defaultBranch: string;\n /** `ok` ran or was already set up, `failed` exited non-zero, `skipped` has no setup command. */\n setupStatus: EnvironmentRepositorySetupStatus;\n /** The change request this session opened in the repository, once it has. */\n changeRequestUrl?: string;\n}\n\nexport interface SessionEnvironmentState {\n /** The workspace root, the session's working directory; repositories sit beneath it. */\n workingDirectory: string;\n repositories: SessionEnvironmentRepositoryState[];\n /** One free-form line the boot wants the agent to know (never a credential), rendered last. */\n note?: string;\n}\n\n// The boot records what it materialized, keyed by the factory session id (the\n// agent's resource id); the processor reads it on the next model step. Boot\n// runs on every sandbox start, so a replacement process re-learns the state\n// the first time the session's sandbox starts again.\nconst environments = new Map<string, { state: SessionEnvironmentState; teardown: SessionEnvironmentTeardown[] }>();\n\n/** A repository's teardown command and the directory it runs in; kept beside the state, never rendered. */\nexport interface SessionEnvironmentTeardown {\n slug: string;\n dir: string;\n command: string;\n}\n\nexport function recordSessionEnvironment(\n sessionId: string,\n state: SessionEnvironmentState,\n teardown: SessionEnvironmentTeardown[] = [],\n): void {\n environments.set(sessionId, { state, teardown });\n}\n\n/**\n * Record what a source-control tool did in one environment repository (the\n * branch it pushed, the change request it opened) so the next signal snapshot\n * tells the agent. A no-op when the session's environment is not recorded in\n * this process or the slug is not part of it.\n */\nexport function updateSessionEnvironmentRepository(\n sessionId: string,\n slug: string,\n patch: { branch?: string; changeRequestUrl?: string },\n): void {\n const entry = environments.get(sessionId);\n if (!entry) return;\n const wanted = slug.toLowerCase();\n const repositories = entry.state.repositories.map(repo => {\n if (repo.slug.toLowerCase() !== wanted) return repo;\n return {\n ...repo,\n ...(patch.branch !== undefined ? { branch: patch.branch } : {}),\n ...(patch.changeRequestUrl !== undefined ? { changeRequestUrl: patch.changeRequestUrl } : {}),\n };\n });\n entry.state = { ...entry.state, repositories };\n}\n\n/** Set or clear the environment's note; a no-op when the session's environment is not recorded here. */\nexport function setSessionEnvironmentNote(sessionId: string, note: string | null): void {\n const entry = environments.get(sessionId);\n if (!entry) return;\n const { note: _previous, ...rest } = entry.state;\n entry.state = note ? { ...rest, note } : rest;\n}\n\nexport function clearSessionEnvironment(sessionId: string): void {\n environments.delete(sessionId);\n}\n\nexport function peekSessionEnvironment(sessionId: string): SessionEnvironmentState | undefined {\n return environments.get(sessionId)?.state;\n}\n\n/** Teardown commands of the booted environment, in position order. */\nexport function peekSessionEnvironmentTeardown(sessionId: string): SessionEnvironmentTeardown[] {\n return environments.get(sessionId)?.teardown ?? [];\n}\n\nexport function __clearSessionEnvironmentsForTests(): void {\n environments.clear();\n}\n\nfunction escapeText(value: string): string {\n return value.replaceAll('&', '&').replaceAll('<', '<').replaceAll('>', '>');\n}\n\n// Unlike factory runs, a user session carries no `factoryProjectId` in its\n// controller state, and the environment is recorded for both, so only the\n// session id is required.\nfunction sessionIdFromContext(requestContext: RequestContext | undefined): string | null {\n if (!requestContext || typeof requestContext.get !== 'function') return null;\n const controller = requestContext.get('controller') as { sessionId?: unknown } | undefined;\n return typeof controller?.sessionId === 'string' && controller.sessionId ? controller.sessionId : null;\n}\n\nfunction environmentCacheKey(state: SessionEnvironmentState): string {\n return `environment:${createHash('sha256').update(JSON.stringify(state)).digest('hex').slice(0, 16)}`;\n}\n\n/**\n * Tells the agent which repositories its sandbox holds and where: the\n * workspace root is the session's working directory and every environment\n * repository is a directory beneath it. Snapshot mode only; a new snapshot\n * is emitted when the booted set changes (a start after an environment edit).\n */\nexport class FactoryEnvironmentStateProcessor implements Processor<'factory-environment'> {\n readonly id = STATE_ID;\n readonly stateId = STATE_ID;\n\n async computeStateSignal(args: ComputeStateSignalArgs): Promise<ComputeStateSignalResult> {\n const sessionId = sessionIdFromContext(args.requestContext);\n if (!sessionId) return;\n const state = environments.get(sessionId)?.state;\n if (!state) return;\n const cacheKey = environmentCacheKey(state);\n const hasBase = Boolean(args.lastSnapshot) && args.contextWindow.hasSnapshot;\n if (hasBase && (args.tracking?.currentCacheKey ?? args.lastSnapshot?.metadata?.state?.cacheKey) === cacheKey)\n return;\n const lines = state.repositories.map(\n (repo, index) =>\n `${index + 1}. ${escapeText(repo.slug)} at ${escapeText(repo.dir)} on ${escapeText(repo.branch ?? '(detached)')} (default ${escapeText(repo.defaultBranch)}, setup ${repo.setupStatus})` +\n (repo.changeRequestUrl ? `, change request ${escapeText(repo.changeRequestUrl)}` : ''),\n );\n const only = state.repositories.length === 1 ? state.repositories[0] : undefined;\n const contents =\n (only\n ? `Factory environment: 1 repository, ${escapeText(only.slug)} at ${escapeText(only.dir)}, your working directory.\\n`\n : `Factory environment: ${state.repositories.length} repositories under ${escapeText(state.workingDirectory)}, your working directory.\\n`) +\n lines.join('\\n') +\n (only ? '' : '\\nRun git and project commands inside the repository directory they belong to.') +\n (state.note ? `\\n${escapeText(state.note)}` : '');\n return {\n id: STATE_ID,\n cacheKey,\n mode: 'snapshot',\n tagName: 'factory-environment',\n contents,\n value: { environment: state },\n attributes: { workingDirectory: only?.dir ?? state.workingDirectory, repositories: state.repositories.length },\n metadata: { value: { environment: state } },\n };\n }\n}\n"],"mappings":";;AAIA,MAAM,WAAW;AA8BjB,MAAM,+BAAe,IAAI,IAAwF;AASjH,SAAgB,yBACd,WACA,OACA,WAAyC,CAAC,GACpC;CACN,aAAa,IAAI,WAAW;EAAE;EAAO;CAAS,CAAC;AACjD;;;;;;;AAQA,SAAgB,mCACd,WACA,MACA,OACM;CACN,MAAM,QAAQ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AO,MAAM;IAAkB,cAAc,MAAM,aAAa;GAAO;GAC7G,UAAU,EAAE,OAAO,EAAE,aAAa,MAAM,EAAE;EAC5C;CACF;AACF"}
|
|
@@ -4,7 +4,7 @@ import { resolveTenantProviderDefaultModel } from "../routes/tenant-credentials.
|
|
|
4
4
|
import { seedSessionOrg } from "./org-seed.js";
|
|
5
5
|
import { effectiveModelScope } from "../storage/domains/projects/base.js";
|
|
6
6
|
import { SourceControlConnectionNotFoundError } from "../storage/domains/source-control/base.js";
|
|
7
|
-
|
|
7
|
+
// src/session/factory-session.ts
|
|
8
8
|
var FactorySourceControlConflictError = class extends Error {};
|
|
9
9
|
/** Resolve the model and exclusive credential scope for a Factory session. */
|
|
10
10
|
async function resolveFactorySessionModel(args) {
|
|
@@ -250,7 +250,6 @@ async function hydrateFactorySession(session, args) {
|
|
|
250
250
|
}
|
|
251
251
|
return switched ? selectedModelId : void 0;
|
|
252
252
|
}
|
|
253
|
-
//#endregion
|
|
254
253
|
export { FactorySourceControlConflictError, FactorySourceSessionResolutionError, createSourceControlSessionLookup, ensureFactorySourceSession, hydrateFactorySession, resolveFactorySessionModel, resolveFactorySourceControl, resolvePrimaryEnvironmentRepository };
|
|
255
254
|
|
|
256
255
|
//# sourceMappingURL=factory-session.js.map
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import { peekSessionSandbox, sessionLayout } from "../sandbox/session-sandbox.js";
|
|
2
2
|
import { peekSessionEnvironment } from "./environment-state-processor.js";
|
|
3
3
|
import { isMeaningfulToolName } from "./first-exec-capture.js";
|
|
4
|
-
|
|
4
|
+
// src/session/filesystem-capture.ts
|
|
5
5
|
/** Exit code of `GIT_CHANGED_FILES_SCRIPT` when the checkout is not there: the repository is skipped, not failed. */
|
|
6
6
|
const CHECKOUT_MISSING_EXIT_CODE = 3;
|
|
7
7
|
const GIT_CHANGED_FILES_SCRIPT = `
|
|
@@ -189,7 +189,7 @@ function observeSessionFilesystem(session, dependencies) {
|
|
|
189
189
|
suspended.delete(event.toolCallId);
|
|
190
190
|
if (event.isError || event.denied) return;
|
|
191
191
|
if (isMeaningfulToolName(toolName)) workspaceTouched = true;
|
|
192
|
-
|
|
192
|
+
break;
|
|
193
193
|
}
|
|
194
194
|
}
|
|
195
195
|
});
|
|
@@ -224,7 +224,6 @@ function observeSessionFilesystem(session, dependencies) {
|
|
|
224
224
|
unsubscribeEnd();
|
|
225
225
|
};
|
|
226
226
|
}
|
|
227
|
-
//#endregion
|
|
228
227
|
export { ROOT_FILES_LIST_COMMAND, captureSessionFilesystem, observeSessionFilesystem, parseFilesystemCaptureFiles, touchStamp, waitForPendingFilesystemCapture };
|
|
229
228
|
|
|
230
229
|
//# sourceMappingURL=filesystem-capture.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"filesystem-capture.js","names":[],"sources":["../../src/session/filesystem-capture.ts"],"sourcesContent":["import type { AgentControllerEvent, SessionBeforeAgentEndListener } from '@mastra/core/agent-controller';\nimport type { WorkspaceSandbox } from '@mastra/core/workspace';\nimport { peekSessionSandbox, sessionLayout } from '../sandbox/session-sandbox.js';\nimport type { SessionLayoutRepository } from '../sandbox/session-sandbox.js';\n\nimport type { FilesystemFile, FilesystemStorage } from '../storage/domains/filesystem/base.js';\nimport type { SourceControlStorageHandle } from '../storage/domains/source-control/base.js';\nimport { peekSessionEnvironment } from './environment-state-processor.js';\nimport { isMeaningfulToolName } from './first-exec-capture.js';\n\n/** Exit code of `GIT_CHANGED_FILES_SCRIPT` when the checkout is not there: the repository is skipped, not failed. */\nconst CHECKOUT_MISSING_EXIT_CODE = 3;\nconst GIT_CHANGED_FILES_SCRIPT = `\nset -e\nworkdir=$1\nbase_branch=$2\ntest -d \"$workdir\" || exit ${CHECKOUT_MISSING_EXIT_CODE}\nbase=HEAD\nif merge_base=$(git -C \"$workdir\" merge-base HEAD \"origin/$base_branch\" 2>/dev/null); then\n base=$merge_base\nfi\ngit -C \"$workdir\" diff --name-only -z --find-renames --diff-filter=ACMRTUXB \"$base\"\ngit -C \"$workdir\" ls-files --others --exclude-standard -z\n`;\nconst ARTIFACTS_LIST_COMMAND = 'cd \"$1\" && test -d .artifacts && find .artifacts -type f -print0 || true';\n/**\n * Regular files directly under the workspace root written since the session\n * was created ($2 is a UTC `touch -t` stamp, `YYYYMMDDhhmm.SS`), such as the\n * agent's notes. Files the template shipped with predate the session and stay\n * out; the checkouts are covered by git. Dotfiles are never listed: a listed\n * path becomes readable through the thread's file route, and the root is where\n * setup leaves `.env`, `.pgpass`, `.netrc` and other credential files.\n * `touch -t` plus `-newer` works on GNU and BSD find alike; `-newermt\n * \"@epoch\"` is GNU only.\n */\nexport const ROOT_FILES_LIST_COMMAND = [\n 'cd \"$1\" && ref=$(mktemp) && TZ=UTC touch -t \"$2\" \"$ref\"',\n '&& find . -mindepth 1 -maxdepth 1 -type f ! -name \\'.*\\' -newer \"$ref\" -print0',\n '; status=$?; rm -f \"$ref\"; exit $status',\n].join(' ');\n\n/** `touch -t` stamp of a moment, in UTC. */\nexport function touchStamp(date: Date): string {\n const two = (value: number) => String(value).padStart(2, '0');\n return (\n `${date.getUTCFullYear()}${two(date.getUTCMonth() + 1)}${two(date.getUTCDate())}` +\n `${two(date.getUTCHours())}${two(date.getUTCMinutes())}.${two(date.getUTCSeconds())}`\n );\n}\n\nexport interface FilesystemCaptureSession {\n readonly identity: { getId(): string };\n readonly thread: { requireId(): string };\n getWorkspace(): { sandbox?: Pick<WorkspaceSandbox, 'executeCommand'> } | undefined;\n onBeforeAgentEnd(listener: SessionBeforeAgentEndListener): () => void;\n subscribe(listener: (event: AgentControllerEvent) => void): () => void;\n}\n\nexport interface FilesystemCaptureDependencies {\n filesystem: Pick<FilesystemStorage, 'replaceFiles'>;\n sourceControl: {\n sessions: Pick<SourceControlStorageHandle['sessions'], 'getBySessionId'>;\n };\n}\n\nexport function parseFilesystemCaptureFiles(output: string): FilesystemFile[] {\n const files = new Map<string, FilesystemFile>();\n for (const record of output.split('\\0')) {\n if (!record) continue;\n const path = record.replace(/^\\.\\//, '');\n if (path) files.set(path, { path });\n }\n\n return [...files.values()].toSorted((a, b) => a.path.localeCompare(b.path));\n}\n\nexport async function captureSessionFilesystem(\n session: FilesystemCaptureSession,\n { filesystem, sourceControl }: FilesystemCaptureDependencies,\n ids?: { sessionId: string; threadId: string },\n): Promise<void> {\n try {\n // Scheduled captures pass ids read at schedule time: a session deleted\n // before the queued capture runs has already cleared its thread.\n const sessionId = ids?.sessionId ?? session.identity.getId();\n const threadId = ids?.threadId ?? session.thread.requireId();\n const sourceSession = await sourceControl.sessions.getBySessionId(sessionId);\n // Chat-only sessions run without a workspace; there is nothing to capture.\n const sandbox = session.getWorkspace()?.sandbox;\n if (!sourceSession || !sandbox?.executeCommand) return;\n // The live workdir comes from the per-process memo (the deterministic\n // truth) ONLY — never the persisted observability column, which a row\n // written under a previous provider can point at a workdir that no\n // longer exists (the stale-workdir incident class). No memo entry means\n // no live sandbox worth capturing in this replica; capture is\n // best-effort telemetry, so skip.\n const entry = peekSessionSandbox(sourceSession.id);\n if (!entry) return;\n // Telemetry must never provision a VM: executeCommand lazily starts the\n // sandbox via ensureRunning, so a chat turn that never touched the\n // workspace would otherwise boot (and clone into) a fresh VM just to\n // capture an empty git status. Only capture when the turn already has a\n // running sandbox.\n if (entry.sandbox.status !== 'running') return;\n // Running-but-unresolved should not happen (the start hook resolves the\n // workdir), but capture is best-effort: skip rather than guess.\n const layout = sessionLayout(entry);\n if (!layout) return;\n\n // One git pass per checkout, in parallel so three repositories stay well\n // inside the 10 s readers wait for a pending capture. The session's own\n // repository compares against the session base branch; the others sit on\n // their default branch and compare against that. A repository whose\n // checkout is missing (exit 3) is skipped: it has nothing to list and\n // must not block the others. Any other failure is treated as transient\n // and leaves the previous listing in place.\n const multiRepo = layout.repos.length > 1;\n const environment = multiRepo ? peekSessionEnvironment(sourceSession.sessionId) : undefined;\n const ownRepo = entry.ownRepo.toLowerCase();\n // The boot records the state at its end, after every setup command; until\n // then a secondary checkout compares against its own `origin/HEAD`.\n const baseBranchFor = (repo: SessionLayoutRepository): string => {\n if (repo.slug.toLowerCase() === ownRepo) return sourceSession.baseBranch;\n const state = environment?.repositories.find(\n candidate => candidate.slug.toLowerCase() === repo.slug.toLowerCase(),\n );\n return state?.defaultBranch ?? 'HEAD';\n };\n const targets = layout.repos.map(repo => ({ repo, baseBranch: baseBranchFor(repo) }));\n const executeCommand = sandbox.executeCommand.bind(sandbox);\n const results = await Promise.all(\n targets.map(({ repo, baseBranch }) =>\n executeCommand('sh', ['-c', GIT_CHANGED_FILES_SCRIPT, 'mastracode-changed-files', repo.dir, baseBranch], {\n timeout: 30_000,\n }),\n ),\n );\n const files = new Map<string, FilesystemFile>();\n let captured = 0;\n for (const [index, result] of results.entries()) {\n if (result.exitCode === CHECKOUT_MISSING_EXIT_CODE) continue;\n if (result.exitCode !== 0) {\n console.warn('[Factory filesystem capture] Unable to inspect Git changes.', result.stderr);\n return;\n }\n captured += 1;\n const prefix = targets[index]!.repo.prefix;\n for (const file of parseFilesystemCaptureFiles(result.stdout)) {\n files.set(`${prefix}${file.path}`, { path: `${prefix}${file.path}` });\n }\n }\n if (captured === 0) return;\n\n const artifacts = await executeCommand('sh', ['-c', ARTIFACTS_LIST_COMMAND, 'sh', layout.root], {\n timeout: 30_000,\n });\n if (artifacts.exitCode !== 0) {\n console.warn('[Factory filesystem capture] Unable to list workspace artifacts.', artifacts.stderr);\n return;\n }\n for (const path of artifacts.stdout.split('\\0')) {\n const normalizedPath = path.replace(/^\\.\\//, '');\n if (normalizedPath) {\n files.set(normalizedPath, { path: normalizedPath });\n }\n }\n\n // With several checkouts the root is a plain directory nothing else lists.\n // A failed listing is logged and the git and artifact results still land.\n if (multiRepo) {\n const since = touchStamp(sourceSession.createdAt);\n const rootFiles = await executeCommand('sh', ['-c', ROOT_FILES_LIST_COMMAND, 'sh', layout.root, since], {\n timeout: 30_000,\n });\n if (rootFiles.exitCode !== 0) {\n console.warn('[Factory filesystem capture] Unable to list workspace root files.', rootFiles.stderr);\n } else {\n for (const path of rootFiles.stdout.split('\\0')) {\n const normalizedPath = path.replace(/^\\.\\//, '');\n if (normalizedPath && !normalizedPath.startsWith('.')) {\n files.set(normalizedPath, { path: normalizedPath });\n }\n }\n }\n }\n\n // The listing describes the session's workspace, not its memory resource,\n // which the session shares with others: rows are keyed by the session id.\n await filesystem.replaceFiles({\n resourceId: sessionId,\n threadId,\n files: [...files.values()].toSorted((a, b) => a.path.localeCompare(b.path)),\n });\n } catch (error) {\n console.warn('[Factory filesystem capture] Unable to persist files.', error);\n }\n}\n\n/**\n * In-flight capture chains keyed by session id. Serves two purposes: readers\n * of the persisted file listing (the /web/workspace routes) await the capture\n * for the turn that just ended instead of racing it, and captures for the same\n * session stay sequential (last write wins). In-process only: the factory\n * server that runs the session controller also serves those routes.\n */\nconst pendingCaptures = new Map<string, Promise<void>>();\n\n/**\n * Resolve once the session's in-flight filesystem capture (if any) has\n * persisted, or after `timeoutMs` so a reader that arrives mid-capture is\n * never blocked by the execs' worst-case 30s timeouts. Never rejects: the\n * capture body is fully try/catch contained.\n */\nexport async function waitForPendingFilesystemCapture(sessionId: string, timeoutMs = 10_000): Promise<void> {\n let pending = pendingCaptures.get(sessionId);\n if (!pending) return;\n let timer: ReturnType<typeof setTimeout> | undefined;\n let timedOut = false;\n const deadline = new Promise<void>(resolve => {\n timer = setTimeout(() => {\n timedOut = true;\n resolve();\n }, timeoutMs);\n });\n try {\n // A turn that ends while we wait chains a successor capture; keep waiting\n // until the latest chain settles so the final snapshot is not lost.\n while (pending && !timedOut) {\n await Promise.race([pending, deadline]);\n const next = pendingCaptures.get(sessionId);\n pending = next === pending ? undefined : next;\n }\n } finally {\n clearTimeout(timer);\n }\n}\n\nexport function observeSessionFilesystem(\n session: FilesystemCaptureSession,\n dependencies: FilesystemCaptureDependencies,\n): () => void {\n let fallbackChain = Promise.resolve();\n // Capture only runs after a turn that actually touched the workspace: a\n // successful workspace tool call both proves the sandbox is awake and is\n // the only way the listing can have changed. Without this gate every chat\n // turn would run two sandbox execs — and since executeCommand resumes an\n // idle VM, a pure-chat turn would keep waking a sandbox it never used.\n // Same bookkeeping as first-exec capture: tool names resolve at tool_end\n // via the tool_start map, and suspended calls survive agent_end so a\n // resumed run's eventual completion still counts for that turn.\n let workspaceTouched = false;\n const toolNames = new Map<string, string>();\n const suspended = new Set<string>();\n const unsubscribeEvents = session.subscribe(event => {\n switch (event.type) {\n case 'tool_start': {\n toolNames.set(event.toolCallId, event.toolName);\n return;\n }\n case 'tool_suspended': {\n suspended.add(event.toolCallId);\n return;\n }\n case 'tool_suspension_cancelled': {\n toolNames.delete(event.toolCallId);\n suspended.delete(event.toolCallId);\n return;\n }\n case 'agent_end': {\n for (const id of toolNames.keys()) {\n if (!suspended.has(id)) toolNames.delete(id);\n }\n return;\n }\n case 'tool_end': {\n const toolName = toolNames.get(event.toolCallId);\n toolNames.delete(event.toolCallId);\n suspended.delete(event.toolCallId);\n if (event.isError || event.denied) return;\n if (isMeaningfulToolName(toolName)) workspaceTouched = true;\n return;\n }\n }\n });\n const unsubscribeEnd = session.onBeforeAgentEnd(() => {\n // onBeforeAgentEnd fires before agent_end is emitted, so every tool_end\n // of the finishing run has already been observed; read then reset.\n if (!workspaceTouched) return;\n workspaceTouched = false;\n // Chain so captures stay sequential (last write wins), but do NOT return\n // the chain: finishAgentRun awaits every listener before emitting\n // agent_end, and the capture's sandbox execs (git status + artifacts\n // find, 30s timeouts each) must not gate turn completion. Readers that\n // need the fresh listing await the pending capture through\n // waitForPendingFilesystemCapture instead. The un-returned chain cannot\n // leak an unhandled rejection: captureSessionFilesystem's entire body\n // runs inside its own try/catch, and disposal of this listener does not\n // cancel an in-flight chain, so a final turn's capture still persists.\n let sessionId: string;\n try {\n sessionId = session.identity.getId();\n } catch {\n // No identity means no route can address this session's listing; keep\n // a per-observer chain so captures still run sequentially.\n fallbackChain = fallbackChain.then(() => captureSessionFilesystem(session, dependencies));\n return;\n }\n let threadId: string;\n try {\n threadId = session.thread.requireId();\n } catch {\n return;\n }\n const ids = { sessionId, threadId };\n const chain = (pendingCaptures.get(sessionId) ?? Promise.resolve()).then(() =>\n captureSessionFilesystem(session, dependencies, ids),\n );\n pendingCaptures.set(sessionId, chain);\n void chain.finally(() => {\n if (pendingCaptures.get(sessionId) === chain) {\n pendingCaptures.delete(sessionId);\n }\n });\n });\n return () => {\n unsubscribeEvents();\n unsubscribeEnd();\n };\n}\n"],"mappings":";;;;;AAWA,MAAM,6BAA6B;AACnC,MAAM,2BAA2B;;;;6BAIJ,2BAA2B;;;;;;;;AAQxD,MAAM,yBAAyB;;;;;;;;;;;AAW/B,MAAa,0BAA0B;CACrC;CACA;CACA;AACF,CAAC,CAAC,KAAK,GAAG;;AAGV,SAAgB,WAAW,MAAoB;CAC7C,MAAM,OAAO,UAAkB,OAAO,KAAK,CAAC,CAAC,SAAS,GAAG,GAAG;CAC5D,OACE,GAAG,KAAK,eAAe,IAAI,IAAI,KAAK,YAAY,IAAI,CAAC,IAAI,IAAI,KAAK,WAAW,CAAC,IAC3E,IAAI,KAAK,YAAY,CAAC,IAAI,IAAI,KAAK,cAAc,CAAC,EAAE,GAAG,IAAI,KAAK,cAAc,CAAC;AAEtF;AAiBA,SAAgB,4BAA4B,QAAkC;CAC5E,MAAM,wBAAQ,IAAI,IAA4B;CAC9C,KAAK,MAAM,UAAU,OAAO,MAAM,IAAI,GAAG;EACvC,IAAI,CAAC,QAAQ;EACb,MAAM,OAAO,OAAO,QAAQ,SAAS,EAAE;EACvC,IAAI,MAAM,MAAM,IAAI,MAAM,EAAE,KAAK,CAAC;CACpC;CAEA,OAAO,CAAC,GAAG,MAAM,OAAO,CAAC,CAAC,CAAC,UAAU,GAAG,MAAM,EAAE,KAAK,cAAc,EAAE,IAAI,CAAC;AAC5E;AAEA,eAAsB,yBACpB,SACA,EAAE,YAAY,iBACd,KACe;CACf,IAAI;EAGF,MAAM,YAAY,KAAK,aAAa,QAAQ,SAAS,MAAM;EAC3D,MAAM,WAAW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;EAGpD,IAAI,CAAC,kBAAkB;EACvB,mBAAmB;EAUnB,IAAI;EACJ,IAAI;GACF,YAAY,QAAQ,SAAS,MAAM;EACrC,QAAQ;GAGN,gBAAgB,cAAc,WAAW,yBAAyB,SAAS,YAAY,CAAC;GACxF;EACF;EACA,IAAI;EACJ,IAAI;GACF,WAAW,QAAQ,OAAO,UAAU;EACtC,QAAQ;GACN;EACF;EACA,MAAM,MAAM;GAAE;GAAW;EAAS;EAClC,MAAM,SAAS,gBAAgB,IAAI,SAAS,KAAK,QAAQ,QAAQ,EAAA,CAAG,WAClE,yBAAyB,SAAS,cAAc,GAAG,CACrD;EACA,gBAAgB,IAAI,WAAW,KAAK;EACpC,MAAW,cAAc;GACvB,IAAI,gBAAgB,IAAI,SAAS,MAAM,OACrC,gBAAgB,OAAO,SAAS;EAEpC,CAAC;CACH,CAAC;CACD,aAAa;EACX,kBAAkB;EAClB,eAAe;CACjB;AACF"}
|
|
1
|
+
{"version":3,"file":"filesystem-capture.js","names":[],"sources":["../../src/session/filesystem-capture.ts"],"sourcesContent":["import type { AgentControllerEvent, SessionBeforeAgentEndListener } from '@mastra/core/agent-controller';\nimport type { WorkspaceSandbox } from '@mastra/core/workspace';\nimport { peekSessionSandbox, sessionLayout } from '../sandbox/session-sandbox.js';\nimport type { SessionLayoutRepository } from '../sandbox/session-sandbox.js';\n\nimport type { FilesystemFile, FilesystemStorage } from '../storage/domains/filesystem/base.js';\nimport type { SourceControlStorageHandle } from '../storage/domains/source-control/base.js';\nimport { peekSessionEnvironment } from './environment-state-processor.js';\nimport { isMeaningfulToolName } from './first-exec-capture.js';\n\n/** Exit code of `GIT_CHANGED_FILES_SCRIPT` when the checkout is not there: the repository is skipped, not failed. */\nconst CHECKOUT_MISSING_EXIT_CODE = 3;\nconst GIT_CHANGED_FILES_SCRIPT = `\nset -e\nworkdir=$1\nbase_branch=$2\ntest -d \"$workdir\" || exit ${CHECKOUT_MISSING_EXIT_CODE}\nbase=HEAD\nif merge_base=$(git -C \"$workdir\" merge-base HEAD \"origin/$base_branch\" 2>/dev/null); then\n base=$merge_base\nfi\ngit -C \"$workdir\" diff --name-only -z --find-renames --diff-filter=ACMRTUXB \"$base\"\ngit -C \"$workdir\" ls-files --others --exclude-standard -z\n`;\nconst ARTIFACTS_LIST_COMMAND = 'cd \"$1\" && test -d .artifacts && find .artifacts -type f -print0 || true';\n/**\n * Regular files directly under the workspace root written since the session\n * was created ($2 is a UTC `touch -t` stamp, `YYYYMMDDhhmm.SS`), such as the\n * agent's notes. Files the template shipped with predate the session and stay\n * out; the checkouts are covered by git. Dotfiles are never listed: a listed\n * path becomes readable through the thread's file route, and the root is where\n * setup leaves `.env`, `.pgpass`, `.netrc` and other credential files.\n * `touch -t` plus `-newer` works on GNU and BSD find alike; `-newermt\n * \"@epoch\"` is GNU only.\n */\nexport const ROOT_FILES_LIST_COMMAND = [\n 'cd \"$1\" && ref=$(mktemp) && TZ=UTC touch -t \"$2\" \"$ref\"',\n '&& find . -mindepth 1 -maxdepth 1 -type f ! -name \\'.*\\' -newer \"$ref\" -print0',\n '; status=$?; rm -f \"$ref\"; exit $status',\n].join(' ');\n\n/** `touch -t` stamp of a moment, in UTC. */\nexport function touchStamp(date: Date): string {\n const two = (value: number) => String(value).padStart(2, '0');\n return (\n `${date.getUTCFullYear()}${two(date.getUTCMonth() + 1)}${two(date.getUTCDate())}` +\n `${two(date.getUTCHours())}${two(date.getUTCMinutes())}.${two(date.getUTCSeconds())}`\n );\n}\n\nexport interface FilesystemCaptureSession {\n readonly identity: { getId(): string };\n readonly thread: { requireId(): string };\n getWorkspace(): { sandbox?: Pick<WorkspaceSandbox, 'executeCommand'> } | undefined;\n onBeforeAgentEnd(listener: SessionBeforeAgentEndListener): () => void;\n subscribe(listener: (event: AgentControllerEvent) => void): () => void;\n}\n\nexport interface FilesystemCaptureDependencies {\n filesystem: Pick<FilesystemStorage, 'replaceFiles'>;\n sourceControl: {\n sessions: Pick<SourceControlStorageHandle['sessions'], 'getBySessionId'>;\n };\n}\n\nexport function parseFilesystemCaptureFiles(output: string): FilesystemFile[] {\n const files = new Map<string, FilesystemFile>();\n for (const record of output.split('\\0')) {\n if (!record) continue;\n const path = record.replace(/^\\.\\//, '');\n if (path) files.set(path, { path });\n }\n\n return [...files.values()].toSorted((a, b) => a.path.localeCompare(b.path));\n}\n\nexport async function captureSessionFilesystem(\n session: FilesystemCaptureSession,\n { filesystem, sourceControl }: FilesystemCaptureDependencies,\n ids?: { sessionId: string; threadId: string },\n): Promise<void> {\n try {\n // Scheduled captures pass ids read at schedule time: a session deleted\n // before the queued capture runs has already cleared its thread.\n const sessionId = ids?.sessionId ?? session.identity.getId();\n const threadId = ids?.threadId ?? session.thread.requireId();\n const sourceSession = await sourceControl.sessions.getBySessionId(sessionId);\n // Chat-only sessions run without a workspace; there is nothing to capture.\n const sandbox = session.getWorkspace()?.sandbox;\n if (!sourceSession || !sandbox?.executeCommand) return;\n // The live workdir comes from the per-process memo (the deterministic\n // truth) ONLY — never the persisted observability column, which a row\n // written under a previous provider can point at a workdir that no\n // longer exists (the stale-workdir incident class). No memo entry means\n // no live sandbox worth capturing in this replica; capture is\n // best-effort telemetry, so skip.\n const entry = peekSessionSandbox(sourceSession.id);\n if (!entry) return;\n // Telemetry must never provision a VM: executeCommand lazily starts the\n // sandbox via ensureRunning, so a chat turn that never touched the\n // workspace would otherwise boot (and clone into) a fresh VM just to\n // capture an empty git status. Only capture when the turn already has a\n // running sandbox.\n if (entry.sandbox.status !== 'running') return;\n // Running-but-unresolved should not happen (the start hook resolves the\n // workdir), but capture is best-effort: skip rather than guess.\n const layout = sessionLayout(entry);\n if (!layout) return;\n\n // One git pass per checkout, in parallel so three repositories stay well\n // inside the 10 s readers wait for a pending capture. The session's own\n // repository compares against the session base branch; the others sit on\n // their default branch and compare against that. A repository whose\n // checkout is missing (exit 3) is skipped: it has nothing to list and\n // must not block the others. Any other failure is treated as transient\n // and leaves the previous listing in place.\n const multiRepo = layout.repos.length > 1;\n const environment = multiRepo ? peekSessionEnvironment(sourceSession.sessionId) : undefined;\n const ownRepo = entry.ownRepo.toLowerCase();\n // The boot records the state at its end, after every setup command; until\n // then a secondary checkout compares against its own `origin/HEAD`.\n const baseBranchFor = (repo: SessionLayoutRepository): string => {\n if (repo.slug.toLowerCase() === ownRepo) return sourceSession.baseBranch;\n const state = environment?.repositories.find(\n candidate => candidate.slug.toLowerCase() === repo.slug.toLowerCase(),\n );\n return state?.defaultBranch ?? 'HEAD';\n };\n const targets = layout.repos.map(repo => ({ repo, baseBranch: baseBranchFor(repo) }));\n const executeCommand = sandbox.executeCommand.bind(sandbox);\n const results = await Promise.all(\n targets.map(({ repo, baseBranch }) =>\n executeCommand('sh', ['-c', GIT_CHANGED_FILES_SCRIPT, 'mastracode-changed-files', repo.dir, baseBranch], {\n timeout: 30_000,\n }),\n ),\n );\n const files = new Map<string, FilesystemFile>();\n let captured = 0;\n for (const [index, result] of results.entries()) {\n if (result.exitCode === CHECKOUT_MISSING_EXIT_CODE) continue;\n if (result.exitCode !== 0) {\n console.warn('[Factory filesystem capture] Unable to inspect Git changes.', result.stderr);\n return;\n }\n captured += 1;\n const prefix = targets[index]!.repo.prefix;\n for (const file of parseFilesystemCaptureFiles(result.stdout)) {\n files.set(`${prefix}${file.path}`, { path: `${prefix}${file.path}` });\n }\n }\n if (captured === 0) return;\n\n const artifacts = await executeCommand('sh', ['-c', ARTIFACTS_LIST_COMMAND, 'sh', layout.root], {\n timeout: 30_000,\n });\n if (artifacts.exitCode !== 0) {\n console.warn('[Factory filesystem capture] Unable to list workspace artifacts.', artifacts.stderr);\n return;\n }\n for (const path of artifacts.stdout.split('\\0')) {\n const normalizedPath = path.replace(/^\\.\\//, '');\n if (normalizedPath) {\n files.set(normalizedPath, { path: normalizedPath });\n }\n }\n\n // With several checkouts the root is a plain directory nothing else lists.\n // A failed listing is logged and the git and artifact results still land.\n if (multiRepo) {\n const since = touchStamp(sourceSession.createdAt);\n const rootFiles = await executeCommand('sh', ['-c', ROOT_FILES_LIST_COMMAND, 'sh', layout.root, since], {\n timeout: 30_000,\n });\n if (rootFiles.exitCode !== 0) {\n console.warn('[Factory filesystem capture] Unable to list workspace root files.', rootFiles.stderr);\n } else {\n for (const path of rootFiles.stdout.split('\\0')) {\n const normalizedPath = path.replace(/^\\.\\//, '');\n if (normalizedPath && !normalizedPath.startsWith('.')) {\n files.set(normalizedPath, { path: normalizedPath });\n }\n }\n }\n }\n\n // The listing describes the session's workspace, not its memory resource,\n // which the session shares with others: rows are keyed by the session id.\n await filesystem.replaceFiles({\n resourceId: sessionId,\n threadId,\n files: [...files.values()].toSorted((a, b) => a.path.localeCompare(b.path)),\n });\n } catch (error) {\n console.warn('[Factory filesystem capture] Unable to persist files.', error);\n }\n}\n\n/**\n * In-flight capture chains keyed by session id. Serves two purposes: readers\n * of the persisted file listing (the /web/workspace routes) await the capture\n * for the turn that just ended instead of racing it, and captures for the same\n * session stay sequential (last write wins). In-process only: the factory\n * server that runs the session controller also serves those routes.\n */\nconst pendingCaptures = new Map<string, Promise<void>>();\n\n/**\n * Resolve once the session's in-flight filesystem capture (if any) has\n * persisted, or after `timeoutMs` so a reader that arrives mid-capture is\n * never blocked by the execs' worst-case 30s timeouts. Never rejects: the\n * capture body is fully try/catch contained.\n */\nexport async function waitForPendingFilesystemCapture(sessionId: string, timeoutMs = 10_000): Promise<void> {\n let pending = pendingCaptures.get(sessionId);\n if (!pending) return;\n let timer: ReturnType<typeof setTimeout> | undefined;\n let timedOut = false;\n const deadline = new Promise<void>(resolve => {\n timer = setTimeout(() => {\n timedOut = true;\n resolve();\n }, timeoutMs);\n });\n try {\n // A turn that ends while we wait chains a successor capture; keep waiting\n // until the latest chain settles so the final snapshot is not lost.\n while (pending && !timedOut) {\n await Promise.race([pending, deadline]);\n const next = pendingCaptures.get(sessionId);\n pending = next === pending ? undefined : next;\n }\n } finally {\n clearTimeout(timer);\n }\n}\n\nexport function observeSessionFilesystem(\n session: FilesystemCaptureSession,\n dependencies: FilesystemCaptureDependencies,\n): () => void {\n let fallbackChain = Promise.resolve();\n // Capture only runs after a turn that actually touched the workspace: a\n // successful workspace tool call both proves the sandbox is awake and is\n // the only way the listing can have changed. Without this gate every chat\n // turn would run two sandbox execs — and since executeCommand resumes an\n // idle VM, a pure-chat turn would keep waking a sandbox it never used.\n // Same bookkeeping as first-exec capture: tool names resolve at tool_end\n // via the tool_start map, and suspended calls survive agent_end so a\n // resumed run's eventual completion still counts for that turn.\n let workspaceTouched = false;\n const toolNames = new Map<string, string>();\n const suspended = new Set<string>();\n const unsubscribeEvents = session.subscribe(event => {\n switch (event.type) {\n case 'tool_start': {\n toolNames.set(event.toolCallId, event.toolName);\n return;\n }\n case 'tool_suspended': {\n suspended.add(event.toolCallId);\n return;\n }\n case 'tool_suspension_cancelled': {\n toolNames.delete(event.toolCallId);\n suspended.delete(event.toolCallId);\n return;\n }\n case 'agent_end': {\n for (const id of toolNames.keys()) {\n if (!suspended.has(id)) toolNames.delete(id);\n }\n return;\n }\n case 'tool_end': {\n const toolName = toolNames.get(event.toolCallId);\n toolNames.delete(event.toolCallId);\n suspended.delete(event.toolCallId);\n if (event.isError || event.denied) return;\n if (isMeaningfulToolName(toolName)) workspaceTouched = true;\n break;\n }\n }\n });\n const unsubscribeEnd = session.onBeforeAgentEnd(() => {\n // onBeforeAgentEnd fires before agent_end is emitted, so every tool_end\n // of the finishing run has already been observed; read then reset.\n if (!workspaceTouched) return;\n workspaceTouched = false;\n // Chain so captures stay sequential (last write wins), but do NOT return\n // the chain: finishAgentRun awaits every listener before emitting\n // agent_end, and the capture's sandbox execs (git status + artifacts\n // find, 30s timeouts each) must not gate turn completion. Readers that\n // need the fresh listing await the pending capture through\n // waitForPendingFilesystemCapture instead. The un-returned chain cannot\n // leak an unhandled rejection: captureSessionFilesystem's entire body\n // runs inside its own try/catch, and disposal of this listener does not\n // cancel an in-flight chain, so a final turn's capture still persists.\n let sessionId: string;\n try {\n sessionId = session.identity.getId();\n } catch {\n // No identity means no route can address this session's listing; keep\n // a per-observer chain so captures still run sequentially.\n fallbackChain = fallbackChain.then(() => captureSessionFilesystem(session, dependencies));\n return;\n }\n let threadId: string;\n try {\n threadId = session.thread.requireId();\n } catch {\n return;\n }\n const ids = { sessionId, threadId };\n const chain = (pendingCaptures.get(sessionId) ?? Promise.resolve()).then(() =>\n captureSessionFilesystem(session, dependencies, ids),\n );\n pendingCaptures.set(sessionId, chain);\n void chain.finally(() => {\n if (pendingCaptures.get(sessionId) === chain) {\n pendingCaptures.delete(sessionId);\n }\n });\n });\n return () => {\n unsubscribeEvents();\n unsubscribeEnd();\n };\n}\n"],"mappings":";;;;;AAWA,MAAM,6BAA6B;AACnC,MAAM,2BAA2B;;;;6BAIJ,2BAA2B;;;;;;;;AAQxD,MAAM,yBAAyB;;;;;;;;;;;AAW/B,MAAa,0BAA0B;CACrC;CACA;CACA;AACF,CAAC,CAAC,KAAK,GAAG;;AAGV,SAAgB,WAAW,MAAoB;CAC7C,MAAM,OAAO,UAAkB,OAAO,KAAK,CAAC,CAAC,SAAS,GAAG,GAAG;CAC5D,OACE,GAAG,KAAK,eAAe,IAAI,IAAI,KAAK,YAAY,IAAI,CAAC,IAAI,IAAI,KAAK,WAAW,CAAC,IAC3E,IAAI,KAAK,YAAY,CAAC,IAAI,IAAI,KAAK,cAAc,CAAC,EAAE,GAAG,IAAI,KAAK,cAAc,CAAC;AAEtF;AAiBA,SAAgB,4BAA4B,QAAkC;CAC5E,MAAM,wBAAQ,IAAI,IAA4B;CAC9C,KAAK,MAAM,UAAU,OAAO,MAAM,IAAI,GAAG;EACvC,IAAI,CAAC,QAAQ;EACb,MAAM,OAAO,OAAO,QAAQ,SAAS,EAAE;EACvC,IAAI,MAAM,MAAM,IAAI,MAAM,EAAE,KAAK,CAAC;CACpC;CAEA,OAAO,CAAC,GAAG,MAAM,OAAO,CAAC,CAAC,CAAC,UAAU,GAAG,MAAM,EAAE,KAAK,cAAc,EAAE,IAAI,CAAC;AAC5E;AAEA,eAAsB,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AM,QAAQ;IACnC,IAAI,qBAAqB,QAAQ,GAAG,mBAAmB;IACvD;GACF;EACF;CACF,CAAC;CACD,MAAM,iBAAiB,QAAQ,uBAAuB;EAGpD,IAAI,CAAC,kBAAkB;EACvB,mBAAmB;EAUnB,IAAI;EACJ,IAAI;GACF,YAAY,QAAQ,SAAS,MAAM;EACrC,QAAQ;GAGN,gBAAgB,cAAc,WAAW,yBAAyB,SAAS,YAAY,CAAC;GACxF;EACF;EACA,IAAI;EACJ,IAAI;GACF,WAAW,QAAQ,OAAO,UAAU;EACtC,QAAQ;GACN;EACF;EACA,MAAM,MAAM;GAAE;GAAW;EAAS;EAClC,MAAM,SAAS,gBAAgB,IAAI,SAAS,KAAK,QAAQ,QAAQ,EAAA,CAAG,WAClE,yBAAyB,SAAS,cAAc,GAAG,CACrD;EACA,gBAAgB,IAAI,WAAW,KAAK;EACpC,MAAW,cAAc;GACvB,IAAI,gBAAgB,IAAI,SAAS,MAAM,OACrC,gBAAgB,OAAO,SAAS;EAEpC,CAAC;CACH,CAAC;CACD,aAAa;EACX,kBAAkB;EAClB,eAAe;CACjB;AACF"}
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { WORKSPACE_TOOLS_PREFIX } from "@mastra/core/workspace";
|
|
2
|
-
|
|
2
|
+
// src/session/first-exec-capture.ts
|
|
3
3
|
/**
|
|
4
4
|
* Tool names that count as "meaningful exec" independent of the workspace
|
|
5
5
|
* prefix. The workspace tools get remapped from `mastra_workspace_*` to
|
|
@@ -79,13 +79,12 @@ function observeSessionFirstExec(session, { sourceControl }) {
|
|
|
79
79
|
seen = true;
|
|
80
80
|
unsubscribe();
|
|
81
81
|
sourceControl.sessions.markFirstMeaningfulExec({ sessionId: session.identity.getId() }).catch((error) => console.warn("[Factory first-exec capture] Unable to persist first exec time.", error));
|
|
82
|
-
|
|
82
|
+
break;
|
|
83
83
|
}
|
|
84
84
|
}
|
|
85
85
|
});
|
|
86
86
|
return unsubscribe;
|
|
87
87
|
}
|
|
88
|
-
//#endregion
|
|
89
88
|
export { isMeaningfulToolName, observeSessionFirstExec };
|
|
90
89
|
|
|
91
90
|
//# sourceMappingURL=first-exec-capture.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"first-exec-capture.js","names":[],"sources":["../../src/session/first-exec-capture.ts"],"sourcesContent":["import type { AgentControllerEvent } from '@mastra/core/agent-controller';\nimport { WORKSPACE_TOOLS_PREFIX } from '@mastra/core/workspace';\n\nimport type { SourceControlStorageHandle } from '../storage/domains/source-control/base.js';\n\nexport interface FirstExecCaptureSession {\n readonly identity: { getId(): string };\n subscribe(listener: (event: AgentControllerEvent) => void): () => void;\n}\n\nexport interface FirstExecCaptureDependencies {\n sourceControl: {\n sessions: Pick<SourceControlStorageHandle['sessions'], 'markFirstMeaningfulExec'>;\n };\n}\n\n/**\n * Tool names that count as \"meaningful exec\" independent of the workspace\n * prefix. The workspace tools get remapped from `mastra_workspace_*` to\n * mastracode-friendly names (see `mastracode/sdk/src/tool-names.ts`), and\n * this listener runs on the emitted tool name after remap, so both spellings\n * need to match.\n */\nconst MEANINGFUL_TOOL_NAMES: ReadonlySet<string> = new Set([\n // Filesystem (post-remap)\n 'view',\n 'write_file',\n 'string_replace_lsp',\n 'find_files',\n 'delete_file',\n 'file_stat',\n 'mkdir',\n // Search\n 'search_content',\n // Code intelligence\n 'ast_smart_edit',\n 'lsp_inspect',\n // Sandbox\n 'execute_command',\n 'get_process_output',\n 'kill_process',\n]);\n\nexport function isMeaningfulToolName(name: string | undefined): boolean {\n if (!name) return false;\n if (name.startsWith(`${WORKSPACE_TOOLS_PREFIX}_`)) return true;\n return MEANINGFUL_TOOL_NAMES.has(name);\n}\n\n/**\n * Record when a session's agent completed its first successful meaningful\n * tool call (the TTFME anchor — \"time to first meaningful exec\").\n *\n * Meaningful = a workspace tool the agent invoked itself (filesystem,\n * search, code intelligence, sandbox exec, process control). We accept any\n * tool whose name starts with the workspace prefix `mastra_workspace_` or\n * matches the post-remap mastracode tool names. Non-workspace tools (memory,\n * notification inbox, subagent, etc.) and skill-loader / preflight /\n * materializer `sandbox.executeCommand()` calls that never flow through the\n * tool layer are intentionally excluded.\n *\n * Failed tool calls (`isError === true`) don't count. Approval-denied and\n * abort-while-parked tool completions (`denied === true`) also don't count:\n * the run-engine emits `tool_end` with `isError: false` for those paths\n * because the tool didn't fail, but it also never ran, so treating them as\n * \"meaningful exec\" would re-introduce the same contamination this fix is\n * removing on the message side. The listener stays subscribed until a\n * successful qualifying end, then unsubscribes. The storage write is guarded\n * (`first_meaningful_exec_at IS NULL`), so restarts, re-materialized\n * sessions, and sessions without a source-control row are no-ops.\n */\nexport function observeSessionFirstExec(\n session: FirstExecCaptureSession,\n { sourceControl }: FirstExecCaptureDependencies,\n): () => void {\n let seen = false;\n // toolCallId -> toolName. Populated on `tool_start`, consumed on `tool_end`.\n // Suspended entries survive `agent_end` so the resumed run can still resolve\n // its tool name when the eventual `tool_end` arrives.\n const toolNames = new Map<string, string>();\n const suspended = new Set<string>();\n const unsubscribe = session.subscribe(event => {\n if (seen) return;\n switch (event.type) {\n case 'tool_start': {\n toolNames.set(event.toolCallId, event.toolName);\n return;\n }\n case 'tool_suspended': {\n suspended.add(event.toolCallId);\n return;\n }\n case 'tool_suspension_cancelled': {\n toolNames.delete(event.toolCallId);\n suspended.delete(event.toolCallId);\n return;\n }\n case 'agent_end': {\n // Drop any in-flight starts that will never see a matching `tool_end`\n // on this run. Genuinely suspended calls stay so their eventual\n // resume-time `tool_end` can still map back to a tool name. Without\n // this, sessions that repeatedly abort or error before a qualifying\n // completion would accumulate stale entries for the entire lifetime\n // of the subscription.\n for (const id of toolNames.keys()) {\n if (!suspended.has(id)) toolNames.delete(id);\n }\n return;\n }\n case 'tool_end': {\n const toolName = toolNames.get(event.toolCallId);\n toolNames.delete(event.toolCallId);\n suspended.delete(event.toolCallId);\n if (event.isError) return;\n if (event.denied) return;\n if (!isMeaningfulToolName(toolName)) return;\n seen = true;\n unsubscribe();\n void sourceControl.sessions\n .markFirstMeaningfulExec({ sessionId: session.identity.getId() })\n .catch(error => console.warn('[Factory first-exec capture] Unable to persist first exec time.', error));\n
|
|
1
|
+
{"version":3,"file":"first-exec-capture.js","names":[],"sources":["../../src/session/first-exec-capture.ts"],"sourcesContent":["import type { AgentControllerEvent } from '@mastra/core/agent-controller';\nimport { WORKSPACE_TOOLS_PREFIX } from '@mastra/core/workspace';\n\nimport type { SourceControlStorageHandle } from '../storage/domains/source-control/base.js';\n\nexport interface FirstExecCaptureSession {\n readonly identity: { getId(): string };\n subscribe(listener: (event: AgentControllerEvent) => void): () => void;\n}\n\nexport interface FirstExecCaptureDependencies {\n sourceControl: {\n sessions: Pick<SourceControlStorageHandle['sessions'], 'markFirstMeaningfulExec'>;\n };\n}\n\n/**\n * Tool names that count as \"meaningful exec\" independent of the workspace\n * prefix. The workspace tools get remapped from `mastra_workspace_*` to\n * mastracode-friendly names (see `mastracode/sdk/src/tool-names.ts`), and\n * this listener runs on the emitted tool name after remap, so both spellings\n * need to match.\n */\nconst MEANINGFUL_TOOL_NAMES: ReadonlySet<string> = new Set([\n // Filesystem (post-remap)\n 'view',\n 'write_file',\n 'string_replace_lsp',\n 'find_files',\n 'delete_file',\n 'file_stat',\n 'mkdir',\n // Search\n 'search_content',\n // Code intelligence\n 'ast_smart_edit',\n 'lsp_inspect',\n // Sandbox\n 'execute_command',\n 'get_process_output',\n 'kill_process',\n]);\n\nexport function isMeaningfulToolName(name: string | undefined): boolean {\n if (!name) return false;\n if (name.startsWith(`${WORKSPACE_TOOLS_PREFIX}_`)) return true;\n return MEANINGFUL_TOOL_NAMES.has(name);\n}\n\n/**\n * Record when a session's agent completed its first successful meaningful\n * tool call (the TTFME anchor — \"time to first meaningful exec\").\n *\n * Meaningful = a workspace tool the agent invoked itself (filesystem,\n * search, code intelligence, sandbox exec, process control). We accept any\n * tool whose name starts with the workspace prefix `mastra_workspace_` or\n * matches the post-remap mastracode tool names. Non-workspace tools (memory,\n * notification inbox, subagent, etc.) and skill-loader / preflight /\n * materializer `sandbox.executeCommand()` calls that never flow through the\n * tool layer are intentionally excluded.\n *\n * Failed tool calls (`isError === true`) don't count. Approval-denied and\n * abort-while-parked tool completions (`denied === true`) also don't count:\n * the run-engine emits `tool_end` with `isError: false` for those paths\n * because the tool didn't fail, but it also never ran, so treating them as\n * \"meaningful exec\" would re-introduce the same contamination this fix is\n * removing on the message side. The listener stays subscribed until a\n * successful qualifying end, then unsubscribes. The storage write is guarded\n * (`first_meaningful_exec_at IS NULL`), so restarts, re-materialized\n * sessions, and sessions without a source-control row are no-ops.\n */\nexport function observeSessionFirstExec(\n session: FirstExecCaptureSession,\n { sourceControl }: FirstExecCaptureDependencies,\n): () => void {\n let seen = false;\n // toolCallId -> toolName. Populated on `tool_start`, consumed on `tool_end`.\n // Suspended entries survive `agent_end` so the resumed run can still resolve\n // its tool name when the eventual `tool_end` arrives.\n const toolNames = new Map<string, string>();\n const suspended = new Set<string>();\n const unsubscribe = session.subscribe(event => {\n if (seen) return;\n switch (event.type) {\n case 'tool_start': {\n toolNames.set(event.toolCallId, event.toolName);\n return;\n }\n case 'tool_suspended': {\n suspended.add(event.toolCallId);\n return;\n }\n case 'tool_suspension_cancelled': {\n toolNames.delete(event.toolCallId);\n suspended.delete(event.toolCallId);\n return;\n }\n case 'agent_end': {\n // Drop any in-flight starts that will never see a matching `tool_end`\n // on this run. Genuinely suspended calls stay so their eventual\n // resume-time `tool_end` can still map back to a tool name. Without\n // this, sessions that repeatedly abort or error before a qualifying\n // completion would accumulate stale entries for the entire lifetime\n // of the subscription.\n for (const id of toolNames.keys()) {\n if (!suspended.has(id)) toolNames.delete(id);\n }\n return;\n }\n case 'tool_end': {\n const toolName = toolNames.get(event.toolCallId);\n toolNames.delete(event.toolCallId);\n suspended.delete(event.toolCallId);\n if (event.isError) return;\n if (event.denied) return;\n if (!isMeaningfulToolName(toolName)) return;\n seen = true;\n unsubscribe();\n void sourceControl.sessions\n .markFirstMeaningfulExec({ sessionId: session.identity.getId() })\n .catch(error => console.warn('[Factory first-exec capture] Unable to persist first exec time.', error));\n break;\n }\n }\n });\n return unsubscribe;\n}\n"],"mappings":";;;;;;;;;AAuBA,MAAM,wCAA6C,IAAI,IAAI;CAEzD;CACA;CACA;CACA;CACA;CACA;CACA;CAEA;CAEA;CACA;CAEA;CACA;CACA;AACF,CAAC;AAED,SAAgB,qBAAqB,MAAmC;CACtE,IAAI,CAAC,MAAM,OAAO;CAClB,IAAI,KAAK,WAAW,GAAG,uBAAuB,EAAE,GAAG,OAAO;CAC1D,OAAO,sBAAsB,IAAI,IAAI;AACvC;;;;;;;;;;;;;;;;;;;;;;;AAwBA,SAAgB,wBACd,SACA,EAAE,iBACU;CACZ,IAAI,OAAO;CAIX,MAAM,4BAAY,IAAI,IAAoB;CAC1C,MAAM,4BAAY,IAAI,IAAY;CAClC,MAAM,cAAc,QAAQ,WAAU,UAAS;EAC7C,IAAI,MAAM;EACV,QAAQ,MAAM,MAAd;GACE,KAAK;IACH,UAAU,IAAI,MAAM,YAAY,MAAM,QAAQ;IAC9C;GAEF,KAAK;IACH,UAAU,IAAI,MAAM,UAAU;IAC9B;GAEF,KAAK;IACH,UAAU,OAAO,MAAM,UAAU;IACjC,UAAU,OAAO,MAAM,UAAU;IACjC;GAEF,KAAK;IAOH,KAAK,MAAM,MAAM,UAAU,KAAK,GAC9B,IAAI,CAAC,UAAU,IAAI,EAAE,GAAG,UAAU,OAAO,EAAE;IAE7C;GAEF,KAAK,YAAY;IACf,MAAM,WAAW,UAAU,IAAI,MAAM,UAAU;IAC/C,UAAU,OAAO,MAAM,UAAU;IACjC,UAAU,OAAO,MAAM,UAAU;IACjC,IAAI,MAAM,SAAS;IACnB,IAAI,MAAM,QAAQ;IAClB,IAAI,CAAC,qBAAqB,QAAQ,GAAG;IACrC,OAAO;IACP,YAAY;IACZ,cAAmB,SAChB,wBAAwB,EAAE,WAAW,QAAQ,SAAS,MAAM,EAAE,CAAC,CAAC,CAChE,OAAM,UAAS,QAAQ,KAAK,mEAAmE,KAAK,CAAC;IACxG;GACF;EACF;CACF,CAAC;CACD,OAAO;AACT"}
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
|
|
1
|
+
// src/session/first-message-capture.ts
|
|
2
2
|
/**
|
|
3
3
|
* Record when a session's agent first produced an actual conversational
|
|
4
4
|
* message (the TTFI anchor — "time to first interaction").
|
|
@@ -29,7 +29,6 @@ function observeSessionFirstMessage(session, { sourceControl }) {
|
|
|
29
29
|
});
|
|
30
30
|
return unsubscribe;
|
|
31
31
|
}
|
|
32
|
-
//#endregion
|
|
33
32
|
export { observeSessionFirstMessage };
|
|
34
33
|
|
|
35
34
|
//# sourceMappingURL=first-message-capture.js.map
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
|
|
1
|
+
// src/session/live-sessions.ts
|
|
2
2
|
/**
|
|
3
3
|
* The sessions this process has materialized, by session id.
|
|
4
4
|
*
|
|
@@ -84,7 +84,6 @@ var LiveSessions = class {
|
|
|
84
84
|
return () => this.#parkedListeners.delete(listener);
|
|
85
85
|
}
|
|
86
86
|
};
|
|
87
|
-
//#endregion
|
|
88
87
|
export { LiveSessions };
|
|
89
88
|
|
|
90
89
|
//# sourceMappingURL=live-sessions.js.map
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { hasResolvedOrg, seedSessionOrg } from "./org-seed.js";
|
|
2
|
-
|
|
2
|
+
// src/session/memory-settings-hydration.ts
|
|
3
3
|
/** Default thresholds mirror the TUI `/om` fallbacks. */
|
|
4
4
|
const DEFAULT_OBSERVATION_THRESHOLD = 3e4;
|
|
5
5
|
const DEFAULT_REFLECTION_THRESHOLD = 4e4;
|
|
@@ -20,7 +20,6 @@ async function hydrateSessionMemorySettings(session, { sourceControl }) {
|
|
|
20
20
|
if (!session.state.get()?.factoryOrgId) await seedSessionOrg(session, void 0);
|
|
21
21
|
}
|
|
22
22
|
}
|
|
23
|
-
//#endregion
|
|
24
23
|
export { DEFAULT_OBSERVATION_THRESHOLD, DEFAULT_REFLECTION_THRESHOLD, hydrateSessionMemorySettings };
|
|
25
24
|
|
|
26
25
|
//# sourceMappingURL=memory-settings-hydration.js.map
|
package/dist/session/org-seed.js
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
|
|
1
|
+
// src/session/org-seed.ts
|
|
2
2
|
/** Read the tenant org off a request context's `user` key, if there is one. */
|
|
3
3
|
function readRequestContextOrgId(requestContext) {
|
|
4
4
|
if (!requestContext) return void 0;
|
|
@@ -47,7 +47,6 @@ async function seedSessionOrg(session, orgId) {
|
|
|
47
47
|
console.warn("[Factory org seed] Unable to record the session organization.", error);
|
|
48
48
|
}
|
|
49
49
|
}
|
|
50
|
-
//#endregion
|
|
51
50
|
export { hasResolvedOrg, readRequestContextOrgId, seedSessionOrg };
|
|
52
51
|
|
|
53
52
|
//# sourceMappingURL=org-seed.js.map
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import { credentialLabel, getAuthProviderId } from "../routes/provider-credentials.js";
|
|
2
2
|
import { resolveCredentialStore, resolveTenantFromRequestContext } from "@mastra/code-sdk/agents/credential-resolver";
|
|
3
3
|
import { normalizeLegacyProviderId } from "@mastra/code-sdk/providers/model-ids";
|
|
4
|
-
|
|
4
|
+
// src/session/reply-credential-processor.ts
|
|
5
5
|
/**
|
|
6
6
|
* Stamps each assistant reply with the credential that answered it, as
|
|
7
7
|
* `content.metadata.credentialLabel` ("Claude Pro/Max", "Anthropic API key")
|
|
@@ -32,7 +32,6 @@ var FactoryReplyCredentialProcessor = class {
|
|
|
32
32
|
return messageList;
|
|
33
33
|
}
|
|
34
34
|
};
|
|
35
|
-
//#endregion
|
|
36
35
|
export { FactoryReplyCredentialProcessor };
|
|
37
36
|
|
|
38
37
|
//# sourceMappingURL=reply-credential-processor.js.map
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { externallyAuthoredWorkItem } from "../rules/types.js";
|
|
2
2
|
import { sessionStampCounts } from "./session-threads.js";
|
|
3
|
-
|
|
3
|
+
// src/session/resource-migration.ts
|
|
4
4
|
/** Slack-started sessions live on a `slack/<thread>` branch (see `threadBranch` in the Slack integration). */
|
|
5
5
|
const SLACK_SESSION_BRANCH_PREFIX = "slack/";
|
|
6
6
|
/**
|
|
@@ -189,7 +189,6 @@ async function moveThread(deps, thread, resourceId) {
|
|
|
189
189
|
}
|
|
190
190
|
});
|
|
191
191
|
}
|
|
192
|
-
//#endregion
|
|
193
192
|
export { migrateSessionResources, privatizeOwnerResourceSessions, sessionMemoryResource };
|
|
194
193
|
|
|
195
194
|
//# sourceMappingURL=resource-migration.js.map
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { z } from "zod";
|
|
2
|
-
|
|
2
|
+
// src/session/run-audit.ts
|
|
3
3
|
const FACTORY_OPEN_RUNS_SETTING = "factoryOpenRuns";
|
|
4
4
|
const factoryOpenRunSchema = z.object({
|
|
5
5
|
kickoffId: z.string(),
|
|
@@ -209,7 +209,6 @@ function observeSessionRunEnd(session, { audit }) {
|
|
|
209
209
|
serializeRunAudit(session, () => recordRunEnds(session, audit, event.reason, void 0, turn));
|
|
210
210
|
});
|
|
211
211
|
}
|
|
212
|
-
//#endregion
|
|
213
212
|
export { FACTORY_OPEN_RUNS_SETTING, FACTORY_OPEN_RUN_STALE_MS, FACTORY_RUN_USAGE_STEPS_JSON_BUDGET, heartbeatSessionOpenRun, isOpenRunLiveElsewhere, listSessionOpenRuns, observeSessionRunEnd, recordSessionRunStart, waitForSessionRunAudit };
|
|
214
213
|
|
|
215
214
|
//# sourceMappingURL=run-audit.js.map
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
|
|
1
|
+
// src/session/session-threads.ts
|
|
2
2
|
/**
|
|
3
3
|
* The one memory resource a Factory session runs under. A Slack session uses
|
|
4
4
|
* its Factory's, or its sender's for a DM; a side session uses its Factory's,
|
|
@@ -91,7 +91,6 @@ async function listFactorySessionThreads(controller, session, runs) {
|
|
|
91
91
|
for (const thread of [...owned, ...legacy]) threads.set(thread.id, thread);
|
|
92
92
|
return [...threads.values()];
|
|
93
93
|
}
|
|
94
|
-
//#endregion
|
|
95
94
|
export { isRunBound, isWorkerSession, listFactorySessionThreads, memoryResourceOf, sessionMemoryResourceId, sessionStampCounts, sessionThreadsToMove, userSessionResourceFor };
|
|
96
95
|
|
|
97
96
|
//# sourceMappingURL=session-threads.js.map
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
|
|
1
|
+
// src/session/session-title.ts
|
|
2
2
|
const MAX_SESSION_TITLE_LENGTH = 80;
|
|
3
3
|
/**
|
|
4
4
|
* The one shape a session row's title may take, wherever it comes from — typed
|
|
@@ -8,7 +8,6 @@ const MAX_SESSION_TITLE_LENGTH = 80;
|
|
|
8
8
|
function normalizeSessionTitle(title) {
|
|
9
9
|
return [...title.replace(/\s+/g, " ").trim()].slice(0, MAX_SESSION_TITLE_LENGTH).join("").trimEnd() || null;
|
|
10
10
|
}
|
|
11
|
-
//#endregion
|
|
12
11
|
export { normalizeSessionTitle };
|
|
13
12
|
|
|
14
13
|
//# sourceMappingURL=session-title.js.map
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
|
|
1
|
+
// src/session/shell-commands.ts
|
|
2
2
|
/** Two tool observers read the same `gh pr create`, so the reading lives here rather than once per observer. */
|
|
3
3
|
const GH_PR_CREATE_RE = /(?:^|\n|;|&&|\|\|)\s*gh\s+pr\s+create(?:\s|$)/;
|
|
4
4
|
/** Heredoc bodies dropped, so prose inside a document never reads as a command. */
|
|
@@ -19,7 +19,6 @@ function executableCommand(command) {
|
|
|
19
19
|
function runsPullRequestCreate(command) {
|
|
20
20
|
return GH_PR_CREATE_RE.test(executableCommand(command));
|
|
21
21
|
}
|
|
22
|
-
//#endregion
|
|
23
22
|
export { executableCommand, runsPullRequestCreate };
|
|
24
23
|
|
|
25
24
|
//# sourceMappingURL=shell-commands.js.map
|