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
7 changes: 7 additions & 0 deletions apps/server/scripts/acp-mock-agent.ts
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,8 @@ const failSetConfigOption = process.env.T3_ACP_FAIL_SET_CONFIG_OPTION === "1";
const authRequiredOnSetConfigOption = process.env.T3_ACP_FAIL_SET_CONFIG_OPTION === "auth";
const exitOnSetConfigOption = process.env.T3_ACP_EXIT_ON_SET_CONFIG_OPTION === "1";
const promptResponseText = process.env.T3_ACP_PROMPT_RESPONSE_TEXT;
/** Refuses the first prompt it gets, as an agent that errors before taking it does. */
let failFirstPrompt = process.env.T3_ACP_FAIL_FIRST_PROMPT === "1";
/** Ends every prompt with this stop reason and no reply, as a refusing model does. */
const silentPromptStopReason = process.env.T3_ACP_SILENT_PROMPT_STOP_REASON;
/** fx's retry notice, sent before that silent stop. */
Expand Down Expand Up @@ -409,6 +411,11 @@ const program = Effect.gen(function* () {
Effect.gen(function* () {
const requestedSessionId = String(request.sessionId ?? sessionId);

if (failFirstPrompt) {
failFirstPrompt = false;
return yield* AcpError.AcpRequestError.invalidParams("The mock agent refused this prompt.");
}

if (silentPromptStopReason) {
if (silentPromptStatus) {
yield* agent.client.sessionUpdate({
Expand Down
1 change: 1 addition & 0 deletions apps/server/src/environment/Layers/ServerEnvironment.ts
Original file line number Diff line number Diff line change
Expand Up @@ -119,6 +119,7 @@ export const makeServerEnvironment = Effect.fn("makeServerEnvironment")(function
phoneAlertControls: true,
projectLead: true,
childStartSelection: true,
projectContext: true,
deviceNames: true,
draftGoalSetup: true,
pullRequestSwitchesByNumber: true,
Expand Down
19 changes: 19 additions & 0 deletions apps/server/src/guide/topics.ts
Original file line number Diff line number Diff line change
Expand Up @@ -328,6 +328,25 @@ When a Claude or Codex usage limit stops a thread, the notice above the composer
body: `{place:settings.plugins} manages what agents can use beyond their own tools, per provider, on this computer or one project: {place:plugins.installed}, {place:plugins.apps}, {place:plugins.connections} (MCP servers) and {place:plugins.hooks}. Its Skills tab is {place:plugins.skills}.

{place:settings.instructions} shows the instruction files each provider reads in a project (like AGENTS.md or CLAUDE.md), to open or edit.`,
},
{
id: "project-brief",
title: "Project brief",
keywords: [
"brief",
"project brief",
"project instructions",
"standing instructions",
"rules for every thread",
"project memory",
],
body: `A project's brief is text the user writes once. Every thread in the project gets it as the user's standing instructions, on any agent. It is set in {place:instructions.brief}: pick the project at the top, write it, Save. Up to 8,000 characters. Agents can't change it.

New threads get a change at once. A thread that is already open gets it the next time its agent starts: after the app restarts, after a model switch, or after a stop. Threads behind the link fence, or started by an outside agent, don't get it.

Threadlines keeps it on each computer, not in the repository. Save stores it on every connected computer that has the project, and the line under the box says where it went. If the computers hold different briefs, the page shows the picked computer's and offers to copy it to the others. If another device saved first, Save says so and shows the newer text instead of overwriting it. Set up on another computer copies the brief with the project.

The project menu's Project brief, the command palette and the lead chat's crown card open it too.`,
},
{
id: "browser-panel",
Expand Down
2 changes: 2 additions & 0 deletions apps/server/src/persistence/Migrations.ts
Original file line number Diff line number Diff line change
Expand Up @@ -141,6 +141,7 @@ import Migration0118 from "./Migrations/118_SessionStopRequestedTurn.ts";
import Migration0119 from "./Migrations/119_LinkMoveFamilies.ts";
import Migration0120 from "./Migrations/120_ThreadAdoptedFromLink.ts";
import Migration0121 from "./Migrations/121_ProjectionThreadSecretRequests.ts";
import Migration0122 from "./Migrations/122_ProjectBriefs.ts";

/**
* Migration loader with all migrations defined inline.
Expand Down Expand Up @@ -274,6 +275,7 @@ export const migrationEntries = [
[119, "LinkMoveFamilies", Migration0119],
[120, "ThreadAdoptedFromLink", Migration0120],
[121, "ProjectionThreadSecretRequests", Migration0121],
[122, "ProjectBriefs", Migration0122],
] as const;

/** Highest id in the full registry, so the "n of total" count is the real total. */
Expand Down
20 changes: 20 additions & 0 deletions apps/server/src/persistence/Migrations/122_ProjectBriefs.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
import * as Effect from "effect/Effect";
import * as SqlClient from "effect/sql/SqlClient";

/**
* A project's brief (docs/design/project-brief-notes.md): the user's standing
* instructions for every thread in the project, kept outside the event log.
* One row per project, so the text and its revision change together.
*/
export default Effect.gen(function* () {
const sql = yield* SqlClient.SqlClient;

yield* sql`
CREATE TABLE IF NOT EXISTS project_briefs (
project_id TEXT PRIMARY KEY,
text TEXT NOT NULL,
revision INTEGER NOT NULL,
updated_at TEXT NOT NULL
)
`;
});
113 changes: 113 additions & 0 deletions apps/server/src/projectContext/ProjectBriefRepository.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,113 @@
/**
* ProjectBriefRepository: `project_briefs`, one row per project that has a
* brief (docs/design/project-brief-notes.md). A save names the revision it
* expects, so two devices saving at once cannot overwrite each other.
*/
import { IsoDateTime, NonNegativeInt, ProjectId, type ProjectBrief } from "@threadlines/contracts";
import * as Context from "effect/Context";
import * as Effect from "effect/Effect";
import * as Layer from "effect/Layer";
import * as Option from "effect/Option";
import * as Schema from "effect/Schema";
import * as SqlClient from "effect/sql/SqlClient";
import * as SqlSchema from "effect/sql/SqlSchema";

import { type PersistenceSqlError, toPersistenceSqlError } from "../persistence/Errors.ts";

const ProjectBriefRow = Schema.Struct({
projectId: ProjectId,
text: Schema.String,
revision: NonNegativeInt,
updatedAt: IsoDateTime,
});

export interface ProjectBriefRepositoryShape {
/** Every project's brief row. */
readonly listAll: () => Effect.Effect<ReadonlyArray<ProjectBrief>, PersistenceSqlError>;
/** The project's brief; none before its first save. */
readonly get: (
projectId: ProjectId,
) => Effect.Effect<Option.Option<ProjectBrief>, PersistenceSqlError>;
/**
* Save `text` as the next revision when the stored revision is
* `expectedRevision` (0: no row yet). None when it isn't: nothing written.
*/
readonly save: (input: {
readonly projectId: ProjectId;
readonly text: string;
readonly expectedRevision: number;
readonly now: string;
}) => Effect.Effect<Option.Option<ProjectBrief>, PersistenceSqlError>;
}

export class ProjectBriefRepository extends Context.Service<
ProjectBriefRepository,
ProjectBriefRepositoryShape
>()("threadlines/projectContext/ProjectBriefRepository") {}

export const makeProjectBriefRepository = Effect.gen(function* () {
const sql = yield* SqlClient.SqlClient;

const selectAll = SqlSchema.findAll({
Request: Schema.Void,
Result: ProjectBriefRow,
execute: () => sql`
SELECT project_id AS "projectId", text, revision, updated_at AS "updatedAt"
FROM project_briefs
ORDER BY project_id
`,
});

const selectOne = SqlSchema.findOneOption({
Request: ProjectId,
Result: ProjectBriefRow,
execute: (projectId) => sql`
SELECT project_id AS "projectId", text, revision, updated_at AS "updatedAt"
FROM project_briefs
WHERE project_id = ${projectId}
`,
});

const listAll: ProjectBriefRepositoryShape["listAll"] = () =>
selectAll(undefined).pipe(
Effect.mapError(toPersistenceSqlError("ProjectBriefRepository.listAll")),
);

const get: ProjectBriefRepositoryShape["get"] = (projectId) =>
selectOne(projectId).pipe(Effect.mapError(toPersistenceSqlError("ProjectBriefRepository.get")));

const save: ProjectBriefRepositoryShape["save"] = (input) =>
Effect.gen(function* () {
const current = yield* selectOne(input.projectId);
const currentRevision = Option.match(current, {
onNone: () => 0,
onSome: (row) => row.revision,
});
if (currentRevision !== input.expectedRevision) return Option.none();
const next = {
projectId: input.projectId,
text: input.text,
revision: currentRevision + 1,
updatedAt: input.now,
};
yield* sql`
INSERT INTO project_briefs (project_id, text, revision, updated_at)
VALUES (${next.projectId}, ${next.text}, ${next.revision}, ${next.updatedAt})
ON CONFLICT (project_id) DO UPDATE SET
text = excluded.text,
revision = excluded.revision,
updated_at = excluded.updated_at
`;
return Option.some(next);
}).pipe(
sql.withTransaction,
Effect.mapError(toPersistenceSqlError("ProjectBriefRepository.save")),
);

return { listAll, get, save } satisfies ProjectBriefRepositoryShape;
});

export const ProjectBriefRepositoryLive = Layer.effect(
ProjectBriefRepository,
makeProjectBriefRepository,
);
Loading
Loading