jac-has-fields

Declares typed fields on Jac archetypes with defaults, postinit, properties, and access tags.

Updated Jul 26, 2026
One-click install
npx skills add https://github.com/PMN123/trapdoor --skill jac-has-fields-pmn123
Or copy as Structured Prompt for Agent
Please help me install this Agent Skill.
Skill: jac-has-fields
Source: https://github.com/PMN123/trapdoor/tree/main/.agents/skills/jac-has-fields
Command: npx skills add https://github.com/PMN123/trapdoor --skill jac-has-fields-pmn123

SYSTEM DOCUMENTATION & REQUIREMENTS

What problem does it solve? Writing stateful types in Jac requires knowing the exact has field syntax, and small mistakes like ordering defaulted fields before required ones or adding dynamic attributes cause cryptic compiler errors or runtime crashes. This Skill provides the verified rules and patterns for declaring typed fields on any Jac archetype so code passes jac check on the first attempt. ## Core Features & Use Cases - Field Declaration Rules: Covers required-before-default ordering, multi-field has forms, static class-level fields, and typed lists and optional references. - Computed Fields and Properties: Documents the postinit pattern for derived values and getter/setter accessor blocks backed by private storage fields. - Pitfall Prevention: Catalogs real compiler errors (E2004, E0080, E1005, E0067) and runtime traps like the dataclass inheritance default crash and reserved-word field names. - Use Case: When defining a node or obj in a Jac program, load this Skill to declare its fields correctly, including computed properties and encapsulation via has:pub, has:protect, and has:priv access tags. ## Quick Start Ask the AI to define a Jac object with typed fields, a computed postinit property, and validated setter using the jac-has-fields rules.

Frequently Asked Questions about jac-has-fields

High-intent search queries and answers about installing and using this skill.

FAQPage Schema
How do I declare typed fields on a Jac object?

Use the `has` keyword inside any Jac archetype: `has name: str;` for required fields and `has age: int = 0;` for defaults. All non-default fields must be declared before any defaulted field, and instances are built with kwargs since the constructor is auto-generated.

How do I create a computed field in Jac?

Declare the field with the `postinit` modifier, which excludes it from the constructor, then assign it in a `def postinit` block that runs after the auto-generated init. For example, `has area: float postinit;` computed from width and height.

Why does Jac fail with non-default argument follows default argument?

This happens when a parent archetype has a defaulted field and the subclass adds a required field, violating the dataclass constraint. It passes `jac check` but crashes at runtime, so give every subclass field a default when any inherited field has one.

Can Jac fields use Python reserved words like class?

No, Python reserved words cannot name fields even when backtick-escaped, because the generated Python needs a real identifier and `jac check` fails with E0067. Use a non-reserved name like `kind` or `cls` instead.

What is the difference between a Jac field and a property?

A `has` with an accessor block is a property that never allocates storage, while a plain `has` is a stored field. Combining a default value with an accessor block is rejected with E0080, so back properties with a separate underscore-prefixed field.