import { CollationStage } from '../../types/collator'; import { ActivityDuplex } from '../../types/activity'; import { HotMeshGraph } from '../../types/hotmesh'; import { ProviderTransaction } from '../../types/provider'; import { Activity } from '../activities/activity'; import { Cycle } from '../activities/cycle'; declare class CollatorService { static targetLength: number; /** * Positional weights for the 15-digit activity/GUID ledger. * * Position: 1 2 3 4 5 6 7 8-15 * Weight: 100T 10T 1T 100B 10B 1B 100M 10M..1 */ static WEIGHTS: { AUTH: number; FINALIZE: number; LEG1_ENTRY: number; LEG1_COMPLETE: number; STEP1_WORK: number; STEP2_SPAWN: number; STEP3_CLEANUP: number; LEG2_ENTRY: number; GUID_SNAPSHOT: number; }; /** * Upon re/entry, verify that the job status is active */ static assertJobActive(status: number, jobId: string, activityId: string, threshold?: number): void; /** * returns the dimensional address (dad) for the target; due * to the nature of the notary system, the dad for leg 2 entry * must target the `0` index while leg 2 exit must target the * current index (0) */ static getDimensionalAddress(activity: Activity, isEntry?: boolean): Record; /** * resolves the dimensional address for the * ancestor in the graph to go back to. this address * is determined by trimming the last digits from * the `dad` (including the target). * the target activity index is then set to `0`, so that * the origin node can be queried for approval/entry. */ static resolveReentryDimension(activity: Cycle): string; /** * Leg1 entry: increment attempt counter (+1T). * NOT bundled with Leg1 work — exists only to mark entry. */ static notarizeEntry(activity: Activity, transaction?: ProviderTransaction): Promise; /** * Leg1 completion: increment +100B to mark Leg1 complete. * For cycle=true activities, also pre-seeds the Leg2 entry counter (+1) * so the first real Leg2 gets adjacentIndex=1 (new dimension). * MUST be bundled in the same transaction as Leg1 durable work. */ static notarizeLeg1Completion(activity: Activity, transaction?: ProviderTransaction): Promise; /** * Leg1 early exit: marks Leg1 complete for activities that * only run Leg1 and fully close (e.g., Cycle). * Increment +100B (Leg1 completion marker). */ static notarizeEarlyExit(activity: Activity, transaction?: ProviderTransaction): Promise; /** * Leg1 early completion: marks Leg1 complete for Leg1-only * activities that spawn children (e.g., Signal, Hook passthrough, * Interrupt-another). Increment +100B. */ static notarizeEarlyCompletion(activity: Activity, transaction?: ProviderTransaction): Promise; /** * Leg2 entry: atomically increments the activity ledger (+1) and * seeds the GUID ledger with the ordinal IF NOT EXISTS. * Returns [activityLedger, guidLedger] after the compound operation. */ static notarizeLeg2Entry(activity: Activity, guid: string, transaction?: ProviderTransaction): Promise<[number, number]>; /** * Step 1: Mark Leg2 work done (+10B on GUID ledger only). * MUST be bundled with Leg2 durable work writes. */ static notarizeStep1(activity: Activity, guid: string, transaction: ProviderTransaction): Promise; /** * Step 2: Mark children spawned (+1B on GUID ledger only). * The job semaphore update and GUID job-closed snapshot are handled * by the compound `setStatusAndCollateGuid` primitive, which MUST * be called in the same transaction. */ static notarizeStep2(activity: Activity, guid: string, transaction: ProviderTransaction): Promise; /** * Step 3: Mark job completion tasks done (+100M on GUID ledger only). * MUST be bundled with job completion durable writes. */ static notarizeStep3(activity: Activity, guid: string, transaction: ProviderTransaction): Promise; /** * Finalize: close the activity to new Leg2 GUIDs (+200T). * Sets pos 1 to 2 (finalized). * Only for non-cycle activities after final SUCCESS/ERROR. */ static notarizeFinalize(activity: Activity, transaction: ProviderTransaction): Promise; /** * Check if Step 1 (work done) is complete on the GUID ledger. * Position 5 (10B digit) > 0. */ static isGuidStep1Done(guidLedger: number): boolean; /** * Check if Step 2 (children spawned) is complete on the GUID ledger. * Position 6 (1B digit) > 0. */ static isGuidStep2Done(guidLedger: number): boolean; /** * Check if Step 3 (job completion tasks) is complete on the GUID ledger. * Position 7 (100M digit) > 0. */ static isGuidStep3Done(guidLedger: number): boolean; /** * Check if this GUID was responsible for closing the job. * Position 4 (100B digit) > 0 (job closed snapshot). */ static isGuidJobClosed(guidLedger: number): boolean; /** * Get the attempt count from the GUID ledger (last 8 digits). */ static getGuidAttemptCount(guidLedger: number): number; /** * Gets the digit at a 1-indexed position from a 15-digit ledger value. * The value is left-padded to 15 digits before extraction. */ static getDigitAtPosition(num: number, position: number): number; /** * @deprecated Use getDigitAtPosition (1-indexed) instead */ static getDigitAtIndex(num: number, targetDigitIndex: number): number | null; /** * Extracts the dimensional index from the Leg2 entry counter. * Non-cycle activities: first Leg2 → leg2Count=1 → 1-1=0 (same dimension as Leg1). * Cycle activities: first Leg2 → leg2Count=2 (pre-seeded +1) → 2-1=1 (new dimension). */ static getDimensionalIndex(num: number): number | null; /** * Verifies the GUID ledger value for step-level resume decisions. * The GUID ledger is seeded with an ordinal position (last 8 digits) * on first entry; step markers drive all resume/reject logic. * * Fully processed: Step 3 done, or Steps 1+2 done without job closure. * Crash recovery: Any incomplete step combination is allowed for resume. */ static verifySyntheticInteger(amount: number): void; /** * Verifies the activity ledger value at entry boundaries. * * Leg1 enter: pos 3 (1T digit) must be > 0 after +1T (proves seed exists). * pos 4 (100B) must be 0 (Leg1 not yet complete). * If pos 3 > 1 and pos 4 == 1, it's a stale/replayed message. * * Leg2 enter: pos 4 (100B) must be > 0 (Leg1 complete, reentry authorized). * pos 1 (100T) must be < 2 (not finalized) — cycle activities exempt. */ static verifyInteger(amount: number, leg: ActivityDuplex, stage: CollationStage): void; static getDimensionsById(ancestors: string[], dad: string): Record; /** * All trigger activities are assigned a status seed in a completed state. * Seed: 101100000000001 (authorized, 1 Leg1 entry, Leg1 complete, 1 Leg2 entry) */ static getTriggerSeed(): string; /** * entry point for compiler-type activities. This is called by the compiler * to bind the sorted activity IDs to the trigger activity. These are then used * at runtime by the activities to track job/activity status. * @param graphs */ static compile(graphs: HotMeshGraph[]): void; /** * binds the ancestor array to each activity. * Used in conjunction with the dimensional * address (dad). If dad is `,0,1,0,0` and the * ancestor array is `['t1', 'a1', 'a2']` for * activity 'a3', then the SAVED DAD * will always have the trailing * 0's removed. This ensures that the addressing * remains consistent even if the graph changes. * id DAD SAVED DAD * * t1 => ,0 => [empty] * * a1 => ,0,1 => ,0,1 * * a2 => ,0,1,0 => ,0,1 * * a3 => ,0,1,0,0 => ,0,1 * */ static bindAncestorArray(graphs: HotMeshGraph[]): void; /** * All activities exist on a dimensional plane. Zero * is the default. A value of * `AxY,0,0,0,0,1,0,0` would reflect that * an ancestor activity was dimensionalized beyond * the default. */ static getDimensionalSeed(index?: number): string; } export { CollatorService };