Skip to content

The open alternative to Salesforce, designed for AI.

93.6 KB
Raw Blame
import { msg } from '@lingui/core/macro';

import { type FlatSkill } from 'src/engine/metadata-modules/flat-skill/types/flat-skill.type';
import { type AllStandardSkillName } from 'src/engine/workspace-manager/twenty-standard-application/types/all-standard-skill-name.type';
import { i18nLabel } from 'src/engine/workspace-manager/twenty-standard-application/utils/i18n-label.util';
import {
  type CreateStandardSkillArgs,
  createStandardSkillFlatMetadata,
} from 'src/engine/workspace-manager/twenty-standard-application/utils/skill-metadata/create-standard-skill-flat-metadata.util';

export const STANDARD_FLAT_SKILL_METADATA_BUILDERS_BY_SKILL_NAME = {
  'workflow-building': (args: Omit<CreateStandardSkillArgs, 'context'>) =>
    createStandardSkillFlatMetadata({
      ...args,
      context: {
        skillName: 'workflow-building',
        name: 'workflow-building',
        label: i18nLabel(
          msg({ message: `Workflow Building`, context: 'skill.label' }),
        ),
        description: i18nLabel(
          msg({
            message: `Use when the user wants something to happen automatically: creating, changing, debugging or deleting a workflow, or phrasing a rule as when X happens do Y`,
            context: 'skill.description',
          }),
        ),
        icon: 'IconSettingsAutomation',
        content: `# Workflow Building Skill

You help users create and manage automation workflows.

## Capabilities

- Create workflows from scratch
- Modify existing workflows (add, remove, update steps)
- Delete workflows entirely (with their versions, runs and triggers) - IMPORTANT : Always confirm with the user before deleting
- Explain workflow structure and suggest improvements
- Troubleshoot workflow runs (inspect status, failed steps, and execution logs)

## Key Concepts

- **Triggers**: DATABASE_EVENT, MANUAL, CRON, WEBHOOK
- **Steps**: CREATE_RECORD, SEND_EMAIL, CODE, LOGIC_FUNCTION, PICK_RECORD, CLASSIFY, etc.
- **Data flow**: Use {{stepId.fieldName}} to reference previous step outputs
- **Relationships**: Use nested objects like {"company": {"id": "{{reference}}"}}

## CRON Trigger Settings Schema

For CRON triggers, settings.type must be one of these exact values:

1. **DAYS** - Daily schedule
   - Requires: schedule: { day: number (1+), hour: number (0-23), minute: number (0-59) }
   - Example: { type: "DAYS", schedule: { day: 1, hour: 9, minute: 0 }, outputSchema: {} }

2. **HOURS** - Hourly schedule (USE THIS FOR "EVERY HOUR")
   - Requires: schedule: { hour: number (1+), minute: number (0-59) }
   - Example: { type: "HOURS", schedule: { hour: 1, minute: 0 }, outputSchema: {} }
   - This runs every X hours at Y minutes past the hour

3. **MINUTES** - Minute-based schedule
   - Requires: schedule: { minute: number (1+) }
   - Example: { type: "MINUTES", schedule: { minute: 15 }, outputSchema: {} }

4. **CUSTOM** - Custom cron pattern
   - Requires: pattern: string (cron expression)
   - Example: { type: "CUSTOM", pattern: "0 * * * *", outputSchema: {} }

## CODE Steps

Create the step using \`create_workflow_version_step\` (stepType: "CODE") or \`create_complete_workflow\`. This returns a step with a \`logicFunctionId\` in settings.input — the step starts with a default function, not the user's desired code.

## LOGIC_FUNCTION Steps

LOGIC_FUNCTION steps execute logic functions provided by installed applications. To add one:

1. Call \`list_logic_function_tools\` to discover available logic function tools with their IDs.
2. Use \`create_workflow_version_step\` with stepType "LOGIC_FUNCTION" and pass the logicFunctionId in defaultSettings:
   { "stepType": "LOGIC_FUNCTION", "coreWorkflowVersionId": "<core-version-id>", "defaultSettings": { "input": { "logicFunctionId": "<logic-function-id>" } } }
3. Or when using \`create_complete_workflow\`, include a step with type "LOGIC_FUNCTION" and settings.input.logicFunctionId.

## Listing Workflows

To discover existing workflows in the workspace, use \`list_workflows\`. Use this before modifying a workflow when the user refers to it by name rather than id — resolve the \`coreWorkflowId\` here first, then call \`get_workflow_current_version\` with it.

## Deleting Workflows

To delete a workflow entirely, use \`delete_workflow\` with its \`coreWorkflowId\`. This also removes the workflow's versions, runs and automated triggers, and deactivates any active version — it is a destructive, irreversible operation.

- If the user refers to the workflow by name, resolve its \`coreWorkflowId\` with \`list_workflows\` first.
- IMPORTANT : Always confirm with the user before deleting, and make sure you are deleting the correct workflow.
- To simply stop a workflow from running without removing it, prefer \`deactivate_workflow_version\` instead of deleting.

## Troubleshooting Workflow Runs

When a user reports a failing or misbehaving workflow, diagnose it with two read-only tools:

- \`list_workflow_runs\`: lists runs (optional \`coreWorkflowId\`, optional \`status\`, optional \`limit\`), most recent first. Each result carries the run \`id\`, \`name\`, \`status\`, run-level \`error\`, \`startedAt\`, \`endedAt\`, \`coreWorkflowId\`, and \`coreWorkflowVersionId\`.
- \`get_workflow_run\`: returns full details for one run (\`workflowRunId\`) — overall status, run-level error, every step's status/error, and the execution logs of the steps that failed.

### Resolving the run when no id is given

For requests like "fix my latest failed workflow" where no run or workflow id is provided, call \`list_workflow_runs\` with \`status\` "FAILED" and NO \`coreWorkflowId\` — this returns the most recent failed run across all workflows, and each result already carries \`coreWorkflowId\`, \`coreWorkflowVersionId\`, and a human-readable \`name\`, so you never need an id from the user. If the user names a specific workflow, resolve its \`coreWorkflowId\` first and pass it as a filter.

### Flow

1. Identify the run via \`list_workflow_runs\` (use \`limit\` 5 when no \`coreWorkflowId\` so you can detect multiple failing workflows).
2. If results span multiple \`coreWorkflowId\`s, disambiguate by name with the user before editing anything.
3. Call \`get_workflow_run\` on the chosen run id to read the failed step(s) and their error/logs.
4. Map back to the workflow definition via \`get_workflow_current_version(coreWorkflowId)\`, then propose or apply a fix.
## PICK_RECORD Steps

PICK_RECORD selects one record from a candidate pool (settings.input.recordIds) and outputs it for later steps to reference — useful for assignment workflows like picking an owner. Set settings.input.strategy to RANDOM, ROUND_ROBIN, or LOAD_BALANCED; LOAD_BALANCED also needs settings.input.loadBalance.{objectNameSingular, fieldName} to pick the candidate with the fewest related records.

## CLASSIFY Steps

CLASSIFY asks an AI model one or more typed questions about a single piece of text and returns a typed answer for each, so later steps can branch on the result. Reach for it when the user describes sorting, routing, triaging, tagging or rating something written — "route support emails to the right team", "flag angry replies", "rate how urgent this is". Prefer it over a CODE step for those: it needs no code and no logic function.

settings.input takes:
- **state** — the text every question is asked about. Usually a variable, e.g. "{{trigger.properties.after.bodyV2.markdown}}".
- **questions** — an array. Each needs id (a UUID), name, type, instructions and criteria.
- **modelId** — optional. Omit it to use the workspace's classification model, which is almost always what you want.

Per question:
- **name** is the answer key, NOT a label. Downstream steps read {{<classify-step-id>.answers.<name>}}, so it must be 1 to 64 characters of letters, digits, underscores and dashes — no spaces, no dots. Two questions in one step cannot share a name.
- **instructions** is the question itself, and must not be empty.
- **type** is one of:
  - **choice** — picks one option. criteria are the options, at least one, each with a UUID id and a name. Option names must be unique and must not contain a dot, because each one keys a probability. Read the answer with {{<id>.answers.<name>.choice}}.
  - **score** — grades an ordered rubric. criteria are the levels, lowest first, at least two. Read it with {{<id>.answers.<name>.score}}, a number from 0 to the number of levels minus one.
  - **boolean** — estimates the probability that a statement holds. criteria are unused, so leave the array empty. Read it with {{<id>.answers.<name>.probability}}, from 0 to 1. Only an evaluation model can answer this one, so a workspace with none configured will fail the run — prefer a two-option choice question unless the user needs a probability.

A step created with create_workflow_version_step arrives with one empty choice question, so fill in state, the question's instructions and its options before validating.

## Critical Notes

Always rely on tool schema definitions:
- The workflow creation tool provides comprehensive schemas with examples
- Follow schema definitions exactly for field names, types, and structures
- Schema includes validation rules and common patterns

## Validation Strategy

Build steps fully configured up front so the workflow is correct on the first try. Malformed content (a bare string in a rich text field, a step targeting an object that does not exist, a broken graph) is rejected at write time: the mutation tool fails with the error and nothing is saved, so fix the payload and retry.

Do NOT call \`validate_workflow\` after every change. Call it exactly ONCE at the end, before activating: it runs the exact check activation runs and, when the version is not ready, fails with the list of issues (code, message, stepId). Fix them and call it again until it succeeds, then activate.


## Approach

- Ask clarifying questions to understand user needs
- List logic function tools. Present relevant ones to the user as options before defaulting to CODE steps.
- Suggest appropriate actions for the use case
- Explain each step and why it's needed
- For modifications, understand current structure first
- Ensure workflow logic remains coherent

Prioritize user understanding and workflow effectiveness.`,
        isSystem: true,
      },
    }),

  'data-manipulation': (args: Omit<CreateStandardSkillArgs, 'context'>) =>
    createStandardSkillFlatMetadata({
      ...args,
      context: {
        skillName: 'data-manipulation',
        name: 'data-manipulation',
        label: i18nLabel(
          msg({ message: `Data Manipulation`, context: 'skill.label' }),
        ),
        description: i18nLabel(
          msg({
            message: `Use when finding, filtering, creating, updating or importing records, and whenever a request needs sorting or touches more than a handful of rows`,
            context: 'skill.description',
          }),
        ),
        icon: 'IconDatabase',
        content: `# Data Manipulation Skill

You explore and manage data across companies, people, opportunities, tasks, notes, and custom objects.

## Capabilities

- Search, filter, sort, create, update records
- Manage relationships between records
- Bulk operations and data analysis

## Constraints

- READ and WRITE access to all objects
- CANNOT delete records or access workflow objects
- CANNOT modify workspace settings

## Multi-step Approach

- Chain queries to solve complex requests (e.g., find companies → get their opportunities → calculate totals)
- If a query fails or returns no results, try alternative filters or approaches
- Validate data exists before referencing it (search before update)
- Use results from one query to inform the next
- Try 2-3 different approaches before giving up

## Sorting (Critical)

For "top N" queries, use orderBy with limit:
- Examples: orderBy: [{"employees": "DescNullsLast"}], orderBy: [{"createdAt": "AscNullsFirst"}]
- Valid directions: "AscNullsFirst", "AscNullsLast", "DescNullsFirst", "DescNullsLast"

## Before Bulk Operations

- Confirm the scope and impact
- Explain what will change

## Bulk Import

You import bulk data (CSV, Excel, spreadsheets, pasted tables) into records as cheaply and reliably as possible.

### Golden Rule: one code_interpreter run, not many tool calls

For anything beyond a handful of rows (>~50), do the ENTIRE import inside a SINGLE \`code_interpreter\` execution. Do NOT loop \`execute_tool\` from chat: every chat tool call re-sends the whole conversation as new input tokens, so dozens of small writes explode cost. Inside the sandbox the loop runs server-side and the agent only sees one small summary.

This means: read the file, parse it, inspect schemas, resolve IDs, write all records, and print the summary — all inside one \`code_interpreter\` call. Not two. Not five. One.

The sandbox exposes a pre-bound \`twenty\` object (see the code-interpreter skill). Use its bulk helpers instead of hand-rolling loops.

### Pre-flight: inspect schemas at the LLM level before entering the sandbox

**Before your first \`code_interpreter\` call**, use \`learn_tools\` at the LLM level (not inside the sandbox) to fetch the input schemas for every object you will create or update. For example, if importing companies, people, and opportunities:

\`\`\`
learn_tools(["create_one_company", "create_one_person", "create_one_opportunity"])
\`\`\`

This is free — it runs before the sandbox and does not add a code_interpreter round-trip. You will know the exact field names before writing any code. Do NOT call \`twenty.call_tool('learn_tools', ...)\` from inside the sandbox to learn schemas — that wastes a full sandbox round-trip per schema and pollutes the conversation context.

### Recipe

1. **Read the file robustly** with pandas (\`/home/user/{filename}\`). Real-world files have messy delimiters and ragged rows, so don't rely on defaults:
   \`\`\`python
   # Auto-detect the separator and skip malformed rows instead of crashing.
   df = pd.read_csv(path, sep=None, engine='python', on_bad_lines='skip', dtype=str)
   \`\`\`
   Read and parse the file in the same code cell — never split file reading across multiple \`code_interpreter\` calls.
   Inspect columns and a few rows once with \`df.head()\` — never re-dump the full frame.
2. **Use schemas learned at step 0.** You already know the field names from the pre-flight \`learn_tools\` call. Do not call \`twenty.call_tool('learn_tools', ...)\` inside the sandbox unless you genuinely missed a schema. If you do need it, call it once and cache the result in a Python variable.
3. **Resolve relations to IDs.** Relations link by ID, not by name. Build a lookup map ONCE for only the values referenced in the file:
   \`\`\`python
   company_ids = twenty.lookup_by('companies', 'name', df['company'].dropna().unique().tolist())
   \`\`\`
   Then set each row's relation via the scalar foreign key — NOT a nested object:
   \`\`\`python
   record['companyId'] = company_ids.get(row['company'])  # correct
   # record['company'] = {'id': ...}   # WRONG: rejected with
   #   'Relation "company" requires connect or disconnect operation'
   \`\`\`
   To-one relations are written by their \`<relation>Id\` scalar (e.g. \`companyId\`), or an explicit \`{'connect': {'id': ...}}\`. A bare nested \`{'id': ...}\` is rejected. Never read the whole related table.
4. **Resolve just-created IDs with a bounded \`lookup_by\` — never paginate the table.** \`bulk_upsert\` returns only a count summary (created / updated / failed), not the records, so to link subsequent records (e.g. people to the companies you just upserted) resolve the IDs you need with a \`lookup_by\` bounded to your own values:
   \`\`\`python
   # After upserting companies, resolve by name using lookup_by (bounded to your values, not the whole table)
   company_ids = twenty.lookup_by('companies', 'name', [r['name'] for r in company_records])
   # Then use company_ids to set companyId on person records
   \`\`\`
   Never paginate through hundreds of existing records with \`find_many_*\` to find the ones you just created.
5. **Confirm the mapping before writing.** Present the proposed column → field mapping to the user (source column → target field, relation strategy such as "Company matched by name → companyId", and any type coercions) and wait for them to confirm or adjust. Do not write anything before this confirmation.
6. **Silently validate the mapping with a 2-row upsert.** Inside the same \`code_interpreter\` run, upsert just the first 2 rows as an internal correctness check. This is NOT a user-facing step: do not announce or narrate it. Only surface it if it FAILS — then report the error and the offending mapping so it can be fixed before the full import.
7. **Write the remaining rows with bulk_upsert.** Write \`records[2:]\`, never the full list again: objects without a unique field (opportunities, tasks, notes, most custom objects) cannot dedupe, so the 2 check rows would be created twice. Prefer upsert so dedup on unique fields (e.g. email) is handled server-side and re-runs are idempotent:
   \`\`\`python
   summary = twenty.bulk_upsert('people', records[2:])
   print(summary)  # { 'created': 4000, 'updated': 380, 'upserted': 4380, 'failed': 0, 'errors': [] }
   \`\`\`
   \`bulk_upsert\` batches at 200 (the platform maximum) and paginates to completion. Never stop at "partial" — if some batches failed, report the count and retry the failed offsets.
8. **Report a compact summary only** — the \`created\` / \`updated\` / \`failed\` split plus a few sample errors. Add the 2 check rows' \`created\` / \`updated\` counts so the totals cover every row. Never echo the created records back into the conversation.

### Anti-patterns — never do these

- **Reading a file across multiple sandbox calls.** Do \`print(content[:3000])\` then \`print(content[3000:])\` in separate calls? That is two wasted round-trips. Read once, parse once, in the same cell.
- **Calling \`twenty.call_tool('learn_tools', ...)\` inside the sandbox** to discover field names. Inspect schemas at the LLM level with \`learn_tools\` before entering the sandbox. Guessing a field name and fixing the failure (e.g. \`annualRecurringRevenue\` → 10 failed writes → re-fetch schema) costs one failed batch plus a round-trip.
- **Re-fetching records you just created** to build an ID map. Use \`lookup_by\` bounded to the values you need, not \`find_many_*\` with pagination through the whole table.
- **Looping \`find_many_*\` one record at a time** inside the sandbox to resolve IDs (N+1 pattern). Use \`lookup_by\` instead — it batches the query server-side.
- **Multiple \`code_interpreter\` calls for a single import.** Each extra call is a full sandbox round-trip that adds latency, costs tokens, and accumulates output in the conversation context. Everything from file reading to final summary belongs in one call.

### Key constraints

- Relations are linked by ID only via the scalar \`<relation>Id\` (e.g. \`companyId\`); there is no name-based relation mapping and a nested \`{'id': ...}\` is rejected. Resolve IDs with \`lookup_by\` first.
- Deduplicate via upsert on unique fields rather than pre-reading existing records. \`bulk_upsert\` already reports how many rows were \`created\` vs \`updated\`, so you do NOT need to scan the whole object first to detect duplicates — just upsert and read back the split.
- If a write fails with 'no permission to write field "X" on "Y"', that field is restricted for the current role. Drop that single field and continue importing the rest instead of retrying the same failing write.
- If the user says "import for me", do it programmatically with this recipe — do not just describe the in-app CSV UI.

### Keep each thread to one objective

Every tool round-trip re-sends the ENTIRE conversation (system prompt, loaded skills, and all prior tool inputs/outputs) as new input tokens, so a long thread makes every later step progressively more expensive. When the user finishes an import and moves on to a distinct objective (e.g. field configuration, segmentation, dashboards, or a second unrelated import), suggest starting a NEW thread for it rather than continuing in the same one, which resets the context and keeps cost low. Keep a single import (inspect, confirm, validate, write, report) within one thread.

Prioritize data integrity and provide clear feedback on operations performed.`,
        isSystem: true,
      },
    }),

  'workspace-demo-seeding': (args: Omit<CreateStandardSkillArgs, 'context'>) =>
    createStandardSkillFlatMetadata({
      ...args,
      context: {
        skillName: 'workspace-demo-seeding',
        name: 'workspace-demo-seeding',
        label: i18nLabel(
          msg({ message: `Workspace Demo Seeding`, context: 'skill.label' }),
        ),
        description: i18nLabel(
          msg({
            message: `Use only when explicitly asked to fill a workspace with demonstration data for a given industry`,
            context: 'skill.description',
          }),
        ),
        icon: 'IconDatabase',
        content: `# Workspace Demo Seeding Skill
You will transform the existing standard workspace into a fully custom demo tailored to the user's business type.

The goal is to tell a coherent and realistic story with the data: custom fields added to standard objects, new custom objects for domain-specific entities, rich relations, seeded and updated records, views, and enrichment data (emails, calendar events, tasks, notes, files) that make the workspace feel like a real company in operation.

## Object strategy

**Keep the standard objects — People, Companies, and Opportunities — and reuse their existing seed data.** They already have emails and calendar events linked to them as participants. The demo story is built on top of them, not instead of them.

- **People** → map to the domain's "contact" role (e.g. clients, candidates, customers, agents)
- **Companies** → map to the domain's "organisation" role (e.g. suppliers, agencies, employers)
- **Opportunities** → map to the domain's "deal/pipeline" role (e.g. job applications, deals, repair estimates)

**Add 2 to 3 additional custom objects** for domain-specific entities that don't map to People/Companies/Opportunities (e.g. Properties, Cars, Products, Projects). Keep the custom object count low — the standard objects carry most of the story.

**Add custom fields** to People, Companies, and Opportunities to enrich them with domain-specific data (e.g. add "specialisation", "licenseNumber" to People; add "industry vertical", "tier" to Companies; add "stage", "closeDate" to Opportunities).

Create rich relation fields between standard and custom objects to show off the relational capabilities of the platform.

If you have to create multiple things you *MUST* use the relevant create many tool if it exists:
- Use *create_many_object_metadata* to create all custom objects at once
- Use *create_many_field_metadata* to create all non-relation fields at once (including new fields on standard objects)
- Use *create_many_relation_fields* to create all relation fields between objects at once (do this AFTER creating the objects and non-relation fields)

For the fields you will create, make sure to create a good variety of field types to showcase the different capabilities of the platform, for example:
- Create SELECT and SELECT_MULTIPLE field types for building demo board index views and table with groups views
- Create DATE_TIME fields to be able to create calendar views
- Create CURRENCY and NUMERIC fields for graphs

*Here are the steps to follow closely:*

STEP 0: Present a plan to the user and wait for approval.
- Use get_object_metadata to see all available objects in the workspace
- Use find_many_people (limit: 5) and find_many_companies (limit: 5) and find_many_opportunities (limit: 5) to understand the existing seed data shape
- Based on the user's business type, propose a plan that lists:
  - How People, Companies, and Opportunities map to the domain story (e.g. "People = Candidates", "Companies = Employers")
  - The 2–3 custom objects you will create, each with a one-line description of their role
  - The custom fields you will add to People, Companies, and Opportunities
  - A brief description of the key relations between objects
- Present this plan to the user and *wait for their confirmation or adjustments* before proceeding
- Once approved, archive every existing custom object without asking for further confirmation: call get_object_metadata, keep the objects where isCustom is true, then set isActive to false on all of them in a single update_many_object_metadata call

STEP 1: Create all the custom objects at once with create_many_object_metadata
name must start with lowercase letter and contain only alphanumeric letters

STEP 2: Create all NON-RELATION fields for ALL objects by batch with create_many_field_metadata.
Do a separate batch call for each object.
This includes:
- New custom fields for the standard objects (Person, Company, Opportunity) — use their objectMetadataId from get_object_metadata
- All non-relation fields for the new custom objects
DO NOT include relation fields in this step. Only create TEXT, NUMBER, BOOLEAN, DATE_TIME, SELECT, MULTI_SELECT, CURRENCY, etc.
SELECT option values must be UPPER_SNAKE_CASE

STEP 3: Create all RELATION fields between objects at once with create_many_relation_fields
The name property should be camel-cased or the backend will throw, targetFieldLabel must be a string, targetFieldIcon must be a string, type must be one of the following values: MANY_TO_ONE, ONE_TO_MANY
targetFieldIcon is like IconSomething, it's ok if it doesn't exist in the icon library, it will just be a blank icon, but it needs to be a string that starts with Icon and is in PascalCase

STEP 4: Rename and enrich the first N records of People, Companies, and Opportunities.
- Use find_many_people (limit: 50, orderBy: [{ position: "AscNullsFirst" }]), find_many_companies (limit: 50, orderBy: [{ position: "AscNullsFirst" }]), find_many_opportunities (limit: 50, orderBy: [{ position: "AscNullsFirst" }]) to get the IDs of the first records in each table
  - Ordering by position ascending gives the earliest-inserted records, which are contiguous in the table — this keeps the demo data tightly grouped and makes the workspace feel coherent
- For each standard object, call update_one_person / update_one_company / update_one_opportunity **individually per record** (one call per record) to set domain-relevant names and field values:
  - **People**: replace nameFirstName + nameLastName with realistic names that fit the domain role (e.g. for a law firm: "Sophie Martin", "James O'Brien"; for a clinic: "Dr. Clara Reyes", "Marco Bianchi"). Also set jobTitle to a domain-appropriate title.
  - **Companies**: replace name with realistic company names that fit the domain (e.g. for a law firm: "Ashford & Partners", "Nexus Legal Group"; for a clinic: "Meridian Health Clinic", "CarePoint Medical").
  - **Opportunities**: replace name with a domain-relevant deal name (e.g. "Q2 retainer — Ashford & Partners", "New patient intake — Meridian Health").
  - Also set the new custom fields on each record: spread realistic values across SELECT fields, set plausible CURRENCY/NUMERIC amounts, set DATE_TIME fields around TODAY.
- Do this one record at a time — the API does not support bulk individual updates with different values per record

STEP 5: Add view fields to the default views of standard objects to expose the new custom fields.
For each of People, Companies, and Opportunities:
- Use create_many_view_fields to add all the new custom fields to the default view so they are visible
  - Use decimal positions between 0 and 1 to insert them right after the label identifier field

STEP 6: For each new custom object, repeat ALL of the following sub-steps before moving to the next object:
- Create the view fields for the default view, use the create_many_view_fields tool, and make sure to include all created fields, including the relation fields, so that we have a complete view of the object with all its fields.
  BE CAREFUL to use a position that will put those view fields right after the first label identifier field
  which has a position of 0 and the next system created fields which begin at 1, *so use decimal positions between 0 and 1*
  *YOU MUST CREATE ALL VIEW FIELDS FOR ALL FIELDS, INCLUDING RELATION FIELDS, IN THIS STEP, DO NOT LEAVE ANY FIELD WITHOUT A VIEW FIELD, OTHERWISE IT WILL NOT BE VISIBLE IN THE DEFAULT VIEW AND THE USER WON'T KNOW IT EXISTS*

- Seed relevant and realistic mock data for this object:
  - use the relevant tool to create many records for this object
  - between 20 and 50
  - with a coherent combination of values
  - link records to existing People and Companies using the relation fields you created
  - use dates that are around TODAY so it's relevant for seeing past / future and present records

- Then create 2 to 3 additional views for this object, one at a time. For each view, complete ALL of the following sub-steps before creating the next view:
  - Create the view using the create_view tool:
    - If the object has a SELECT field (e.g. status, stage, priority, type), create a **KANBAN** view grouped by that SELECT field with a relevant name like "By Status", "Pipeline", "By Priority".
      - Set kanbanAggregateOperation to COUNT so each column shows the number of records.
      - If there is a CURRENCY or NUMERIC field, also set kanbanAggregateOperationFieldName to that field for a SUM aggregate view.
    - If the object has a DATE or DATE_TIME field (e.g. dueDate, closedAt, scheduledAt), create a **CALENDAR** view and pass both \`calendarFieldName\` (that field name) and \`calendarLayout\` ("DAY", "WEEK", or "MONTH") with a relevant name like "Calendar", "Schedule", "Timeline".
    - Create a **TABLE** view with a meaningful group (mainGroupByFieldName set to a SELECT field) with a name like "By Type", "By Stage", "Grouped", or similar.
  - Use create_many_view_fields to add all relevant field columns to this view (using decimal positions between 0 and 1)
  - Add filters and sorts to this view:
    - **KANBAN views**: Sort by a CURRENCY or NUMERIC field DESC (biggest value first) if one exists, or by createdAt DESC. Add a filter to exclude archived/cancelled records if such a SELECT option exists.
    - **CALENDAR views**: Sort by the date field ASC (earliest events first). Add a filter using IS_IN_FUTURE or IS_RELATIVE to show only upcoming records by default.
    - **TABLE with groups**: Sort by createdAt DESC (most recent first) and add a filter on a meaningful field (e.g. status IS_NOT "CANCELLED", or amount GREATER_THAN_OR_EQUAL to some threshold that keeps ~80% of the records visible).

Also create additional views for the standard objects (People, Companies, Opportunities) that showcase the new custom fields:
- For People: a KANBAN view grouped by the new SELECT field you added (e.g. "By Specialisation", "By Status")
- For Opportunities: a KANBAN view grouped by the new stage/status field (pipeline view)
- For Companies: a TABLE view grouped by the new SELECT field

Share links to the configured objects and views so the user can open them when ready.

Loop STEP 6 for all the custom objects
`,
        isSystem: true,
      },
    }),

  'dashboard-building': (args: Omit<CreateStandardSkillArgs, 'context'>) =>
    createStandardSkillFlatMetadata({
      ...args,
      context: {
        skillName: 'dashboard-building',
        name: 'dashboard-building',
        label: i18nLabel(
          msg({ message: `Dashboard Building`, context: 'skill.label' }),
        ),
        description: i18nLabel(
          msg({
            message: `Use when the user asks for a dashboard, a chart, a metric tile or a report page, or wants to change one that exists`,
            context: 'skill.description',
          }),
        ),
        icon: 'IconLayoutDashboard',
        content: `# Dashboard Building Skill

You help users create and manage dashboards with widgets.

## Tools

- list_dashboards, get_dashboard
- create_complete_dashboard
- add_dashboard_tab, add_dashboard_widget, update_dashboard_widget, delete_dashboard_widget
- get_object_metadata / get_field_metadata (resolve object + field IDs)

## Confirmation gate (ALWAYS ask before creating or updating)

Before calling ANY tool that creates or modifies a dashboard (\`create_complete_dashboard\`, \`add_dashboard_tab\`, \`add_dashboard_widget\`, \`update_dashboard_widget\`, \`delete_dashboard_widget\`), you MUST first present a short plan and get explicit user confirmation.

- Resolve metadata first (read-only tools like get_object_metadata / get_field_metadata / get_dashboard are allowed before confirmation), then summarize what you intend to build or change: the widgets/charts, the fields they group by and aggregate, the layout, and any assumptions or defaults you are making.
- Ask the user to confirm (or adjust) and then STOP and wait for their answer. Do NOT call any creation/update tool in the same turn as the plan.
- Only after the user confirms do you proceed to build/modify in the next turn.
- Keep the plan concise — a few bullets, not an essay. The goal is a quick "yes, go ahead" or a correction, not a lengthy back-and-forth.

## Build Workflow (creating a new dashboard, AFTER confirmation)

Once the user has confirmed the plan, your job is to deliver the dashboard in that turn.

1. Resolve metadata in as few calls as possible: call get_object_metadata and get_field_metadata for the relevant object(s) once, and batch field lookups. Do NOT re-fetch metadata you already have in context.
2. Build the full widget configuration using the rules below.
3. **Emit \`create_complete_dashboard\` with ALL widgets in a single call.** Prefer one-shot \`create_complete_dashboard\` over building the dashboard incrementally with multiple \`add_dashboard_widget\` calls — fewer round-trips means lower cost and fewer points to stall.
4. After the tool returns success, confirm to the user what was built (and restate any assumptions you made).

### Completion guard (critical, applies once confirmed)

- After the user has confirmed, you MUST call the appropriate dashboard tool for the requested change in that turn (e.g. \`create_complete_dashboard\`, \`add_dashboard_widget\`, \`update_dashboard_widget\`, or \`delete_dashboard_widget\`). **Never end your turn on a "now let me…" / "I'll build this…" preamble without actually calling the tool.** A preamble with no following tool call (after confirmation) is a failure.
- Do NOT yield or hand back to the user until at least one dashboard tool has returned success — unless you are still waiting on confirmation or genuinely blocked on something only the user can answer.

### Default-and-proceed (resolve defaults in the plan, do not stall)

- If the request references a field or concept that does not exist in the workspace (e.g. "Lead Source", a "Won/Lost" stage, a "conversion" status), do NOT turn it into an open-ended question. Choose a sensible default — group by the closest existing categorical field, or plan to create the missing field/select option — and surface that default as an assumption in the confirmation plan.
- Reserve extra clarifying questions for genuinely ambiguous requests where no reasonable default exists. Otherwise, propose something useful in the plan and let the user confirm or refine.

## Modifying an existing dashboard

- Call get_dashboard first to read the current layout, then present the intended changes and get confirmation (see the confirmation gate above) before calling add_dashboard_widget / update_dashboard_widget / delete_dashboard_widget. Use activeTabId from context if available.
- Only call get_dashboard when modifying — never before creating a brand-new dashboard.

## Field Resolution Rules

- All *MetadataId fields must be real UUIDs from metadata.
- Match by name or label, but write UUIDs into all *MetadataId fields.
- Subfield names use FIELD NAMES, not labels.
- Composite group-by requires a subfield (e.g. address → "addressCity").
- **CRITICAL: Relation fields (RELATION, MORPH_RELATION) MUST always include a subFieldName** (e.g. "name", "email", "stage"). Without a subFieldName, the chart groups by raw UUIDs which produces unreadable charts. Always pick a meaningful scalar field from the target object.

## Subfield Syntax

- Composite: \`address\` + \`addressCity\` → subFieldName "addressCity"
- Relation to scalar field: \`company.name\` → subFieldName "name" (only when target "name" is a simple TEXT/NUMBER field)
- Relation to composite field: \`owner.name\` where "name" is FULL_NAME → subFieldName must be "name.firstName" or "name.lastName" (NOT just "name")
- Relation + composite: \`company.address.addressCity\` → subFieldName "address.addressCity"
- **Never omit subFieldName for relation fields** — grouping by ID is almost never useful
- **IMPORTANT**: Check the target field's type from get_field_metadata. If it is composite (FULL_NAME, ADDRESS, CURRENCY, EMAILS, PHONES, LINKS), you MUST drill into a specific subfield using dot notation (e.g. "name.firstName", "address.addressCity", "emails.primaryEmail").

## User Language Notes

- "X axis" / "categories" → primaryAxisGroupByFieldMetadataId
- "Y axis" / "metric" → aggregateFieldMetadataId + aggregateOperation
- "Group by" / "stacking" / "colors" → secondaryAxisGroupByFieldMetadataId
- "Unstacked" / "remove group by" → clear secondaryAxisGroupByFieldMetadataId only
- "KPI" / "just a number" → AGGREGATE_CHART
- "Legend" → displayLegend
- "Data labels" → displayDataLabel
- "Hide empty values" → omitNullValues
- "Min range" / "Max range" → rangeMin / rangeMax
- "Running total" → isCumulative

## Graph Configuration Rules

- Use the tool schema as the source of truth for required/optional fields.
- Supported graph configurationType values: AGGREGATE_CHART, BAR_CHART, LINE_CHART, PIE_CHART.
- BAR_CHART and LINE_CHART use primaryAxisGroupByFieldMetadataId.
- PIE_CHART uses groupByFieldMetadataId (not primaryAxisGroupByFieldMetadataId).
- If any orderBy is MANUAL, include the matching manual sort array.
- If rangeMin and rangeMax are both set, rangeMin must be <= rangeMax.
- Set date granularity only when grouping by date fields.
- "stacked bars" means secondaryAxisGroupByFieldMetadataId + groupMode STACKED.
- "stacked lines" means isStacked true.

## Non-graph Widgets

- IFRAME: configurationType "IFRAME" + url
- STANDALONE_RICH_TEXT: configurationType "STANDALONE_RICH_TEXT" + body with markdown content
  - IMPORTANT: Put the actual text content in configuration.body.markdown, NOT in the widget title
  - Widget title should be a short label (e.g. "Notes", "Summary"), body.markdown holds the real content
- RECORD_TABLE: configurationType "RECORD_TABLE" — displays a filterable, sortable record list
  - **MANDATORY: create the dedicated view in ONE call before creating the widget**:
    - Call \`upsert_complete_view\` once with the view plus its fields, filters, and sorts. Do NOT use the separate create_view / create_many_view_fields / create_many_view_filters / create_view_sort calls — that is several round-trips where one suffices.
    - Reference fields by NAME (fieldName) — you generally do not need field UUIDs. Pass fieldMetadataId only if you already have it.
    - Include 4–6 of the most relevant fields (label identifier + key SELECT/DATE/CURRENCY fields). Order in the array IS the column order.
    - Add filters/sorts to focus the table (e.g. filter out DONE/CANCELLED records, sort by a date field).
  - Never reuse a record index view — widget views and record index views must be separate
  - Leave the view's visibility as WORKSPACE (the default) — never set UNLISTED on a widget-backing view, or the widget will render a blank table
  - Set objectMetadataId on the widget (top-level, required)
  - Set configuration.viewId to the UUID returned by upsert_complete_view (required)
  - columnSpan 12 (full width) or 6 (half width), rowSpan 6–10

Example (STANDALONE_RICH_TEXT):
{
  "configurationType": "STANDALONE_RICH_TEXT",
  "body": { "markdown": "## Quarterly Summary\\n\\nKey metrics:\\n- Revenue up 15%\\n- 42 new deals closed\\n\\n**Next steps**: Focus on enterprise pipeline." }
}

Example (RECORD_TABLE — one view call, then the widget):
Step 1 — upsert_complete_view: {
  "name": "Active Repairs",
  "objectNameSingular": "repair",
  "type": "TABLE",
  "fields": [{ "fieldName": "name" }, { "fieldName": "status" }, { "fieldName": "amount" }],
  "filters": [{ "fieldName": "status", "operand": "IS_NOT", "value": ["DONE"] }],
  "sorts": [{ "fieldName": "createdAt", "direction": "DESC" }]
} → { "success": true, "message": "...", "result": { "id": "<view-uuid>", ... } }
Step 2 — add_dashboard_widget: { "type": "RECORD_TABLE", "objectMetadataId": "<repair-object-uuid>", "configuration": { "configurationType": "RECORD_TABLE", "viewId": "<view-uuid>" }, "position": { "layoutMode": "GRID", "row": 0, "column": 0, "rowSpan": 8, "columnSpan": 12 } }

## Tabs

Use add_dashboard_tab to create multiple tabs in a dashboard. Each tab has its own set of widgets.
Good tab structure: one overview tab (KPIs + charts) + one or more detail tabs (RECORD_TABLE + focused charts).
After creating a tab, use its returned tabId as pageLayoutTabId when calling add_dashboard_widget.

## Grid System

- 12 columns (0-11)
- KPI widgets: rowSpan 2-4, columnSpan 3-4
- Charts: rowSpan 6-8, columnSpan 6-12
- Record tables: rowSpan 6-10, columnSpan 6-12 (full-width preferred)
- Common layouts: 4 KPIs in a row (columnSpan 3), 2 charts side by side (columnSpan 6), full width chart or table (columnSpan 12)

## Best Practices

- Place KPIs at the top (row 0)
- Group related charts together
- Use consistent heights within rows
- Start simple, add complexity as needed
- When modifying a chart, confirm whether the user wants to change settings or change chart type
- Use RECORD_TABLE widgets to give users direct access to filtered record lists without leaving the dashboard`,
        isSystem: true,
      },
    }),

  'metadata-building': (args: Omit<CreateStandardSkillArgs, 'context'>) =>
    createStandardSkillFlatMetadata({
      ...args,
      context: {
        skillName: 'metadata-building',
        name: 'metadata-building',
        label: i18nLabel(
          msg({ message: `Metadata Building`, context: 'skill.label' }),
        ),
        description: i18nLabel(
          msg({
            message: `Use when the data model itself changes: adding or editing objects, fields, relations or select options`,
            context: 'skill.description',
          }),
        ),
        icon: 'IconBuildingSkyscraper',
        content: `# Metadata Building Skill

You help users manage their workspace data model by creating, updating, and organizing custom objects and fields.

## Capabilities

- Create new custom objects with appropriate naming and configuration
- Add fields to existing objects (text, number, date, select, relation, etc.)
- Update object and field properties (labels, descriptions, icons)
- Manage field settings (required, unique, default values)
- Create relations between objects

## Key Concepts

- **Objects**: Represent entities in the data model (e.g., Company, Person, Opportunity)
- **Fields**: Properties of objects with specific types (TEXT, NUMBER, DATE_TIME, SELECT, RELATION, etc.)
- **Relations**: Links between objects (one-to-many, many-to-one)
- **Labels vs Names**: Labels are for display, names are internal identifiers (camelCase)

## Tool Output Format

- **get_object_metadata** returns its objects as an array under \`result.objects\`. System objects (attachment, message, etc.) are returned as compact \`{id, nameSingular, namePlural}\`, which is enough to locate an object and read its id. Only pass \`includeFullSystemObjects: true\` when you specifically need a system object's full configuration (e.g. when creating relations to workspaceMember).
- **get_field_metadata** returns its fields as an array under \`result.fields\`. System fields are returned as compact \`{id, name, type}\`, which is enough to know which fields exist and their types. Only pass \`includeFullSystemFields: true\` when you specifically need a system field's full configuration (settings, defaultValue, relation targets). Internal fields (searchVector, position, updatedBy) are always excluded. Null properties are omitted from non-system fields.
## Field Types Available

- **TEXT**: Simple text fields
- **NUMBER**: Numeric values (integers or decimals)
- **BOOLEAN**: True/false values
- **DATE_TIME**: Date and time values
- **DATE**: Date only values
- **SELECT**: Single choice from options
- **MULTI_SELECT**: Multiple choices from options
- **LINK**: URL fields
- **LINKS**: Multiple URL fields
- **EMAIL**: Email address fields
- **EMAILS**: Multiple email fields
- **PHONE**: Phone number fields
- **PHONES**: Multiple phone fields
- **CURRENCY**: Monetary values
- **RATING**: Star ratings
- **RELATION**: Links to other objects
- **RICH_TEXT**: Formatted rich text content

## Best Practices

- Use clear, descriptive names for objects and fields
- Follow naming conventions: singular for object names, camelCase for field names
- Add helpful descriptions to objects and fields
- Choose appropriate field types for the data being stored
- Consider relationships between objects when designing the data model

## Icons

- Always set the \`icon\` property when creating objects and fields — otherwise they render with a meaningless default icon
- Icons are Tabler icon names: PascalCase with an \`Icon\` prefix (e.g. \`IconBuildingSkyscraper\`, \`IconPaw\`, \`IconCurrencyDollar\`)
- Pick an icon matching the meaning: a Pets object → \`IconPaw\`, a budget field → \`IconCurrencyDollar\`, a deadline field → \`IconCalendarDue\`

## Approach

- Ask clarifying questions to understand the user's data modeling needs
- Suggest best practices for naming and organization
- Explain the impact of changes to the data model
- Verify object and field existence before making updates
- Provide clear feedback on operations performed

Prioritize data model integrity and user understanding.`,
        isSystem: true,
      },
    }),

  'code-interpreter': (args: Omit<CreateStandardSkillArgs, 'context'>) =>
    createStandardSkillFlatMetadata({
      ...args,
      context: {
        skillName: 'code-interpreter',
        name: 'code-interpreter',
        label: i18nLabel(
          msg({ message: `Code Interpreter`, context: 'skill.label' }),
        ),
        description: i18nLabel(
          msg({
            message: `Use for Python over data the record tools cannot express: statistics, chart images, parsing an uploaded file. Do not use it for ordinary record reads and writes`,
            context: 'skill.description',
          }),
        ),
        icon: 'IconCode',
        content: `# Code Interpreter Skill

You have access to the \`code_interpreter\` tool to execute Python code in a sandboxed environment.

## How to Use
Call the \`code_interpreter\` tool with your Python code. The tool will execute the code and return stdout, stderr, and any generated files.

## Capabilities
- Analyze CSV, Excel, and JSON data files
- Create charts and visualizations (matplotlib, seaborn)
- Generate reports (PDF, PPTX, Excel)
- Perform calculations and data transformations

## Pre-installed Libraries
pandas, numpy, matplotlib, seaborn, scikit-learn, openpyxl, python-pptx

## Input Files
- User-uploaded files are available at \`/home/user/{filename}\`
- Always check the file exists before processing

## Output Files
- Charts: Save to \`/home/user/output/\` directory - these are automatically returned as downloadable URLs
- For matplotlib: \`plt.savefig('/home/user/output/chart.png')\`
- Generated files: Save to \`/home/user/output/{filename}\`

## Example: Create a Bar Chart
\`\`\`python
import matplotlib.pyplot as plt
import os

# Data
months = ['Jan', 'Feb', 'Mar', 'Apr', 'May', 'Jun']
sales = [100, 150, 200, 175, 250, 300]

# Create chart
plt.figure(figsize=(10, 6))
plt.bar(months, sales, color='skyblue')
plt.title('Monthly Sales')
plt.xlabel('Month')
plt.ylabel('Sales')
plt.tight_layout()

# Save to output directory
os.makedirs('/home/user/output', exist_ok=True)
plt.savefig('/home/user/output/sales_chart.png')
print('Chart saved!')
\`\`\`

## Example: Analyze CSV
\`\`\`python
import pandas as pd
import matplotlib.pyplot as plt
import os

# Load data
df = pd.read_csv('/home/user/data.csv')
print(f"Loaded {len(df)} rows")

# Create visualization
plt.figure(figsize=(10, 6))
df.groupby('category')['value'].mean().plot(kind='bar')
plt.title('Average Value by Category')
plt.tight_layout()

os.makedirs('/home/user/output', exist_ok=True)
plt.savefig('/home/user/output/analysis.png')
print('Analysis complete!')
\`\`\`

## Calling Twenty Tools from Python (MCP Bridge)

**A \`twenty\` variable is already bound in your code's scope.** Do NOT write
\`import twenty\` — there is no Python package by that name. The helper is an
instance of a class that has been pre-instantiated for you; just call methods
on it directly.

Real catalog tools follow the pattern \`find_many_<object>\` / \`find_one_<object>\` /
\`create_one_<object>\` / \`create_many_<object>\` / \`update_one_<object>\` / \`update_many_<object>\` /
\`delete_one_<object>\` / \`delete_many_<object>\` / \`group_by_<object>\` —
e.g. \`find_many_companies\`, \`find_one_company\`, \`create_one_person\`.
Call \`twenty.list_tools()\` to discover exact names. Catalog tools are routed
through \`execute_tool\` automatically, and the helper raises an Exception on
server-side failures with the error message.

\`\`\`python
# List catalog tools (flat list, not grouped)
tools = twenty.list_tools()
print(f"{len(tools)} catalog tools available")
for tool in tools[:5]:
    print(f"- {tool['name']}")

# Find records — returns { 'records': [...], 'count': '5' }
companies = twenty.call_tool('find_many_companies', {'limit': 5, 'offset': 0})
for c in companies['records']:
    print(c['name'], c.get('employees'))

# Create a record — arguments match the tool's inputSchema directly,
# no nested 'data' wrapper.
result = twenty.call_tool('create_one_company', {
    'name': 'Acme Corp',
    'domainName': {'primaryLinkUrl': 'https://acme.com'},
    'position': 'first',
})
print(f"Created company id={result['id']}")

# Update a record
twenty.call_tool('update_one_person', {
    'id': 'person-uuid-here',
    'jobTitle': 'CEO',
})
\`\`\`

This lets you orchestrate multi-step data workflows in a single sandbox
execution — faster than an equivalent chain of individual tool calls from
the agent, and the computation stays server-side.

## Schema inspection: do it at the LLM level, not inside the sandbox

If you need to know a tool's input schema (e.g. field names for \`create_one_company\`), call \`learn_tools\` as an LLM-level tool call **before** entering the sandbox:

\`\`\`
learn_tools(["create_one_company", "create_one_person"])
\`\`\`

Do NOT call \`twenty.call_tool('learn_tools', ...)\` from inside the sandbox to learn schemas — that costs a full round-trip, adds output to the conversation context, and is unnecessary when you can inspect the schema for free before writing any code. Only use \`twenty.call_tool('learn_tools', ...)\` inside the sandbox if you discover at runtime that you need a schema you could not have anticipated beforehand.

## One sandbox run per task

Each \`code_interpreter\` call is a round-trip: it adds latency, accumulates output in the conversation, and increases cost. Design your code to complete the entire task in one call:
- Read and parse the input file in the same cell that processes it — never read in two parts.
- Do all schema inspection at the LLM level upfront (see above).
- Write all records and print the summary in the same run.

Multiple sandbox calls are acceptable only when the user asks a follow-up question that changes the task scope, or when a genuine runtime error forces a corrective retry.

### Bulk helpers (use these for imports)

For bulk writes, prefer these higher-level helpers over hand-rolled loops:

\`\`\`python
# Idempotent batched write (max 200/batch, paginates to completion).
# Dedupes on unique fields server-side; safe to re-run.
summary = twenty.bulk_upsert('people', records)  # { 'created': C, 'updated': U, 'upserted': N, 'failed': 0, 'errors': [] }

# Bounded { value: id } map for resolving relations to IDs, scoped to the
# values you pass (NOT the whole table). Link to-one relations via the scalar
# FK (e.g. record['companyId'] = company_ids[...]), never a nested {'id': ...}.
company_ids = twenty.lookup_by('companies', 'name', ['Acme', 'Globex'])
\`\`\`

For importing CSV/Excel/spreadsheet data, load the \`data-manipulation\` skill for the full recipe.`,
        isSystem: true,
      },
    }),

  xlsx: (args: Omit<CreateStandardSkillArgs, 'context'>) =>
    createStandardSkillFlatMetadata({
      ...args,
      context: {
        skillName: 'xlsx',
        name: 'xlsx',
        label: i18nLabel(
          msg({ message: `Excel & Spreadsheets`, context: 'skill.label' }),
        ),
        description: i18nLabel(
          msg({
            message: `Use whenever a spreadsheet is the input or the output, including formulas, formatting, charts and CSV conversion`,
            context: 'skill.description',
          }),
        ),
        icon: 'IconFileSpreadsheet',
        content: `# Excel Processing Skill

**IMPORTANT**: Save all output files to \`/home/user/output/\` for them to be downloadable.

## Pre-installed Scripts

- \`python /home/user/scripts/xlsx/recalc.py <excel_file> [timeout]\` - Recalculate formulas using LibreOffice

## Requirements

### Zero Formula Errors
Every Excel model MUST be delivered with ZERO formula errors (#REF!, #DIV/0!, #VALUE!, #N/A, #NAME?)

### Use Formulas, Not Hardcoded Values
**Always use Excel formulas instead of calculating values in Python and hardcoding them.**

\`\`\`python
# ❌ WRONG - Hardcoding
total = df['Sales'].sum()
sheet['B10'] = total

# ✅ CORRECT - Using formulas
sheet['B10'] = '=SUM(B2:B9)'
\`\`\`

## Reading and Analyzing Data

\`\`\`python
import pandas as pd

# Read Excel
df = pd.read_excel('file.xlsx')
all_sheets = pd.read_excel('file.xlsx', sheet_name=None)  # All sheets as dict

# Analyze
df.head()
df.info()
df.describe()
\`\`\`

## Creating New Excel Files

\`\`\`python
from openpyxl import Workbook
from openpyxl.styles import Font, PatternFill, Alignment

wb = Workbook()
sheet = wb.active

# Add data
sheet['A1'] = 'Hello'
sheet.append(['Row', 'of', 'data'])

# Add formula
sheet['B2'] = '=SUM(A1:A10)'

# Formatting
sheet['A1'].font = Font(bold=True)
sheet['A1'].fill = PatternFill('solid', start_color='FFFF00')
sheet['A1'].alignment = Alignment(horizontal='center')

# Column width
sheet.column_dimensions['A'].width = 20

wb.save('/home/user/output/output.xlsx')
\`\`\`

## Editing Existing Files

\`\`\`python
from openpyxl import load_workbook

wb = load_workbook('existing.xlsx')
sheet = wb.active

# Modify cells
sheet['A1'] = 'New Value'
sheet.insert_rows(2)

wb.save('/home/user/output/modified.xlsx')
\`\`\`

## Recalculating Formulas (MANDATORY)

After creating/editing files with formulas, run:
\`\`\`bash
python /home/user/scripts/xlsx/recalc.py /home/user/output/output.xlsx
\`\`\`

The script returns JSON with error details:
\`\`\`json
{
  "status": "success",
  "total_errors": 0,
  "total_formulas": 42,
  "error_summary": {}
}
\`\`\`

If errors found, fix them and recalculate again.

## Financial Model Color Coding

- **Blue text**: Hardcoded inputs
- **Black text**: Formulas and calculations
- **Green text**: Links from other worksheets
- **Yellow background**: Key assumptions needing attention

## Number Formatting

- Years: Format as text ("2024" not "2,024")
- Currency: Use $#,##0 format
- Percentages: 0.0% format
- Negatives: Use parentheses (123) not minus -123

## Quick Reference

| Task | Tool | Example |
|------|------|---------|
| Read Excel | pandas | \`pd.read_excel('file.xlsx')\` |
| Create Excel | openpyxl | \`Workbook()\` |
| Add formula | openpyxl | \`sheet['B2'] = '=SUM(A1:A10)'\` |
| Recalculate | script | \`python /home/user/scripts/xlsx/recalc.py file.xlsx\` |`,
        isSystem: true,
      },
    }),

  pdf: (args: Omit<CreateStandardSkillArgs, 'context'>) =>
    createStandardSkillFlatMetadata({
      ...args,
      context: {
        skillName: 'pdf',
        name: 'pdf',
        label: i18nLabel(
          msg({ message: `PDF Processing`, context: 'skill.label' }),
        ),
        description: i18nLabel(
          msg({
            message: `Use whenever a PDF is involved: reading text or tables, filling a form, creating, merging or splitting one`,
            context: 'skill.description',
          }),
        ),
        icon: 'IconFileTypePdf',
        content: `# PDF Processing Skill

**IMPORTANT**: Save all output files to \`/home/user/output/\` for them to be downloadable.

## Pre-installed Scripts

### Field Extraction
- \`python /home/user/scripts/pdf/extract_form_field_info.py <pdf_file>\` - Extract all fillable field names and types (JSON output)
- \`python /home/user/scripts/pdf/check_fillable_fields.py <pdf_file>\` - Check if PDF has fillable fields

### Form Filling
- \`python /home/user/scripts/pdf/fill_fillable_fields.py <pdf_file> <json_data> <output_file>\` - Fill PDF form fields
- \`python /home/user/scripts/pdf/fill_pdf_form_with_annotations.py <pdf_file> <json_data> <output_file>\` - Fill with annotation support

### Validation
- \`python /home/user/scripts/pdf/create_validation_image.py <pdf_file>\` - Create validation image of filled PDF
- \`python /home/user/scripts/pdf/check_bounding_boxes.py <pdf_file>\` - Check field boundaries
- \`python /home/user/scripts/pdf/convert_pdf_to_images.py <pdf_file>\` - Convert PDF pages to images

## Reading PDFs

\`\`\`python
import fitz  # PyMuPDF

# Open PDF
doc = fitz.open('document.pdf')

# Extract text from all pages
for page in doc:
    text = page.get_text()
    print(text)

# Extract text from specific page
page = doc[0]  # First page
text = page.get_text()
\`\`\`

## Extracting Tables

\`\`\`python
import pdfplumber

with pdfplumber.open('document.pdf') as pdf:
    for page in pdf.pages:
        tables = page.extract_tables()
        for table in tables:
            for row in table:
                print(row)
\`\`\`

## Filling PDF Forms

### Step 1: Extract field information
\`\`\`bash
python /home/user/scripts/pdf/extract_form_field_info.py form.pdf > fields.json
\`\`\`

### Step 2: Create fill data JSON
\`\`\`json
{
  "field_name_1": "value1",
  "field_name_2": "value2",
  "checkbox_field": true
}
\`\`\`

### Step 3: Fill the form
\`\`\`bash
python /home/user/scripts/pdf/fill_fillable_fields.py form.pdf fill_data.json /home/user/output/output.pdf
\`\`\`

### Step 4: Validate the output
\`\`\`bash
python /home/user/scripts/pdf/create_validation_image.py /home/user/output/output.pdf
\`\`\`

## Creating PDFs

\`\`\`python
from reportlab.lib.pagesizes import letter
from reportlab.pdfgen import canvas

c = canvas.Canvas('/home/user/output/output.pdf', pagesize=letter)
c.drawString(100, 750, 'Hello World!')
c.save()
\`\`\`

## Merging PDFs

\`\`\`python
from PyPDF2 import PdfMerger

merger = PdfMerger()
merger.append('file1.pdf')
merger.append('file2.pdf')
merger.write('/home/user/output/merged.pdf')
merger.close()
\`\`\`

## Splitting PDFs

\`\`\`python
from PyPDF2 import PdfReader, PdfWriter

reader = PdfReader('document.pdf')

# Extract specific pages
writer = PdfWriter()
writer.add_page(reader.pages[0])  # First page
writer.write('/home/user/output/page1.pdf')
\`\`\`

## Quick Reference

| Task | Tool | Command/Example |
|------|------|-----------------|
| Extract text | PyMuPDF | \`page.get_text()\` |
| Extract tables | pdfplumber | \`page.extract_tables()\` |
| List form fields | script | \`python extract_form_field_info.py form.pdf\` |
| Fill form | script | \`python fill_fillable_fields.py form.pdf data.json out.pdf\` |
| Validate fill | script | \`python create_validation_image.py filled.pdf\` |
| Create PDF | reportlab | \`canvas.Canvas('out.pdf')\` |
| Merge PDFs | PyPDF2 | \`PdfMerger()\` |`,
        isSystem: true,
      },
    }),

  docx: (args: Omit<CreateStandardSkillArgs, 'context'>) =>
    createStandardSkillFlatMetadata({
      ...args,
      context: {
        skillName: 'docx',
        name: 'docx',
        label: i18nLabel(
          msg({ message: `Word Documents`, context: 'skill.label' }),
        ),
        description: i18nLabel(
          msg({
            message: `Use whenever a Word document is the input or the output, including templates, styles and tracked changes`,
            context: 'skill.description',
          }),
        ),
        icon: 'IconFileTypeDocx',
        content: `# Word Document Processing Skill

**IMPORTANT**: Save all output files to \`/home/user/output/\` for them to be downloadable.

## Pre-installed Scripts (OOXML Editing)

- \`python /home/user/scripts/docx/unpack.py <docx_file> <output_dir>\` - Unpack .docx to XML files for direct editing
- \`python /home/user/scripts/docx/pack.py <input_dir> <docx_file>\` - Repack XML files into .docx
- \`python /home/user/scripts/docx/validate.py <docx_file>\` - Validate document structure

### Validation Scripts
- \`/home/user/scripts/docx/validation/docx.py\` - DOCX validation module
- \`/home/user/scripts/docx/validation/redlining.py\` - Track changes/redline validation

## High-Level API (python-docx)

### Reading Documents

\`\`\`python
from docx import Document

doc = Document('document.docx')

# Read paragraphs
for para in doc.paragraphs:
    print(para.text)

# Read tables
for table in doc.tables:
    for row in table.rows:
        for cell in row.cells:
            print(cell.text)
\`\`\`

### Creating Documents

\`\`\`python
from docx import Document
from docx.shared import Inches, Pt
from docx.enum.text import WD_ALIGN_PARAGRAPH

doc = Document()

# Add heading
doc.add_heading('Document Title', 0)

# Add paragraph with formatting
para = doc.add_paragraph('Normal text. ')
run = para.add_run('Bold text.')
run.bold = True

# Add table
table = doc.add_table(rows=2, cols=2)
table.cell(0, 0).text = 'Header 1'
table.cell(0, 1).text = 'Header 2'

# Add image
doc.add_picture('image.png', width=Inches(4))

doc.save('/home/user/output/output.docx')
\`\`\`

## Low-Level OOXML Editing

For complex edits (tracked changes, custom XML), use the unpack/edit/pack workflow:

### Step 1: Unpack
\`\`\`bash
python /home/user/scripts/docx/unpack.py document.docx ./unpacked/
\`\`\`

### Step 2: Edit XML directly
\`\`\`python
import xml.etree.ElementTree as ET

tree = ET.parse('./unpacked/word/document.xml')
root = tree.getroot()

# Edit XML...
# Namespaces: w = http://schemas.openxmlformats.org/wordprocessingml/2006/main

tree.write('./unpacked/word/document.xml', xml_declaration=True, encoding='UTF-8')
\`\`\`

### Step 3: Validate & Repack
\`\`\`bash
python /home/user/scripts/docx/validate.py ./unpacked/
python /home/user/scripts/docx/pack.py ./unpacked/ /home/user/output/output.docx
\`\`\`

## Template Processing

### Find and Replace
\`\`\`python
from docx import Document

doc = Document('template.docx')

for para in doc.paragraphs:
    if '{{name}}' in para.text:
        para.text = para.text.replace('{{name}}', 'John Doe')

doc.save('/home/user/output/filled.docx')
\`\`\`

### Preserve Formatting During Replace
\`\`\`python
def replace_in_paragraph(para, old_text, new_text):
    """Replace text while preserving formatting"""
    for run in para.runs:
        if old_text in run.text:
            run.text = run.text.replace(old_text, new_text)

for para in doc.paragraphs:
    replace_in_paragraph(para, '{{name}}', 'John Doe')
\`\`\`

## Working with Styles

\`\`\`python
from docx.shared import Pt, RGBColor

# Set font
run.font.name = 'Arial'
run.font.size = Pt(12)
run.font.color.rgb = RGBColor(0, 0, 0)

# Paragraph formatting
para.alignment = WD_ALIGN_PARAGRAPH.CENTER
para.paragraph_format.space_before = Pt(12)
para.paragraph_format.space_after = Pt(12)
\`\`\`

## Quick Reference

| Task | Tool | Example |
|------|------|---------|
| Read document | python-docx | \`Document('file.docx')\` |
| Create document | python-docx | \`Document()\` |
| Add heading | python-docx | \`doc.add_heading('Title', 0)\` |
| Add table | python-docx | \`doc.add_table(rows=2, cols=2)\` |
| Unpack for editing | script | \`python unpack.py doc.docx ./out/\` |
| Repack | script | \`python pack.py ./out/ doc.docx\` |
| Validate | script | \`python validate.py doc.docx\` |`,
        isSystem: true,
      },
    }),

  'view-building': (args: Omit<CreateStandardSkillArgs, 'context'>) =>
    createStandardSkillFlatMetadata({
      ...args,
      context: {
        skillName: 'view-building',
        name: 'view-building',
        label: i18nLabel(
          msg({ message: `View Building`, context: 'skill.label' }),
        ),
        description: i18nLabel(
          msg({
            message: `Use when creating or changing a view of any type, table, kanban or calendar, including the columns, filters, sorts and grouping on it`,
            context: 'skill.description',
          }),
        ),
        icon: 'IconLayoutBoard',
        content: `# View Building Skill

You help users create and configure views, and the filters and sorts that decide which records those views show.

## View Types

- **TABLE**: Standard table/grid view. Works for any object. Default view type.
- **KANBAN**: Board view grouped by a SELECT field. Best for pipeline/status-based workflows.
- **CALENDAR**: Calendar view using a DATE or DATE_TIME field. Best for time-based records.

## Tools

- **upsert_complete_view** - Create OR update a view together with its fields, filters, and sorts in a single call. PREFER THIS for building or reconfiguring a view — it replaces the need to chain create_view + create_many_view_fields + create_many_view_filters + create_view_sort.
- get_views - List existing views (filter by object name)
- create_view - Create a new view (low-level; prefer upsert_complete_view)
- update_view - Update view name/icon (low-level; prefer upsert_complete_view)
- delete_view - Delete a view
- create_many_view_fields - Add visible columns to a view (low-level; prefer upsert_complete_view)
- update_many_view_fields - Update column configuration
- get_view_fields - List columns in a view
- get_object_metadata / get_field_metadata - Discover objects and their fields

## upsert_complete_view (preferred)

One call builds or reconfigures an entire view:
- Omit \`id\` to CREATE (requires \`objectNameSingular\`); provide \`id\` to UPDATE an existing view.
- Reference fields by NAME (\`fieldName\`) in fields/filters/sorts — they are resolved server-side, so you usually do NOT need get_field_metadata first. You may pass \`fieldMetadataId\` instead when you already have the UUID.
- \`fields\`, \`filters\`, and \`sorts\` are DECLARATIVE: a provided array REPLACES all existing entries of that kind, \`[]\` clears them, and omitting the key leaves them untouched. So to edit a view you just pass the desired end state — no need to fetch child ids.
- KANBAN requires \`mainGroupByFieldName\` (a SELECT field); CALENDAR requires \`calendarFieldName\` + \`calendarLayout\`.

Example: { "objectNameSingular": "opportunity", "type": "KANBAN", "name": "Pipeline", "mainGroupByFieldName": "stage", "kanbanAggregateOperation": "SUM", "kanbanAggregateOperationFieldName": "amount", "fields": [{ "fieldName": "name" }, { "fieldName": "amount" }, { "fieldName": "stage" }], "sorts": [{ "fieldName": "amount", "direction": "DESC" }] }

## Workflow

1. **Identify the target object**: If the user didn't specify which object, ask them. Present available objects and explain what each holds:
   - **Company**: Business accounts (name, domain, employees, revenue, address)
   - **Person**: Contacts (name, email, phone, job title, company)
   - **Opportunity**: Pipeline deals (name, stage, amount, close date, company, contact)
   - **Task**: Action items (title, status, due date, assignee)
   - **Note**: Free-form notes (title, body)
   - Plus any custom objects in the workspace

2. **Choose the view type**: Suggest the best type based on the object's data:
   - TABLE: Good default for any object, great for browsing large datasets
   - KANBAN: Ideal when objects have a SELECT field representing stages/statuses (e.g., Opportunity → stage, Task → status)
   - CALENDAR: Ideal when objects have DATE/DATE_TIME fields (e.g., Opportunity → closeDate, Task → dueAt)

3. **Create the view AND its columns/filters/sorts in one call**: Use \`upsert_complete_view\` with the view config plus the \`fields\` (and optionally \`filters\`/\`sorts\`) arrays. Reference fields by name.
   - For KANBAN: mainGroupByFieldName is required — ask user which SELECT field to group by, or suggest the most natural one.
   - For CALENDAR: provide both \`calendarFieldName\` (a DATE/DATE_TIME field name) and \`calendarLayout\` ("DAY", "WEEK", or "MONTH").
   - For TABLE: No special configuration needed beyond the fields list.

4. **Share the view**: Include a clickable view reference using the id returned by upsert_complete_view so the user can open it.

## KANBAN Best Practices

- The grouping field must be a SELECT type
- Common groupings: Opportunity by stage, Task by status
- Optionally set kanbanAggregateOperation (COUNT, SUM, AVG, MIN, MAX) and kanbanAggregateOperationFieldName for column summaries
- Example: Sum of amount per stage for Opportunity board

## CALENDAR Best Practices

- Requires a DATE or DATE_TIME field on the object
- Best for: Opportunity close dates, Task due dates, any event-based data

## TABLE with Groups

- TABLE views can also be grouped by a field using mainGroupByFieldName
- This creates collapsible sections in the table, organized by the grouping field values
- Works with SELECT fields for categorical grouping

## Filter Operators by Field Type

| Field Type | Available Operators |
|---|---|
| TEXT | CONTAINS, DOES_NOT_CONTAIN, IS, IS_NOT, IS_EMPTY, IS_NOT_EMPTY |
| EMAILS, FULL_NAME, ADDRESS, LINKS, PHONES | CONTAINS, DOES_NOT_CONTAIN, IS_EMPTY, IS_NOT_EMPTY |
| NUMBER, NUMERIC | IS, IS_NOT, GREATER_THAN_OR_EQUAL, LESS_THAN_OR_EQUAL, IS_EMPTY, IS_NOT_EMPTY |
| CURRENCY | GREATER_THAN_OR_EQUAL, LESS_THAN_OR_EQUAL, IS_EMPTY, IS_NOT_EMPTY |
| DATE, DATE_TIME | IS, IS_RELATIVE, IS_IN_PAST, IS_IN_FUTURE, IS_TODAY, IS_BEFORE, IS_AFTER, IS_EMPTY, IS_NOT_EMPTY |
| SELECT | IS, IS_NOT, IS_EMPTY, IS_NOT_EMPTY |
| MULTI_SELECT, ARRAY | CONTAINS, DOES_NOT_CONTAIN, IS_EMPTY, IS_NOT_EMPTY |
| RELATION | IS, IS_NOT, IS_EMPTY, IS_NOT_EMPTY |
| BOOLEAN | IS |

Using an operator the field type does not support will fail, so check the type first.

## Sorts and Filter Groups

- Directions are ASC (A to Z, oldest first) and DESC (Z to A, newest first).
- Filters combine with AND by default; OR and NOT are available, and groups nest for conditions like name CONTAINS "tech" AND (revenue above 1M OR employees above 100).
- \`upsert_complete_view\` replaces the whole filter or sort array, so pass the end state you want rather than editing entries one by one.

## Common Filter Patterns

- Overdue work: a DATE field IS_IN_PAST combined with status IS_NOT done
- Upcoming deadlines: a DATE field IS_IN_FUTURE
- Recent activity: updatedAt or createdAt IS_AFTER a date
- Open pipeline: stage IS_NOT the won and lost values
- Unassigned or orphaned records: a relation field IS_EMPTY
- High value: amount GREATER_THAN_OR_EQUAL a threshold

## Common Sort Patterns

- Pipeline boards sort by amount DESC, so the biggest deals read first
- Task lists sort by dueAt ASC, so the most urgent reads first
- Activity lists sort by updatedAt DESC

## Composite Fields

Some fields carry sub-fields you filter on directly:
- CURRENCY uses subFieldName "amountMicros" for the numeric value
- ADDRESS uses sub-fields such as "addressCity" and "addressCountry"
- FULL_NAME uses "firstName" and "lastName"
- EMAILS and LINKS filter on the primary entry

## Approach

- If the user is vague (e.g., "create a board"), ask which object they want to see
- Suggest the most relevant view type based on the object's fields
- After creating a view, configure useful view fields and share a clickable view reference
- Explain what each view type does so users can make informed choices`,
        isSystem: true,
      },
    }),

  pptx: (args: Omit<CreateStandardSkillArgs, 'context'>) =>
    createStandardSkillFlatMetadata({
      ...args,
      context: {
        skillName: 'pptx',
        name: 'pptx',
        label: i18nLabel(
          msg({ message: `PowerPoint`, context: 'skill.label' }),
        ),
        description: i18nLabel(
          msg({
            message: `Use whenever a PowerPoint deck is the input or the output, including slides, templates, tables and charts`,
            context: 'skill.description',
          }),
        ),
        icon: 'IconPresentation',
        content: `# PowerPoint Processing Skill

**IMPORTANT**: Save all output files to \`/home/user/output/\` for them to be downloadable.

## Pre-installed Scripts

- \`python /home/user/scripts/pptx/thumbnail.py <pptx_file> [output_dir]\` - Generate slide thumbnails
- \`python /home/user/scripts/pptx/rearrange.py <pptx_file> <slide_order_json> <output_file>\` - Reorder slides
- \`python /home/user/scripts/pptx/inventory.py <pptx_file>\` - List all slides and their content
- \`python /home/user/scripts/pptx/replace.py <pptx_file> <replacements_json> <output_file>\` - Find/replace text

## Reading Presentations

\`\`\`python
from pptx import Presentation

prs = Presentation('presentation.pptx')

# Iterate through slides
for slide in prs.slides:
    for shape in slide.shapes:
        if shape.has_text_frame:
            print(shape.text)
\`\`\`

## Creating Presentations

\`\`\`python
from pptx import Presentation
from pptx.util import Inches, Pt

prs = Presentation()

# Add title slide
slide_layout = prs.slide_layouts[0]  # Title layout
slide = prs.slides.add_slide(slide_layout)
title = slide.shapes.title
subtitle = slide.placeholders[1]

title.text = "Presentation Title"
subtitle.text = "Subtitle goes here"

# Add content slide
slide_layout = prs.slide_layouts[1]  # Title and content
slide = prs.slides.add_slide(slide_layout)
title = slide.shapes.title
body = slide.placeholders[1]

title.text = "Slide Title"
tf = body.text_frame
tf.text = "First bullet"
p = tf.add_paragraph()
p.text = "Second bullet"
p.level = 1

prs.save('/home/user/output/output.pptx')
\`\`\`

## Adding Images

\`\`\`python
from pptx.util import Inches

slide = prs.slides.add_slide(prs.slide_layouts[6])  # Blank layout
slide.shapes.add_picture(
    'image.png',
    left=Inches(1),
    top=Inches(1),
    width=Inches(5)
)
\`\`\`

## Adding Tables

\`\`\`python
from pptx.util import Inches

slide = prs.slides.add_slide(prs.slide_layouts[6])
table = slide.shapes.add_table(
    rows=3, cols=3,
    left=Inches(1), top=Inches(1),
    width=Inches(8), height=Inches(2)
).table

# Set cell values
table.cell(0, 0).text = "Header 1"
table.cell(0, 1).text = "Header 2"
table.cell(1, 0).text = "Data 1"
\`\`\`

## Adding Charts

\`\`\`python
from pptx.chart.data import CategoryChartData
from pptx.enum.chart import XL_CHART_TYPE
from pptx.util import Inches

chart_data = CategoryChartData()
chart_data.categories = ['East', 'West', 'Midwest']
chart_data.add_series('Series 1', (19.2, 21.4, 16.7))

slide = prs.slides.add_slide(prs.slide_layouts[6])
chart = slide.shapes.add_chart(
    XL_CHART_TYPE.COLUMN_CLUSTERED,
    Inches(1), Inches(1), Inches(8), Inches(5),
    chart_data
).chart
\`\`\`

## Using Scripts

### Generate Thumbnails
\`\`\`bash
python /home/user/scripts/pptx/thumbnail.py presentation.pptx ./thumbnails/
# Creates: thumbnails/slide_1.png, slide_2.png, etc.
\`\`\`

### Get Slide Inventory
\`\`\`bash
python /home/user/scripts/pptx/inventory.py presentation.pptx
# Returns JSON with all slide content and shapes
\`\`\`

### Reorder Slides
\`\`\`bash
# Order: [3, 1, 2] means slide 3 becomes first, slide 1 second, etc.
python /home/user/scripts/pptx/rearrange.py input.pptx '[3, 1, 2]' output.pptx
\`\`\`

### Find and Replace Text
\`\`\`bash
python /home/user/scripts/pptx/replace.py input.pptx '{"{{company}}": "Acme Corp", "{{date}}": "2024"}' output.pptx
\`\`\`

## Template Processing Workflow

1. **Generate thumbnails** to understand slide structure:
   \`\`\`bash
   python /home/user/scripts/pptx/thumbnail.py template.pptx ./preview/
   \`\`\`

2. **Get inventory** to find placeholder text:
   \`\`\`bash
   python /home/user/scripts/pptx/inventory.py template.pptx
   \`\`\`

3. **Replace placeholders**:
   \`\`\`bash
   python /home/user/scripts/pptx/replace.py template.pptx '{"{{title}}": "Q4 Report"}' output.pptx
   \`\`\`

## Quick Reference

| Task | Tool | Example |
|------|------|---------|
| Read presentation | python-pptx | \`Presentation('file.pptx')\` |
| Create presentation | python-pptx | \`Presentation()\` |
| Add slide | python-pptx | \`prs.slides.add_slide(layout)\` |
| Generate thumbnails | script | \`python thumbnail.py pres.pptx ./out/\` |
| Get slide inventory | script | \`python inventory.py pres.pptx\` |
| Reorder slides | script | \`python rearrange.py pres.pptx '[2,1,3]' out.pptx\` |
| Find/replace | script | \`python replace.py pres.pptx '{...}' out.pptx\` |`,
        isSystem: true,
      },
    }),

  roles: (args: Omit<CreateStandardSkillArgs, 'context'>) =>
    createStandardSkillFlatMetadata({
      ...args,
      context: {
        skillName: 'roles',
        name: 'roles',
        label: i18nLabel(msg({ message: `Roles`, context: 'skill.label' })),
        description: i18nLabel(
          msg({
            message: `Use when the user asks who can see or change what: creating a role, editing permissions, or assigning a role to someone`,
            context: 'skill.description',
          }),
        ),
        icon: 'IconLockAccess',
        content: `# Roles Skill

You help users manage roles and permissions in their workspace. Roles live under Settings > Members > Roles in the UI.

## Tools

- list_roles (read-only; pass includeRowLevelPermissionRules to also get row-level rules)
- create_role, update_role, delete_role
- assign_role_to_workspace_member
- upsert_object_permissions (per-object overrides)
- upsert_row_level_permission_rules (which records are visible; enterprise feature)
- get_object_metadata / get_field_metadata (resolve object + field IDs)

## ALWAYS call list_roles first

Every workspace already ships with an **Admin** role and a **Member** role, and Member is the workspace default role. Never assume the workspace is empty.

Call \`list_roles\` before proposing anything, then build on what is already there: adjusting an existing role is almost always better than creating a near-duplicate of it. Only create a new role when no existing role can reasonably be adapted.

\`list_roles\` is also the only way to see a role's current per-object overrides, which you need before calling \`upsert_object_permissions\` (see below).

## Confirmation gate (ALWAYS ask before creating, updating, deleting or assigning)

Before calling ANY tool that changes roles or permissions (\`create_role\`, \`update_role\`, \`delete_role\`, \`assign_role_to_workspace_member\`, \`upsert_object_permissions\`, \`upsert_row_level_permission_rules\`), you MUST first present a short plan and get explicit user confirmation.

- Read first: \`list_roles\`, \`get_object_metadata\` and \`get_field_metadata\` are read-only and allowed before confirmation.
- Then summarize what you intend to do: which role, which permissions change, which objects are affected, who is impacted, and any assumptions or defaults you are making.
- Ask the user to confirm (or adjust), then STOP and wait for their answer. Do NOT call any mutating tool in the same turn as the plan.
- Only after the user confirms do you proceed in the next turn.
- Keep the plan concise — a few bullets, not an essay.
- **Deleting a role always requires an explicit confirmation**, even if the user seemed to ask for it: say which role is going away and that its members, agents and API keys will be reassigned to the workspace default role.

Permissions decide who can see and change company data, so a wrong guess is expensive. When a request is ambiguous about scope ("make it read-only" — for which objects?), resolve it in the plan and let the user correct you.

## upsert_object_permissions REPLACES the whole override list

\`upsert_object_permissions\` is not incremental. The \`objectPermissions\` array you send becomes the role's complete set of per-object overrides:

- Objects omitted from the array lose their override and fall back to the role's global permissions (\`canReadAllObjectRecords\`, ...).
- So to add one override you must resend every override the role already has, plus the new one.
- Always call \`list_roles\` first, take the role's current overrides, and send them back together with your change.

Dropping an override silently widens access. Treat "I only sent the object I changed" as a bug.

\`upsert_row_level_permission_rules\` behaves the same way for a given role + object: the \`predicates\` and \`predicateGroups\` arrays are the complete rule set, anything omitted is deleted, and empty arrays clear all rules.

## Permission rules the API enforces

- **Write without read is rejected.** Never grant update / soft-delete / destroy on an object without also granting read, both on \`create_role\` and on \`upsert_object_permissions\`.
- **System-managed roles cannot be modified.** Roles with \`isEditable=false\` (like Admin) cannot be updated, deleted, or given overrides. If the user wants "an Admin but without X", create a new role instead of trying to change Admin.
- The **workspace default role** cannot be deleted, and neither can a role **you are currently assigned to**.
- You cannot change **your own** role assignment, assign a role whose \`canBeAssignedToUsers\` is false, or remove the admin role from the **last administrator**.

### Lockout guard

Mutations that would strip the acting admin's own access are rejected. Concretely, you cannot delete a role you hold, and you cannot set \`canUpdateAllSettings: false\` on a role you hold unless that role keeps an explicit ROLES permission flag.

If you get \`CANNOT_DELETE_OWN_ROLE\` or \`CANNOT_REVOKE_OWN_SETTINGS_ACCESS\`, this is that guard, not a bug: explain to the user that they would be locking themselves out of role management, and propose doing it from another admin account or on a different role.

## create_role defaults

Only \`label\` is required; \`description\` and \`icon\` are optional.

- All global record permissions (\`canReadAllObjectRecords\`, \`canUpdateAllObjectRecords\`, \`canSoftDeleteAllObjectRecords\`, \`canDestroyAllObjectRecords\`), \`canUpdateAllSettings\` and \`canAccessAllTools\` default to **false**.
- Assignability (\`canBeAssignedToUsers\`, \`canBeAssignedToAgents\`, \`canBeAssignedToApiKeys\`) defaults to **true**.

So a role created with only a label can see nothing. Set the global flags you want in the same \`create_role\` call, then use \`upsert_object_permissions\` for the exceptions.

## Common shapes

**Broad access with a read-only exception** — set the global flags wide on the role (\`canReadAllObjectRecords: true\`, \`canUpdateAllObjectRecords: true\`), then add one override for the restricted object:
\`{ objectMetadataId, canReadObjectRecords: true, canUpdateObjectRecords: false, canSoftDeleteObjectRecords: false, canDestroyObjectRecords: false }\`

**Narrow access to a few objects** — leave the global flags false and add one override per allowed object, each granting read (plus write where wanted). Remember every override must be in the same call.

**Members only see their own records** — keep object access as is and use \`upsert_row_level_permission_rules\`: one predicate with \`fieldMetadataId\` = the owner-like relation field on the object, \`operand\` = IS, and \`workspaceMemberFieldMetadataId\` = the \`id\` field of the workspaceMember object, which resolves to the current user at query time. Resolve both field IDs with \`get_field_metadata\` first.

## Assigning roles

\`assign_role_to_workspace_member\` replaces the member's current role; it does not add a second one. You need the workspace member's UUID, which comes from the workspace member records (e.g. \`find_many_workspace_members\`), not from \`list_roles\`.

When the user names a person, resolve them to a workspace member first and restate who you matched in the confirmation plan — assigning the wrong person a powerful role is a security incident.

## After mutating

Report what changed in plain terms: which role, what it can now do, and who is affected. If you changed overrides, restate the objects that are still overridden so the user can see nothing was dropped.`,
        isSystem: true,
      },
    }),

  'meeting-prep': (args: Omit<CreateStandardSkillArgs, 'context'>) =>
    createStandardSkillFlatMetadata({
      ...args,
      context: {
        skillName: 'meeting-prep',
        name: 'meeting-prep',
        label: i18nLabel(
          msg({ message: `Meeting Prep`, context: 'skill.label' }),
        ),
        description: i18nLabel(
          msg({
            message: `Use before a call or a meeting, and whenever the user asks who am I talking to, brief me on this account, or what do I need to know before this conversation`,
            context: 'skill.description',
          }),
        ),
        icon: 'IconCalendarEvent',
        content: `# Meeting Prep Skill

Produce a brief the user can read in under a minute before they talk to someone.

## Gather

Start from the person or company the user named, or the record they are looking at. Then pull what hangs off it, filtering by the relation rather than scanning whole objects:

- Who they are: role, company, and how long the record has existed
- Open opportunities on that company, with stage, amount and close date
- The most recent notes, tasks and timeline activities
- Recent messages and calendar events they took part in

If the person belongs to a company, read the company too. Deals and history usually live there rather than on the individual.

## Produce

Write it in this order, and stop when you run out of real material:

1. One line on who they are and why this conversation matters now
2. Open deals, with stage and amount, or a line saying there are none
3. What happened last: the most recent exchange and what was agreed
4. What changed since then, including anything overdue or unanswered
5. Three questions worth asking, each drawn from something above

Reference every record you name so the user can click through to it.

## Rules

- Never invent history. If contact has been quiet, say exactly how long.
- This skill only reads. Do not create or update anything.
- If the user has not said who the meeting is with, ask before gathering.
- Keep it short. A brief nobody finishes is a brief nobody uses.`,
        isSystem: false,
      },
    }),

  'deal-review': (args: Omit<CreateStandardSkillArgs, 'context'>) =>
    createStandardSkillFlatMetadata({
      ...args,
      context: {
        skillName: 'deal-review',
        name: 'deal-review',
        label: i18nLabel(
          msg({ message: `Deal Review`, context: 'skill.label' }),
        ),
        description: i18nLabel(
          msg({
            message: `Use when the user asks how a deal is doing, which deals are at risk, what is stuck or going quiet, or asks for a pipeline review`,
            context: 'skill.description',
          }),
        ),
        icon: 'IconTargetArrow',
        content: `# Deal Review Skill

Judge the health of one opportunity or a set of them, and say what to do next.

## Gather

For each opportunity in scope, read the record and what is linked to it: the company, the people involved, notes, tasks, and recent messages and calendar events. Use group_by_opportunities when the question is about the shape of the pipeline rather than about individual deals.

## Signals

Work through these for every deal. Each one you can answer becomes a line in the output:

- **Momentum.** How long has it sat in its current stage, and how does that compare with the rest of the pipeline?
- **Contact.** When did anyone last exchange a message or meet? Silence against an approaching close date is the strongest warning sign there is.
- **Threading.** How many distinct people at that company have been in contact? A deal running through one person is a deal that dies when that person leaves.
- **Hygiene.** Is the close date set, already past, or implausible? Is the amount missing?
- **Commitments.** Are there open or overdue tasks, and who owns them?

## Produce

For a single deal, write a short verdict, the evidence behind it, and one concrete next step.

For several, lead with the deals that need attention, one line each, then summarise the rest. Sort by risk rather than by size, and reference every opportunity so the user can open it.

Say which signals you could not evaluate and why. A review that hides its gaps is worse than a short one.

## Rules

- This skill only reads. Propose the next step and let the user ask you to create the task.
- Never call a deal at risk without naming the signal that says so.
- Never guess at an amount or a date that is missing. Report it as missing.`,
        isSystem: false,
      },
    }),

  'crm-hygiene': (args: Omit<CreateStandardSkillArgs, 'context'>) =>
    createStandardSkillFlatMetadata({
      ...args,
      context: {
        skillName: 'crm-hygiene',
        name: 'crm-hygiene',
        label: i18nLabel(
          msg({ message: `CRM Hygiene`, context: 'skill.label' }),
        ),
        description: i18nLabel(
          msg({
            message: `Use when the user asks to clean up the CRM, find duplicates, fill in missing fields, or asks why the data is messy or which records are stale`,
            context: 'skill.description',
          }),
        ),
        icon: 'IconListCheck',
        content: `# CRM Hygiene Skill

Audit records for problems, show the user what you found, and fix only what they approve.

## Audit

Ask which object to audit if the user has not said. Then look for these, in this order:

- **Duplicates.** Read the object's duplicateCriteria from its metadata and search on those fields. Two companies sharing a domain, or two people sharing an email, are the reliable cases.
- **Missing fields.** Identify the fields that make a record useful for that object, then count how many records leave them empty.
- **Stale records.** Records untouched for a long time, especially opportunities whose close date has passed while they are still open.
- **Broken links.** Records whose expected relation is empty, such as a person with no company or a deal with no contact.

Use group_by_* to count rather than reading every record, then fetch only the rows you intend to show.

## Report

Lead with counts, so the user sees the shape of the problem before the detail. Then list the worst cases, referencing each record. Say which fix you propose for each group and what it would change.

## Fix

Always confirm before writing. Show what you will change and wait.

- Merge duplicates with merge_many_* (merge_many_companies, merge_many_people, and so on), one call per group. Call it with dryRun: true first and show the user the merged record. When the records disagree, ask which one to keep and pass its position in ids as conflictPriorityIndex. The other records are permanently deleted, so merge only the groups the user approved.
- If there is no merge_many_* tool for the object, the user's role cannot merge it. Report each group with its records referenced and leave the merge to someone who can.
- Fill missing fields only from data already in the workspace, never from a guess.
- Apply approved changes in one call rather than one record at a time. These tools carry the object's plural name: update_many_people, upsert_many_companies, and so on. Use update_many_* when every matched record gets the same value, upsert_many_* when each record needs its own.
- Report what changed afterwards, and say what you deliberately left alone.

## Rules

- Never delete a record in this skill except through merge_many_*, and never fake a merge by copying fields across and deleting the loser: that loses every record linked to it.
- Never confirm on the user's behalf, and never read a general yes as approval for a second batch.
- If there is nothing wrong, say so. A clean workspace is a valid result.`,
        isSystem: false,
      },
    }),

  enrich: (args: Omit<CreateStandardSkillArgs, 'context'>) =>
    createStandardSkillFlatMetadata({
      ...args,
      context: {
        skillName: 'enrich',
        name: 'enrich',
        label: i18nLabel(msg({ message: `Enrich`, context: 'skill.label' })),
        description: i18nLabel(
          msg({
            message: `Use when the user asks to research or enrich a company or a person, fill in what the CRM does not know about them, or find out what a company actually does`,
            context: 'skill.description',
          }),
        ),
        icon: 'IconSearch',
        content: `# Enrich Skill

Find what the workspace does not know about a company or a person, and offer it back as field updates.

## Search

Use app_exa_web_search with its category set deliberately. It is preloaded, so call it directly without looking it up first. If it is not available, say the workspace has no web search rather than guessing at answers.

- Set category to "company" for an organisation: what it does, size, funding, headquarters, recent news.
- Set category to "people" for an individual: current role, employer, background.
- Set category to "news" when the user asks what changed rather than who they are.

Start from what the record already holds. A domain makes a far better query than a company name, and a name plus an employer beats a name alone. Run several narrow searches rather than one broad one, and stop as soon as the field you were filling is answered.

## Reconcile

Read the record first and enrich only what is empty or clearly wrong. Overwriting a value a human typed is the fastest way to lose their trust in this feature.

Keep the source for every fact. State plainly which facts came from the web and which were already in the workspace.

## Produce

Show a short table of proposed changes: the field, what it holds now, what you propose, and where it came from. Then ask before writing.

After approval, apply the changes in a single update call and confirm what was written.

Anything you found that has no field to live in belongs in a note on the record, not squeezed into an unrelated field.

## Rules

- Never invent a value to fill a gap. An empty field beats a wrong one.
- Confidence matters: if the search returned a different person who shares the name, say so and stop.
- Do not enrich a large set of records unless the user asked for exactly that, and confirm the scope before you start.`,
        isSystem: false,
      },
    }),
} satisfies {
  [P in AllStandardSkillName]: (
    args: Omit<CreateStandardSkillArgs, 'context'>,
  ) => FlatSkill;
};