Java library for reading, writing, signing, and verifying Open Prompt Archive (OPA) files.
OPA is a ZIP-based archive format for packaging AI prompts with their associated data, session history, and metadata. It follows JAR conventions for both manifest and digital signature formats.
Zero external dependencies — requires only Java 11+.
- Create, read, inspect, and extract OPA archives
- Digital signing and verification (RSA, DSA, EC) using JAR/PKCS#7 conventions
- Multi-turn session history with rich content blocks (text, images, tool use)
- Data asset management with directory support
- CLI tool for all operations
- Stream and file-based I/O
<dependency>
<groupId>ca.weblite</groupId>
<artifactId>opa-core</artifactId>
<version>0.1.0-SNAPSHOT</version>
</dependency>OpaManifest manifest = new OpaManifest();
manifest.setTitle("My Prompt");
manifest.setDescription("Summarise a document");
manifest.setExecutionMode(ExecutionMode.INTERACTIVE);
OpaWriter writer = new OpaWriter();
writer.setManifest(manifest);
writer.setPrompt("You are a helpful assistant. Summarise the document in data/doc.txt.");
writer.addDataFile("data/doc.txt", "Contents of the document...");
writer.writeTo(new File("my-prompt.opa"));OpaArchive archive = OpaReader.read(new File("my-prompt.opa"));
System.out.println(archive.getManifest().getTitle());
System.out.println(archive.getPrompt());
for (String path : archive.getDataEntryPaths()) {
byte[] data = archive.getEntry(path);
// ...
}// Sign
PrivateKey key = ...;
Certificate[] chain = ...;
OpaSigner signer = new OpaSigner(key, chain);
signer.sign(new File("unsigned.opa"), new File("signed.opa"));
// Verify
OpaVerifier verifier = new OpaVerifier();
verifier.addTrustedCertificate(chain[0]);
OpaVerifier.Result result = verifier.verify(new File("signed.opa"));
if (result.isSigned() && result.isValid() && result.isTrusted()) {
// archive is authentic and from a trusted signer
}SessionHistory history = new SessionHistory("session-001");
history.addMessage(new Message(MessageRole.USER, "Summarise this document"));
history.addMessage(new Message(MessageRole.ASSISTANT, "Here is a summary..."));
OpaWriter writer = new OpaWriter();
writer.setManifest(manifest);
writer.setPrompt("You are a helpful assistant.");
writer.setSessionHistory(history);
writer.writeTo(new File("with-session.opa"));Build the project, then run via java -cp target/classes ca.weblite.opa.OpaCli (or java -jar target/opa-core-0.1.0-SNAPSHOT.jar).
opa create \
--prompt prompt.md \
--title "My Prompt" \
--description "Does something useful" \
--mode interactive \
--data-dir ./data \
--output my-prompt.opaOptions:
-p, --prompt <file>— prompt file--prompt-text <text>— inline prompt text-o, --output <file>— output path-t, --title <title>— archive title-d, --description <desc>— description--mode <mode>—interactive,batch, orautonomous--agent-hint <hint>— e.g.claude-sonnet--session <file>— session history JSON--data-dir <dir>— add directory as data assets--data-file <spec>— add a data file (pathorarchivePath=localPath)
opa sign my-prompt.opa --key private.pem --cert certificate.pemopa verify my-prompt.opa --cert trusted-cert.pemopa inspect my-prompt.opaopa extract my-prompt.opa --output ./extractedAn OPA file is a standard ZIP archive:
META-INF/
MANIFEST.MF # JAR-style manifest with OPA metadata
SIGNATURE.SF # (if signed) signature file with digests
SIGNATURE.RSA # (if signed) PKCS#7 SignedData block
prompt.md # main prompt content
data/ # data assets
INDEX.json # asset metadata
feed.xml # example data file
session/
history.json # conversation history
attachments/ # binary attachments referenced in messages
The manifest follows JAR format:
Manifest-Version: 1.0
OPA-Version: 0.1
Title: My Prompt
Description: Does something useful
Execution-Mode: interactive
Created-By: opa-java
The samples/ directory contains:
sample-key.pem/sample-cert.pem— test RSA keypair (not for production use)ai-feed-summary.opa— signed example that summarises a Hacker News feedpirate-news/— complete example with a pirate-themed news summarizerprompt.md— prompt that generates an HTML news digest in pirate speakdata/feed.xml— sample RSS feedgenerate-opa.sh— script to build, sign, and verify the archive
Run the pirate-news example:
cd samples/pirate-news
./generate-opa.sh# Compile
javac --release 11 -d target/classes src/main/java/ca/weblite/opa/*.java
# Or with Maven
mvn packageMIT