Repository navigation
Conversation
Templates whose models extend org.accordproject.templatedata@1.0.0 and runtime@1.0.0 can write their logic with defineLogic(), imported from '@accordproject/template-engine/logic', instead of a TemplateLogic class: one handler per request type, each taking (request, self), where self is the template instance's node in an agreement@1.0.0 Agreement (models#205). - src/agreement/logic.ts: the logic API (defineLogic, Self, Clause, ApiOf, conceptType / identifiedType factories). Self-contained, so it is also what the compiler declares to template logic. - src/agreement/execute.ts: initialise() and execute(), from JSON to JSON, over the agreement's tree of instances and its runtime@1.0.0 AgreementState. Writes are buffered in a transaction that commits as one revision; a composed clause runs in a nested transaction. - src/agreement/types.ts and codegen.ts, bin/codegen.js: one factory per concrete model type (logic/generated/types.ts), generated with Concerto's interfaces by template-engine-codegen. - src/agreement/loader.ts: loads compiled logic, supplying the logic API, the factories, generated enums, dayjs and jsonpath to its imports. - src/agreement/testing.ts: testInstance and stubClause, as '@accordproject/template-engine/testing'. - TemplateArchiveProcessor: init() and trigger() run such logic as the one document of an agreement; draft() names the template model explicitly; runtime hierarchy checks accept runtime@1.0.0 alongside 0.2.0. - AgreementProcessor: runs an agreement over several templates. TemplateLogic templates are unchanged. Depends on cicero-core finding the template model by TemplateData (template-archive#946, #950), installed from that PR's dist branch until it is released. Signed-off-by: Claude <noreply@anthropic.com> Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_011LWZaJoaq9HFMVceNxCXMS
mttrbrts
pushed a commit
to accordproject/cicero-template-library
that referenced
this pull request
Oct 1, 2026
… API, as three templates The prototype's local runtime is replaced by the released shape of the design: - Models: the 1.0.0 namespaces are refreshed from accordproject/models#205, which folds the prototype's proposal namespace (composition.cto) into agreement@1.0.0 (Clause with data and clauses, AgreementReference with a documentId), runtime@1.0.0 (AgreementState.states) and obligation@1.0.0 (ObligationIssued). composition.cto is removed. - Templates: the composed late payment clause and the licensed work schedule become sibling templates, late-payment-poc and licensed-work-schedule-poc, since cicero-core loads model/ and logic/ recursively. The licence keeps copies of their models, which its logic uses, and names its template model in package.json (accordproject.templateModel). - Logic imports defineLogic from @accordproject/template-engine/logic and its factories from logic/generated/types.ts, which template-engine-codegen writes with Concerto's interfaces (npm run compile). runtime/ and scripts/generate-types.js are removed. - Tests use @accordproject/template-engine/testing, and the agreement tests run on template-engine's AgreementProcessor, which compiles and loads each template's logic. Without a direct concerto-core import, the vitest alias around concerto-core's ESM version is no longer needed. - The library depends on template-engine and cicero-core from the dist branches of accordproject/template-engine#187 and accordproject/template-archive#950, so the render suite loads, drafts, initialises and triggers all three templates; the expectedLoadFailures entry is removed. Signed-off-by: Claude <noreply@anthropic.com> Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_011LWZaJoaq9HFMVceNxCXMS
4 tasks done
Coverage Report for CI Build 36911453722Coverage increased (+7.8%) to 62.208%Details
Uncovered Changes
Coverage RegressionsNo coverage regressions found. Coverage Stats💛 - Coveralls |
Contributor
|
This PR is stale because it has been open with no activity. Remove the stale label or comment to keep it active. Only items with maintainer engagement are auto-closed. |
This branch has not been deployed
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
Adds a second way to write template logic, for templates on the org.accordproject 1.0.0 namespaces. Their data extends
templatedata@1.0.0.TemplateData, their state extendsStateData, and their requests extendruntime@1.0.0.Request(accordproject/models#200, plus #205's composed clauses). Templates that useTemplateLogicare unchanged, and all existing tests pass as before.How logic runs
(request, self).selfis the instance. It is this template instance's node in anagreement@1.0.0Agreement. The Agreement is one tree of instances: each document is the root instance, and each composedClauseis an instance with its own data and state.selfreads everything in the tree but writes only its own state (setState), its events (emit) and the clauses composed into it (self.clauses.x.trigger(...)).Clause<ApiOf<typeof thatLogic>>gives the clause'striggeran overload for each request type it handles.runtime@1.0.0.AgreementState, or not at all if the handler throws. A composed clause runs in a nested transaction, so a parent that catches a clause's error loses only that clause's writes.PayOut.create({...})fills in$class, so logic never writes one by hand.What's added
src/agreement/logic.tssrc/runtime/logicDeclarations.ts, generated at prebuild).src/agreement/execute.tsinitialise()/execute(), JSON in and JSON out, so a stateless function (e.g. serverless) can host an agreement. AlsoTransaction, the tree, and read-only views.src/agreement/types.ts,codegen.ts,bin/codegen.jstemplate-engine-codegen [dir] [--offline]writeslogic/generated/*.ts: Concerto's interfaces plustypes.ts.src/agreement/loader.tssrc/agreement/testing.tstestInstance(aselfwithcommitted) andstubClause(typed by the clause's API), exported as@accordproject/template-engine/testing.src/AgreementProcessor.tsTemplateArchiveProcessorinit/triggerrun such logic as the one document of an agreement.draftpasses the template model's FQN explicitly. Runtime hierarchy checks accept runtime@1.0.0 as well as runtime@0.2.0.Dependencies
This needs cicero-core to find the template model by
TemplateDataand to readaccordproject.templateModel(accordproject/template-archive#946 and #950). Until those are released,@accordproject/cicero-corepoints at #950's prebuilt dist branch. Swap it for the release before merging.The prebuilt dist branch
claude/agreement-1.0-logic-dist(5.2.0-agreement.0) lets cicero-template-library install this branch from git.Tests
test/AgreementLogic.test.tscovers the transaction semantics with toy logic: nested clauses, catch and rethrow, read-only views, reference resolution, dispatch to a supertype handler, and validation. It also covers the testing helpers.test/AgreementProcessor.test.tsruns an agreement of three real templates (test/archives/agreement, copied from cicero-template-library), compiled and loaded by the engine:It also covers
TemplateArchiveProcessor's draft, init and trigger for these templates, plus codegen and import rewriting.npm testgives 140 passed: the 109 existing tests are unchanged, plus 31 new.npm run webpackbuilds.Related: accordproject/models#205, accordproject/template-archive#950, accordproject/cicero-template-library#528.
🤖 Generated with Claude Code
https://claude.ai/code/session_011LWZaJoaq9HFMVceNxCXMS
Generated by Claude Code