Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 6 additions & 4 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,7 @@ jobs:
# file, docs included. The `Check` job at the end of this file passes only
# when every other job passes or was skipped by `changes`.
lint:
if: ${{ !startsWith(github.head_ref, 'kin/worker/') }}
permissions:
contents: read
id-token: write
Expand Down Expand Up @@ -118,7 +119,7 @@ jobs:
id-token: write
name: Build and Typecheck
needs: changes
if: ${{ !cancelled() && (needs.changes.outputs.build != 'false' || needs.changes.outputs.typecheck != 'false') }}
if: ${{ !startsWith(github.head_ref, 'kin/worker/') && (!cancelled() && (needs.changes.outputs.build != 'false' || needs.changes.outputs.typecheck != 'false')) }}
runs-on: ubuntu-24.04
timeout-minutes: 10
steps:
Expand Down Expand Up @@ -247,7 +248,7 @@ jobs:
id-token: write
name: Test
needs: changes
if: ${{ !cancelled() && needs.changes.outputs.test != 'false' }}
if: ${{ !startsWith(github.head_ref, 'kin/worker/') && (!cancelled() && needs.changes.outputs.test != 'false') }}
runs-on: ubuntu-24.04
timeout-minutes: 10
steps:
Expand Down Expand Up @@ -332,7 +333,7 @@ jobs:
id-token: write
name: Test Web
needs: changes
if: ${{ !cancelled() && needs.changes.outputs.test_web != 'false' }}
if: ${{ !startsWith(github.head_ref, 'kin/worker/') && (!cancelled() && needs.changes.outputs.test_web != 'false') }}
runs-on: ubuntu-24.04
timeout-minutes: 20
steps:
Expand Down Expand Up @@ -387,6 +388,7 @@ jobs:
# The shards are the longest jobs, so they gate themselves instead of waiting
# ~15s for `changes`: a shard the change cannot affect stops after checkout.
test_server:
if: ${{ !startsWith(github.head_ref, 'kin/worker/') }}
permissions:
contents: read
id-token: write
Expand Down Expand Up @@ -572,7 +574,7 @@ jobs:
id-token: write
name: Release Smoke
needs: changes
if: ${{ !cancelled() && needs.changes.outputs.release_smoke != 'false' }}
if: ${{ !startsWith(github.head_ref, 'kin/worker/') && (!cancelled() && needs.changes.outputs.release_smoke != 'false') }}
runs-on: ubuntu-24.04
timeout-minutes: 10
steps:
Expand Down
6 changes: 4 additions & 2 deletions .github/workflows/desktop-macos-preview-publish.yml
Original file line number Diff line number Diff line change
Expand Up @@ -31,9 +31,11 @@ jobs:
resolve:
name: Verify preview eligibility
if: >-
!startsWith(github.event.workflow_run.head_branch, 'kin/worker/') && (
github.event_name == 'workflow_run' &&
github.event.workflow_run.event == 'pull_request' &&
github.event.workflow_run.conclusion == 'success'
)
# The build workflow completes for every PR push (its label gate is on the
# job), so this runs often and usually finds nothing. Keep it cheap.
runs-on: ubuntu-24.04
Expand Down Expand Up @@ -283,7 +285,7 @@ jobs:
build:
name: Package and sign macOS arm64 preview
needs: resolve
if: needs.resolve.outputs.eligible == 'true'
if: ${{ !startsWith(github.event.workflow_run.head_branch, 'kin/worker/') && (needs.resolve.outputs.eligible == 'true') }}
concurrency:
group: desktop-macos-preview-${{ needs.resolve.outputs.pr_number }}-build
cancel-in-progress: true
Expand Down Expand Up @@ -324,7 +326,7 @@ jobs:
publish:
name: Publish anonymous download
needs: [resolve, build]
if: needs.resolve.outputs.eligible == 'true' && needs.build.result == 'success'
if: ${{ !startsWith(github.event.workflow_run.head_branch, 'kin/worker/') && (needs.resolve.outputs.eligible == 'true' && needs.build.result == 'success') }}
runs-on: blacksmith-8vcpu-ubuntu-2404
timeout-minutes: 10
# Its own group, so a publish never cancels a newer commit's signing job
Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/desktop-macos-preview.yml
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ concurrency:
jobs:
build:
name: Build preview JS bundle
if: github.event.label.name == 'preview:mac'
if: ${{ !startsWith(github.head_ref, 'kin/worker/') && (github.event.label.name == 'preview:mac') }}
runs-on: blacksmith-32vcpu-ubuntu-2404
timeout-minutes: 30
steps:
Expand Down
2 changes: 2 additions & 0 deletions .github/workflows/mobile-eas-preview-fork.yml
Original file line number Diff line number Diff line change
Expand Up @@ -20,8 +20,10 @@ jobs:
preview:
name: EAS Preview
if: >-
!startsWith(github.head_ref, 'kin/worker/') && (
github.event.pull_request.head.repo.full_name != github.repository &&
github.event.label.name == '🚀 Mobile Continuous Deployment'
)
runs-on: blacksmith-8vcpu-ubuntu-2404
concurrency:
group: mobile-eas-preview-fork-${{ github.event.pull_request.number }}
Expand Down
2 changes: 2 additions & 0 deletions .github/workflows/mobile-eas-preview.yml
Original file line number Diff line number Diff line change
Expand Up @@ -9,9 +9,11 @@ jobs:
name: EAS Preview
# Fork PRs deploy one reviewed commit per label through mobile-eas-preview-fork.yml.
if: |
!startsWith(github.head_ref, 'kin/worker/') && (
github.event.pull_request.head.repo.full_name == github.repository &&
contains(github.event.pull_request.labels.*.name, '🚀 Mobile Continuous Deployment') &&
(github.event.action != 'labeled' || github.event.label.name == '🚀 Mobile Continuous Deployment')
)
runs-on: blacksmith-8vcpu-ubuntu-2404
concurrency:
group: mobile-eas-preview-${{ github.event.pull_request.number }}
Expand Down
2 changes: 2 additions & 0 deletions .github/workflows/mobile-fingerprint-label.yml
Original file line number Diff line number Diff line change
Expand Up @@ -21,8 +21,10 @@ jobs:
name: Sync native change label
# A cancelled run was superseded by a newer push, whose run labels instead.
if: >-
!startsWith(github.event.workflow_run.head_branch, 'kin/worker/') && (
github.event.workflow_run.event == 'pull_request' &&
github.event.workflow_run.conclusion == 'success'
)
runs-on: ubuntu-24.04
timeout-minutes: 5
permissions:
Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/pr-vouch.yml
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,7 @@ jobs:
label:
name: Label PR ${{ matrix.target.number }}
needs: collect-targets
if: ${{ needs.collect-targets.outputs.targets != '[]' }}
if: ${{ !startsWith(github.head_ref, 'kin/worker/') && (needs.collect-targets.outputs.targets != '[]') }}
runs-on: ubuntu-24.04
concurrency:
group: pr-vouch-${{ matrix.target.number }}
Expand Down
4 changes: 3 additions & 1 deletion .github/workflows/relay-preview-cleanup.yml
Original file line number Diff line number Diff line change
Expand Up @@ -24,12 +24,14 @@ jobs:
cleanup_pr:
name: Tear down relay preview
if: >-
!startsWith(github.head_ref, 'kin/worker/') && (
github.ref == 'refs/heads/main' &&
github.event_name == 'pull_request_target' &&
(
(github.event.action == 'unlabeled' && github.event.label.name == 'relay:preview') ||
(github.event.action == 'closed' && contains(github.event.pull_request.labels.*.name, 'relay:preview'))
)
)
# Job-level so that events which skip this job, such as a closed PR without
# the label, never take the group's pending slot. GitHub replaces a pending
# run in a group with a newer one, which would drop a queued teardown.
Expand Down Expand Up @@ -124,7 +126,7 @@ jobs:
sweep_pr:
name: Retry teardown for PR ${{ matrix.number }}
needs: list_closed_previews
if: github.ref == 'refs/heads/main' && needs.list_closed_previews.outputs.numbers != '[]'
if: ${{ !startsWith(github.head_ref, 'kin/worker/') && (github.ref == 'refs/heads/main' && needs.list_closed_previews.outputs.numbers != '[]') }}
runs-on: blacksmith-8vcpu-ubuntu-2404
timeout-minutes: 30
strategy:
Expand Down
2 changes: 2 additions & 0 deletions .github/workflows/relay-preview.yml
Original file line number Diff line number Diff line change
Expand Up @@ -20,8 +20,10 @@ jobs:
deploy_preview:
name: Deploy relay preview
if: >-
!startsWith(github.head_ref, 'kin/worker/') && (
github.event.pull_request.head.repo.full_name == github.repository &&
contains(github.event.pull_request.labels.*.name, 'relay:preview')
)
runs-on: blacksmith-8vcpu-ubuntu-2404
timeout-minutes: 20
environment:
Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/thread-transfer-report.yml
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ permissions:
jobs:
publish:
name: Publish PR comment
if: github.event.workflow_run.event == 'pull_request'
if: ${{ !startsWith(github.event.workflow_run.head_branch, 'kin/worker/') && (github.event.workflow_run.event == 'pull_request') }}
runs-on: ubuntu-24.04
concurrency:
group: thread-transfer-report-${{ github.event.workflow_run.pull_requests[0].number || github.event.workflow_run.id }}
Expand Down
2 changes: 2 additions & 0 deletions .github/workflows/web-preview.yml
Original file line number Diff line number Diff line change
Expand Up @@ -34,9 +34,11 @@ jobs:
# workflow should skip rather than fail for them. On `labeled` events, only
# the preview label itself triggers a deploy.
if: >-
!startsWith(github.head_ref, 'kin/worker/') && (
github.event.pull_request.head.repo.full_name == github.repository &&
contains(github.event.pull_request.labels.*.name, 'preview:web') &&
(github.event.action != 'labeled' || github.event.label.name == 'preview:web')
)
runs-on: blacksmith-8vcpu-ubuntu-2404
timeout-minutes: 10
env:
Expand Down
21 changes: 20 additions & 1 deletion apps/server/scripts/kin-shadow-dry-run.ts
Original file line number Diff line number Diff line change
Expand Up @@ -69,6 +69,9 @@ import * as RoutineContent from "../src/kin/lead/RoutineContent.ts";
import * as WakeupRunner from "../src/kin/lead/WakeupRunner.ts";
import { orchestrationStack } from "../src/kin/lead/WakeupRunner.testkit.ts";
import * as Workers from "../src/kin/lead/Workers.ts";
import * as WorkerEnvironment from "../src/kin/lead/workerEnvironment.ts";
import * as WorkerTracker from "../src/kin/lead/WorkerTracker.ts";
import * as RepositoryIdentityResolver from "../src/project/RepositoryIdentityResolver.ts";
import { KinLeadToolkit } from "../src/kin/lead/mcp/tools.ts";
import { handlers as leadHandlers } from "../src/kin/lead/mcp/handlers.ts";
import { KinChatToolkit, handlers as chatHandlers } from "../src/kin/mcp/KinChatToolkit.ts";
Expand Down Expand Up @@ -570,8 +573,24 @@ export const runDryRun = Effect.fn("KinDryRun.run")(
McpHttpServer.toolkitRegistration(KinChatToolkit, chatHandlers),
KinApprovalsMcp.registrationWith(facts),
).pipe(Layer.provideMerge(McpHttpServer.layerInProcessMcpServer));
// The dry run starts no worker: with no worker environment, kin_delegate at L2 is refused.
const noWorkers = Layer.mergeAll(
Layer.succeed(
WorkerEnvironment.KinWorkerEnvironment,
WorkerEnvironment.KinWorkerEnvironment.of({
environmentId: Option.none(),
call: Effect.fn("KinDryRun.workerEnvironmentCall")(function* () {
return yield* Effect.die("The dry run starts no workers.");
}),
stopServer: Effect.die("The dry run starts no workers."),
startServer: Effect.die("The dry run starts no workers."),
}),
),
Layer.mock(WorkerTracker.WorkerTracker)({}),
Layer.mock(RepositoryIdentityResolver.RepositoryIdentityResolver)({}),
);
const lead = Layer.mergeAll(WakeupRunner.layer, tools).pipe(
Layer.provideMerge(Workers.layer),
Layer.provideMerge(Workers.layer.pipe(Layer.provide(noWorkers))),
Layer.provideMerge(LeadMemory.layer),
Layer.provideMerge(writer),
Layer.provideMerge(RoutineContent.layer.pipe(Layer.provide(github))),
Expand Down
2 changes: 1 addition & 1 deletion apps/server/src/kin/approvals/mcp.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ import { ThreadManagementService } from "../../orchestration-v2/ThreadManagement
import { KinIdentity } from "../chat/KinIdentity.ts";
import * as RequestAction from "./RequestAction.ts";

// Reads `KinIdentity`, which the Kin MCP endpoint provides per call: `KinServer` reaches the judge.
// Reads `KinIdentity`, which the Kin MCP endpoint provides per call.
const enabled = () => {
const fiber = Fiber.getCurrent();
if (!fiber) return false;
Expand Down
1 change: 0 additions & 1 deletion apps/server/src/kin/approvals/rpcHandlers.ts
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,6 @@ export const connectionOf = Effect.serviceOption(HttpServerRequest.HttpServerReq

export const makeKinApprovalHandlers = Effect.fn("makeKinApprovalHandlers")(function* (
session: AuthenticatedSession,
// Passed in rather than read from `KinServer`, whose service union reaches the judge.
kin: Option.Option<Context.Context<KinIdentity | ApproverKeys | GrantVerifier>>,
) {
const connection = yield* connectionOf;
Expand Down
51 changes: 45 additions & 6 deletions apps/server/src/kin/chat/KinChatService.ts
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,8 @@ import {
type KinAuthor,
type KinAgentId,
type ThreadId,
type EnvironmentId,
type KinTaskCardState,
type KinChat,
type KinChatListEvent,
type KinChatStreamEvent,
Expand Down Expand Up @@ -155,6 +157,11 @@ export class KinChatService extends Context.Service<
readonly threadId: ThreadId;
readonly title: string;
readonly model: string | null;
/** A thread in a linked environment: no thread here to read, so the caller says its status. */
readonly remote?: {
readonly environmentId: EnvironmentId;
readonly status: KinTaskCardState["status"];
};
}) => Effect.Effect<KinWidget, ServiceError, OrchestratorV2 | ServerEnvironment>;
/** Server-only, like createTaskCard: Kin's worker launcher closes and reopens worker cards. */
readonly setTaskCardClosed: (input: {
Expand All @@ -163,6 +170,13 @@ export class KinChatService extends Context.Service<
readonly threadId: ThreadId;
readonly closed: boolean;
}) => Effect.Effect<KinWidget, ServiceError>;
/** Server-only: a remote card's live fields, which no thread here can refresh. */
readonly setTaskCardState: (input: {
readonly orgId: KinOrgId;
readonly chatId: KinChatId;
readonly threadId: ThreadId;
readonly state: Pick<KinTaskCardState, "status" | "pullRequests" | "lastError">;
}) => Effect.Effect<KinWidget, ServiceError>;
readonly act: (
identity: PersonCaller,
input: KinWidgetsActInput,
Expand Down Expand Up @@ -1166,9 +1180,12 @@ const make = Effect.gen(function* () {
if (input.orgId !== "kin-default") return yield* notFound;
const environment = yield* ServerEnvironment;
const orchestrator = yield* OrchestratorV2;
const shell = yield* orchestrator
.getThreadShell(input.threadId)
.pipe(Effect.orElseSucceed(() => null));
const shell =
input.remote === undefined
? yield* orchestrator
.getThreadShell(input.threadId)
.pipe(Effect.orElseSucceed(() => null))
: undefined;
if (shell === null) return yield* notFound;
const agent = yield* requireRecord(
repo.getAgent({ orgId: input.orgId, agentId: input.authorAgentId }),
Expand Down Expand Up @@ -1209,10 +1226,10 @@ const make = Effect.gen(function* () {
taskId: input.threadId,
environmentId: yield* environment.getEnvironmentId,
threadId: input.threadId,
remoteEnvironmentId: null,
remoteEnvironmentId: input.remote?.environmentId ?? null,
title: input.title,
model: input.model,
status: "waiting",
status: input.remote?.status ?? "waiting",
pullRequests: [],
lastError: null,
updatedAt,
Expand Down Expand Up @@ -1250,7 +1267,7 @@ const make = Effect.gen(function* () {
widgetClass: "native",
type: "task",
revision: 1,
state: TaskCard.taskCardState(state, shell, updatedAt),
state: shell === undefined ? state : TaskCard.taskCardState(state, shell, updatedAt),
source: null,
feed: null,
awaiting: [],
Expand Down Expand Up @@ -1286,6 +1303,28 @@ const make = Effect.gen(function* () {
yield* hub.publish({ type: "widget.updated", orgId: input.orgId, widget });
return widget;
}, transaction),
setTaskCardState: Effect.fn("KinChatService.setTaskCardState")(function* (input) {
const existing = yield* requireRecord(
repo.getWidget({ orgId: input.orgId, widgetId: yield* taskCardWidgetId(input) }),
);
if (existing.type !== "task" || existing.chatId !== input.chatId) return yield* notFound;
const previous = yield* TaskCard.decodeTaskCardEffect(existing.state).pipe(
Effect.mapError(() => invalidState),
);
if (previous.remoteEnvironmentId === null) return yield* invalidState;
const next = { ...previous, ...input.state };
if (existing.closedAt !== null || TaskCard.taskCardEquivalent(next, previous))
return existing;
const updatedAt = yield* now;
const widget = yield* repo.updateWidget({
...existing,
state: { ...next, updatedAt },
expectedRevision: existing.revision,
updatedAt,
});
yield* hub.publish({ type: "widget.updated", orgId: input.orgId, widget });
return widget;
}, transaction),
upsertWidget: Effect.fn("KinChatService.upsertWidget")(function* (identity, input) {
const member = yield* memberFor(identity, input.chatId);
yield* canWrite(identity, member);
Expand Down
Loading