Linger is An Open-Source Personal Agent That Runs Fully on Your PC. We aim to break Big Tech’s grip on AI by bringing powerful local AI to everyday computers through efficient model–harness co-design, so everyone can run their own.
fix(teamhub): report a Room without team.md as an unpublished protocol
LeoXing43e346c23008
diff --git a/apps/teamhub-cli/README.md b/apps/teamhub-cli/README.mdindex b12de401..0ab578ec 100644--- a/apps/teamhub-cli/README.md+++ b/apps/teamhub-cli/README.md@@ -30,6 +30,8 @@ teamhub room collaborate --file ./team.md --jsonMessages go to the configured Room or Task by default; `--thread <thread-id>` picks a Thread in that Room, and `--alterego <task-id>` and `--meta <task-id>` are for permitted private collaboration. `message read --inbox` accepts `room:`, `thread:`, `task:`, `meta:` and `taskmeta:` addresses, so another authorized Room is read with `--inbox room:<room-id>`; a Meta reads a Task's public messages with `--inbox task:<task-id>`. Publishing files and submitting the message are one atomic operation. For complex ordered resources use `--message` or `--message-file` with an object holding the full `segments` array; private targets accept no uploads, media or segments. A structured mention in a message is written `[@name](user:actor_id)` or `[@name](agent:actor_id)`; a plain `@name` mentions no one.+`room collaborate` publishes the Room's `team.md` and `room protocol` reads the current one. A Room where none has been published yet, the normal state of a new Room, is not an error: `room protocol` prints that no protocol has been published, and `--json` returns `published: false` with `revision: 0`.+## Documents and recovery`docs update` changes only the given heading, text or block; do not simulate a partial edit with a full replacement. Block operations need real stable IDs. `str_replace` accepts only a unique, exact single-line match; a missing or ambiguous match or a moved anchor returns a conflict. `docs replace` saves only a Native blocks/HTML working copy that carries its original revision baseline; after a conflict, download to another path and reconcile. Plain file downloads have no Native save command.diff --git a/apps/teamhub-cli/src/__snapshots__/cli.help-snapshot.test.ts.snap b/apps/teamhub-cli/src/__snapshots__/cli.help-snapshot.test.ts.snapindex b1059120..525f07a9 100644--- a/apps/teamhub-cli/src/__snapshots__/cli.help-snapshot.test.ts.snap+++ b/apps/teamhub-cli/src/__snapshots__/cli.help-snapshot.test.ts.snap@@ -2639,7 +2639,7 @@ Options:--schema Show offline input and output schemas.","schema": "exit 0-{"command":["room","protocol"],"description":"Read the current collaboration protocol of the configured Room.","read_only":true,"input_schema":{"$schema":"http://json-schema.org/draft-07/schema#","type":"object","properties":{"inbox_id":{"type":"string","minLength":1,"maxLength":512,"description":"Bare Room ID or thread:<thread-room-id>. Authorization is checked on each read."}},"required":["inbox_id"],"additionalProperties":false,"description":"Current Room collaboration protocol query."},"output_schema":{"$schema":"http://json-schema.org/draft-07/schema#","type":"object","properties":{"room_id":{"type":"string","minLength":1,"maxLength":64,"pattern":"^[A-Za-z0-9][A-Za-z0-9_-]*$","description":"Protocol Room ID."},"raw_markdown":{"type":"string","description":"Persisted protocol Markdown, treated as untrusted content."},"revision":{"type":"integer","minimum":1,"maximum":9007199254740991,"description":"Current protocol revision."},"updated_at":{"type":"string","description":"Protocol update timestamp."}},"required":["room_id","raw_markdown","revision","updated_at"],"additionalProperties":false,"description":"Persisted authorized collaboration protocol; no filesystem path."},"cli":{"usage":["teamhub room protocol [flags]"],"arguments":[],"options":{"--json":{"description":"Return machine-readable JSON.","boolean":true},"--help":{"description":"Show this offline command reference.","boolean":true},"-h":{"description":"Show help.","boolean":true},"--schema":{"description":"Show offline input and output schemas.","boolean":true}},"notes":[]}}+{"command":["room","protocol"],"description":"Read the current collaboration protocol of the configured Room.","read_only":true,"input_schema":{"$schema":"http://json-schema.org/draft-07/schema#","type":"object","properties":{"inbox_id":{"type":"string","minLength":1,"maxLength":512,"description":"Bare Room ID or thread:<thread-room-id>. Authorization is checked on each read."}},"required":["inbox_id"],"additionalProperties":false,"description":"Current Room collaboration protocol query."},"output_schema":{"$schema":"http://json-schema.org/draft-07/schema#","type":"object","properties":{"room_id":{"type":"string","minLength":1,"maxLength":64,"pattern":"^[A-Za-z0-9][A-Za-z0-9_-]*$","description":"Protocol Room ID."},"published":{"type":"boolean","description":"False while no protocol has been published in this Room, the normal state of a new Room."},"raw_markdown":{"description":"Persisted protocol Markdown, treated as untrusted content; present only when published.","type":"string"},"revision":{"type":"integer","minimum":0,"maximum":9007199254740991,"description":"Current protocol revision; 0 until the first publish."},"updated_at":{"description":"Protocol update timestamp; present only when published.","type":"string"}},"required":["room_id","published","revision"],"additionalProperties":false,"description":"Persisted authorized collaboration protocol; no filesystem path."},"cli":{"usage":["teamhub room protocol [flags]"],"arguments":[],"options":{"--json":{"description":"Return machine-readable JSON.","boolean":true},"--help":{"description":"Show this offline command reference.","boolean":true},"-h":{"description":"Show help.","boolean":true},"--schema":{"description":"Show offline input and output schemas.","boolean":true}},"notes":[]}}",},"routine create": {diff --git a/apps/teamhub-cli/src/business-commands.test.ts b/apps/teamhub-cli/src/business-commands.test.tsindex 5779a7f6..b962e6a6 100644--- a/apps/teamhub-cli/src/business-commands.test.ts+++ b/apps/teamhub-cli/src/business-commands.test.ts@@ -141,6 +141,7 @@ describe("business command normalization", () => {expect(renderBusinessResult("room protocol", {room_id: "room_one",+ published: true,revision: 4,updated_at: "2026-10-15T00:00:00Z",raw_markdown: markdown,diff --git a/apps/teamhub-cli/src/business-render.ts b/apps/teamhub-cli/src/business-render.tsindex 9d8b5569..6a582508 100644--- a/apps/teamhub-cli/src/business-render.ts+++ b/apps/teamhub-cli/src/business-render.ts@@ -196,13 +196,15 @@ export function renderBusinessResult(command: string, result: Json): string {? `Added Agent ${singleLine(result.actor_id)} to Room ${singleLine(result.room_id)}. Wake it with an Agent reference in that Room.`: `Agent ${singleLine(result.actor_id)} is already a member of Room ${singleLine(result.room_id)}.`;if (command === "room protocol")- return [- `Room: ${singleLine(result.room_id)}`,- `Revision: ${String(result.revision)}`,- `Updated at: ${String(result.updated_at)}`,- "",- String(result.raw_markdown),- ].join("\n");+ return result.published === false+ ? "No team.md collaboration protocol has been published in this Room yet."+ : [+ `Room: ${singleLine(result.room_id)}`,+ `Revision: ${String(result.revision)}`,+ `Updated at: ${String(result.updated_at)}`,+ "",+ String(result.raw_markdown),+ ].join("\n");if (command === "agent get")return [`Agent: ${singleLine(result.name)}`,diff --git a/apps/teamhub-cli/src/cli.openapi.test.ts b/apps/teamhub-cli/src/cli.openapi.test.tsindex 1e76c063..98e1ee6d 100644--- a/apps/teamhub-cli/src/cli.openapi.test.ts+++ b/apps/teamhub-cli/src/cli.openapi.test.ts@@ -234,6 +234,7 @@ async function respond(request: Request): Promise<Response> {if (endpoint.endsWith("/team-md/query"))return Response.json({room_id: "room_one",+ published: true,raw_markdown: "# Protocol",revision: 2,updated_at: "2026-10-12T00:00:00Z",diff --git a/apps/teamhub-cli/src/context-reads.test.ts b/apps/teamhub-cli/src/context-reads.test.tsindex e7e93665..e779c4ef 100644--- a/apps/teamhub-cli/src/context-reads.test.ts+++ b/apps/teamhub-cli/src/context-reads.test.ts@@ -1,6 +1,11 @@-import { expect, it } from "vitest";+import { mkdtemp, rm } from "node:fs/promises";+import { tmpdir } from "node:os";+import path from "node:path";+import { expect, it, vi } from "vitest";import { loadAgentCommandSchema } from "./command-schema-loader.js";import { routesByToolName } from "./business-routes.js";+import { runCli } from "./cli.js";+import { writeCliConfig } from "./test-support/cli-config.js";it("exposes live membership and collaboration protocol reads", async () => {for (const [toolName, input, endpoint] of [@@ -44,3 +49,41 @@ it("accepts registered Agent identity alongside Human members", async () => {expect(schema.output.parse(output)).toEqual(output);}});++it.each([true, false])(+ "reports a Room without team.md as a result, not an error (json=%s)",+ async (json) => {+ const directory = await mkdtemp(+ path.join(tmpdir(), "teamhub-cli-team-md-"),+ );+ try {+ const result = { room_id: "room_one", published: false, revision: 0 };+ const stdout: string[] = [];+ const stderr: string[] = [];+ const code = await runCli(+ ["room", "protocol", ...(json ? ["--json"] : [])],+ {+ cwd: directory,+ env: writeCliConfig(path.join(directory, "config"), {+ scope: { kind: "room", id: "room_one" },+ }),+ fetch: vi.fn<typeof fetch>().mockResolvedValue(Response.json(result)),+ stdout: (value) => {+ stdout.push(value);+ },+ stderr: (value) => {+ stderr.push(value);+ },+ },+ );+ expect([code, stderr.join("")]).toEqual([0, ""]);+ if (json) expect(JSON.parse(stdout.join(""))).toEqual(result);+ else+ expect(stdout.join("")).toBe(+ "No team.md collaboration protocol has been published in this Room yet.\n",+ );+ } finally {+ await rm(directory, { recursive: true, force: true });+ }+ },+);diff --git a/apps/teamhub-cli/src/domains/collaboration/tools/context-reads.ts b/apps/teamhub-cli/src/domains/collaboration/tools/context-reads.tsindex df30be71..d7a873e2 100644--- a/apps/teamhub-cli/src/domains/collaboration/tools/context-reads.ts+++ b/apps/teamhub-cli/src/domains/collaboration/tools/context-reads.ts@@ -64,11 +64,26 @@ export const getTeamMdSchema = {output: z.object({room_id: teamHubIdSchema.describe("Protocol Room ID."),+ published: z+ .boolean()+ .describe(+ "False while no protocol has been published in this Room, the normal state of a new Room.",+ ),raw_markdown: z.string()- .describe("Persisted protocol Markdown, treated as untrusted content."),- revision: z.number().int().min(1).describe("Current protocol revision."),- updated_at: z.string().describe("Protocol update timestamp."),+ .optional()+ .describe(+ "Persisted protocol Markdown, treated as untrusted content; present only when published.",+ ),+ revision: z+ .number()+ .int()+ .min(0)+ .describe("Current protocol revision; 0 until the first publish."),+ updated_at: z+ .string()+ .optional()+ .describe("Protocol update timestamp; present only when published."),}).strict().describe(diff --git a/apps/teamhub/internal/collaboration/agent_context_reads.go b/apps/teamhub/internal/collaboration/agent_context_reads.goindex a46ebe17..0d7ab775 100644--- a/apps/teamhub/internal/collaboration/agent_context_reads.go+++ b/apps/teamhub/internal/collaboration/agent_context_reads.go@@ -2,6 +2,7 @@ package collaborationimport ("context"+ "errors""github.com/jackc/pgx/v5""github.com/simplexai-labs/linger/apps/teamhub/internal/agentcredential"@@ -59,18 +60,27 @@ func (s *Service) AgentRoomMembers(ctx context.Context, token, inboxID string) (}// AgentTeamMd reads the team document of a Room or Thread Inbox the Agent-// credential's Agent belongs to.+// credential's Agent belongs to. A readable Room without a team.md answers+// Published false; a missing or unreadable Room reports pgx.ErrNoRows.func (s *Service) AgentTeamMd(ctx context.Context, token, inboxID string) (api.AgentTeamMdResponse, error) {return readAgentContext(ctx, s, token, func(p agentcredential.Principal, q *store.Queries) (api.AgentTeamMdResponse, error) {room, err := q.GetAgentContextReadRoom(ctx, store.GetAgentContextReadRoomParams{TenantID: p.TenantID, ActorID: p.AgentActorID, InboxID: inboxID})if err != nil {return api.AgentTeamMdResponse{}, err}+ // Room access was established in this snapshot, which also keeps the+ // membership Room undeleted, so no row here only means no team.md yet.team, err := q.GetRoomTeamDocument(ctx, store.GetRoomTeamDocumentParams{TenantID: p.TenantID, RoomID: room.MembershipRoomID})+ if errors.Is(err, pgx.ErrNoRows) {+ return api.AgentTeamMdResponse{RoomId: room.MembershipRoomID}, nil+ }if err != nil {return api.AgentTeamMdResponse{}, err}- return api.AgentTeamMdResponse{RoomId: room.MembershipRoomID, RawMarkdown: team.RawMarkdown, Revision: team.Revision, UpdatedAt: team.UpdatedAt.Time}, nil+ return api.AgentTeamMdResponse{+ RoomId: room.MembershipRoomID, Published: true, RawMarkdown: &team.RawMarkdown,+ Revision: team.Revision, UpdatedAt: &team.UpdatedAt.Time,+ }, nil})}diff --git a/apps/teamhub/tests/integration/agent_context_reads_test.go b/apps/teamhub/tests/integration/agent_context_reads_test.goindex 7dd00d9e..84fac42b 100644--- a/apps/teamhub/tests/integration/agent_context_reads_test.go+++ b/apps/teamhub/tests/integration/agent_context_reads_test.go@@ -95,7 +95,7 @@ func TestAgentContextReadsCurrentAuthorityWithoutRun(t *testing.T) {t.Fatal(err)}code, body = read("team-md/query", map[string]any{"inbox_id": roomID})- if code != http.StatusOK || !strings.Contains(string(body), `"revision":3`) || !strings.Contains(string(body), `# Current protocol`) || strings.Contains(string(body), `"path"`) {+ if code != http.StatusOK || !strings.Contains(string(body), `"published":true`) || !strings.Contains(string(body), `"revision":3`) || !strings.Contains(string(body), `# Current protocol`) || strings.Contains(string(body), `"path"`) {t.Fatalf("team.md: %d %s", code, body)}// Historical message text remains unchanged; the attachment supplies its ID.@@ -208,3 +208,32 @@ func TestAgentContextReadsCurrentAuthorityWithoutRun(t *testing.T) {t.Fatal("reads created a Local Run")}}++func TestAgentTeamMdReadReportsUnpublishedProtocolOnlyForReadableRoom(t *testing.T) {+ allowParallelIntegrationTest(t)+ env, alice, credential, roomID := newAgentCLIIdentity(t)+ unreadableRoomID := createPrivateRoom(t, env, alice, "Room without the Agent", "team-md-unreadable-room")+ read := func(inboxID string) (int, []byte) {+ t.Helper()+ code, _, body := taskWorkerJSONRequest(t, env, http.MethodPost, "/api/agent/v1/team-md/query", credential.AccessToken, map[string]any{"inbox_id": inboxID})+ return code, body+ }+ code, body := read(roomID)+ if code != http.StatusOK || string(body) != `{"published":false,"revision":0,"room_id":"`+roomID+`"}` {+ t.Fatalf("readable Room without team.md: %d %s", code, body)+ }+ // Neither a Room the Agent cannot read nor a missing one may reveal+ // whether it has a team.md.+ for _, inboxID := range []string{unreadableRoomID, "room_team_md_missing"} {+ code, body := read(inboxID)+ var response struct {+ Error struct {+ Code string `json:"code"`+ } `json:"error"`+ }+ decode(t, body, &response)+ if code != http.StatusNotFound || response.Error.Code != "NOT_FOUND" {+ t.Fatalf("unavailable Room %s: %d %s", inboxID, code, body)+ }+ }+}diff --git a/contracts/generated/go/teamhubagentapi/openapi.gen.go b/contracts/generated/go/teamhubagentapi/openapi.gen.goindex c70fad09..a5985c45 100644--- a/contracts/generated/go/teamhubagentapi/openapi.gen.go+++ b/contracts/generated/go/teamhubagentapi/openapi.gen.go@@ -2568,14 +2568,21 @@ type AgentTaskSummary struct {UpdatedAt time.Time `json:"updated_at"`}-// AgentTeamMdResponse defines model for AgentTeamMdResponse.+// AgentTeamMdResponse The Room's current team.md. A readable Room where none has been published yet, the normal state of a new Room, answers published false and revision 0 without raw_markdown or updated_at.type AgentTeamMdResponse struct {- RawMarkdown string `json:"raw_markdown"`- Revision int64 `json:"revision"`+ Published bool `json:"published"`++ // RawMarkdown Present exactly when published is true.+ RawMarkdown *string `json:"raw_markdown,omitempty"`++ // Revision 0 until the first publish, then 1 and up.+ Revision int64 `json:"revision"`// RoomId Opaque, case-sensitive identifier. Clients must not infer type or time from it.- RoomId Id `json:"room_id"`- UpdatedAt time.Time `json:"updated_at"`+ RoomId Id `json:"room_id"`++ // UpdatedAt Present exactly when published is true.+ UpdatedAt *time.Time `json:"updated_at,omitempty"`}// AgentTextMessageSegment Plain text segment. Include type: text and content.diff --git a/contracts/generated/typescript/src/generated/teamhub-agent-api/types.ts b/contracts/generated/typescript/src/generated/teamhub-agent-api/types.tsindex 48717470..5d87c606 100644--- a/contracts/generated/typescript/src/generated/teamhub-agent-api/types.ts+++ b/contracts/generated/typescript/src/generated/teamhub-agent-api/types.ts@@ -1324,13 +1324,22 @@ export interface components {membership_revision: number;members: components["schemas"]["AgentContextMember"][];};+ /** @description The Room's current team.md. A readable Room where none has been published yet, the normal state of a new Room, answers published false and revision 0 without raw_markdown or updated_at. */AgentTeamMdResponse: {room_id: components["schemas"]["Id"];- raw_markdown: string;- /** Format: int64 */+ published: boolean;+ /** @description Present exactly when published is true. */+ raw_markdown?: string;+ /**+ * Format: int64+ * @description 0 until the first publish, then 1 and up.+ */revision: number;- /** Format: date-time */- updated_at: string;+ /**+ * Format: date-time+ * @description Present exactly when published is true.+ */+ updated_at?: string;};AgentMessageCommitMultipart: {/** @description Strict AgentMessageCommitMetadata JSON, at most 5 MiB, sent before file parts. Uploads identify immutable file parts by upload_id; file part filename is that ID. Local filesystem paths and binary/base64 data do not belong in metadata. Like every Agent command, it carries no execution fields: the CLI names its Local Run in the X-TeamHub-Run-Id header, which TeamHub records on the Message only for a running Run of the same Tenant and Agent whose status shows in the target's collaboration Room. */@@ -2885,7 +2894,7 @@ export interface operations {};};responses: {- /** @description Current collaboration state in one authorized database snapshot. */+ /** @description Current collaboration protocol in one authorized database snapshot, or published false when the Room has none yet. */200: {headers: {[name: string]: unknown;diff --git a/contracts/openapi/components/agent-context-reads.yaml b/contracts/openapi/components/agent-context-reads.yamlindex 94958319..56f5ba24 100644--- a/contracts/openapi/components/agent-context-reads.yaml+++ b/contracts/openapi/components/agent-context-reads.yaml@@ -33,10 +33,24 @@ schemas:items: { $ref: "#/schemas/AgentContextMember" }AgentTeamMdResponse:type: object+ description: >-+ The Room's current team.md. A readable Room where none has been+ published yet, the normal state of a new Room, answers published false+ and revision 0 without raw_markdown or updated_at.additionalProperties: false- required: [room_id, raw_markdown, revision, updated_at]+ required: [room_id, published, revision]properties:room_id: { $ref: "./common.yaml#/components/schemas/Id" }- raw_markdown: { type: string }- revision: { type: integer, format: int64, minimum: 1 }- updated_at: { type: string, format: date-time }+ published: { type: boolean }+ raw_markdown:+ type: string+ description: Present exactly when published is true.+ revision:+ type: integer+ format: int64+ minimum: 0+ description: 0 until the first publish, then 1 and up.+ updated_at:+ type: string+ format: date-time+ description: Present exactly when published is true.diff --git a/contracts/openapi/paths/agent-context-reads.yaml b/contracts/openapi/paths/agent-context-reads.yamlindex c65f52e6..9b30e9f8 100644--- a/contracts/openapi/paths/agent-context-reads.yaml+++ b/contracts/openapi/paths/agent-context-reads.yaml@@ -33,7 +33,9 @@ teamMd:$ref: "../components/agent-context-reads.yaml#/schemas/AgentRoomMembersRequest"responses:"200":- description: Current collaboration state in one authorized database snapshot.+ description: >-+ Current collaboration protocol in one authorized database snapshot,+ or published false when the Room has none yet.content:application/json:schema: