Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
17 commits
Select commit Hold shift + click to select a range
7c2d14e
fix: redact PII on manual Verify artifact edits in anonymised projects
JorimTheuns Nov 30, 2026
30393f6
feat: strict ParticipantTokens.require and portal X-Participant-Token…
JorimTheuns Nov 30, 2026
3fd7cc1
chore(frontend): refresh lingui catalog line references
JorimTheuns Nov 30, 2026
ee3da74
refactor(portal): sessionStorage participant tokens, 403/finish clear…
JorimTheuns Dec 1, 2026
e599b33
feat: add conversation landscape gate, producer wiring, and canary test
JorimTheuns Nov 30, 2026
ebfb529
fix: handle Date timestamps in loadTranscripts and isoTimestamp
JorimTheuns Dec 1, 2026
d39f66b
fix: unblock canary test hang in Bun, gate Canvas producer, and apply…
JorimTheuns Dec 1, 2026
546edc8
fix(portal): retry a rejected participant token once without it; keep…
ussaama Dec 2, 2026
f5ef690
fix(verify): redact names too in hand edits on anonymised projects
ussaama Dec 2, 2026
6a89496
Merge branch 'fix/verify-manual-edit-pii-redaction' into feat/portal-…
ussaama Dec 2, 2026
d70e78f
Merge branch 'feat/portal-participant-token' into feat/landscape-gate
ussaama Dec 2, 2026
16d9a4c
Merge remote-tracking branch 'origin/main' into fix/verify-manual-edi…
ussaama Dec 2, 2026
e496436
Merge branch 'fix/verify-manual-edit-pii-redaction' into feat/portal-…
ussaama Dec 2, 2026
dca1835
Merge branch 'feat/portal-participant-token' into feat/landscape-gate
ussaama Dec 2, 2026
a063fc0
Pin host-private landscape policy in docs and canary
ussaama Dec 2, 2026
25ab10f
Shorten landscape gate doc comment
ussaama Dec 2, 2026
c0d8859
Merge branch 'main' into feat/landscape-gate
ussaama Dec 2, 2026
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
485 changes: 485 additions & 0 deletions dembrane/platform/apps/api/test/landscape-canary.integration.test.ts

Large diffs are not rendered by default.

1 change: 1 addition & 0 deletions dembrane/platform/packages/analysis/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ export * as popcornShared from "./popcorn-shared";
export {
ASSESSMENT_RECIPE_ID,
countConversationsWithTranscripts,
loadTranscripts,
POPCORN_SOURCES_KEY,
POPCORN_TENSIONS_SOURCES_KEY,
type PopcornSources,
Expand Down
61 changes: 39 additions & 22 deletions dembrane/platform/packages/analysis/src/recipes/services.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import { inRoomSql, usesAcceptedText } from "@dembrane/db";
import { isoTimestamp } from "@dembrane/legacy-shape";
import type { Completer, CompletionRequest, Embedder } from "@dembrane/llm";
import type { Json } from "../contracts";
Expand Down Expand Up @@ -52,35 +53,44 @@ export async function loadTranscripts(
const conversations = await q<{
id: string;
participant_name: string | null;
created_at: string | null;
created_at: string | Date | null;
landscape_status: string | null;
landscape_text: string | null;
}>(
store.sql,
`SELECT id::text AS id, participant_name, created_at FROM conversation
WHERE project_id = $1 AND deleted_at IS NULL
`SELECT id::text AS id, participant_name, created_at, landscape_status, landscape_text
FROM conversation
WHERE project_id = $1 AND deleted_at IS NULL AND ${inRoomSql("conversation")}
ORDER BY created_at, id`,
[projectId],
);
if (!conversations.length) return [];
const chunks = await q<{ conversation_id: string; transcript: string | null }>(
store.sql,
`SELECT conversation_id::text AS conversation_id, transcript FROM conversation_chunk
WHERE conversation_id = ANY($1::uuid[]) AND transcript IS NOT NULL
ORDER BY timestamp, created_at, id`,
[conversations.map((c) => c.id)],
);
const ungatedIds = conversations.filter((c) => !usesAcceptedText(c)).map((c) => c.id);
const texts = new Map<string, string[]>();
for (const chunk of chunks) {
const text = String(chunk.transcript ?? "").trim();
if (!text) continue;
const list = texts.get(chunk.conversation_id) ?? [];
list.push(text);
texts.set(chunk.conversation_id, list);
if (ungatedIds.length) {
const chunks = await q<{ conversation_id: string; transcript: string | null }>(
store.sql,
`SELECT conversation_id::text AS conversation_id, transcript FROM conversation_chunk
WHERE conversation_id = ANY($1::uuid[]) AND transcript IS NOT NULL
ORDER BY timestamp, created_at, id`,
[ungatedIds],
);
for (const chunk of chunks) {
const text = String(chunk.transcript ?? "").trim();
if (!text) continue;
const list = texts.get(chunk.conversation_id) ?? [];
list.push(text);
texts.set(chunk.conversation_id, list);
}
}
const out: Transcript[] = [];
conversations.forEach((c, i) => {
const text = (texts.get(c.id) ?? []).join("\n").trim();
const gated = usesAcceptedText(c);
const text = gated
? String(c.landscape_text ?? "").trim()
: (texts.get(c.id) ?? []).join("\n").trim();
if (!text) return;
const name = String(c.participant_name ?? "").trim();
const name = gated ? "" : String(c.participant_name ?? "").trim();
out.push({
id: c.id,
label: name || `Conversation ${i + 1}`,
Expand All @@ -99,10 +109,17 @@ export async function countConversationsWithTranscripts(
): Promise<number> {
const rows = await q<{ n: string }>(
store.sql,
`SELECT count(DISTINCT ch.conversation_id) AS n
FROM conversation_chunk AS ch JOIN conversation AS c ON c.id = ch.conversation_id
WHERE c.project_id = $1 AND c.deleted_at IS NULL
AND ch.transcript IS NOT NULL AND ch.transcript <> ''`,
`SELECT count(*)::int AS n
FROM conversation AS c
WHERE c.project_id = $1 AND c.deleted_at IS NULL AND ${inRoomSql("c")}
AND (
(c.landscape_status IS NULL AND EXISTS (
SELECT 1 FROM conversation_chunk AS ch
WHERE ch.conversation_id = c.id
AND ch.transcript IS NOT NULL AND ch.transcript <> ''
))
OR (c.landscape_status IS NOT NULL AND btrim(coalesce(c.landscape_text, '')) <> '')
)`,
[projectId],
);
return Number(rows[0]?.n ?? 0);
Expand Down
79 changes: 79 additions & 0 deletions dembrane/platform/packages/analysis/test/load-transcripts.test.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,79 @@
import { describe, expect, test } from "bun:test";
import { loadTranscripts } from "../src/recipes/services";
import type { AnalysisStore } from "../src/store";

function fakeStore(results: readonly unknown[][]): AnalysisStore {
let i = 0;
return {
sql: {
unsafe: async () => results[i++] ?? [],
},
} as unknown as AnalysisStore;
}

describe("loadTranscripts", () => {
test("handles both Date instances and Postgres timestamp strings for created_at", async () => {
const legacyId = "b0000000-0000-4000-8000-000000000001";
const enteredId = "b0000000-0000-4000-8000-000000000002";
const store = fakeStore([
[
{
id: legacyId,
participant_name: "Ada",
created_at: new Date("2026-11-30T10:01:00.000Z"),
landscape_status: null,
landscape_text: null,
},
{
id: enteredId,
participant_name: "Hidden Name",
created_at: "2026-11-30 10:07:00+00",
landscape_status: "accepted",
landscape_text: "Accepted landscape text",
},
],
[{ conversation_id: legacyId, transcript: "Legacy chunk transcript" }],
]);

const transcripts = await loadTranscripts(store, "p0000000-0000-4000-8000-000000000001");
expect(transcripts).toEqual([
{
id: legacyId,
label: "Ada",
createdAt: "2026-11-30T10:01:00.000Z",
text: "Legacy chunk transcript",
},
{
id: enteredId,
label: "Conversation 2",
createdAt: "2026-11-30T10:07:00.000Z",
text: "Accepted landscape text",
},
]);
});

test("returns null createdAt for null or invalid Date values", async () => {
const id = "b0000000-0000-4000-8000-000000000003";
const store = fakeStore([
[
{
id,
participant_name: null,
created_at: new Date("invalid"),
landscape_status: "accepted",
landscape_text: "Valid accepted text",
},
],
]);

const transcripts = await loadTranscripts(store, "p0000000-0000-4000-8000-000000000001");
expect(transcripts).toEqual([
{
id,
label: "Conversation 1",
createdAt: null,
text: "Valid accepted text",
},
]);
});
});
2 changes: 2 additions & 0 deletions dembrane/platform/packages/canvas/src/index.ts
Original file line number Diff line number Diff line change
@@ -1,2 +1,4 @@
export { executeGatherSpec, type GatherDeps } from "./gather";
export { type CanvasWorkerDeps, canvasApiJobs, canvasTick, canvasWorker } from "./jobs";
export { type CanvasRoutesDeps, canvasRoutes } from "./routes";
export { type CanvasStore, canvasStore } from "./storage";
47 changes: 41 additions & 6 deletions dembrane/platform/packages/canvas/src/storage.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import { newId } from "@dembrane/core";
import type { Db } from "@dembrane/db";
import { type Db, inRoomSql, usesAcceptedText } from "@dembrane/db";
import { isoTimestamp } from "@dembrane/legacy-shape";
import type postgres from "postgres";
import type { Json } from "./py";

Expand Down Expand Up @@ -294,8 +295,12 @@ export function canvasStore(sql: Sql) {
const tags = tagIds.filter(isUuid);
if (conversationIds.length && !ids.length) return [];
if (tagIds.length && !tags.length) return [];
return sql`select c.id, c.participant_name, c.created_at from conversation c
return sql`select c.id,
case when c.landscape_status is null then c.participant_name else null end as participant_name,
c.created_at, c.landscape_status, c.landscape_text, c.landscape_entered_at
from conversation c
where c.project_id = ${projectId} and c.deleted_at is null
and ${sql.unsafe(inRoomSql("c"))}
${ids.length ? sql`and c.id = any(${ids}::uuid[])` : sql``}
${
tags.length
Expand All @@ -307,10 +312,40 @@ export function canvasStore(sql: Sql) {
},

async gatherChunks(conversationId: string, since: string | null): Promise<Row[]> {
return sql`select id, transcript, created_at, timestamp from conversation_chunk
where conversation_id = ${conversationId} and transcript is not null
${since ? sql`and created_at >= ${since}` : sql``}
order by timestamp asc, created_at asc limit 1500`;
const [conv] =
await sql`select id, created_at, landscape_status, landscape_text, landscape_entered_at
from conversation
where id = ${conversationId} and deleted_at is null
and ${sql.unsafe(inRoomSql("conversation"))}
limit 1`;
if (!conv) return [];
if (
usesAcceptedText({ landscape_status: (conv.landscape_status as string | null) ?? null })
) {
const text = typeof conv.landscape_text === "string" ? conv.landscape_text.trim() : "";
if (!text) return [];
const at = (conv.landscape_entered_at ?? conv.created_at) as string | Date | null;
const atIso = isoTimestamp(at);
if (since && atIso && Date.parse(atIso) < Date.parse(since)) return [];
return [
{
id: conv.id,
transcript: conv.landscape_text,
created_at: at,
timestamp: at,
},
];
}
return sql`select ch.id, ch.transcript, ch.created_at, ch.timestamp
from conversation_chunk ch
join conversation c on c.id = ch.conversation_id
where ch.conversation_id = ${conversationId}
and c.deleted_at is null
and ${sql.unsafe(inRoomSql("c"))}
and c.landscape_status is null
and ch.transcript is not null
${since ? sql`and ch.created_at >= ${since}` : sql``}
order by ch.timestamp asc, ch.created_at asc limit 1500`;
},

// ── history reads ────────────────────────────────────────────────
Expand Down
4 changes: 4 additions & 0 deletions dembrane/platform/packages/conversations/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@ export { conversationWorker } from "./pipeline/worker";
export { pipelineWorkflows, RETRIES, type RetryPolicy } from "./pipeline/workflows";
export { requirePortalAi } from "./portal-ai";
export { conversationRoutes } from "./routes";
export { searchStorage } from "./search/storage";
export {
type ChunkRow,
type ConversationRow,
Expand All @@ -43,11 +44,14 @@ export {
transaction,
} from "./storage";
export {
adjacentConversations,
ContentPolicyError,
CURRENT_CONVERSATION_NAME,
formatConversation,
OTHER_CONVERSATION_NAME,
type ReplyProject,
replyPrompt,
replyProtocol,
sampleReply,
} from "./v1/reply";
export { type V1Store, v1Store } from "./v1/storage";
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ async function reachableConversations(db: Db, who: Searcher): Promise<string[]>
const rows = await db.execute<{ id: string }>(sql`
select c.id from conversation c
join project p on p.id = c.project_id
where p.deleted_at is null and (
where p.deleted_at is null and c.deleted_at is null and (
p.workspace_id in (
select wm.workspace_id from workspace_membership wm
where wm.user_id = ${who.appUserId} and wm.deleted_at is null)
Expand Down
23 changes: 22 additions & 1 deletion dembrane/platform/packages/conversations/src/v1/reply.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import { contextForPrompt } from "@dembrane/core";
import { usesAcceptedText } from "@dembrane/db";
import { isoTimestamp } from "@dembrane/legacy-shape";
import { type Models, modelErrorShape, speechHint } from "@dembrane/llm";
import { renderPrompt } from "@dembrane/prompts";
Expand Down Expand Up @@ -64,7 +65,7 @@ export const CURRENT_CONVERSATION_NAME = "this conversation";
export const OTHER_CONVERSATION_NAME = "another group";

/** The project's other conversations, as Explore may read them when cross-pollination is on. */
async function adjacentConversations(
export async function adjacentConversations(
store: V1Store,
projectId: string,
excludeId: string,
Expand All @@ -75,6 +76,26 @@ async function adjacentConversations(
const tagsOf = (id: string) => (tags.get(id) ?? []).filter((t): t is string => t !== null);
const candidates: [string, number][] = [];
for (const row of rows) {
if (usesAcceptedText(row)) {
const text = row.landscape_text?.trim();
if (!text) continue;
const c: Conv = {
name: OTHER_CONVERSATION_NAME,
tags: tagsOf(row.id),
transcript: text,
};
let f = formatConversation(c);
let tokens = countTokens(f);
if (!useSummaries && tokens > TARGET_TOKENS_PER_CONV) {
const ratio = TARGET_TOKENS_PER_CONV / tokens;
const chars = [...c.transcript];
c.transcript = `${chars.slice(0, Math.trunc(chars.length * ratio)).join("")}\n[Truncated for brevity...]`;
f = formatConversation(c);
tokens = countTokens(f);
}
candidates.push([f, tokens]);
continue;
}
if (useSummaries) {
if (row.summary === null) continue;
const f = formatConversation({
Expand Down
37 changes: 33 additions & 4 deletions dembrane/platform/packages/conversations/src/v1/storage.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
import { newId } from "@dembrane/core";
import type { Db } from "@dembrane/db";
import { schema } from "@dembrane/db";
import { type Db, inRoomSql, schema, usesAcceptedText } from "@dembrane/db";
import { and, asc, desc, eq, inArray, isNotNull, isNull, ne, sql } from "drizzle-orm";
import { isUuid } from "../storage";

Expand Down Expand Up @@ -221,15 +220,22 @@ export function v1Store(db: Db) {
return db
.select({
id: conversation.id,
participant_name: conversation.participant_name,
summary: conversation.summary,
participant_name: sql<
string | null
>`CASE WHEN ${conversation.landscape_status} IS NULL THEN ${conversation.participant_name} ELSE NULL END`,
summary: sql<
string | null
>`CASE WHEN ${conversation.landscape_status} IS NULL THEN ${conversation.summary} ELSE ${conversation.landscape_text} END`,
landscape_status: conversation.landscape_status,
landscape_text: conversation.landscape_text,
})
.from(conversation)
.where(
and(
eq(conversation.project_id, projectId),
ne(conversation.id, excludeId),
isNull(conversation.deleted_at),
sql.raw(inRoomSql("conversation")),
),
)
.orderBy(asc(conversation.id))
Expand All @@ -238,6 +244,29 @@ export function v1Store(db: Db) {

/** Latest chunks and replies of adjacent conversations, newest first (deep sort). */
async adjacentContent(conversationId: string) {
const [conv] = await db
.select({
created_at: conversation.created_at,
landscape_status: conversation.landscape_status,
landscape_text: conversation.landscape_text,
})
.from(conversation)
.where(
and(
eq(conversation.id, conversationId),
isNull(conversation.deleted_at),
sql.raw(inRoomSql("conversation")),
),
)
.limit(1);
if (!conv) return { chunks: [], replies: [] };
if (usesAcceptedText(conv)) {
const text = conv.landscape_text?.trim() ? conv.landscape_text : null;
return {
chunks: text !== null ? [{ timestamp: conv.created_at, transcript: text }] : [],
replies: [],
};
}
const [chunks, replies] = await Promise.all([
db
.select({
Expand Down
Loading
Loading