From 8bbbfd7fd044df87552c79ce8abea195e6100e48 Mon Sep 17 00:00:00 2001 From: leemour Date: Mon, 16 Nov 2026 13:36:37 +0100 Subject: [PATCH 1/2] fix(meetings): move old caller ids to E.164 on sync; call fields; cli-core 0.674.0 MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Builds before #19 stored a call's client as `phone:<10 national digits>`, and the one-day #18 build as `phone:+<10 digits>` (with the same wrong number in `identities.phone`). 0.1.0 writes `phone:+7…` via clientPhone(), so a sync over an old store added a second client per caller and its calls never linked to the CRM contact (the owner's store: ~1626 old ids). - store.ts: oldClientRekeys() maps both old forms to the clientPhone() id and phone; current E.164 ids and extensions stay. rekeyOldClients() lists every beeline identity (all profiles) and calls cli-core's store.people.rekeyIdentities in passes until every pair is taken; renamed, merged and refused counts only, never the ids (they are phone numbers). - meetings sync runs it after the store opens, before the pull, and prints the counts on stderr only when something moved. Idempotent: a second sync is quiet. - SourceMeeting.call = { direction in|out, clientPhone } (cli-core 0.674.0); the manager participant already had role `manager`. A re-sync rewrites an old call's title and fills its call fields (tested). - @wirecat/cli-core 0.671.0 -> 0.674.0 (store version 67); cli-base stays 0.103.0 (latest). Reusable workflows pinned to cli-base v0.103.0 (183e251), changelog guard included; covers Dependabot #22-#24. - Drop scripts/audit.sh (CI runs cli-dev audit --family directly) and its template.json entry. - Audit differences: drop meeting-project.stale and meeting_participants (no longer found); meeting and meeting_details differ from zm 0.77.0 (cli-core 0.667.0) until zm publishes on 0.674.0. - Changelog: 0.2.0 (not yet on npm) gains the call fields and the migration; README, README.ru and DESIGN say what sync does with old ids. Tests: src/client-rekey.test.ts on a temp store: both old forms renamed, an old id merged into the E.164 one already stored (participants move), an extension untouched, a second run all unchanged, call fields after a re-sync. Rules: WC-ARCH-21, WC-TEST-2, WC-DOC-3. Co-Authored-By: Claude Opus 5.5 --- .github/workflows/changelog-guard.yml | 2 +- .github/workflows/ci.yml | 2 +- .github/workflows/monthly.yml | 2 +- .github/workflows/release-start.yml | 2 +- .github/workflows/release.yml | 2 +- CHANGELOG.md | 13 ++- README.md | 7 +- README.ru.md | 7 +- docs/commands.md | 4 +- docs/dev/DESIGN.md | 7 +- lint/audit-differences.json | 15 +-- package.json | 2 +- pnpm-lock.yaml | 10 +- scripts/audit.sh | 9 -- src/call-source.ts | 1 + src/client-rekey.test.ts | 154 ++++++++++++++++++++++++++ src/commands/meetings.ts | 10 +- src/store.ts | 39 ++++++- template.json | 1 - 19 files changed, 241 insertions(+), 48 deletions(-) delete mode 100755 scripts/audit.sh create mode 100644 src/client-rekey.test.ts diff --git a/.github/workflows/changelog-guard.yml b/.github/workflows/changelog-guard.yml index 9ec468e..b0ae279 100644 --- a/.github/workflows/changelog-guard.yml +++ b/.github/workflows/changelog-guard.yml @@ -9,4 +9,4 @@ permissions: jobs: changelog: - uses: WireCatLabs/cli-base/.github/workflows/changelog-guard.yml@fe3430bae73bc7ccb5854124343fcb4549c26243 # cli-base main at #555: the guard accepts changes/ fragments + uses: WireCatLabs/cli-base/.github/workflows/changelog-guard.yml@183e25196cb9c9b777946b8783d0f7f222bd66f9 # v0.103.0 diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 01ca750..b8bed2f 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -19,7 +19,7 @@ permissions: jobs: ci: - uses: WireCatLabs/cli-base/.github/workflows/node-ci.yml@34a442be7352a59598b0bdcccc03186ae1f6a728 # v0.85.1 + uses: WireCatLabs/cli-base/.github/workflows/node-ci.yml@183e25196cb9c9b777946b8783d0f7f222bd66f9 # v0.103.0 with: pack: ${{ inputs.pack || false }} bun-run: pnpm build && pnpm smoke:bun diff --git a/.github/workflows/monthly.yml b/.github/workflows/monthly.yml index 44ec6a9..80a2a00 100644 --- a/.github/workflows/monthly.yml +++ b/.github/workflows/monthly.yml @@ -22,7 +22,7 @@ jobs: contents: read actions: read security-events: write - uses: WireCatLabs/cli-base/.github/workflows/release-checks.yml@34a442be7352a59598b0bdcccc03186ae1f6a728 # v0.85.1 + uses: WireCatLabs/cli-base/.github/workflows/release-checks.yml@183e25196cb9c9b777946b8783d0f7f222bd66f9 # v0.103.0 with: dependencies: true languages: '["actions","javascript-typescript"]' diff --git a/.github/workflows/release-start.yml b/.github/workflows/release-start.yml index 8b60bde..9582b94 100644 --- a/.github/workflows/release-start.yml +++ b/.github/workflows/release-start.yml @@ -12,7 +12,7 @@ jobs: permissions: contents: read actions: write - uses: WireCatLabs/cli-base/.github/workflows/release-start.yml@34a442be7352a59598b0bdcccc03186ae1f6a728 # v0.85.1 + uses: WireCatLabs/cli-base/.github/workflows/release-start.yml@183e25196cb9c9b777946b8783d0f7f222bd66f9 # v0.103.0 with: app-client-id: ${{ vars.RELEASE_APP_CLIENT_ID }} check: '[ -d kit ] || pnpm exec cli-dev live check --version "$VERSION"' diff --git a/.github/workflows/release.yml b/.github/workflows/release.yml index 5b6f8b6..f0abe74 100644 --- a/.github/workflows/release.yml +++ b/.github/workflows/release.yml @@ -56,7 +56,7 @@ jobs: contents: read actions: read security-events: write - uses: WireCatLabs/cli-base/.github/workflows/release-checks.yml@34a442be7352a59598b0bdcccc03186ae1f6a728 # v0.85.1 + uses: WireCatLabs/cli-base/.github/workflows/release-checks.yml@183e25196cb9c9b777946b8783d0f7f222bd66f9 # v0.103.0 build: needs: [checks, validation] diff --git a/CHANGELOG.md b/CHANGELOG.md index b5db854..a96e40b 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -6,14 +6,23 @@ Notable changes to `@wirecat/beeline-cli`. One section per version, newest first ### Added -- **The meetings answers mark other people's text untrusted** (cli-core 0.671.0, was 0.663.0; cli-base 0.103.0, was - 0.100.0). `meetings transcript` and `meetings export` answer an `untrusted` list: each line's text and speaker, and +- **A call says its direction, its manager and the client's number.** `meetings list`, `meetings show` and the + meetings of a deal, lead or person in another WireCat CLI carry `call`: `direction` (`in` or `out`), `manager` + (`name`, `person`) and `client_phone`. A call synced before gets them at its next sync; `--since-time` reaches the + older ones. +- **The meetings answers mark other people's text untrusted** (cli-core 0.674.0, was 0.663.0; cli-base 0.103.0, was + 0.100.0). The shared store moves to version 67, which the other WireCat CLIs on the same store open from their + releases on cli-core 0.674.0. `meetings transcript` and `meetings export` answer an `untrusted` list: each line's text and speaker, and the export's `content`. A caller and its agent read those fields as data, not instructions. - **A `search meetings` hit may carry `by`, `score` and `passage`**, the fields of a search by meaning, so beeline's hits keep the same shape as every other meetings tool. ### Fixed +- **`meetings sync` moves callers stored under old numbers to their `+7` numbers.** An unpublished build from before + 13.11.2026 kept a client as `phone:9…` (or, for a day, `phone:+9…`), so its calls did not link to the CRM contact + and a new sync added a second client. Each sync now first renames such a client, or merges it into the client the + `+7` number already has, and prints how many it moved. A second sync finds nothing to move. - **`meetings transcribe --help` quotes its `duration_ms>=60000` example**, so a shell no longer reads `>` as a redirect to a file named `=60000`. diff --git a/README.md b/README.md index 559f9e4..554b112 100644 --- a/README.md +++ b/README.md @@ -102,9 +102,10 @@ Calls synced by a version before this one are not linked until a sync saves them days again, `--since-time` reaches further back. The same holds for a contact added to Bitrix24 after its calls were synced. -A store that already holds calls synced by an unpublished build from before 13.11.2026 keeps their old client numbers -(`phone:9…`, without `+7`). Those calls do not link, and a re-sync adds a second client to each, until a later version -migrates them. A fresh install is not affected. +A store that holds calls synced by an unpublished build from before 13.11.2026 has their clients under old numbers +(`phone:9…`, without `+7`). Since 0.2.0, `meetings sync` moves each to its `+7` number first, merging it into the client +that number already has, and says how many it moved. A `--since-time` back to the first call then also corrects the +older calls' titles. A fresh install is not affected. More: [use it](docs/usage.md). diff --git a/README.ru.md b/README.ru.md index 7a2712f..d87a00f 100644 --- a/README.ru.md +++ b/README.ru.md @@ -103,9 +103,10 @@ beeline work meetings sync --since-time 2026-01-01T00:00:00Z # и более последние 30 дней, `--since-time` уходит дальше в прошлое. То же для контакта, добавленного в Битрикс24 после того, как его звонки уже скопированы. -Если в базе уже есть звонки, скопированные неопубликованной сборкой до 13.11.2026, у их клиентов остаётся старый номер -(`phone:9…`, без `+7`). Такие звонки не связываются, а повторная синхронизация добавляет каждому второго клиента, пока -одна из следующих версий их не перенесёт. Новой установки это не касается. +Если в базе есть звонки, скопированные неопубликованной сборкой до 13.11.2026, их клиенты записаны под старыми номерами +(`phone:9…`, без `+7`). С версии 0.2.0 `meetings sync` сначала переносит каждого на номер с `+7`, объединяя с клиентом, +у которого этот номер уже есть, и пишет, сколько перенёс. Синхронизация с `--since-time` до первого звонка затем +исправляет и названия старых звонков. Новой установки это не касается. ## ИИ-агент diff --git a/docs/commands.md b/docs/commands.md index 9492138..1bcba85 100644 --- a/docs/commands.md +++ b/docs/commands.md @@ -153,7 +153,7 @@ beeline meetings list [query] [options] | `--limit ` | meetings per page; the profile's defaults.limit when absent. | | `--page ` | which page, starting at 1. | -**Returns:** meeting — ref, id, provider_id, provider, account, title, url, started_at, and 11 more; every field: beeline commands info meetings list +**Returns:** meeting — ref, id, provider_id, provider, account, title, url, started_at, and 12 more; every field: beeline commands info meetings list **Next usually:** `beeline meetings show `, `beeline meetings transcript `, `beeline meetings export ` @@ -175,7 +175,7 @@ beeline meetings show [options] |---|---| | `--backend ` | where to read: the store (archive), the service (server), or both, kept in the store (default: both). | -**Returns:** meeting details — ref, id, provider_id, provider, account, title, url, started_at, and 20 more; every field: beeline commands info meetings show +**Returns:** meeting details — ref, id, provider_id, provider, account, title, url, started_at, and 21 more; every field: beeline commands info meetings show **Next usually:** `beeline meetings transcript `, `beeline meetings export ` diff --git a/docs/dev/DESIGN.md b/docs/dev/DESIGN.md index d42b63c..55f0d85 100644 --- a/docs/dev/DESIGN.md +++ b/docs/dev/DESIGN.md @@ -69,9 +69,10 @@ Owner, 2026-11-13 (NEED-2600 A). The client participant carries its number as `p country to the source, and Beeline is a Russian PBX. A number that plan does not read (an extension, a foreign number) keeps its raw digits in the id and gets no phone. -A store written by an unpublished build before this fix keeps `phone:` ids (the owner's: 1626 of them on -2026-11-13). They stay until cli-core offers an identity rename and merge and beeline calls it once on a writable -open; beeline writes no SQL of its own. A fresh install is not affected. cli-core links the callers a sync saved +A store written by an unpublished build before this fix has `phone:` ids, and a build of one day +`phone:+` ones (the owner's: 1626 old ids on 2026-11-13). Each `meetings sync` first moves them to the id +`clientPhone` gives, through cli-core's `rekeyIdentities` (0.674.0), which merges one into the identity already there; +beeline writes no SQL of its own. A second run finds nothing to move. A fresh install is not affected. cli-core links the callers a sync saved to the CRM contact that holds the same number: at once for a mobile only the two of them hold, as a proposal for a landline, which everyone in an office shares. It joins only when the identity is exactly `phone:`, so the `+` must be there. The manager is keyed by Beeline's `abonent` and gets no phone: an extension is the company's, not a diff --git a/lint/audit-differences.json b/lint/audit-differences.json index e7384d8..29cbc5e 100644 --- a/lint/audit-differences.json +++ b/lint/audit-differences.json @@ -1,23 +1,16 @@ [ - { - "group": "shared-roots", - "rule": "same-error-reason", - "target": "reason meeting-project.stale: code", - "reason": "cli-core 0.651.0 made a stale meeting project fingerprint conflict, not configuration_error; the published CLIs are still on 0.650.0 or older, and the entry goes once they publish on 0.651.0.", - "review_after": "2026-11-27" - }, { "group": "shared-roots", "rule": "same-entity-schema", - "target": "entity meeting_details", - "reason": "cli-core 0.650.0 names each participant's person in meetings show; the published zm is older, and the entry goes once it publishes on 0.650.0+.", + "target": "entity meeting", + "reason": "cli-core 0.674.0 adds a phone call's `call` (direction, manager, client_phone) to each meeting; the published zm is on 0.667.0, and the entry goes once it publishes on 0.674.0+.", "review_after": "2026-11-27" }, { "group": "shared-roots", "rule": "same-entity-schema", - "target": "entity meeting_participants", - "reason": "cli-core 0.650.0 names each participant's person in meetings people; the published zm is older, and the entry goes once it publishes on 0.650.0+.", + "target": "entity meeting_details", + "reason": "cli-core 0.674.0 adds a phone call's `call` (direction, manager, client_phone) to meetings show; the published zm is on 0.667.0, and the entry goes once it publishes on 0.674.0+.", "review_after": "2026-11-27" } ] diff --git a/package.json b/package.json index 7bfd498..7a70edd 100644 --- a/package.json +++ b/package.json @@ -60,7 +60,7 @@ }, "dependencies": { "@wirecat/cli-base": "0.103.0", - "@wirecat/cli-core": "0.671.0", + "@wirecat/cli-core": "0.674.0", "commander": "15.0.0", "valibot": "1.5.0" }, diff --git a/pnpm-lock.yaml b/pnpm-lock.yaml index 6296855..70003b4 100644 --- a/pnpm-lock.yaml +++ b/pnpm-lock.yaml @@ -16,8 +16,8 @@ importers: specifier: 0.103.0 version: 0.103.0(commander@15.0.0)(esbuild@0.28.2)(typescript@7.0.2)(vitest@5.0.5) '@wirecat/cli-core': - specifier: 0.671.0 - version: 0.671.0(@wirecat/cli-base@0.103.0(commander@15.0.0)(esbuild@0.28.2)(typescript@7.0.2)(vitest@5.0.5))(commander@15.0.0)(typescript@7.0.2)(zod@4.6.7) + specifier: 0.674.0 + version: 0.674.0(@wirecat/cli-base@0.103.0(commander@15.0.0)(esbuild@0.28.2)(typescript@7.0.2)(vitest@5.0.5))(commander@15.0.0)(typescript@7.0.2)(zod@4.6.7) commander: specifier: 15.0.0 version: 15.0.0 @@ -1177,8 +1177,8 @@ packages: '@wirecat/cli-core-sqlite@1.1.0': resolution: {integrity: sha512-GpGlh/dAIX/nblBYCdT6DfWSLFxav9mxxeELQAfEuw+QZdT9unKxbi5xa02s/s4JS1P7n0PQx2sCABj4FlMRNw==} - '@wirecat/cli-core@0.671.0': - resolution: {integrity: sha512-44jrdlKg4tTumz37av21hXfhvFFFuYLqFR7yKcOhxOu4BaC/TnDGk0NanI5qcJnK5g24Ecdj2JBoh9AMwMUpYA==} + '@wirecat/cli-core@0.674.0': + resolution: {integrity: sha512-j7adV/a5l17D96Busy71d2i2Gg0SEVhAxivLMHsYEoqOHR6s5qyBXnDCcrKTy6Gb1ohyxIei2krpF11NW22znQ==} engines: {node: ^22.16.0 || >=24} hasBin: true peerDependencies: @@ -3184,7 +3184,7 @@ snapshots: '@wirecat/cli-core-sqlite@1.1.0': {} - '@wirecat/cli-core@0.671.0(@wirecat/cli-base@0.103.0(commander@15.0.0)(esbuild@0.28.2)(typescript@7.0.2)(vitest@5.0.5))(commander@15.0.0)(typescript@7.0.2)(zod@4.6.7)': + '@wirecat/cli-core@0.674.0(@wirecat/cli-base@0.103.0(commander@15.0.0)(esbuild@0.28.2)(typescript@7.0.2)(vitest@5.0.5))(commander@15.0.0)(typescript@7.0.2)(zod@4.6.7)': dependencies: '@anthropic-ai/sdk': 1.3.0(zod@4.6.7) '@bomb.sh/tab': 0.0.22(commander@15.0.0) diff --git a/scripts/audit.sh b/scripts/audit.sh deleted file mode 100755 index 1dd9077..0000000 --- a/scripts/audit.sh +++ /dev/null @@ -1,9 +0,0 @@ -#!/usr/bin/env bash -# The built CLI beside the latest published CLI of every parity group, each run in an empty home with D-Bus off; -# fails only on a new finding that names this CLI. -set -euo pipefail - -root=$(cd "$(dirname "$0")/.." && pwd) -cd "$root" -command=$(node --input-type=module -e "import('$root/dist/identity.js').then((m) => console.log(m.IDENTITY.command))") -exec "$root/node_modules/.bin/cli-dev" audit --cli "dist/bin/$command.js" --family diff --git a/src/call-source.ts b/src/call-source.ts index 3ada851..6b7e25b 100644 --- a/src/call-source.ts +++ b/src/call-source.ts @@ -29,6 +29,7 @@ export const callTitle = (record: CallRecord): string => (clientPhone(record.phone) ?? record.phone) const meetingOf = (record: CallRecord): SourceMeeting => ({ + call: { direction: record.direction === "INBOUND" ? "in" : "out", clientPhone: clientPhone(record.phone) ?? null }, series: null, occurrence: { id: record.id, diff --git a/src/client-rekey.test.ts b/src/client-rekey.test.ts new file mode 100644 index 0000000..bb8f763 --- /dev/null +++ b/src/client-rekey.test.ts @@ -0,0 +1,154 @@ +import { DatabaseSync } from "node:sqlite" +import type { FetchLike } from "@wirecat/cli-base/http" +import { storePath } from "@wirecat/cli-core/store" +import { afterEach, expect, it } from "vitest" +import { run } from "./program.js" +import { oldClientRekeys, openBeelineStore, rekeyOldClients } from "./store.js" +import { record } from "./testing/records.js" + +const ran = async (argv: string[], fetch: FetchLike) => { + const out: string[] = [] + const err: string[] = [] + const code = await run(argv, { + streams: { data: (text) => out.push(text), diagnostic: (text) => err.push(text) }, + tty: false, + fetch, + }) + return { code, out: out.join("\n"), err: err.join("\n") } +} + +const sync = (records: ReturnType[]) => + ran(["work", "meetings", "sync", "--since-time", "2026-10-01T00:00:00Z", "--json"], async () => + Response.json(records), + ) + +const sql = (work: (db: DatabaseSync) => T): T => { + const db = new DatabaseSync(storePath(process.env)) + try { + return work(db) + } finally { + db.close() + } +} + +const clientIds = () => + sql((db) => + db + .prepare( + "SELECT external_id AS id, phone FROM identities WHERE provider = 'beeline' AND external_id LIKE 'phone:%'", + ) + .all() + .map((row) => ({ id: String(row.id), phone: row.phone })), + ) + +const clientOfMeeting = (call: string) => + sql( + (db) => + db + .prepare( + `SELECT i.external_id AS id FROM meeting_participants p JOIN identities i ON i.id = p.identity_id + JOIN meetings m ON m.id = p.meeting_id WHERE m.external_id = ? AND p.role = 'client'`, + ) + .get(call)?.id, + ) + +afterEach(() => { + delete process.env.BEELINE_TOKEN +}) + +it("names the old caller ids' E.164 ids and leaves the current ones and extensions", () => { + expect( + oldClientRekeys([ + "phone:9000000009", + "phone:+9000000009", + "phone:+4950000001", + "phone:+79000000009", + "phone:1234", + "abonent:70000000001@example.test", + ]), + ).toEqual([ + { from: "phone:9000000009", to: "phone:+79000000009", phone: "+79000000009" }, + { from: "phone:+9000000009", to: "phone:+79000000009", phone: "+79000000009" }, + { from: "phone:+4950000001", to: "phone:+74950000001", phone: "+74950000001" }, + ]) +}) + +it("a sync moves the callers an older build stored to their E.164 ids, merging into one already there", async () => { + process.env.BEELINE_TOKEN = "test-token" + const first = await sync([ + record(701, { phone: "9000000001" }), + record(702, { phone: "9000000002" }), + record(703, { phone: "9000000003" }), + record(704, { phone: "1234" }), + ]) + expect(first.code, first.err).toBe(0) + // As development builds of 0.1.0 wrote them; 703's client is 701's in the other old form. + sql((db) => { + const rename = db.prepare("UPDATE identities SET external_id = ?, phone = ? WHERE external_id = ?") + rename.run("phone:9000000001", null, "phone:+79000000001") + rename.run("phone:+9000000002", "+9000000002", "phone:+79000000002") + rename.run("phone:+9000000001", "+9000000001", "phone:+79000000003") + }) + expect(clientOfMeeting("703")).toBe("phone:+9000000001") + + const second = await sync([]) + expect(second.code, second.err).toBe(0) + expect(second.err).toContain("moved old caller ids to their E.164 numbers: 2 renamed, 1 merged") + expect(clientIds()).toEqual( + expect.arrayContaining([ + { id: "phone:+79000000001", phone: "+79000000001" }, + { id: "phone:+79000000002", phone: "+79000000002" }, + { id: "phone:1234", phone: null }, + ]), + ) + expect(clientIds()).toHaveLength(3) + expect(clientOfMeeting("701")).toBe("phone:+79000000001") + expect(clientOfMeeting("703")).toBe("phone:+79000000001") + + const third = await sync([]) + expect(third.code, third.err).toBe(0) + expect(third.err).not.toContain("moved old caller ids") + const store = await openBeelineStore(process.env) + try { + expect(await rekeyOldClients(store)).toEqual({ renamed: 0, merged: 0, refused: 0 }) + } finally { + await store.close() + } +}) + +it("merges an old caller id into the E.164 id a newer sync already stored", async () => { + process.env.BEELINE_TOKEN = "test-token" + expect((await sync([record(801, { phone: "9000000004" }), record(802, { phone: "9000000005" })])).code).toBe(0) + sql((db) => + db + .prepare("UPDATE identities SET external_id = ? WHERE external_id = ?") + .run("phone:9000000004", "phone:+79000000005"), + ) + + const synced = await sync([]) + expect(synced.code, synced.err).toBe(0) + expect(synced.err).toContain("0 renamed, 1 merged") + expect(clientOfMeeting("802")).toBe("phone:+79000000004") +}) + +it("a call synced again gets its direction, the client's number and a corrected title", async () => { + process.env.BEELINE_TOKEN = "test-token" + const call = record(901, { phone: "9000000006", direction: "INBOUND" }) + expect((await sync([call])).code).toBe(0) + // As an older build stored it: a `+` before the national number, no call fields. + sql((db) => + db + .prepare("UPDATE meetings SET title = ?, direction = NULL, client_phone = NULL WHERE external_id = '901'") + .run("Входящий звонок · Test Manager ↔ +9000000006"), + ) + expect((await sync([call])).code).toBe(0) + const listed = await ran(["work", "meetings", "list", "--json"], async () => Response.json([])) + const id = (JSON.parse(listed.out).items as { id: number; title: string }[]).find((one) => + one.title.endsWith("+79000000006"), + )?.id + const shown = await ran(["work", "meetings", "show", String(id), "--json"], async () => Response.json([])) + expect(shown.code, shown.err).toBe(0) + expect(JSON.parse(shown.out).item).toMatchObject({ + call: { direction: "in", client_phone: "+79000000006", manager: { name: "Test Manager" } }, + }) +}) diff --git a/src/commands/meetings.ts b/src/commands/meetings.ts index 0d80867..a858ae1 100644 --- a/src/commands/meetings.ts +++ b/src/commands/meetings.ts @@ -258,7 +258,7 @@ export const meetingsMount = () => { const run = environmentOf(at) const { settings, env, keyring } = baseContext(at, configuration.resolveSettings) const { profile } = settings - const [{ openProfileStore }, { beelineFor }, { callSource }] = await Promise.all([ + const [{ openProfileStore, rekeyOldClients }, { beelineFor }, { callSource }] = await Promise.all([ import("../store.js"), import("../beeline.js"), import("../call-source.js"), @@ -272,6 +272,14 @@ export const meetingsMount = () => { const close = () => (closed ??= store.close()) // Still tracked: a command that fails never reaches postAction. run.trackCloseable?.({ close }) + if (pathOf(at).join(" ") === "meetings sync" && at.optsWithGlobals().dryRun !== true) { + const moved = await rekeyOldClients(store) + if (moved.renamed + moved.merged + moved.refused > 0) + run.streams?.diagnostic( + `moved old caller ids to their E.164 numbers: ${moved.renamed} renamed, ${moved.merged} merged` + + (moved.refused ? `, ${moved.refused} left as they were (they could not merge)` : ""), + ) + } let api: BeelineApi | undefined let source: MeetingSource | undefined const signedIn = () => { diff --git a/src/store.ts b/src/store.ts index c3edf1e..82f12d5 100644 --- a/src/store.ts +++ b/src/store.ts @@ -2,8 +2,8 @@ import { mkdtempSync, rmSync } from "node:fs" import { tmpdir } from "node:os" import { join } from "node:path" import { isCliError } from "@wirecat/cli-base" -import type { MessageStore } from "@wirecat/cli-core/store" -import { PROVIDER_NAME } from "./call-source.js" +import type { IdentityRekey, MessageStore } from "@wirecat/cli-core/store" +import { clientPhone, PROVIDER_NAME } from "./call-source.js" import { IDENTITY } from "./identity.js" export const PROVIDER = { @@ -88,3 +88,38 @@ const openEmptyStore = async (env: NodeJS.ProcessEnv, profile: string) => { throw error } } + +/** + * A caller's id as an older build wrote it, moved to the `phone:+7…` id it gets now. Development builds of 0.1.0 first wrote the 10-digit + * national number Beeline sends (`phone:9000000009`); then, for a day, that number behind a `+` (`phone:+9000000009`). + * An id `clientPhone` cannot read, such as an extension, stays. + */ +export const oldClientRekeys = (ids: readonly string[]): IdentityRekey[] => + ids.flatMap((from) => { + const raw = /^phone:(?:\+(?=\d{10}$))?(\d+)$/.exec(from)?.[1] + const phone = raw === undefined ? undefined : clientPhone(raw) + const to = phone && `phone:${phone}` + return phone && to && to !== from ? [{ from, to, phone }] : [] + }) + +export interface ClientRekeys { + renamed: number + merged: number + refused: number +} + +/** Moves every profile's old caller ids to E.164 in passes short enough for other commands to get the write lock. */ +export const rekeyOldClients = async (store: MessageStore): Promise => { + const ids = (await store.people.people(PROVIDER_NAME)).all().map((one) => String(one.id)) + let rest = oldClientRekeys(ids) + const total = { renamed: 0, merged: 0, refused: 0 } + while (rest.length > 0) { + const pass = await store.people.rekeyIdentities(PROVIDER_NAME, rest, { by: IDENTITY.command }) + total.renamed += pass.renamed + total.merged += pass.merged + total.refused += pass.refused.length + if (pass.taken === 0) break + rest = rest.slice(pass.taken) + } + return total +} diff --git a/template.json b/template.json index a53fe6a..a711d8f 100644 --- a/template.json +++ b/template.json @@ -31,7 +31,6 @@ "docs/dev/skills/release/SKILL.md": "868f14f964ebb977e15fc4b3dd8036e72cc8583e601249df762ee4ec0a2c7b7c", "docs/dev/skills/release/fresh-audit.md": "a6dacd97ce098552756593a2e7661c97af729b0ece54f17feeeb9223375ff52b", "lefthook.yml": "c41b0b3b90a5c1e3f5b8c78a524139bdbafb836a0e0e4ebd90ccb2c7939b57ed", - "scripts/audit.sh": "9c4b6dca3029243f5c236dbc0f317ed0f025c50173d55828e91aeff536a88613", "scripts/changelog-fragments.ts": "2565a3e477b5409a91952985c1c5e50f1d656bafac2dde0e428bf7930dc8de13", "tsconfig.json": "1d6455eff0cd509e4d24217757d7b2c5ff8fe70dad8fac2d9d4eb4e9b5d7ee50", "tsconfig.scripts.json": "5987bd02d21f42c55ad06cedbb49ede9fa39debccb44286cda23f0c605ee6107", From c85b73828a5dca6b6d87f09542e17f24b34ddc50 Mon Sep 17 00:00:00 2001 From: leemour Date: Mon, 16 Nov 2026 13:37:38 +0100 Subject: [PATCH 2/2] chore(live): record the read-only live check of 8bbbfd7 bin/beeline-live nbzb against the owner's Beeline account, read-only, in a throwaway store: session check, 245 calls synced with 0 warnings, the list carries call, one call transcribed. Co-Authored-By: Claude Opus 5.5 --- docs/dev/live-checks.txt | 1 + 1 file changed, 1 insertion(+) diff --git a/docs/dev/live-checks.txt b/docs/dev/live-checks.txt index d80dd66..358a340 100644 --- a/docs/dev/live-checks.txt +++ b/docs/dev/live-checks.txt @@ -7,3 +7,4 @@ 0.1.0 2c646f665c19c605b697e8791e14b3dea0a88243 2026-11-14 bin/beeline-live v2:7bba9f9dea2e6697d70b53920e7f5bb299d8b74496f23ace63a154564b9795aa 0.1.0 abb4fc2cc641b06dac08b70549932e7ecd957abd 2026-11-14 bin/beeline-live v2:f0890ea000648a4b52e18c94c7033f5d57afa91143a19ea49db193641232f230 0.2.0 2ca139df848db1862a2638e8dc8ebf7f48974bf8 2026-11-16 bin/beeline-live v2:01b5cb21edd481af660362e286ef321399e8704e175b1c1178971b6bb6418134 +0.2.0 8bbbfd7fd044df87552c79ce8abea195e6100e48 2026-11-16 bin/beeline-live v2:eadc369017ed7ef2941f203c6521991eb8e3a6c05f0c98ffbd2ef655c590b516