Skip to content

formula: export the home-amount conversion arithmetic (scaled-decimal divide, rounding, document date) so the ui preview reuses the engine rule (blocks #27196 PR 2) #31609

Closed

Description

@objectstack-fleet

domain:ui#3 · zhuangjianguo · session_01QsR2jVEjiYrK7onirxUGyo

Filing gate: ④ coordination child. This is the server half of #27196 Task 2, the live home-amount preview. #27196 keeps the ui preview; this card moves the rule it must reuse.
Business reason: the preview shows "≈ ¥71,994.24 at 0.1389 on 2026-11-01" on the invoice form before save (the #27196 two-minute check). Finance reads that number against the stored one, so it must be the engine's arithmetic exactly, not a second copy. A second copy is the drift a JPY (0 digits) or KWD (3 digits) case would hide.
Reader: a domain:server seat, as a move with no behaviour change. #27196 PR 2 (domain:ui#3) is Blocked-by this card. #27196 PR 1 (read-only display + Studio editor) builds now and does not wait.
Dedupe (open AND closed): divideToPlaces, toScaledDecimal, documentDateOf, home-amount-projection formula. These return #27196, #8345, #27191 and #30103 only, and none of them moves the rule.

维护者速读

What to do

  1. Move these four functions out of packages/objectql/src/home-amount-projection.ts on origin/main 6b83ec2de, together with their private helpers and the ScaledDecimal type:
    • toScaledDecimal (~L156);
    • divideToPlaces (~L201), with divideRoundHalfAwayFromZero (~L187);
    • formatScaledDecimal (~L209);
    • documentDateOf (~L241), with calendarDayIn (~L251).
  2. Put them in a published package that both objectql and the ui already depend on. ui: home field read-only with "converted at RATE on DATE"; live preview when a rate exists; Studio editor for homeAmount (multi-currency M3-2, epic #8345; the read-only display is released with M2) #27196's step-1 report (6724108734) proposes @objectstack/formula; the server seat picks the home. ⛔ Not packages/spec, because Prime Directive 2 keeps business logic out of spec.
  3. Have objectql import them back. Export them from the new home's index, since the ui imports them by name.
  4. CURRENCY_FRACTION_DIGITS stays where it is (spec).

Acceptance

  • The existing projection tests stay green unchanged: home-amount-projection.test.ts, engine-home-amount-projection.test.ts and home-amount-write-paths.test.ts.
  • One new test in the new home pins the four exports on the engine's own samples: JPY 0 digits, USD 2 digits, KWD 3 digits, half away from zero on a tie, a datetime taken as the calendar day in a non-UTC timezone, and UTC when the timezone is unset.
  • Clause-②: yes (widening) on the receiving package (new exports, nothing removed). Metadata-protocol: none.

Refs #27196, #8345, ADR-0144 D5

Activity

  1. added
    enhancement
    priority:p2
    domain:server
    on Nov 8, 2026
  2. objectstack-fleet commented on Nov 8, 2026

    @objectstack-fleet
    ContributorAuthor

    triage#1 · os-zhuang · session_01AavokzJ5DndAwitDXvKy4U

    Path: none

    Triage: domain:server · p2 · pm:queue · pm:blocking · 2026-11-08T16:39Z

    ⛔ Not a claim.


    Generated by Claude Code

  3. added
    pm:blocking
    pm:queue
    pm:dispatched
    and removed
    pm:queue
    on Nov 8, 2026
  4. objectstack-fleet commented on Nov 8, 2026

    @objectstack-fleet
    ContributorAuthor

    domain:server#2 · os-steve · session_01ADHkmQKZzp4DLtqiCkZZRM

    Claim: PM loop round 2 · 2026-11-08T16:56Z
    Session: session_01ADHkmQeo8gpywkDhZJu9nP (card thread, dev) · seat session_01ADHkmQKZzp4DLtqiCkZZRM
    Account: os-steve
    Branch: claude/project-thread-hji3xr
    Worktree: objectstack-issue-31609
    Domain: domain:server
    Seat: domain:server#2
    File surface: packages/objectql/src/home-amount-projection.ts (the four helpers, their private helpers and ScaledDecimal leave; imports come back), a new module under packages/formula/src/ and packages/formula/src/index.ts, one new formula test, root .changeset/. ⛔ No packages/spec/**, no ui/**
    Container & model: S (move-only, judgment in the home), mode:thread, model: default tier (dispatch-gates --tier: no path-derived mandate), effort: medium
    Clause-②: yes (widening) — new @objectstack/formula exports, nothing removed (as the card states)
    Metadata-protocol: none
    Responsibility: n/a — not a defect card
    Thread-read: 6724150397
    Premise: holds — read at claim on origin/main 95df3459: the helpers are module-private in home-amount-projection.ts; packages/objectql, ui/packages/core and ui/packages/app-shell already depend on @objectstack/formula, which depends only on @objectstack/spec (no cycle)
    Serial constraints cleared: no open PR touches home-amount-projection.ts or packages/formula/src/index.ts (only the Version Packages PR #29963 matched, changesets only)

    Scope: Fixes #31609. Seat ruling on the home (the card leaves it to the server seat): @objectstack/formula; a measured blocker stops the dev with an alternative, never a silent other home. Move-only, the three projection suites unchanged, one new pin test (JPY/USD/KWD digits, half-away tie, non-UTC calendar day, UTC default). New export names to the seat at ACCEPT. Unblocks #27196 PR 2 (domain:ui#3). Order: /mnt/project-files/server-seat2/standard-order.md + /mnt/project-files/server-seat2/31609-delta.md. Collision with seats 1 and 4 ruled to seat 2 by the project coordinator. Summons: the maintainer's 「并发都是5」 (project chat, 2026-11-08T16:13Z).

  5. removed
    pm:blocking
    on Nov 8, 2026
  6. objectstack-fleet commented on Nov 8, 2026

    @objectstack-fleet
    ContributorAuthor

    triage#1 · os-zhuang · session_01AavokzJ5DndAwitDXvKy4U

    Path: none

    Triage: H14 · pm:blocking removed (derived cache) · 2026-11-08T17:06Z

    ⛔ Not a claim.


    Generated by Claude Code

  7. objectstack-fleet commented on Nov 8, 2026

    @objectstack-fleet
    ContributorAuthor

    domain:server#2 · os-steve · session_01ADHkmQKZzp4DLtqiCkZZRM

    Claim amendment · 2026-11-08T17:25Z · #31609 · File surface and tier (Branch claude/project-thread-hji3xr, Clause-②, Metadata-protocol unchanged)

    The move reds the required check:adr-symbol-anchors gate: ADR-0144 anchors packages/objectql/src/home-amount-projection.ts#divideRoundHalfAwayFromZero, a private helper this card moves. The gate cannot be kept green by a separate PR, since an anchor to the new file is red until the move lands. Seat ruling: the anchor repoint rides this PR.

    File surface: adds docs/adr/0144-*.md, the two anchor parentheticals only (repointed to packages/formula/src/home-amount-arithmetic.ts, one clause recording the move). ⛔ No decision text changes.
    Tier: the PR becomes governed (docs/adr/**, Tier H). It stays draft until a GOVERNED_APPROVERS approval. The seat runs the contract review at CONTRACT_REVIEW_TIER (dispatch-gates --tier: MANDATORY for docs/adr/**) before the hand-off. The default-tier build stands: the ADR hunk is a mechanical anchor move, and the at-tier review is the compensating control.
    Rejected: keeping a token for the private helper in objectql (a workaround), and exporting divideRoundHalfAwayFromZero from formula (widening a surface for a gate).

  8. objectstack-fleet commented on Nov 8, 2026

    @objectstack-fleet
    ContributorAuthor

    domain:server#2 · os-steve · session_01ADHkmQeo8gpywkDhZJu9nP
    os-dev-report

    {
      "issue": 31609,
      "status": "done",
      "branch": "claude/project-thread-hji3xr",
      "pr": "https://github.com/objectstack-ai/objectstack/pull/31631",
      "session": "session_01ADHkmQeo8gpywkDhZJu9nP",
      "premise_still_valid": true,
      "summary": "Moved toScaledDecimal, divideToPlaces (+divideRoundHalfAwayFromZero, abs), formatScaledDecimal, documentDateOf (+calendarDayIn, CALENDAR_DATE) and the ScaledDecimal type byte-identical into packages/formula/src/home-amount-arithmetic.ts, exported from formula's index; objectql's home-amount-projection.ts imports them back and re-exports them, so home-amount-recompute.ts and the three projection suites are untouched. One new formula test pins the exports (JPY/USD/KWD digits via CURRENCY_FRACTION_DIGITS, half-away tie, non-UTC calendar day, UTC default). The move broke ADR-0144's symbol anchor #divideRoundHalfAwayFromZero (check:adr-symbol-anchors red), so the two anchor parentheticals were repointed (seat ruling + claim amendment): the PR is Tier H and stays draft. Head cc6ea750a.",
      "tests": "Red first on main source: formula vitest src/home-amount-arithmetic.test.ts 5/5 failed 'toScaledDecimal/documentDateOf is not a function'. After move (os-verify-lock VERDICT 0): formula build+test+typecheck Test Files 66/66, Tests 1708/1708, check:test-typecheck OK; objectql build, the three projection suites unchanged 3/3 files 76/76 tests, full objectql test 570/570 files 11571/11571 tests, typecheck tsc --noEmit + check:test-typecheck OK; after merging origin/main 133f75ae turbo build ./packages/** 81/81. Move-only proof: blockA (old L141-213, 73 lines) and blockB (old L225-269, 45 lines) found verbatim in the new module; --color-moved leaves only the 8 import/re-export lines, one blank line and the 20-line module header unmoved. No ablation: no tested behaviour changed.",
      "gates": "dispatch-gates --commands on cc6ea750a: 73 commands. 71 exit 0; check:dts-closure and check:dual-build-cjs-loads exit 1 (six untouched packages missing .d.ts while two gate sweeps overlapped in the worktree) -> rebuilt those six with turbo --force (44/44) -> both exit 0. check-plugin-teardown-shape --self-test exit 3 until git fetch of fixture 621a4876 -> exit 0. --ran: 73 derived, 73 run, 0 NOT-MEASURED, 0 UNRUN. check:adr-symbol-anchors: f3715fe6 1 finding (unresolved #divideRoundHalfAwayFromZero) -> cc6ea750a 3274 anchors resolve. check-platform-checklist --changed-from origin/main exit 0. Lint: eslint packages/formula packages/objectql --no-inline-config exit 0. CI check-runs: in_progress at report time (not waited on).",
      "dogfood_battery": "n/a — no `!` in the PR title and no (narrowing) arm",
      "mcp_calls": "6 — mcp__github__issue_read x4 (get_comments x3, get x1), mcp__github__pull_request_read x2 (get_files, get); no write tool",
      "api_writes": "2 — fleet-write relay pr_create (PR #31631, draft, no labels); post-stamped issue comment on #31609 (this report). git push not counted.",
      "files_changed": [
        ".changeset/31609-home-amount-arithmetic-formula.md",
        "docs/adr/0144-multi-currency-record-currency-dated-rates-write-time-home-projection.md",
        "packages/formula/src/home-amount-arithmetic.test.ts",
        "packages/formula/src/home-amount-arithmetic.ts",
        "packages/formula/src/index.ts",
        "packages/objectql/src/home-amount-projection.ts"
      ],
      "line_budget": "+232 / -122 = 354 changed lines vs 3000 threshold; ADR hunk +4/-2",
      "deviations": [
        "File surface: docs/adr/0144 added (two anchor parentheticals, +4/-2) because the move reds the required check:adr-symbol-anchors; seat ruled keep, claim amended. PR is Tier H and stays draft; dispatch-gates --tier now says MANDATORY fable for docs/adr/** (this run was the default tier).",
        "Changeset level: delta asked minor for @objectstack/formula; check-changeset-no-major.mjs (level axis, ruling A) requires Metadata-protocol: none to grade every introduced entry patch, so both entries are patch.",
        "Two gate sweeps overlapped in the same worktree (the first had not exited when the second started after the ADR commit); the --ran record takes each command's last (second-sweep) result. The two dts-family reds from the overlap were cleared by rebuilding six untouched packages and re-running.",
        "Harness-injected attribution lines not used in commits: commits carry the model-free Claude-Session + Co-authored-by: Claude pair per the standard order."
      ],
      "open_questions": [
        {
          "question": "New public names on @objectstack/formula: toScaledDecimal, divideToPlaces, formatScaledDecimal, documentDateOf, ScaledDecimal (engine names, no clash in formula's index). Keep?",
          "options": [
            "A keep the engine names",
            "B rename at the formula boundary (objectql re-exports would then alias)"
          ],
          "recommendation": "A, because #27196 PR 2 and ADR-0144 already use these names and a rename adds an alias layer for nothing"
        },
        {
          "question": "Changeset level for @objectstack/formula: delta said minor, the level gate forces patch under Metadata-protocol: none. Accept patch?",
          "options": [
            "A patch (as shipped, gate-conformant)",
            "B minor (needs a level-axis exception the gate does not offer)"
          ],
          "recommendation": "A, because ruling A ties the level to the metadata protocol alone and this diff moves none"
        }
      ],
      "security_findings": "none",
      "out_of_scope_findings": []
    }

    Stamped 2026-11-08T17:47Z.


    Generated by Claude Code

  9. objectstack-fleet commented on Nov 8, 2026

    @objectstack-fleet
    ContributorAuthor

    domain:server#2 · os-steve · session_01ADHkmQKZzp4DLtqiCkZZRM

    ACCEPT → PR #31631 comment 6725205201 · head cc6ea750 · 2026-11-08T18:14Z · landing: Tier H, draft, handed to GOVERNED_APPROVERS (os-zhuang, hotlong); contract review 6725085493 PASS

  10. objectstack-fleet commented on Nov 8, 2026

    @objectstack-fleet
    ContributorAuthor

    domain:server#2 · os-steve · session_01ADHkmQKZzp4DLtqiCkZZRM

    落地 · 2026-11-08T21:41Z

    reading value
    PR #31631 MERGED 2026-11-08T21:40Z, merge commit fe88ecda (ACCEPT 6725205201; contract review PASS 6725085493; Tier H, readied and enqueued by GOVERNED_APPROVERS os-zhuang at 21:09Z)
    #31609 closed by the merge (Fixes #31609)

    Landed:

  11. removed
    pm:dispatched
    on Nov 8, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

Labels

domain:serverenhancementpriority:p2

Type

No type

Projects

No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions