Skip to content

Commit 91a79dd

Browse files
A decided review records when legal decided (#163)
Fixes #159: hook review_decision_stamp stamps clm_review.decided_at when the decision leaves pending, on insert and update, unless a value is set; it never overwrites or clears one. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_017nzWFRUo2U7evMkPdVniAn
1 parent 21f2319 commit 91a79dd

4 files changed

Lines changed: 41 additions & 0 deletions

File tree

‎src/objects/contract.hook.ts‎

Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -42,6 +42,11 @@ import type { HookApi } from './_hook-api.js';
4242
* `route_legal_head` on the parent contract. The other half of F6 — no
4343
* `open` deviation may enter `in_approval` — is the state machine's guard,
4444
* applied on BOTH edges into `in_approval`.
45+
* - `review_decision_stamp` (beforeInsert / beforeUpdate on `clm_review`):
46+
* a review given a decision — approved, changes requested or rejected — is
47+
* stamped `decided_at` on BOTH write paths, unless one is set, the way a
48+
* decided deviation is. It guards no transition: §03 gives the review's
49+
* decision no state machine.
4550
* - `deviation_state_machine`, `signature_state_machine`,
4651
* `obligation_state_machine`, `payment_plan_state_machine`: the child
4752
* machines. The last two also hold the `overdue` reservation — that state
@@ -955,6 +960,38 @@ const deviationGate: Hook = {
955960
},
956961
};
957962

963+
const reviewDecisionStamp: Hook = {
964+
name: 'review_decision_stamp',
965+
object: 'clm_review',
966+
events: ['beforeInsert', 'beforeUpdate'],
967+
priority: 200,
968+
description: 'Stamp decided_at when a review is given a decision (approved, changes requested or rejected), on create as well as on update, unless one is set explicitly.',
969+
handler: async (ctx: HookContext) => {
970+
// The review's counterpart of the deviation's decided_at stamp: the
971+
// decision is legal's to make, the platform records WHEN. It fills an
972+
// empty decided_at and never overwrites or clears one, so a time the
973+
// lawyer typed — in this write or an earlier one — is kept.
974+
//
975+
// A review has no decided_by: its `reviewer` is the person who decides
976+
// (DESIGN.md §03 lists only decided_at on clm_review).
977+
//
978+
// Back to `pending` is not refused — unlike a deviation, a review's
979+
// decision has no transition table in §03 — and it does not clear the
980+
// stamp either: the hook cannot tell a stamped time from a typed one, and
981+
// the field stays editable on the same form.
982+
const { event, input } = ctx;
983+
const previous = event === 'beforeInsert' ? {} : (ctx.previous ?? {});
984+
const to = input.decision;
985+
if (typeof to !== 'string' || to === 'pending') return;
986+
const from = typeof previous.decision === 'string' ? previous.decision : 'pending';
987+
if (to === from) return;
988+
const decidedAt = input.decided_at !== undefined ? input.decided_at : previous.decided_at;
989+
if (decidedAt === undefined || decidedAt === null || decidedAt === '') {
990+
input.decided_at = new Date().toISOString();
991+
}
992+
},
993+
};
994+
958995
const signatureStateMachine: Hook = {
959996
name: 'signature_state_machine',
960997
object: 'clm_signature',
@@ -1185,6 +1222,7 @@ export default [
11851222
contractActivate,
11861223
deviationStateMachine,
11871224
deviationGate,
1225+
reviewDecisionStamp,
11881226
signatureStateMachine,
11891227
obligationStateMachine,
11901228
paymentPlanStateMachine,

‎src/objects/review.object.ts‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -101,6 +101,7 @@ export const Review = ObjectSchema.create({
101101
decided_at: Field.datetime({
102102
label: 'Decided At',
103103
group: 'outcome',
104+
description: 'Stamped when the review is given a decision, unless set explicitly.',
104105
}),
105106
},
106107

‎src/translations/en/objects.lifecycle.ts‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -64,6 +64,7 @@ export const lifecycle: Record<string, ObjectTranslationData> = {
6464
},
6565
decided_at: {
6666
label: 'Decided At',
67+
help: 'Stamped when the review is given a decision, unless set explicitly.',
6768
},
6869
},
6970
_sections: {

‎src/translations/zh-CN/objects.lifecycle.ts‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -64,6 +64,7 @@ export const lifecycle: Record<string, ObjectTranslationData> = {
6464
},
6565
decided_at: {
6666
label: '结论时间',
67+
help: '给出结论时自动写入,除非显式指定。',
6768
},
6869
},
6970
_sections: {

0 commit comments

Comments
 (0)