@kortix/sdk 0.15.0 → 0.15.2
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 +37 -272
- package/dist/browser/session-sync/server-transcript-mirror.d.ts +4 -4
- package/dist/browser/session-sync/server-transcript-mirror.d.ts.map +1 -1
- package/dist/browser/session-sync/server-transcript-mirror.js +4 -4
- package/dist/browser/session-sync/server-transcript-mirror.js.map +1 -1
- package/dist/browser/session-sync/session-cache-ownership.d.ts +5 -5
- package/dist/browser/session-sync/session-cache-ownership.js +5 -5
- package/dist/browser/session-sync/session-sync-registry.d.ts +1 -1
- package/dist/browser/session-sync/session-sync-registry.js +1 -1
- package/dist/browser/stores/{opencode-compaction-store.d.ts → runtime-compaction-store.d.ts} +3 -3
- package/dist/browser/stores/runtime-compaction-store.d.ts.map +1 -0
- package/dist/browser/stores/{opencode-compaction-store.js → runtime-compaction-store.js} +2 -2
- package/dist/browser/stores/runtime-compaction-store.js.map +1 -0
- package/dist/browser/stores/{opencode-pending-store.d.ts → runtime-pending-store.d.ts} +3 -3
- package/dist/browser/stores/runtime-pending-store.d.ts.map +1 -0
- package/dist/browser/stores/{opencode-pending-store.js → runtime-pending-store.js} +1 -1
- package/dist/browser/stores/runtime-pending-store.js.map +1 -0
- package/dist/browser/stores/sandbox-connection-store.d.ts +18 -3
- package/dist/browser/stores/sandbox-connection-store.d.ts.map +1 -1
- package/dist/browser/stores/sandbox-connection-store.js +57 -3
- package/dist/browser/stores/sandbox-connection-store.js.map +1 -1
- package/dist/browser/stores/sync-store.d.ts +2 -2
- package/dist/browser/stores/sync-store.js +3 -3
- package/dist/browser/stores/sync-store.js.map +1 -1
- package/dist/core/agents/composer-agents.js +3 -3
- package/dist/core/agents/composer-agents.js.map +1 -1
- package/dist/core/client/facade-commerce.d.ts +2 -0
- package/dist/core/client/facade-commerce.d.ts.map +1 -1
- package/dist/core/client/facade-commerce.js +2 -0
- package/dist/core/client/facade-commerce.js.map +1 -1
- package/dist/core/client/kortix.d.ts +12 -70
- package/dist/core/client/kortix.d.ts.map +1 -1
- package/dist/core/client/kortix.js +0 -2
- package/dist/core/client/kortix.js.map +1 -1
- package/dist/core/client/project-access-resources.d.ts +4 -1
- package/dist/core/client/project-access-resources.d.ts.map +1 -1
- package/dist/core/client/project-core.d.ts +3 -3
- package/dist/core/client/project-core.d.ts.map +1 -1
- package/dist/core/client/project-operations-admin.d.ts +4 -0
- package/dist/core/client/project-operations-admin.d.ts.map +1 -1
- package/dist/core/client/project-operations-review.d.ts +5 -0
- package/dist/core/client/project-operations-review.d.ts.map +1 -1
- package/dist/core/client/project-operations-review.js +5 -0
- package/dist/core/client/project-operations-review.js.map +1 -1
- package/dist/core/client/project-operations-workspace.d.ts +4 -0
- package/dist/core/client/project-operations-workspace.d.ts.map +1 -1
- package/dist/core/client/project-operations.d.ts +4 -0
- package/dist/core/client/project-operations.d.ts.map +1 -1
- package/dist/core/client/session-handle.d.ts +1 -1
- package/dist/core/client/session-handle.d.ts.map +1 -1
- package/dist/core/client/session-handle.js +3 -3
- package/dist/core/client/session-handle.js.map +1 -1
- package/dist/core/files/client.js +1 -1
- package/dist/core/files/client.js.map +1 -1
- package/dist/core/http/abort-error.d.ts +12 -13
- package/dist/core/http/abort-error.d.ts.map +1 -1
- package/dist/core/http/abort-error.js +14 -15
- package/dist/core/http/abort-error.js.map +1 -1
- package/dist/core/http/response-error.d.ts.map +1 -1
- package/dist/core/http/response-error.js +2 -0
- package/dist/core/http/response-error.js.map +1 -1
- package/dist/core/http/runtime-errors.d.ts +4 -5
- package/dist/core/http/runtime-errors.d.ts.map +1 -1
- package/dist/core/http/runtime-errors.js +7 -12
- package/dist/core/http/runtime-errors.js.map +1 -1
- package/dist/core/models/provider-connections.d.ts +6 -1
- package/dist/core/models/provider-connections.d.ts.map +1 -1
- package/dist/core/models/provider-connections.js +6 -1
- package/dist/core/models/provider-connections.js.map +1 -1
- package/dist/core/models/provider-selection.js +1 -1
- package/dist/core/models/provider-selection.js.map +1 -1
- package/dist/core/multi-agent/tool-data.d.ts +77 -0
- package/dist/core/multi-agent/tool-data.d.ts.map +1 -0
- package/dist/core/multi-agent/tool-data.js +145 -0
- package/dist/core/multi-agent/tool-data.js.map +1 -0
- package/dist/core/rest/projects-client/agent-config.d.ts +7 -8
- package/dist/core/rest/projects-client/agent-config.d.ts.map +1 -1
- package/dist/core/rest/projects-client/agent-config.js.map +1 -1
- package/dist/core/rest/projects-client/apps.d.ts +11 -3
- package/dist/core/rest/projects-client/apps.d.ts.map +1 -1
- package/dist/core/rest/projects-client/apps.js +7 -2
- package/dist/core/rest/projects-client/apps.js.map +1 -1
- package/dist/core/rest/projects-client/artifacts.d.ts +0 -245
- package/dist/core/rest/projects-client/artifacts.d.ts.map +1 -1
- package/dist/core/rest/projects-client/artifacts.js +1 -115
- package/dist/core/rest/projects-client/artifacts.js.map +1 -1
- package/dist/core/rest/projects-client/billing.d.ts +20 -0
- package/dist/core/rest/projects-client/billing.d.ts.map +1 -1
- package/dist/core/rest/projects-client/billing.js +10 -0
- package/dist/core/rest/projects-client/billing.js.map +1 -1
- package/dist/core/rest/projects-client/goals.d.ts +260 -83
- package/dist/core/rest/projects-client/goals.d.ts.map +1 -1
- package/dist/core/rest/projects-client/goals.js +245 -400
- package/dist/core/rest/projects-client/goals.js.map +1 -1
- package/dist/core/rest/projects-client/iam-actions.d.ts +0 -1
- package/dist/core/rest/projects-client/iam-actions.d.ts.map +1 -1
- package/dist/core/rest/projects-client/iam-actions.js +0 -1
- package/dist/core/rest/projects-client/iam-actions.js.map +1 -1
- package/dist/core/rest/projects-client/index.d.ts +0 -2
- package/dist/core/rest/projects-client/index.d.ts.map +1 -1
- package/dist/core/rest/projects-client/index.js +0 -2
- package/dist/core/rest/projects-client/index.js.map +1 -1
- package/dist/core/rest/projects-client/notifications.d.ts +2 -6
- package/dist/core/rest/projects-client/notifications.d.ts.map +1 -1
- package/dist/core/rest/projects-client/notifications.js +3 -5
- package/dist/core/rest/projects-client/notifications.js.map +1 -1
- package/dist/core/rest/projects-client/project-agents.js +1 -1
- package/dist/core/rest/projects-client/project-agents.js.map +1 -1
- package/dist/core/rest/projects-client/projects.d.ts +45 -23
- package/dist/core/rest/projects-client/projects.d.ts.map +1 -1
- package/dist/core/rest/projects-client/projects.js +3 -5
- package/dist/core/rest/projects-client/projects.js.map +1 -1
- package/dist/core/rest/projects-client/public-session-shares.js +1 -1
- package/dist/core/rest/projects-client/public-session-shares.js.map +1 -1
- package/dist/core/rest/projects-client/session-sandbox.d.ts +2 -2
- package/dist/core/rest/projects-client/session-sandbox.js +1 -1
- package/dist/core/rest/projects-client/sessions.d.ts +16 -18
- package/dist/core/rest/projects-client/sessions.d.ts.map +1 -1
- package/dist/core/rest/projects-client/sessions.js +2 -2
- package/dist/core/rest/projects-client/sessions.js.map +1 -1
- package/dist/core/rest/projects-client/spaces.d.ts +32 -0
- package/dist/core/rest/projects-client/spaces.d.ts.map +1 -1
- package/dist/core/rest/projects-client/spaces.js +13 -0
- package/dist/core/rest/projects-client/spaces.js.map +1 -1
- package/dist/core/rest/projects-client/triggers.d.ts +6 -0
- package/dist/core/rest/projects-client/triggers.d.ts.map +1 -1
- package/dist/core/rest/projects-client/triggers.js.map +1 -1
- package/dist/core/runtime/kortix-master.d.ts +1 -0
- package/dist/core/runtime/kortix-master.d.ts.map +1 -1
- package/dist/core/runtime/kortix-master.js.map +1 -1
- package/dist/core/runtime/pty.js +2 -2
- package/dist/core/session/compaction.d.ts +2 -2
- package/dist/core/session/compaction.js +2 -2
- package/dist/core/session/control-stream.d.ts +50 -2
- package/dist/core/session/control-stream.d.ts.map +1 -1
- package/dist/core/session/control-stream.js +99 -9
- package/dist/core/session/control-stream.js.map +1 -1
- package/dist/core/session/current-runtime.d.ts +1 -1
- package/dist/core/session/health.d.ts +9 -19
- package/dist/core/session/health.d.ts.map +1 -1
- package/dist/core/session/health.js +2 -2
- package/dist/core/session/health.js.map +1 -1
- package/dist/core/session/runtime-actions.d.ts +3 -2
- package/dist/core/session/runtime-actions.d.ts.map +1 -1
- package/dist/core/session/runtime-actions.js.map +1 -1
- package/dist/core/session/server-store/active.d.ts +2 -2
- package/dist/core/session/server-store/active.js +2 -2
- package/dist/core/session/server-store/types.d.ts +2 -2
- package/dist/core/session/server-store/types.d.ts.map +1 -1
- package/dist/core/session/server-store/url-helpers.d.ts +5 -5
- package/dist/core/session/server-store/url-helpers.js +5 -5
- package/dist/core/session/session-runtime-registry.d.ts +1 -1
- package/dist/core/session/session-runtime-registry.js +1 -1
- package/dist/core/session/url.d.ts +2 -2
- package/dist/core/session/url.js +4 -4
- package/dist/core/session/url.js.map +1 -1
- package/dist/core/session/wire-message-id.d.ts +12 -42
- package/dist/core/session/wire-message-id.d.ts.map +1 -1
- package/dist/core/session/wire-message-id.js +11 -37
- package/dist/core/session/wire-message-id.js.map +1 -1
- package/dist/core/session/working-server.d.ts +13 -1
- package/dist/core/session/working-server.d.ts.map +1 -1
- package/dist/core/session/working-server.js +15 -1
- package/dist/core/session/working-server.js.map +1 -1
- package/dist/core/session/working.d.ts.map +1 -1
- package/dist/core/session/working.js +3 -1
- package/dist/core/session/working.js.map +1 -1
- package/dist/core/session-log/v1-view.d.ts +2 -2
- package/dist/core/session-log/v1-view.d.ts.map +1 -1
- package/dist/core/session-log/v1-view.js +3 -1
- package/dist/core/session-log/v1-view.js.map +1 -1
- package/dist/core/session-sync/saved-copy-store.d.ts +3 -3
- package/dist/core/session-sync/saved-copy-store.d.ts.map +1 -1
- package/dist/core/session-sync/saved-copy-store.js +3 -3
- package/dist/core/session-sync/saved-copy-store.js.map +1 -1
- package/dist/core/session-sync/saved-transcript.d.ts +5 -5
- package/dist/core/session-sync/saved-transcript.d.ts.map +1 -1
- package/dist/core/session-sync/saved-transcript.js +2 -2
- package/dist/core/session-sync/session-sync-controller.js +2 -2
- package/dist/core/session-sync/session-sync-controller.js.map +1 -1
- package/dist/core/stream/event-attempt.js +1 -1
- package/dist/core/stream/event-attempt.js.map +1 -1
- package/dist/core/stream/event-stream.d.ts +6 -6
- package/dist/core/stream/event-stream.js +4 -4
- package/dist/core/turns/shell.d.ts +2 -2
- package/dist/core/turns/shell.js +2 -2
- package/dist/core/wire-values.d.ts +81 -0
- package/dist/core/wire-values.d.ts.map +1 -0
- package/dist/core/wire-values.js +177 -0
- package/dist/core/wire-values.js.map +1 -0
- package/dist/index.d.ts +8 -9
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +6 -10
- package/dist/index.js.map +1 -1
- package/dist/kortix.esm.min.js +55 -70
- package/dist/kortix.global.js +55 -70
- package/dist/platform/auth-core.d.ts +2 -2
- package/dist/platform/auth-core.js +2 -2
- package/dist/react/chat/use-chat-turns.d.ts +1 -1
- package/dist/react/chat/use-chat-turns.d.ts.map +1 -1
- package/dist/react/hold-live-start.d.ts.map +1 -1
- package/dist/react/hold-live-start.js +4 -11
- package/dist/react/hold-live-start.js.map +1 -1
- package/dist/react/index.d.ts +7 -6
- package/dist/react/index.d.ts.map +1 -1
- package/dist/react/index.js +12 -12
- package/dist/react/index.js.map +1 -1
- package/dist/react/initial-session-pin.d.ts +1 -1
- package/dist/react/initial-session-pin.d.ts.map +1 -1
- package/dist/react/initial-session-pin.js +3 -3
- package/dist/react/initial-session-pin.js.map +1 -1
- package/dist/react/provider-refresh.d.ts +1 -1
- package/dist/react/provider-refresh.js +4 -4
- package/dist/react/provider-refresh.js.map +1 -1
- package/dist/react/query-keys.d.ts +9 -17
- package/dist/react/query-keys.d.ts.map +1 -1
- package/dist/react/query-keys.js +9 -7
- package/dist/react/query-keys.js.map +1 -1
- package/dist/react/reset-identity-state.js +1 -1
- package/dist/react/reset-identity-state.js.map +1 -1
- package/dist/react/runtime-actions.js +1 -1
- package/dist/react/runtime-actions.js.map +1 -1
- package/dist/react/{opencode.d.ts → runtime-hooks.d.ts} +14 -14
- package/dist/react/runtime-hooks.d.ts.map +1 -0
- package/dist/react/{opencode.js → runtime-hooks.js} +19 -19
- package/dist/react/runtime-hooks.js.map +1 -0
- package/dist/react/session-start-stash.d.ts +1 -1
- package/dist/react/session-start-stash.js +8 -8
- package/dist/react/session-start-stash.js.map +1 -1
- package/dist/react/session-stop.d.ts +5 -5
- package/dist/react/session-stop.d.ts.map +1 -1
- package/dist/react/session-stop.js +3 -3
- package/dist/react/session-stop.js.map +1 -1
- package/dist/react/session-title-sync.js +1 -1
- package/dist/react/session-transcript-subscription.d.ts +2 -2
- package/dist/react/session-transcript-subscription.js +2 -2
- package/dist/react/sign-in-with-kortix.d.ts +2 -2
- package/dist/react/turn-end-handoff.d.ts +1 -1
- package/dist/react/turn-end-handoff.d.ts.map +1 -1
- package/dist/react/turn-end-handoff.js +2 -2
- package/dist/react/turn-end-handoff.js.map +1 -1
- package/dist/react/use-admin-credit-codes.d.ts +34 -0
- package/dist/react/use-admin-credit-codes.d.ts.map +1 -0
- package/dist/react/use-admin-credit-codes.js +48 -0
- package/dist/react/use-admin-credit-codes.js.map +1 -0
- package/dist/react/use-artifacts.d.ts +2 -492
- package/dist/react/use-artifacts.d.ts.map +1 -1
- package/dist/react/use-artifacts.js +3 -390
- package/dist/react/use-artifacts.js.map +1 -1
- package/dist/react/{use-canonical-opencode-session.d.ts → use-canonical-runtime-session.d.ts} +6 -6
- package/dist/react/use-canonical-runtime-session.d.ts.map +1 -0
- package/dist/react/{use-canonical-opencode-session.js → use-canonical-runtime-session.js} +5 -5
- package/dist/react/use-canonical-runtime-session.js.map +1 -0
- package/dist/react/use-feature-flag.d.ts +2 -1
- package/dist/react/use-feature-flag.d.ts.map +1 -1
- package/dist/react/use-feature-flag.js +3 -1
- package/dist/react/use-feature-flag.js.map +1 -1
- package/dist/react/use-goals.d.ts +48 -9
- package/dist/react/use-goals.d.ts.map +1 -1
- package/dist/react/use-goals.js +106 -16
- package/dist/react/use-goals.js.map +1 -1
- package/dist/react/use-kortix-master.d.ts +1 -1
- package/dist/react/use-kortix-master.js +4 -4
- package/dist/react/use-kortix-master.js.map +1 -1
- package/dist/react/use-model-store.d.ts +1 -1
- package/dist/react/use-model-store.d.ts.map +1 -1
- package/dist/react/use-model-store.js +14 -3
- package/dist/react/use-model-store.js.map +1 -1
- package/dist/react/use-permission-self-heal.d.ts +1 -1
- package/dist/react/use-permission-self-heal.js +2 -2
- package/dist/react/use-permission-self-heal.js.map +1 -1
- package/dist/react/use-project-apps.d.ts +13 -26
- package/dist/react/use-project-apps.d.ts.map +1 -1
- package/dist/react/use-project-apps.js +15 -4
- package/dist/react/use-project-apps.js.map +1 -1
- package/dist/react/use-project-session.d.ts +1 -1
- package/dist/react/use-project-session.js +1 -1
- package/dist/react/use-project-spaces.d.ts +11 -1
- package/dist/react/use-project-spaces.d.ts.map +1 -1
- package/dist/react/use-project-spaces.js +22 -1
- package/dist/react/use-project-spaces.js.map +1 -1
- package/dist/react/use-question-self-heal.js +1 -1
- package/dist/react/use-question-self-heal.js.map +1 -1
- package/dist/react/use-runtime-boot-stalled.d.ts +1 -1
- package/dist/react/use-runtime-boot-stalled.js +1 -1
- package/dist/react/{use-opencode-config.d.ts → use-runtime-config.d.ts} +4 -4
- package/dist/react/use-runtime-config.d.ts.map +1 -0
- package/dist/react/{use-opencode-config.js → use-runtime-config.js} +5 -5
- package/dist/react/use-runtime-config.js.map +1 -0
- package/dist/react/use-runtime-events/diagnostics.d.ts.map +1 -0
- package/dist/react/{use-opencode-events → use-runtime-events}/diagnostics.js +1 -1
- package/dist/react/use-runtime-events/diagnostics.js.map +1 -0
- package/dist/react/{use-opencode-events → use-runtime-events}/handle-event.d.ts +3 -3
- package/dist/react/use-runtime-events/handle-event.d.ts.map +1 -0
- package/dist/react/{use-opencode-events → use-runtime-events}/handle-event.js +1 -1
- package/dist/react/use-runtime-events/handle-event.js.map +1 -0
- package/dist/react/use-runtime-events/handle-interaction-event.d.ts.map +1 -0
- package/dist/react/use-runtime-events/handle-interaction-event.js.map +1 -0
- package/dist/react/use-runtime-events/handle-message-event.d.ts.map +1 -0
- package/dist/react/use-runtime-events/handle-message-event.js.map +1 -0
- package/dist/react/use-runtime-events/handle-session-event.d.ts.map +1 -0
- package/dist/react/{use-opencode-events → use-runtime-events}/handle-session-event.js +1 -1
- package/dist/react/use-runtime-events/handle-session-event.js.map +1 -0
- package/dist/react/use-runtime-events/handle-workspace-event.d.ts.map +1 -0
- package/dist/react/{use-opencode-events → use-runtime-events}/handle-workspace-event.js +6 -6
- package/dist/react/use-runtime-events/handle-workspace-event.js.map +1 -0
- package/dist/react/{use-opencode-events → use-runtime-events}/handler-context.d.ts +2 -2
- package/dist/react/use-runtime-events/handler-context.d.ts.map +1 -0
- package/dist/react/use-runtime-events/handler-context.js.map +1 -0
- package/dist/react/{use-opencode-events → use-runtime-events}/helpers.d.ts +4 -4
- package/dist/react/use-runtime-events/helpers.d.ts.map +1 -0
- package/dist/react/{use-opencode-events → use-runtime-events}/helpers.js +6 -5
- package/dist/react/use-runtime-events/helpers.js.map +1 -0
- package/dist/react/use-runtime-events/hydrate-core.d.ts.map +1 -0
- package/dist/react/use-runtime-events/hydrate-core.js.map +1 -0
- package/dist/react/{use-opencode-events → use-runtime-events}/index.d.ts +2 -2
- package/dist/react/use-runtime-events/index.d.ts.map +1 -0
- package/dist/react/{use-opencode-events → use-runtime-events}/index.js +8 -8
- package/dist/react/use-runtime-events/index.js.map +1 -0
- package/dist/react/use-runtime-events/log-control.d.ts.map +1 -0
- package/dist/react/{use-opencode-events → use-runtime-events}/log-control.js +11 -7
- package/dist/react/use-runtime-events/log-control.js.map +1 -0
- package/dist/react/use-runtime-events/rehydrate-targets.d.ts.map +1 -0
- package/dist/react/use-runtime-events/rehydrate-targets.js.map +1 -0
- package/dist/react/use-runtime-events/runtime-stream-signals.d.ts.map +1 -0
- package/dist/react/use-runtime-events/runtime-stream-signals.js.map +1 -0
- package/dist/react/use-runtime-events/stream-revival.d.ts.map +1 -0
- package/dist/react/use-runtime-events/stream-revival.js.map +1 -0
- package/dist/react/use-runtime-events/types.d.ts.map +1 -0
- package/dist/react/use-runtime-events/types.js.map +1 -0
- package/dist/react/{use-opencode-events → use-runtime-events}/use-event-stream-refs.d.ts +3 -3
- package/dist/react/use-runtime-events/use-event-stream-refs.d.ts.map +1 -0
- package/dist/react/{use-opencode-events → use-runtime-events}/use-event-stream-refs.js +4 -4
- package/dist/react/use-runtime-events/use-event-stream-refs.js.map +1 -0
- package/dist/react/{use-opencode-local.d.ts → use-runtime-local.d.ts} +1 -1
- package/dist/react/use-runtime-local.d.ts.map +1 -0
- package/dist/react/{use-opencode-local.js → use-runtime-local.js} +1 -1
- package/dist/react/use-runtime-local.js.map +1 -0
- package/dist/react/use-runtime-phase.js +1 -1
- package/dist/react/use-runtime-phase.js.map +1 -1
- package/dist/react/{use-opencode-pty.d.ts → use-runtime-pty.d.ts} +1 -1
- package/dist/react/use-runtime-pty.d.ts.map +1 -0
- package/dist/react/{use-opencode-pty.js → use-runtime-pty.js} +3 -3
- package/dist/react/use-runtime-pty.js.map +1 -0
- package/dist/react/use-runtime-reconnect.d.ts +13 -2
- package/dist/react/use-runtime-reconnect.d.ts.map +1 -1
- package/dist/react/use-runtime-reconnect.js +43 -7
- package/dist/react/use-runtime-reconnect.js.map +1 -1
- package/dist/react/{use-opencode-sessions → use-runtime-sessions}/agents.d.ts +2 -3
- package/dist/react/use-runtime-sessions/agents.d.ts.map +1 -0
- package/dist/react/{use-opencode-sessions → use-runtime-sessions}/agents.js +2 -3
- package/dist/react/use-runtime-sessions/agents.js.map +1 -0
- package/dist/react/use-runtime-sessions/commands.d.ts.map +1 -0
- package/dist/react/use-runtime-sessions/commands.js.map +1 -0
- package/dist/react/use-runtime-sessions/files.d.ts.map +1 -0
- package/dist/react/use-runtime-sessions/files.js.map +1 -0
- package/dist/react/use-runtime-sessions/index.d.ts.map +1 -0
- package/dist/react/{use-opencode-sessions → use-runtime-sessions}/index.js +3 -4
- package/dist/react/use-runtime-sessions/index.js.map +1 -0
- package/dist/react/{use-opencode-sessions → use-runtime-sessions}/keys.d.ts +23 -23
- package/dist/react/use-runtime-sessions/keys.d.ts.map +1 -0
- package/dist/react/{use-opencode-sessions → use-runtime-sessions}/keys.js +22 -22
- package/dist/react/use-runtime-sessions/keys.js.map +1 -0
- package/dist/react/{use-opencode-sessions → use-runtime-sessions}/log-sessions.d.ts +1 -1
- package/dist/react/use-runtime-sessions/log-sessions.d.ts.map +1 -0
- package/dist/react/use-runtime-sessions/log-sessions.js.map +1 -0
- package/dist/react/{use-opencode-sessions → use-runtime-sessions}/messages.d.ts +2 -2
- package/dist/react/use-runtime-sessions/messages.d.ts.map +1 -0
- package/dist/react/{use-opencode-sessions → use-runtime-sessions}/messages.js +3 -3
- package/dist/react/use-runtime-sessions/messages.js.map +1 -0
- package/dist/react/use-runtime-sessions/permissions.d.ts.map +1 -0
- package/dist/react/use-runtime-sessions/permissions.js.map +1 -0
- package/dist/react/use-runtime-sessions/projects.d.ts.map +1 -0
- package/dist/react/use-runtime-sessions/projects.js.map +1 -0
- package/dist/react/use-runtime-sessions/providers.d.ts.map +1 -0
- package/dist/react/{use-opencode-sessions → use-runtime-sessions}/providers.js +3 -3
- package/dist/react/use-runtime-sessions/providers.js.map +1 -0
- package/dist/react/{use-opencode-sessions → use-runtime-sessions}/sessions.d.ts +1 -1
- package/dist/react/use-runtime-sessions/sessions.d.ts.map +1 -0
- package/dist/react/{use-opencode-sessions → use-runtime-sessions}/sessions.js +13 -12
- package/dist/react/use-runtime-sessions/sessions.js.map +1 -0
- package/dist/react/{use-opencode-sessions → use-runtime-sessions}/shared.d.ts +5 -5
- package/dist/react/use-runtime-sessions/shared.d.ts.map +1 -0
- package/dist/react/{use-opencode-sessions → use-runtime-sessions}/shared.js +5 -5
- package/dist/react/use-runtime-sessions/shared.js.map +1 -0
- package/dist/react/use-runtime-sessions/vcs.d.ts.map +1 -0
- package/dist/react/use-runtime-sessions/vcs.js.map +1 -0
- package/dist/react/use-session-log.d.ts +1 -1
- package/dist/react/use-session-log.js +1 -1
- package/dist/react/use-session-model-selection.d.ts +1 -1
- package/dist/react/use-session-model-selection.d.ts.map +1 -1
- package/dist/react/use-session-model-selection.js +1 -1
- package/dist/react/use-session-model-selection.js.map +1 -1
- package/dist/react/use-session-prefetch.d.ts +1 -1
- package/dist/react/use-session-prefetch.d.ts.map +1 -1
- package/dist/react/use-session-prefetch.js +1 -1
- package/dist/react/use-session-prefetch.js.map +1 -1
- package/dist/react/use-session-prompts.d.ts +1 -1
- package/dist/react/use-session-prompts.d.ts.map +1 -1
- package/dist/react/use-session-prompts.js +5 -3
- package/dist/react/use-session-prompts.js.map +1 -1
- package/dist/react/use-session-send.d.ts +5 -5
- package/dist/react/use-session-send.d.ts.map +1 -1
- package/dist/react/use-session-send.js +1 -1
- package/dist/react/use-session-send.js.map +1 -1
- package/dist/react/use-session-stream.d.ts +10 -1
- package/dist/react/use-session-stream.d.ts.map +1 -1
- package/dist/react/use-session-stream.js +59 -12
- package/dist/react/use-session-stream.js.map +1 -1
- package/dist/react/use-session-sync.d.ts +1 -1
- package/dist/react/use-session-sync.js +4 -4
- package/dist/react/use-session-sync.js.map +1 -1
- package/dist/react/use-session-working.d.ts +2 -2
- package/dist/react/use-session-working.d.ts.map +1 -1
- package/dist/react/use-session-working.js +10 -5
- package/dist/react/use-session-working.js.map +1 -1
- package/dist/react/use-session.d.ts +10 -10
- package/dist/react/use-session.d.ts.map +1 -1
- package/dist/react/use-session.js +34 -24
- package/dist/react/use-session.js.map +1 -1
- package/dist/react/use-sessions-needing-input.d.ts +3 -1
- package/dist/react/use-sessions-needing-input.d.ts.map +1 -1
- package/dist/react/use-sessions-needing-input.js +4 -2
- package/dist/react/use-sessions-needing-input.js.map +1 -1
- package/dist/react/use-visible-agents.js +1 -1
- package/dist/react/use-visible-agents.js.map +1 -1
- package/dist/workspace-search/client.d.ts.map +1 -1
- package/dist/workspace-search/client.js +0 -1
- package/dist/workspace-search/client.js.map +1 -1
- package/package.json +3 -3
- package/dist/browser/stores/opencode-compaction-store.d.ts.map +0 -1
- package/dist/browser/stores/opencode-compaction-store.js.map +0 -1
- package/dist/browser/stores/opencode-pending-store.d.ts.map +0 -1
- package/dist/browser/stores/opencode-pending-store.js.map +0 -1
- package/dist/core/artifact-doc/base64.d.ts +0 -17
- package/dist/core/artifact-doc/base64.d.ts.map +0 -1
- package/dist/core/artifact-doc/base64.js +0 -69
- package/dist/core/artifact-doc/base64.js.map +0 -1
- package/dist/core/artifact-doc/index.d.ts +0 -7
- package/dist/core/artifact-doc/index.d.ts.map +0 -1
- package/dist/core/artifact-doc/index.js +0 -7
- package/dist/core/artifact-doc/index.js.map +0 -1
- package/dist/core/artifact-doc/sync.d.ts +0 -178
- package/dist/core/artifact-doc/sync.d.ts.map +0 -1
- package/dist/core/artifact-doc/sync.js +0 -838
- package/dist/core/artifact-doc/sync.js.map +0 -1
- package/dist/core/artifact-live/connection.d.ts +0 -116
- package/dist/core/artifact-live/connection.d.ts.map +0 -1
- package/dist/core/artifact-live/connection.js +0 -433
- package/dist/core/artifact-live/connection.js.map +0 -1
- package/dist/core/artifact-live/index.d.ts +0 -8
- package/dist/core/artifact-live/index.d.ts.map +0 -1
- package/dist/core/artifact-live/index.js +0 -7
- package/dist/core/artifact-live/index.js.map +0 -1
- package/dist/core/artifact-live/protocol.d.ts +0 -167
- package/dist/core/artifact-live/protocol.d.ts.map +0 -1
- package/dist/core/artifact-live/protocol.js +0 -153
- package/dist/core/artifact-live/protocol.js.map +0 -1
- package/dist/core/client/project-artifacts.d.ts +0 -74
- package/dist/core/client/project-artifacts.d.ts.map +0 -1
- package/dist/core/client/project-artifacts.js +0 -38
- package/dist/core/client/project-artifacts.js.map +0 -1
- package/dist/core/rest/projects-client/artifact-doc.d.ts +0 -118
- package/dist/core/rest/projects-client/artifact-doc.d.ts.map +0 -1
- package/dist/core/rest/projects-client/artifact-doc.js +0 -122
- package/dist/core/rest/projects-client/artifact-doc.js.map +0 -1
- package/dist/core/rest/projects-client/artifact-live.d.ts +0 -22
- package/dist/core/rest/projects-client/artifact-live.d.ts.map +0 -1
- package/dist/core/rest/projects-client/artifact-live.js +0 -25
- package/dist/core/rest/projects-client/artifact-live.js.map +0 -1
- package/dist/react/opencode.d.ts.map +0 -1
- package/dist/react/opencode.js.map +0 -1
- package/dist/react/use-artifact-live.d.ts +0 -41
- package/dist/react/use-artifact-live.d.ts.map +0 -1
- package/dist/react/use-artifact-live.js +0 -114
- package/dist/react/use-artifact-live.js.map +0 -1
- package/dist/react/use-canonical-opencode-session.d.ts.map +0 -1
- package/dist/react/use-canonical-opencode-session.js.map +0 -1
- package/dist/react/use-opencode-config.d.ts.map +0 -1
- package/dist/react/use-opencode-config.js.map +0 -1
- package/dist/react/use-opencode-events/diagnostics.d.ts.map +0 -1
- package/dist/react/use-opencode-events/diagnostics.js.map +0 -1
- package/dist/react/use-opencode-events/handle-event.d.ts.map +0 -1
- package/dist/react/use-opencode-events/handle-event.js.map +0 -1
- package/dist/react/use-opencode-events/handle-interaction-event.d.ts.map +0 -1
- package/dist/react/use-opencode-events/handle-interaction-event.js.map +0 -1
- package/dist/react/use-opencode-events/handle-message-event.d.ts.map +0 -1
- package/dist/react/use-opencode-events/handle-message-event.js.map +0 -1
- package/dist/react/use-opencode-events/handle-session-event.d.ts.map +0 -1
- package/dist/react/use-opencode-events/handle-session-event.js.map +0 -1
- package/dist/react/use-opencode-events/handle-workspace-event.d.ts.map +0 -1
- package/dist/react/use-opencode-events/handle-workspace-event.js.map +0 -1
- package/dist/react/use-opencode-events/handler-context.d.ts.map +0 -1
- package/dist/react/use-opencode-events/handler-context.js.map +0 -1
- package/dist/react/use-opencode-events/helpers.d.ts.map +0 -1
- package/dist/react/use-opencode-events/helpers.js.map +0 -1
- package/dist/react/use-opencode-events/hydrate-core.d.ts.map +0 -1
- package/dist/react/use-opencode-events/hydrate-core.js.map +0 -1
- package/dist/react/use-opencode-events/index.d.ts.map +0 -1
- package/dist/react/use-opencode-events/index.js.map +0 -1
- package/dist/react/use-opencode-events/log-control.d.ts.map +0 -1
- package/dist/react/use-opencode-events/log-control.js.map +0 -1
- package/dist/react/use-opencode-events/rehydrate-targets.d.ts.map +0 -1
- package/dist/react/use-opencode-events/rehydrate-targets.js.map +0 -1
- package/dist/react/use-opencode-events/runtime-stream-signals.d.ts.map +0 -1
- package/dist/react/use-opencode-events/runtime-stream-signals.js.map +0 -1
- package/dist/react/use-opencode-events/stream-revival.d.ts.map +0 -1
- package/dist/react/use-opencode-events/stream-revival.js.map +0 -1
- package/dist/react/use-opencode-events/types.d.ts.map +0 -1
- package/dist/react/use-opencode-events/types.js.map +0 -1
- package/dist/react/use-opencode-events/use-event-stream-refs.d.ts.map +0 -1
- package/dist/react/use-opencode-events/use-event-stream-refs.js.map +0 -1
- package/dist/react/use-opencode-local.d.ts.map +0 -1
- package/dist/react/use-opencode-local.js.map +0 -1
- package/dist/react/use-opencode-pty.d.ts.map +0 -1
- package/dist/react/use-opencode-pty.js.map +0 -1
- package/dist/react/use-opencode-sessions/agents.d.ts.map +0 -1
- package/dist/react/use-opencode-sessions/agents.js.map +0 -1
- package/dist/react/use-opencode-sessions/commands.d.ts.map +0 -1
- package/dist/react/use-opencode-sessions/commands.js.map +0 -1
- package/dist/react/use-opencode-sessions/files.d.ts.map +0 -1
- package/dist/react/use-opencode-sessions/files.js.map +0 -1
- package/dist/react/use-opencode-sessions/index.d.ts.map +0 -1
- package/dist/react/use-opencode-sessions/index.js.map +0 -1
- package/dist/react/use-opencode-sessions/keys.d.ts.map +0 -1
- package/dist/react/use-opencode-sessions/keys.js.map +0 -1
- package/dist/react/use-opencode-sessions/log-sessions.d.ts.map +0 -1
- package/dist/react/use-opencode-sessions/log-sessions.js.map +0 -1
- package/dist/react/use-opencode-sessions/messages.d.ts.map +0 -1
- package/dist/react/use-opencode-sessions/messages.js.map +0 -1
- package/dist/react/use-opencode-sessions/permissions.d.ts.map +0 -1
- package/dist/react/use-opencode-sessions/permissions.js.map +0 -1
- package/dist/react/use-opencode-sessions/projects.d.ts.map +0 -1
- package/dist/react/use-opencode-sessions/projects.js.map +0 -1
- package/dist/react/use-opencode-sessions/providers.d.ts.map +0 -1
- package/dist/react/use-opencode-sessions/providers.js.map +0 -1
- package/dist/react/use-opencode-sessions/sessions.d.ts.map +0 -1
- package/dist/react/use-opencode-sessions/sessions.js.map +0 -1
- package/dist/react/use-opencode-sessions/shared.d.ts.map +0 -1
- package/dist/react/use-opencode-sessions/shared.js.map +0 -1
- package/dist/react/use-opencode-sessions/vcs.d.ts.map +0 -1
- package/dist/react/use-opencode-sessions/vcs.js.map +0 -1
- /package/dist/react/{use-opencode-events → use-runtime-events}/diagnostics.d.ts +0 -0
- /package/dist/react/{use-opencode-events → use-runtime-events}/handle-interaction-event.d.ts +0 -0
- /package/dist/react/{use-opencode-events → use-runtime-events}/handle-interaction-event.js +0 -0
- /package/dist/react/{use-opencode-events → use-runtime-events}/handle-message-event.d.ts +0 -0
- /package/dist/react/{use-opencode-events → use-runtime-events}/handle-message-event.js +0 -0
- /package/dist/react/{use-opencode-events → use-runtime-events}/handle-session-event.d.ts +0 -0
- /package/dist/react/{use-opencode-events → use-runtime-events}/handle-workspace-event.d.ts +0 -0
- /package/dist/react/{use-opencode-events → use-runtime-events}/handler-context.js +0 -0
- /package/dist/react/{use-opencode-events → use-runtime-events}/hydrate-core.d.ts +0 -0
- /package/dist/react/{use-opencode-events → use-runtime-events}/hydrate-core.js +0 -0
- /package/dist/react/{use-opencode-events → use-runtime-events}/log-control.d.ts +0 -0
- /package/dist/react/{use-opencode-events → use-runtime-events}/rehydrate-targets.d.ts +0 -0
- /package/dist/react/{use-opencode-events → use-runtime-events}/rehydrate-targets.js +0 -0
- /package/dist/react/{use-opencode-events → use-runtime-events}/runtime-stream-signals.d.ts +0 -0
- /package/dist/react/{use-opencode-events → use-runtime-events}/runtime-stream-signals.js +0 -0
- /package/dist/react/{use-opencode-events → use-runtime-events}/stream-revival.d.ts +0 -0
- /package/dist/react/{use-opencode-events → use-runtime-events}/stream-revival.js +0 -0
- /package/dist/react/{use-opencode-events → use-runtime-events}/types.d.ts +0 -0
- /package/dist/react/{use-opencode-events → use-runtime-events}/types.js +0 -0
- /package/dist/react/{use-opencode-sessions → use-runtime-sessions}/commands.d.ts +0 -0
- /package/dist/react/{use-opencode-sessions → use-runtime-sessions}/commands.js +0 -0
- /package/dist/react/{use-opencode-sessions → use-runtime-sessions}/files.d.ts +0 -0
- /package/dist/react/{use-opencode-sessions → use-runtime-sessions}/files.js +0 -0
- /package/dist/react/{use-opencode-sessions → use-runtime-sessions}/index.d.ts +0 -0
- /package/dist/react/{use-opencode-sessions → use-runtime-sessions}/log-sessions.js +0 -0
- /package/dist/react/{use-opencode-sessions → use-runtime-sessions}/permissions.d.ts +0 -0
- /package/dist/react/{use-opencode-sessions → use-runtime-sessions}/permissions.js +0 -0
- /package/dist/react/{use-opencode-sessions → use-runtime-sessions}/projects.d.ts +0 -0
- /package/dist/react/{use-opencode-sessions → use-runtime-sessions}/projects.js +0 -0
- /package/dist/react/{use-opencode-sessions → use-runtime-sessions}/providers.d.ts +0 -0
- /package/dist/react/{use-opencode-sessions → use-runtime-sessions}/vcs.d.ts +0 -0
- /package/dist/react/{use-opencode-sessions → use-runtime-sessions}/vcs.js +0 -0
|
@@ -1,39 +1,69 @@
|
|
|
1
1
|
/**
|
|
2
2
|
* Goals (project flag `goals`): what a person wants plus a definition of
|
|
3
|
-
* done. An assigned agent works it
|
|
4
|
-
* verifier session
|
|
5
|
-
* `/Company/Goals/<slug>/` by default: `GOAL.md` (front matter = definition
|
|
6
|
-
* and state, `parseGoalFile`), `log.md` (append-only), `evidence/`. The
|
|
7
|
-
* `kortix goals` CLI writes it inside the owner session's sandbox. Its
|
|
8
|
-
* heartbeat is a loop on the owner session. Older folders hold `goal.json`.
|
|
3
|
+
* done. An assigned agent works it in an owner session until an independent
|
|
4
|
+
* verifier session passes every criterion.
|
|
9
5
|
*
|
|
10
|
-
* The
|
|
11
|
-
*
|
|
12
|
-
*
|
|
6
|
+
* The API owns the lifecycle (`/v1/projects/:projectId/goals/*`): state,
|
|
7
|
+
* pause, stop, owner, verifier, caps, wakes and verification live in the
|
|
8
|
+
* goal record, and every write carries the `revision` it read (a stale one
|
|
9
|
+
* throws `ProjectGoalConflictError` with the current goal). The goal's folder
|
|
10
|
+
* in Files holds the brief (`GOAL.md`), `log.md` and `evidence/`; lifecycle
|
|
11
|
+
* fields written into GOAL.md change nothing.
|
|
12
|
+
*
|
|
13
|
+
* Who may do what is the server's decision; `ProjectGoal.capabilities` says
|
|
14
|
+
* it per goal for the caller. A person creates, pauses, resumes, stops,
|
|
15
|
+
* restarts and answers; the owner session reports progress; only the
|
|
16
|
+
* verifier session decides done.
|
|
13
17
|
*/
|
|
14
|
-
import { ApiError } from '../../http/api-client.js';
|
|
18
|
+
import { ApiError, backendApi } from '../../http/api-client.js';
|
|
15
19
|
import { generateSessionId } from '../../../platform/session-id.js';
|
|
16
20
|
import { mintWireMessageId } from '../../session/wire-message-id.js';
|
|
17
|
-
import {
|
|
18
|
-
import {
|
|
19
|
-
import {
|
|
20
|
-
|
|
21
|
-
|
|
21
|
+
import { readDriveFile } from './drives.js';
|
|
22
|
+
import { createSessionPrompt } from './sessions.js';
|
|
23
|
+
import { unwrap } from './shared.js';
|
|
24
|
+
/**
|
|
25
|
+
* A goal write sent a stale `revision` (`409 goal_conflict`): someone or
|
|
26
|
+
* something changed the goal first. `goal` is the goal as it is now. Show it
|
|
27
|
+
* and let the person decide again; never resend the write blindly.
|
|
28
|
+
*/
|
|
29
|
+
export class ProjectGoalConflictError extends ApiError {
|
|
30
|
+
goal;
|
|
31
|
+
constructor(source, goal) {
|
|
32
|
+
super(source.message || 'The goal changed.', {
|
|
33
|
+
status: source.status,
|
|
34
|
+
code: 'goal_conflict',
|
|
35
|
+
details: source.details,
|
|
36
|
+
data: source.data,
|
|
37
|
+
response: source.response,
|
|
38
|
+
name: 'ProjectGoalConflictError',
|
|
39
|
+
});
|
|
40
|
+
this.goal = goal;
|
|
41
|
+
}
|
|
42
|
+
}
|
|
22
43
|
const CLOSED = new Set(['done', 'stopped', 'abandoned']);
|
|
23
44
|
const MISSED_WAKE_MS = 15 * 60_000;
|
|
24
45
|
const VERIFICATION_STALLED_MS = 24 * 3_600_000;
|
|
25
|
-
|
|
46
|
+
function isRecord(goal) {
|
|
47
|
+
return typeof goal.goal_id === 'string';
|
|
48
|
+
}
|
|
49
|
+
/**
|
|
50
|
+
* A goal's health at `now` (ms). For a server record (`ProjectGoalRecord`) it
|
|
51
|
+
* reads the server fields: `blocked_reason`, `next_wake_at` (a wake more than
|
|
52
|
+
* 15 minutes overdue), and the start of a pending verification (more than 24
|
|
53
|
+
* hours). A paused or waiting goal has no wake due, unless it asked to chase.
|
|
54
|
+
* `heartbeat` is ignored for a record. A `ProjectGoalDocument` (a GOAL.md
|
|
55
|
+
* read by hand) is judged by its heartbeat reminder, as before.
|
|
56
|
+
*/
|
|
26
57
|
export function goalHealth(goal, heartbeat, now = Date.now()) {
|
|
27
58
|
if (!goal)
|
|
28
59
|
return { state: 'attention', issues: ['unreadable'] };
|
|
60
|
+
if (isRecord(goal))
|
|
61
|
+
return recordHealth(goal, now);
|
|
29
62
|
if (CLOSED.has(goal.status))
|
|
30
63
|
return { state: 'closed', issues: [] };
|
|
31
|
-
// A person paused it: the disabled heartbeat is the pause, and nothing is due. A heartbeat
|
|
32
|
-
// that still runs means GOAL.md alone claims the pause (any session can write it): judge it as any other.
|
|
33
64
|
if (goal.paused_at && heartbeat?.state !== 'active')
|
|
34
65
|
return { state: 'healthy', issues: [] };
|
|
35
66
|
const issues = [];
|
|
36
|
-
// Started again: the owner's turn end arms the heartbeat, so its absence is a problem only after the missed-wake window.
|
|
37
67
|
const restartedAt = [...(goal.transitions ?? [])].reverse().find((t) => t.from === 'stopped')?.at;
|
|
38
68
|
const waking = !!restartedAt && Date.parse(restartedAt) > now - MISSED_WAKE_MS;
|
|
39
69
|
if (!heartbeat || heartbeat.state === 'done') {
|
|
@@ -56,299 +86,195 @@ export function goalHealth(goal, heartbeat, now = Date.now()) {
|
|
|
56
86
|
}
|
|
57
87
|
return { state: issues.length ? 'attention' : 'healthy', issues };
|
|
58
88
|
}
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
89
|
+
function recordHealth(goal, now) {
|
|
90
|
+
if (goal.state === 'done' || goal.state === 'stopped')
|
|
91
|
+
return { state: 'closed', issues: [] };
|
|
92
|
+
if (goal.paused_at)
|
|
93
|
+
return { state: 'healthy', issues: [] };
|
|
94
|
+
// The reason explains the stall; a wake check on top would say the same twice.
|
|
95
|
+
if (goal.blocked_reason)
|
|
96
|
+
return { state: 'attention', issues: ['blocked'] };
|
|
97
|
+
const issues = [];
|
|
98
|
+
const overdue = !!goal.next_wake_at && Date.parse(goal.next_wake_at) < now - MISSED_WAKE_MS;
|
|
99
|
+
if (goal.state === 'active') {
|
|
100
|
+
if (!goal.next_wake_at)
|
|
101
|
+
issues.push('no_heartbeat');
|
|
102
|
+
else if (overdue)
|
|
103
|
+
issues.push('missed_wake');
|
|
63
104
|
}
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
105
|
+
else if (goal.state === 'waiting_on_user' && goal.chase_at && overdue) {
|
|
106
|
+
issues.push('missed_wake');
|
|
107
|
+
}
|
|
108
|
+
if (goal.state === 'verifying' && goal.verification?.outcome === 'pending' && Date.parse(goal.verification.started_at) < now - VERIFICATION_STALLED_MS) {
|
|
109
|
+
issues.push('verification_stalled');
|
|
69
110
|
}
|
|
111
|
+
return { state: issues.length ? 'attention' : 'healthy', issues };
|
|
70
112
|
}
|
|
71
|
-
|
|
113
|
+
/** The record in the shape of GOAL.md front matter, for callers that read `ProjectGoal.goal`. */
|
|
114
|
+
function recordDocument(record) {
|
|
115
|
+
return {
|
|
116
|
+
version: 1,
|
|
117
|
+
objective: record.title,
|
|
118
|
+
status: record.state,
|
|
119
|
+
summary: record.summary,
|
|
120
|
+
success_criteria: record.criteria.map((c) => ({ id: c.id, text: c.text, met: c.reported_met, evidence: c.evidence })),
|
|
121
|
+
items: [],
|
|
122
|
+
sessions: record.sessions,
|
|
123
|
+
reminder_id: null,
|
|
124
|
+
transitions: [],
|
|
125
|
+
verified_by: record.verification?.outcome === 'pass' ? record.verification.verifier_session_id : null,
|
|
126
|
+
next_wake_at: record.next_wake_at,
|
|
127
|
+
space: record.space,
|
|
128
|
+
agent: record.agent,
|
|
129
|
+
assigned_user: record.assigned_user_id,
|
|
130
|
+
links: [],
|
|
131
|
+
waiting_on: record.waiting_on,
|
|
132
|
+
heartbeat_every: record.heartbeat_every,
|
|
133
|
+
max_wakes_per_day: record.max_wakes_per_day,
|
|
134
|
+
max_sessions: record.max_sessions,
|
|
135
|
+
wake_day: null,
|
|
136
|
+
wake_count: record.wakes_today,
|
|
137
|
+
last_wake_at: record.last_wake_at,
|
|
138
|
+
paused_at: record.paused_at,
|
|
139
|
+
paused_by: record.paused_by_user_id,
|
|
140
|
+
format: 'goal.md',
|
|
141
|
+
};
|
|
142
|
+
}
|
|
143
|
+
function toProjectGoal(record, now = Date.now()) {
|
|
144
|
+
return {
|
|
145
|
+
slug: record.slug,
|
|
146
|
+
scope: record.folder.startsWith('/Company/') ? 'company' : 'personal',
|
|
147
|
+
driveId: record.drive_id,
|
|
148
|
+
folder: record.folder,
|
|
149
|
+
goal: recordDocument(record),
|
|
150
|
+
heartbeat: null,
|
|
151
|
+
coordinatorSessionId: record.owner_session_id,
|
|
152
|
+
health: goalHealth(record, null, now),
|
|
153
|
+
projectId: record.project_id,
|
|
154
|
+
goalId: record.goal_id,
|
|
155
|
+
revision: record.revision,
|
|
156
|
+
capabilities: record.capabilities,
|
|
157
|
+
blockedReason: record.blocked_reason,
|
|
158
|
+
verification: record.verification,
|
|
159
|
+
criteria: record.criteria,
|
|
160
|
+
record,
|
|
161
|
+
};
|
|
162
|
+
}
|
|
163
|
+
function written(record) {
|
|
164
|
+
const projectGoal = toProjectGoal(record);
|
|
165
|
+
return { ...recordDocument(record), projectGoal };
|
|
166
|
+
}
|
|
167
|
+
/** A `409 goal_conflict` with the current goal becomes a `ProjectGoalConflictError`; anything else is thrown as is. */
|
|
168
|
+
function conflict(error) {
|
|
169
|
+
if (!(error instanceof ApiError) || error.status !== 409)
|
|
170
|
+
return error;
|
|
171
|
+
const body = error.details;
|
|
172
|
+
if (body?.error !== 'goal_conflict' || !body.goal || typeof body.goal.goal_id !== 'string')
|
|
173
|
+
return error;
|
|
174
|
+
return new ProjectGoalConflictError(error, toProjectGoal(body.goal));
|
|
175
|
+
}
|
|
176
|
+
/** Send one goal write; a `409 goal_conflict` throws `ProjectGoalConflictError`. */
|
|
177
|
+
async function goalWrite(send) {
|
|
72
178
|
try {
|
|
73
|
-
return
|
|
179
|
+
return unwrap(await send(), 'Goal request failed').goal;
|
|
74
180
|
}
|
|
75
181
|
catch (error) {
|
|
76
|
-
|
|
77
|
-
return null;
|
|
78
|
-
throw error;
|
|
182
|
+
throw conflict(error);
|
|
79
183
|
}
|
|
80
184
|
}
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
185
|
+
const goalsPath = (projectId) => `/projects/${encodeURIComponent(projectId)}/goals`;
|
|
186
|
+
const goalPath = (projectId, goalId) => `${goalsPath(projectId)}/${encodeURIComponent(goalId)}`;
|
|
187
|
+
/** The route is not there for this caller: no such project route (404) or the `goals` flag is off (403 `feature_disabled`). */
|
|
188
|
+
function routeOff(error) {
|
|
189
|
+
return error instanceof ApiError && (error.status === 404 || (error.status === 403 && error.code === 'feature_disabled'));
|
|
190
|
+
}
|
|
191
|
+
/**
|
|
192
|
+
* Every goal in the project the caller may read, from the API: their own,
|
|
193
|
+
* the ones assigned to them, the ones in folders shared with them, and all
|
|
194
|
+
* of them for a project admin. Empty when the `goals` flag is off.
|
|
195
|
+
*/
|
|
196
|
+
export async function listProjectGoals(projectId, options) {
|
|
197
|
+
let records;
|
|
84
198
|
try {
|
|
85
|
-
|
|
86
|
-
if (!value || typeof value !== 'object' || typeof value.objective !== 'string')
|
|
87
|
-
return null;
|
|
88
|
-
// A member can write any JSON here: keep only object entries of real arrays.
|
|
89
|
-
const list = (v) => (Array.isArray(v) ? v.filter((x) => x && typeof x === 'object') : []);
|
|
90
|
-
return {
|
|
91
|
-
...value,
|
|
92
|
-
success_criteria: list(value.success_criteria),
|
|
93
|
-
items: list(value.items),
|
|
94
|
-
sessions: list(value.sessions),
|
|
95
|
-
transitions: list(value.transitions),
|
|
96
|
-
format: 'goal.json',
|
|
97
|
-
};
|
|
199
|
+
records = unwrap(await backendApi.get(goalsPath(projectId)), 'Goals request failed').goals;
|
|
98
200
|
}
|
|
99
|
-
catch {
|
|
100
|
-
|
|
201
|
+
catch (error) {
|
|
202
|
+
if (routeOff(error))
|
|
203
|
+
return [];
|
|
204
|
+
throw error;
|
|
101
205
|
}
|
|
206
|
+
const now = options?.now ?? Date.now();
|
|
207
|
+
return records.map((record) => toProjectGoal(record, now));
|
|
102
208
|
}
|
|
103
|
-
/**
|
|
104
|
-
function
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
/** GOAL.md, else a legacy goal.json. */
|
|
108
|
-
async function readGoalDocument(driveId, folder) {
|
|
109
|
-
const md = await readText(driveId, `${folder}/GOAL.md`);
|
|
110
|
-
if (md !== null)
|
|
111
|
-
return parseGoalFile(md);
|
|
112
|
-
return parseGoalJson(await readText(driveId, `${folder}/goal.json`));
|
|
113
|
-
}
|
|
114
|
-
/** The session that works the goal now: the last `owner` (or legacy `coordinator`). */
|
|
115
|
-
function ownerSessionId(goal) {
|
|
116
|
-
return [...(goal?.sessions ?? [])].reverse().find((s) => s.role === 'owner' || s.role === 'coordinator')?.id ?? null;
|
|
209
|
+
/** One goal by its `goal_id`. Throws `ApiError` 404 (no such goal) or 403 (no access). */
|
|
210
|
+
export async function getProjectGoal(projectId, goalId, options) {
|
|
211
|
+
const { goal } = unwrap(await backendApi.get(goalPath(projectId, goalId)), 'Goal request failed');
|
|
212
|
+
return toProjectGoal(goal, options?.now);
|
|
117
213
|
}
|
|
118
|
-
/**
|
|
119
|
-
function
|
|
120
|
-
const
|
|
121
|
-
const
|
|
122
|
-
|
|
123
|
-
return byId;
|
|
124
|
-
const boxFolder = goalBoxFolder({ scope, slug });
|
|
125
|
-
return live.find((r) => new RegExp(`${boxFolder.replace(/[.*+?^${}()|[\]\\]/g, '\\$&')}(?![\\w-])`).test(r.prompt)) ?? null;
|
|
214
|
+
/** A page of a goal's audit trail, oldest first. Pass `nextCursor` back as `cursor` for the next page; null: no more. */
|
|
215
|
+
export async function listProjectGoalEvents(projectId, goalId, options) {
|
|
216
|
+
const query = options?.cursor ? `?cursor=${encodeURIComponent(options.cursor)}` : '';
|
|
217
|
+
const page = unwrap(await backendApi.get(`${goalPath(projectId, goalId)}/events${query}`), 'Goal events request failed');
|
|
218
|
+
return { events: page.events, nextCursor: page.next_cursor };
|
|
126
219
|
}
|
|
127
220
|
/**
|
|
128
|
-
*
|
|
129
|
-
*
|
|
221
|
+
* Bind a goal to a space or an agent (`PATCH …/goals/:goalId`): null clears
|
|
222
|
+
* one, an absent key keeps it. Grouping only: it grants nothing. A stale
|
|
223
|
+
* `revision` throws `ProjectGoalConflictError`.
|
|
130
224
|
*/
|
|
131
|
-
export async function
|
|
132
|
-
const
|
|
133
|
-
|
|
225
|
+
export async function setProjectGoalBinding(goal, binding) {
|
|
226
|
+
const projectId = goal.projectId ?? goal.record?.project_id;
|
|
227
|
+
if (!projectId)
|
|
228
|
+
throw new Error('setProjectGoalBinding needs the goal\'s projectId.');
|
|
229
|
+
return written(await goalWrite(() => backendApi.patch(goalPath(projectId, goal.goalId), { revision: goal.revision, ...binding })));
|
|
230
|
+
}
|
|
231
|
+
async function readText(driveId, path) {
|
|
232
|
+
try {
|
|
233
|
+
return await (await readDriveFile(driveId, path)).blob.text();
|
|
234
|
+
}
|
|
235
|
+
catch (error) {
|
|
134
236
|
if (error instanceof ApiError && error.status === 404)
|
|
135
237
|
return null;
|
|
136
238
|
throw error;
|
|
137
|
-
}
|
|
138
|
-
if (!drive)
|
|
139
|
-
return [];
|
|
140
|
-
const roots = [{ scope: 'company', path: '/Company/Goals' }];
|
|
141
|
-
if (drive.personalFolder)
|
|
142
|
-
roots.push({ scope: 'personal', path: `${drive.personalFolder}/Goals` });
|
|
143
|
-
const folders = (await Promise.all(roots.map(async (root) => (await folderDirs(drive.driveId, root.path)).sort().map((folder) => ({ ...root, folder }))))).flat();
|
|
144
|
-
if (folders.length === 0)
|
|
145
|
-
return [];
|
|
146
|
-
const [{ reminders }, docs] = await Promise.all([
|
|
147
|
-
listProjectReminders(projectId),
|
|
148
|
-
Promise.all(folders.map((f) => readGoalDocument(drive.driveId, f.folder))),
|
|
149
|
-
]);
|
|
150
|
-
const now = options?.now ?? Date.now();
|
|
151
|
-
return folders.map((f, index) => {
|
|
152
|
-
const goal = docs[index] ?? null;
|
|
153
|
-
const slug = f.folder.split('/').at(-1) ?? f.folder;
|
|
154
|
-
const heartbeat = findHeartbeat(reminders, goal, f.scope, slug);
|
|
155
|
-
return {
|
|
156
|
-
slug,
|
|
157
|
-
scope: f.scope,
|
|
158
|
-
driveId: drive.driveId,
|
|
159
|
-
folder: f.folder,
|
|
160
|
-
goal,
|
|
161
|
-
heartbeat,
|
|
162
|
-
coordinatorSessionId: ownerSessionId(goal) ?? heartbeat?.session_id ?? null,
|
|
163
|
-
health: goalHealth(goal, heartbeat, now),
|
|
164
|
-
};
|
|
165
|
-
});
|
|
166
|
-
}
|
|
167
|
-
/**
|
|
168
|
-
* Bind a goal to a space or an agent: read `goal.json` with its version,
|
|
169
|
-
* merge `space` / `agent` (null clears one, an absent key keeps it) and write
|
|
170
|
-
* it back with `If-Match`. A concurrent write throws `ApiError` 409. Returns
|
|
171
|
-
* the document as written. Grouping only: it grants nothing.
|
|
172
|
-
*/
|
|
173
|
-
export async function setProjectGoalBinding(goal, binding) {
|
|
174
|
-
const path = `${goal.folder}/goal.json`;
|
|
175
|
-
const { blob, version } = await readDriveFile(goal.driveId, path);
|
|
176
|
-
const current = JSON.parse(await blob.text());
|
|
177
|
-
const next = { ...current };
|
|
178
|
-
if (binding.space !== undefined)
|
|
179
|
-
next.space = binding.space;
|
|
180
|
-
if (binding.agent !== undefined)
|
|
181
|
-
next.agent = binding.agent;
|
|
182
|
-
const body = new TextEncoder().encode(`${JSON.stringify(next, null, 2)}\n`);
|
|
183
|
-
await uploadDriveFile(goal.driveId, path, body, { ifMatch: version });
|
|
184
|
-
return next;
|
|
239
|
+
}
|
|
185
240
|
}
|
|
186
241
|
/** A goal folder's text files. A missing file is null. */
|
|
187
242
|
export async function getProjectGoalFiles(driveId, folder) {
|
|
188
|
-
const [log, notes, verification] = await Promise.all([
|
|
243
|
+
const [brief, log, notes, verification] = await Promise.all([
|
|
244
|
+
readText(driveId, `${folder}/GOAL.md`),
|
|
189
245
|
readText(driveId, `${folder}/log.md`),
|
|
190
246
|
readText(driveId, `${folder}/notes.md`),
|
|
191
247
|
readText(driveId, `${folder}/evidence/verification.md`),
|
|
192
248
|
]);
|
|
193
|
-
return { log, notes, verification };
|
|
249
|
+
return { brief, log, notes, verification };
|
|
194
250
|
}
|
|
195
251
|
/**
|
|
196
|
-
* A person stops a goal (any open state → `stopped
|
|
197
|
-
*
|
|
198
|
-
*
|
|
199
|
-
* again. Returns the document as written. Throws on a closed goal and on a
|
|
200
|
-
* legacy `goal.json` folder.
|
|
252
|
+
* A person stops a goal (`POST …/stop`): any open state → `stopped`. The API
|
|
253
|
+
* removes the heartbeat and aborts the owner's running turn. A retry on a
|
|
254
|
+
* goal that is already stopped finishes that cleanup and succeeds.
|
|
201
255
|
*/
|
|
202
256
|
export async function stopProjectGoal(projectId, goal, reason) {
|
|
203
|
-
|
|
204
|
-
const { blob, version } = await readDriveFile(goal.driveId, path);
|
|
205
|
-
const current = parseGoalFile(await blob.text());
|
|
206
|
-
if (!current)
|
|
207
|
-
throw new Error(`${path} is not a goal file.`);
|
|
208
|
-
if (CLOSED.has(current.status))
|
|
209
|
-
throw new Error(`The goal is already ${current.status}.`);
|
|
210
|
-
const at = new Date().toISOString();
|
|
211
|
-
const next = {
|
|
212
|
-
...current,
|
|
213
|
-
status: 'stopped',
|
|
214
|
-
waiting_on: null,
|
|
215
|
-
paused_at: null,
|
|
216
|
-
paused_by: null,
|
|
217
|
-
reminder_id: null,
|
|
218
|
-
next_wake_at: null,
|
|
219
|
-
transitions: [...current.transitions, { from: current.status, to: 'stopped', at, reason, by: 'person' }],
|
|
220
|
-
};
|
|
221
|
-
await uploadDriveFile(goal.driveId, path, new TextEncoder().encode(formatGoalFile(next)), { ifMatch: version });
|
|
222
|
-
await appendGoalLog(goal, `- ${at} ${current.status} → stopped: ${reason}`);
|
|
223
|
-
if (goal.heartbeat?.session_id && goal.heartbeat.state !== 'done') {
|
|
224
|
-
await deleteSessionReminder(projectId, goal.heartbeat.session_id, goal.heartbeat.id);
|
|
225
|
-
}
|
|
226
|
-
return next;
|
|
227
|
-
}
|
|
228
|
-
/** Append one line to the goal's `log.md` (created when missing). */
|
|
229
|
-
async function appendGoalLog(goal, line) {
|
|
230
|
-
const log = (await readText(goal.driveId, `${goal.folder}/log.md`)) ?? '# Log\n';
|
|
231
|
-
await uploadDriveFile(goal.driveId, `${goal.folder}/log.md`, new TextEncoder().encode(`${log.trimEnd()}\n${line}\n`));
|
|
232
|
-
}
|
|
233
|
-
/** Read GOAL.md with its version. Throws on a folder without one (a legacy `goal.json`). */
|
|
234
|
-
async function readGoalForWrite(goal) {
|
|
235
|
-
const path = `${goal.folder}/GOAL.md`;
|
|
236
|
-
const { blob, version } = await readDriveFile(goal.driveId, path);
|
|
237
|
-
const doc = parseGoalFile(await blob.text());
|
|
238
|
-
if (!doc)
|
|
239
|
-
throw new Error(`${path} is not a goal file.`);
|
|
240
|
-
return { doc, version };
|
|
257
|
+
return written(await goalWrite(() => backendApi.post(`${goalPath(projectId, goal.goalId)}/stop`, { revision: goal.revision, reason })));
|
|
241
258
|
}
|
|
242
259
|
/**
|
|
243
|
-
* A person pauses a goal
|
|
244
|
-
*
|
|
245
|
-
* and the
|
|
246
|
-
* up where the goal was. A turn already running finishes; no new one starts.
|
|
247
|
-
* Throws on a closed goal. On a goal GOAL.md already records as paused (a
|
|
248
|
-
* retry after the heartbeat update failed) it only disables the heartbeat.
|
|
260
|
+
* A person pauses a goal (`POST …/pause`). The state does not change; no new
|
|
261
|
+
* turn starts until a person resumes it. A turn already running finishes,
|
|
262
|
+
* and the API refuses its lifecycle writes.
|
|
249
263
|
*/
|
|
250
264
|
export async function pauseProjectGoal(projectId, goal, reason) {
|
|
251
|
-
|
|
252
|
-
if (CLOSED.has(current.status))
|
|
253
|
-
throw new Error(`The goal is already ${current.status}.`);
|
|
254
|
-
let next = current;
|
|
255
|
-
// Already paused: a retry after the heartbeat update failed. Finish that step only.
|
|
256
|
-
if (!current.paused_at) {
|
|
257
|
-
const at = new Date().toISOString();
|
|
258
|
-
next = { ...current, paused_at: at, paused_by: 'person' };
|
|
259
|
-
await uploadDriveFile(goal.driveId, `${goal.folder}/GOAL.md`, new TextEncoder().encode(formatGoalFile(next)), { ifMatch: version });
|
|
260
|
-
await appendGoalLog(goal, `- ${at} paused: ${reason}`);
|
|
261
|
-
}
|
|
262
|
-
if (goal.heartbeat?.session_id && goal.heartbeat.state === 'active') {
|
|
263
|
-
await updateSessionReminder(projectId, goal.heartbeat.session_id, goal.heartbeat.id, { enabled: false });
|
|
264
|
-
}
|
|
265
|
-
return next;
|
|
265
|
+
return written(await goalWrite(() => backendApi.post(`${goalPath(projectId, goal.goalId)}/pause`, { revision: goal.revision, reason })));
|
|
266
266
|
}
|
|
267
|
-
/**
|
|
268
|
-
* A person resumes a paused goal, in this order: the heartbeat is enabled
|
|
269
|
-
* again, GOAL.md clears `paused_at` (`log.md` records it), and the owner
|
|
270
|
-
* session wakes now (its turn end re-arms a heartbeat that went missing). A
|
|
271
|
-
* retry after a later step failed finishes the steps left: a goal GOAL.md
|
|
272
|
-
* already records as running gets its heartbeat enabled, and a wake when it
|
|
273
|
-
* has no live heartbeat.
|
|
274
|
-
*/
|
|
267
|
+
/** A person resumes a paused goal (`POST …/resume`): the heartbeat runs again and the owner wakes once. */
|
|
275
268
|
export async function resumeProjectGoal(projectId, goal) {
|
|
276
|
-
|
|
277
|
-
if (CLOSED.has(current.status))
|
|
278
|
-
throw new Error(`The goal is already ${current.status}.`);
|
|
279
|
-
const pausedAt = current.paused_at;
|
|
280
|
-
// 1. The heartbeat first: whatever fails after it, something still wakes the goal.
|
|
281
|
-
const heartbeatLive = goal.heartbeat?.session_id && goal.heartbeat.state !== 'done';
|
|
282
|
-
if (goal.heartbeat?.session_id && goal.heartbeat.state === 'paused') {
|
|
283
|
-
await updateSessionReminder(projectId, goal.heartbeat.session_id, goal.heartbeat.id, { enabled: true });
|
|
284
|
-
}
|
|
285
|
-
// 2. Clear the pause. Already clear: a retry after a later step failed.
|
|
286
|
-
let next = current;
|
|
287
|
-
if (pausedAt) {
|
|
288
|
-
next = { ...current, paused_at: null, paused_by: null };
|
|
289
|
-
await uploadDriveFile(goal.driveId, `${goal.folder}/GOAL.md`, new TextEncoder().encode(formatGoalFile(next)), { ifMatch: version });
|
|
290
|
-
await appendGoalLog(goal, `- ${new Date().toISOString()} resumed`);
|
|
291
|
-
}
|
|
292
|
-
// 3. Wake the owner now: once per pause (its id names the pause, so a repeat is deduped), or
|
|
293
|
-
// on a retry when no heartbeat would ever wake it.
|
|
294
|
-
const owner = ownerSessionId(current) ?? goal.coordinatorSessionId;
|
|
295
|
-
const wake = `${goalWakePrompt(goalBoxFolder(goal))} A person resumed it.`;
|
|
296
|
-
if (owner && pausedAt)
|
|
297
|
-
await queueText(projectId, owner, wake, `goal-resume:${owner}:${pausedAt}`);
|
|
298
|
-
else if (owner && !heartbeatLive)
|
|
299
|
-
await queueText(projectId, owner, wake);
|
|
300
|
-
return next;
|
|
269
|
+
return written(await goalWrite(() => backendApi.post(`${goalPath(projectId, goal.goalId)}/resume`, { revision: goal.revision })));
|
|
301
270
|
}
|
|
302
271
|
/**
|
|
303
|
-
* A person starts a stopped goal again
|
|
304
|
-
*
|
|
305
|
-
*
|
|
306
|
-
* 409), `log.md` records the move, and then the owner session wakes. Its turn
|
|
307
|
-
* end (`kortix goals check --enforce`) arms the heartbeat the stop removed.
|
|
308
|
-
* The wake id names the stop, so a retry is deduped. A retry after the wake
|
|
309
|
-
* failed (the goal is open again, but no live heartbeat wakes it) writes
|
|
310
|
-
* nothing and only wakes the owner. Throws on any other goal.
|
|
272
|
+
* A person starts a stopped goal again (`POST …/restart`): `active` when it
|
|
273
|
+
* has criteria, else `draft`. When the owner session is gone the API starts a
|
|
274
|
+
* new one (within `max_sessions`).
|
|
311
275
|
*/
|
|
312
276
|
export async function restartProjectGoal(projectId, goal, reason) {
|
|
313
|
-
|
|
314
|
-
const heartbeatLive = !!goal.heartbeat?.session_id && goal.heartbeat.state !== 'done';
|
|
315
|
-
const retry = !CLOSED.has(current.status) && !current.paused_at && !heartbeatLive;
|
|
316
|
-
if (current.status !== 'stopped' && !retry)
|
|
317
|
-
throw new Error(`The goal is ${current.status}, not stopped.`);
|
|
318
|
-
const stoppedAt = [...current.transitions].reverse().find((t) => t.to === 'stopped')?.at ?? null;
|
|
319
|
-
const to = retry ? current.status : current.success_criteria.length ? 'active' : 'draft';
|
|
320
|
-
let next = current;
|
|
321
|
-
if (!retry) {
|
|
322
|
-
const at = new Date().toISOString();
|
|
323
|
-
next = { ...current, status: to, transitions: [...current.transitions, { from: 'stopped', to, at, reason, by: 'person' }] };
|
|
324
|
-
await uploadDriveFile(goal.driveId, `${goal.folder}/GOAL.md`, new TextEncoder().encode(formatGoalFile(next)), { ifMatch: version });
|
|
325
|
-
await appendGoalLog(goal, `- ${at} stopped → ${to}: ${reason}`);
|
|
326
|
-
}
|
|
327
|
-
const owner = ownerSessionId(current) ?? goal.coordinatorSessionId;
|
|
328
|
-
if (owner) {
|
|
329
|
-
const first = to === 'draft'
|
|
330
|
-
? 'A person started it again: write 1 to 8 done criteria someone else can check into GOAL.md, then move it to active and continue the work.'
|
|
331
|
-
: 'A person started it again: read log.md for where it stopped and continue the work.';
|
|
332
|
-
const wakeId = stoppedAt ? `goal-restart:${owner}:${stoppedAt}` : generateSessionId();
|
|
333
|
-
await queueText(projectId, owner, `${goalWakePrompt(goalBoxFolder(goal))} ${first}`, wakeId);
|
|
334
|
-
}
|
|
335
|
-
return next;
|
|
336
|
-
}
|
|
337
|
-
/** The prompt every wake of a goal starts with; the API finds a goal's heartbeat by it. Same text as `kortix goals`. */
|
|
338
|
-
function goalWakePrompt(boxFolder) {
|
|
339
|
-
return `Goal wake: ${boxFolder}. Load the kortix-goals skill and run one wake.`;
|
|
340
|
-
}
|
|
341
|
-
/** A goal folder name from its outcome: lowercase words joined by `-`, at most 5. Same rule as `kortix goals new`. */
|
|
342
|
-
function goalSlug(text) {
|
|
343
|
-
return (text
|
|
344
|
-
.toLowerCase()
|
|
345
|
-
.normalize('NFKD')
|
|
346
|
-
.replace(/[^a-z0-9]+/g, '-')
|
|
347
|
-
// One `-` at most at each end: the line above leaves no `--` (and a `-+$` would backtrack).
|
|
348
|
-
.replace(/^-|-$/g, '')
|
|
349
|
-
.split('-')
|
|
350
|
-
.slice(0, 5)
|
|
351
|
-
.join('-') || 'goal');
|
|
277
|
+
return written(await goalWrite(() => backendApi.post(`${goalPath(projectId, goal.goalId)}/restart`, { revision: goal.revision, reason })));
|
|
352
278
|
}
|
|
353
279
|
const MAX_GOAL_CRITERIA = 8;
|
|
354
280
|
/** My Kortix's sandbox slugs (current and legacy): a session on one mounts no Files, so it cannot run `kortix goals`. */
|
|
@@ -367,126 +293,42 @@ export function defaultGoalAgent(config) {
|
|
|
367
293
|
const pick = agents.find((a) => a.name === config.default_agent) ?? agents.find((a) => a.mode !== 'subagent') ?? agents[0];
|
|
368
294
|
return pick?.name ?? null;
|
|
369
295
|
}
|
|
370
|
-
async function resolveGoalAgent(projectId, requested) {
|
|
371
|
-
const { config } = await getProjectDetail(projectId);
|
|
372
|
-
if (requested) {
|
|
373
|
-
if (!goalAgents(config).some((a) => a.name === requested))
|
|
374
|
-
throw new Error(`${requested} cannot work a goal: it has no Files. Pick another agent.`);
|
|
375
|
-
return requested;
|
|
376
|
-
}
|
|
377
|
-
const pick = defaultGoalAgent(config);
|
|
378
|
-
if (!pick)
|
|
379
|
-
throw new Error('This project has no agent that can work a goal. Add an agent, then try again.');
|
|
380
|
-
return pick;
|
|
381
|
-
}
|
|
382
296
|
/**
|
|
383
|
-
* A person creates a goal
|
|
384
|
-
*
|
|
385
|
-
*
|
|
386
|
-
*
|
|
387
|
-
*
|
|
388
|
-
*
|
|
389
|
-
* the session its owner: no step depends on the model remembering it.
|
|
390
|
-
* A slug another goal holds gets `-2`, `-3`, …. Retrying with the same
|
|
391
|
-
* `sessionId` is safe: a `409` session create is the session that already
|
|
392
|
-
* exists, a folder it owns is reused, and the first wake is deduped.
|
|
297
|
+
* A person creates a goal (`POST /projects/:projectId/goals`). The API puts
|
|
298
|
+
* it in the caller's own folder, writes GOAL.md and log.md, starts the owner
|
|
299
|
+
* session with its heartbeat, and sends the first wake. `goalId` is the
|
|
300
|
+
* idempotency key: a retry with the same id returns the same goal and starts
|
|
301
|
+
* nothing twice. Throws before any request on an empty outcome or more than
|
|
302
|
+
* 8 criteria; the API refuses an agent without Files.
|
|
393
303
|
*/
|
|
394
304
|
export async function createProjectGoal(projectId, input) {
|
|
395
|
-
const
|
|
396
|
-
if (!
|
|
305
|
+
const text = input.outcome.trim();
|
|
306
|
+
if (!text)
|
|
397
307
|
throw new Error('Describe the outcome.');
|
|
398
|
-
|
|
399
|
-
const
|
|
400
|
-
const
|
|
401
|
-
const context = briefContext(rest) || "The request in the person's words, constraints, and what was learned.";
|
|
308
|
+
const [firstLine = '', ...rest] = text.split('\n');
|
|
309
|
+
const context = briefContext(rest);
|
|
310
|
+
const brief = context ? `${firstLine.trim()}\n${context}` : firstLine.trim();
|
|
402
311
|
const criteria = (input.criteria ?? []).map((c) => c.trim()).filter(Boolean);
|
|
403
312
|
if (criteria.length > MAX_GOAL_CRITERIA)
|
|
404
313
|
throw new Error(`A goal has at most ${MAX_GOAL_CRITERIA} done criteria.`);
|
|
405
|
-
const
|
|
406
|
-
const
|
|
407
|
-
if (
|
|
408
|
-
|
|
409
|
-
|
|
410
|
-
|
|
411
|
-
|
|
412
|
-
|
|
413
|
-
|
|
414
|
-
|
|
415
|
-
|
|
416
|
-
|
|
417
|
-
|
|
418
|
-
|
|
419
|
-
|
|
420
|
-
|
|
421
|
-
|
|
422
|
-
|
|
423
|
-
if (ownerSessionId(parseGoalFile(existing)) === sessionId) {
|
|
424
|
-
reuse = true;
|
|
425
|
-
break;
|
|
426
|
-
}
|
|
427
|
-
if (n > 50)
|
|
428
|
-
throw new Error('Too many goals share this name. Reword the outcome.');
|
|
429
|
-
slug = `${base}-${n}`;
|
|
430
|
-
}
|
|
431
|
-
const folder = `${drive.personalFolder}/Goals/${slug}`;
|
|
432
|
-
const boxFolder = goalBoxFolder({ scope: 'personal', slug });
|
|
433
|
-
// 1. The owner session, idle: nothing runs in it before GOAL.md exists.
|
|
434
|
-
try {
|
|
435
|
-
await createProjectSession(projectId, {
|
|
436
|
-
session_id: sessionId,
|
|
437
|
-
// Named after the outcome: a title generated from the wake prompt reads "Goal wake".
|
|
438
|
-
name: outcome.slice(0, 120),
|
|
439
|
-
agent_name: agent,
|
|
440
|
-
metadata: { unattended: 'true', goal: boxFolder, goal_role: 'owner' },
|
|
441
|
-
});
|
|
442
|
-
}
|
|
443
|
-
catch (error) {
|
|
444
|
-
if (!(error instanceof ApiError && error.status === 409))
|
|
445
|
-
throw error;
|
|
446
|
-
}
|
|
447
|
-
if (!reuse) {
|
|
448
|
-
// 2. Its heartbeat, before GOAL.md: `transition active` needs exactly one, and GOAL.md records it.
|
|
449
|
-
const { reminders } = await listSessionReminders(projectId, sessionId);
|
|
450
|
-
const heartbeat = reminders.find((r) => r.state === 'active' && r.prompt.includes(boxFolder)) ??
|
|
451
|
-
(await createSessionReminder(projectId, sessionId, { prompt: goalWakePrompt(boxFolder), in: '4h', every: '4h', name: `goal ${slug}` }));
|
|
452
|
-
// 3. GOAL.md, written once, then log.md.
|
|
453
|
-
const at = input.now ?? new Date().toISOString();
|
|
454
|
-
const doc = {
|
|
455
|
-
version: 1,
|
|
456
|
-
objective: outcome,
|
|
457
|
-
status: 'draft',
|
|
458
|
-
summary: '',
|
|
459
|
-
assigned_user: input.assignedUser ?? null,
|
|
460
|
-
agent,
|
|
461
|
-
space: null,
|
|
462
|
-
success_criteria: criteria.map((text, i) => ({ id: `c${i + 1}`, text, met: false, evidence: null })),
|
|
463
|
-
items: [],
|
|
464
|
-
links: [],
|
|
465
|
-
waiting_on: null,
|
|
466
|
-
heartbeat_every: '4h',
|
|
467
|
-
max_wakes_per_day: 12,
|
|
468
|
-
max_sessions: 10,
|
|
469
|
-
sessions: [{ id: sessionId, role: 'owner', since: at }],
|
|
470
|
-
reminder_id: heartbeat.id,
|
|
471
|
-
next_wake_at: heartbeat.next_fire_at ?? null,
|
|
472
|
-
verified_by: null,
|
|
473
|
-
transitions: [{ from: null, to: 'draft', at, reason: 'goal created', by: 'person' }],
|
|
474
|
-
body: `# ${outcome}\n\n## Context\n\n${context}\n`,
|
|
475
|
-
};
|
|
476
|
-
await uploadDriveFile(drive.driveId, `${folder}/GOAL.md`, new TextEncoder().encode(formatGoalFile(doc)));
|
|
477
|
-
await uploadDriveFile(drive.driveId, `${folder}/log.md`, new TextEncoder().encode(`# Log\n\n- ${at} Goal created: ${outcome}\n`));
|
|
478
|
-
}
|
|
479
|
-
else if ((await readText(drive.driveId, `${folder}/log.md`)) === null) {
|
|
480
|
-
// A retry after the log.md upload failed.
|
|
481
|
-
const at = input.now ?? new Date().toISOString();
|
|
482
|
-
await uploadDriveFile(drive.driveId, `${folder}/log.md`, new TextEncoder().encode(`# Log\n\n- ${at} Goal created: ${outcome}\n`));
|
|
483
|
-
}
|
|
484
|
-
// 4. The first wake. Its id is fixed per session, so a retry is deduped by the server.
|
|
485
|
-
const first = criteria.length
|
|
486
|
-
? 'It is new: check the done criteria in GOAL.md, then move it to active and start the work.'
|
|
487
|
-
: 'It is new: write 1 to 8 done criteria someone else can check into GOAL.md, then move it to active and start the work.';
|
|
488
|
-
await queueText(projectId, sessionId, `${goalWakePrompt(boxFolder)} ${first}`, `goal-start:${sessionId}`);
|
|
489
|
-
return { slug, scope: 'personal', driveId: drive.driveId, folder, sessionId };
|
|
314
|
+
const goalId = input.goalId ?? input.sessionId ?? generateSessionId();
|
|
315
|
+
const payload = { goal_id: goalId, brief };
|
|
316
|
+
if (criteria.length)
|
|
317
|
+
payload.criteria = criteria;
|
|
318
|
+
if (input.agent)
|
|
319
|
+
payload.agent = input.agent;
|
|
320
|
+
if (input.assignedUser)
|
|
321
|
+
payload.assigned_user_id = input.assignedUser;
|
|
322
|
+
const goal = toProjectGoal(await goalWrite(() => backendApi.post(goalsPath(projectId), payload)));
|
|
323
|
+
return {
|
|
324
|
+
slug: goal.slug,
|
|
325
|
+
scope: 'personal',
|
|
326
|
+
driveId: goal.driveId,
|
|
327
|
+
folder: goal.folder,
|
|
328
|
+
sessionId: goal.coordinatorSessionId ?? '',
|
|
329
|
+
goalId: goal.goalId,
|
|
330
|
+
goal,
|
|
331
|
+
};
|
|
490
332
|
}
|
|
491
333
|
/**
|
|
492
334
|
* A brief's lines after its first, as Markdown that reads as written: a plain
|
|
@@ -505,28 +347,31 @@ function briefContext(lines) {
|
|
|
505
347
|
return out.join('\n').trim();
|
|
506
348
|
}
|
|
507
349
|
/**
|
|
508
|
-
*
|
|
509
|
-
*
|
|
510
|
-
*
|
|
350
|
+
* A person answers a goal (`POST …/answer`): the API queues the text into
|
|
351
|
+
* the owner session, attributed to the caller, and a goal waiting on a
|
|
352
|
+
* person goes back to active. `answerId` is the idempotency key: pass the
|
|
353
|
+
* same id to retry, and the owner gets the answer once. Omitted: a new id.
|
|
354
|
+
* Resolves when the answer is durable, not when it is read.
|
|
511
355
|
*/
|
|
512
|
-
export async function replyToProjectGoal(projectId, goal, text) {
|
|
513
|
-
|
|
514
|
-
|
|
515
|
-
|
|
516
|
-
|
|
517
|
-
async function queueText(projectId, sessionId, text, clientMessageId = generateSessionId()) {
|
|
518
|
-
await createSessionPrompt(projectId, sessionId, {
|
|
519
|
-
clientMessageId,
|
|
520
|
-
messageId: mintWireMessageId(),
|
|
521
|
-
parts: [{ type: 'text', text }],
|
|
522
|
-
remintOnDelivery: true,
|
|
356
|
+
export async function replyToProjectGoal(projectId, goal, text, options) {
|
|
357
|
+
// The body is not read: an answer route that replies `202` with no goal is as good as one that returns it.
|
|
358
|
+
const response = await backendApi.post(`${goalPath(projectId, goal.goalId)}/answer`, {
|
|
359
|
+
answer_id: options?.answerId ?? generateSessionId(),
|
|
360
|
+
text,
|
|
523
361
|
});
|
|
362
|
+
if (!response.success)
|
|
363
|
+
throw conflict(response.error ?? new Error('Goal request failed'));
|
|
524
364
|
}
|
|
525
365
|
/** What a session reads when a person asks it to turn the conversation into a goal. */
|
|
526
366
|
export const MAKE_GOAL_PROMPT = 'Make this a goal. Load the kortix-goals skill, then turn what we discussed into a goal with `kortix goals new`: ' +
|
|
527
367
|
'state the outcome, write the done criteria someone else can check, and start working it.';
|
|
528
368
|
/** "Make this a goal" from a chat: queue `MAKE_GOAL_PROMPT` into that session. */
|
|
529
369
|
export async function makeSessionGoal(projectId, sessionId) {
|
|
530
|
-
await
|
|
370
|
+
await createSessionPrompt(projectId, sessionId, {
|
|
371
|
+
clientMessageId: generateSessionId(),
|
|
372
|
+
messageId: mintWireMessageId(),
|
|
373
|
+
parts: [{ type: 'text', text: MAKE_GOAL_PROMPT }],
|
|
374
|
+
remintOnDelivery: true,
|
|
375
|
+
});
|
|
531
376
|
}
|
|
532
377
|
//# sourceMappingURL=goals.js.map
|