{
  "name": "Prism Plastics Order Review",
  "manifestVersion": 2,
  "purpose": "Instructions for personal Codex, Claude, and Grok agents. No model API is involved.",
  "mailAccess": {
    "assumption": "A bot can search whichever mailboxes its own permissions allow by timestamp range, then read threads, replies, and attachments to find new POs or resolve source questions.",
    "boundary": "This page and rulebook contain no email credentials, mailbox grants, or secret keys. Each bot supplies its own authorized mail access outside Prism.",
    "evidence": "Keep source mailbox, message ID or link, message time, selected revision, attachment name, and SHA-256 with the audit where available."
  },
  "database": {
    "provider": "Appwrite",
    "endpoint": "https://data.seljan-fishbowl.com/v1",
    "projectId": "6a0226240026284b66f1",
    "databaseId": "6a02265b0033afad3c2d",
    "rulebookCollectionId": "plastics-order-review-rulebook",
    "activeDocumentId": "active",
    "researchCollectionId": "plastics-order-review-research",
    "intakeCollectionId": "plastics-order-intake",
    "intakeApprovalCollectionId": "plastics-order-intake-approval"
  },
  "directAppwriteProtocol": {
    "documentPath": "/databases/{databaseId}/collections/{collectionId}/documents/{documentId}",
    "collectionPath": "/databases/{databaseId}/collections/{collectionId}/documents",
    "headers": ["X-Appwrite-Project: {projectId}", "X-Appwrite-Key: {your authorized server key} for server-side access; or use your signed-in Appwrite session"],
    "readRulebook": "GET active from rulebookCollectionId; parse active.contentJson for releaseId; GET that releaseId from rulebookCollectionId; hash the exact UTF-8 release.contentJson string with SHA-256 and compare with both documents' contentHash.",
    "writeResearch": "POST one new document per Draft ordered product to researchCollectionId. The data object must have plasticsOrderId, orderedProductId, sourceFileId (empty string for an approved inline email PO), analyzedOn (ISO time), analysisVersion, and result (a JSON string). Include result.rulebook with releaseId, version, and contentHash. Read back the document and verify result. Never overwrite an earlier analysis.",
    "publishRule": "POST an immutable release document to rulebookCollectionId, verify it by GET, then PATCH the active pointer only after checking its prior version and hash. Use the ruleChanges steps below."
  },
  "start": [
    "Use your own authorized Appwrite credential. Credentials are never present in this page or manifest.",
    "Read the rulebook active document. Parse its contentJson to get releaseId. Read that immutable release document.",
    "Verify SHA-256 of the release contentJson equals its contentHash and the active document contentHash. Parse the release contentJson and follow its agentInstructions, rules, and references.",
    "Before creating a Draft line, publish each source PO line to Order Review Intake. An absent exact internal part number is needs-review until existing order lines, customer part numbers, known mappings, and similar products have been checked. Offer a new-product proposal only for confirmed-missing lines with complete evidence.",
    "When the PO number differs but an existing product is confirmed, publish a matched intake result with the selected productId. Preserve the PDF number in order-entry evidence. For C3, use a source productMappings entry tied to that intake hash and PDF SHA-256; preflight verifies it before Draft entry.",
    "A product proposal needs an Intake approval tied to its exact content hash. Scheduled personal bots may poll approved proposals, rerun live matching and a product dry run, then create and verify the product before resuming order entry. Never create merely because a flag changed.",
    "Classify the source, using a published source policy when one applies. Read the current Draft order, its attached source PDF or approved inline email, released products, quote evidence, and live roto schedule directly from Appwrite. Search mail by timestamp with your own authorized mail tool when source evidence or a newer revision is needed.",
    "Run consistency, then pricing, then estimating. A known difference passes consistency only when a published rule matches every required field. Save its warning flag and exact PO/Prism values.",
    "Run applicable customer follow-up checks separately. A pending C3 stock note does not erase completed analysis. Store follow-up status in research; store the final production instruction in the live ordered-product note after authorized stock feedback and verify its read-back.",
    "Resolve any acknowledgement policy for the order from the active rulebook. No matching rule means an acknowledgement is required. A not-required rule means no outbound acknowledgement; show n/a without changing the stored acknowledged boolean. Keep this order-level action separate from line analysis and stock-note follow-up.",
    "Append research to plastics-order-review-research. Record rulebook releaseId and contentHash in result.rulebook. Do not edit ordered products or release lines during analysis."
  ],
  "ruleChanges": [
    "A bot reads and verifies the active release, copies its JSON payload, makes a narrowly scoped change, and advances the version. Keep the old release unchanged.",
    "Test the new rule against a matching order and at least one nonmatching order. Check that intake matching, gate order, and existing rules still behave as intended.",
    "Create a release document with ID release-<version with punctuation replaced by hyphens>, kind release, version, contentHash as SHA-256 of compact JSON contentJson, createdBy, and createdOn.",
    "Read back and verify the new release. Re-read active to check it has not changed; then update the active document to point at the new release. Read back and verify active.",
    "Reanalyze affected Draft orders. Each research snapshot keeps the rulebook version it used."
  ],
  "rulebookDocumentFields": ["kind", "version", "contentHash", "contentJson", "createdBy", "createdOn"],
  "researchResultFields": ["rulebook", "consistency", "pricing", "estimating", "followUps", "observations"],
  "security": "The rulebook collection is readable by signed-in Prism users. Only server-key or separately authorized bot credentials may publish rules."
}
