import { EMPTY_OBJECT_SCHEMA, STRING_SCHEMA, BOOLEAN_SCHEMA, NUMBER_SCHEMA, arraySchema, objectSchema, bodyEnvelopeSchema, methodDescriptor, runtimeEventId } from './method-catalog-shared.js';
import { builtinGatewayHomeGraphMethodDescriptors } from './method-catalog-homegraph.js';
import { GRAPHQL_VARIABLES_SCHEMA, JSON_RECORD_SCHEMA, METADATA_SCHEMA, STRING_LIST_SCHEMA } from './operator-contract-schemas-shared.js';
import { KNOWLEDGE_BATCH_INGEST_RESULT_SCHEMA, KNOWLEDGE_BROWSER_SYNC_RESULT_SCHEMA, KNOWLEDGE_ASK_OUTPUT_SCHEMA, KNOWLEDGE_CONSOLIDATION_DECISION_SCHEMA, KNOWLEDGE_CANDIDATE_OUTPUT_SCHEMA, KNOWLEDGE_CANDIDATES_OUTPUT_SCHEMA, KNOWLEDGE_CONNECTOR_INGEST_INPUT_SCHEMA, KNOWLEDGE_CONNECTOR_DOCTOR_OUTPUT_SCHEMA, KNOWLEDGE_CONNECTORS_OUTPUT_SCHEMA, KNOWLEDGE_CONNECTOR_ENTITY_OUTPUT_SCHEMA, KNOWLEDGE_EXTRACTION_OUTPUT_SCHEMA, KNOWLEDGE_EXTRACTIONS_OUTPUT_SCHEMA, KNOWLEDGE_GRAPHQL_EXECUTE_OUTPUT_SCHEMA, KNOWLEDGE_GRAPHQL_SCHEMA_OUTPUT_SCHEMA, KNOWLEDGE_INGEST_RESULT_SCHEMA, KNOWLEDGE_ITEM_ENTITY_OUTPUT_SCHEMA, KNOWLEDGE_JOB_OUTPUT_SCHEMA, KNOWLEDGE_JOB_RUN_OUTPUT_SCHEMA, KNOWLEDGE_JOB_RUN_REQUEST_SCHEMA, KNOWLEDGE_JOB_RUNS_OUTPUT_SCHEMA, KNOWLEDGE_JOBS_OUTPUT_SCHEMA, KNOWLEDGE_LINT_OUTPUT_SCHEMA, KNOWLEDGE_MAP_OUTPUT_SCHEMA, KNOWLEDGE_MATERIALIZED_PROJECTION_SCHEMA, KNOWLEDGE_NODES_OUTPUT_SCHEMA, KNOWLEDGE_PACKET_SCHEMA, KNOWLEDGE_PACKET_DETAIL_SCHEMA, KNOWLEDGE_PROJECTION_BUNDLE_SCHEMA, KNOWLEDGE_PROJECTION_TARGETS_OUTPUT_SCHEMA, KNOWLEDGE_REINDEX_OUTPUT_SCHEMA, KNOWLEDGE_REFINEMENT_RUN_OUTPUT_SCHEMA, KNOWLEDGE_REFINEMENT_TASK_OUTPUT_SCHEMA, KNOWLEDGE_REFINEMENT_TASKS_OUTPUT_SCHEMA, KNOWLEDGE_REPORT_OUTPUT_SCHEMA, KNOWLEDGE_REPORTS_OUTPUT_SCHEMA, KNOWLEDGE_SCHEDULE_INPUT_SCHEMA, KNOWLEDGE_SCHEDULE_OUTPUT_SCHEMA, KNOWLEDGE_SCHEDULES_OUTPUT_SCHEMA, KNOWLEDGE_SEARCH_OUTPUT_SCHEMA, KNOWLEDGE_SOURCE_TYPE_SCHEMA, KNOWLEDGE_SOURCES_OUTPUT_SCHEMA, KNOWLEDGE_STATUS_SCHEMA, KNOWLEDGE_ISSUE_REVIEW_OUTPUT_SCHEMA, KNOWLEDGE_ISSUES_OUTPUT_SCHEMA, KNOWLEDGE_USAGE_OUTPUT_SCHEMA, } from './operator-contract-schemas-knowledge.js';
import { PROJECT_PLANNING_DECISION_OUTPUT_SCHEMA, PROJECT_PLANNING_DECISIONS_OUTPUT_SCHEMA, PROJECT_PLANNING_EVALUATION_SCHEMA, PROJECT_PLANNING_LANGUAGE_OUTPUT_SCHEMA, PROJECT_PLANNING_SPACE_INPUT_SCHEMA, PROJECT_PLANNING_STATE_OUTPUT_SCHEMA, PROJECT_PLANNING_STATUS_SCHEMA, } from './operator-contract-schemas-project-planning.js';
const KNOWLEDGE_SPACE_INPUT_FIELDS = {
    knowledgeSpaceId: STRING_SCHEMA,
    includeAllSpaces: BOOLEAN_SCHEMA,
};
export const builtinGatewayKnowledgeMethodDescriptors = [
    methodDescriptor({
        id: 'knowledge.status',
        title: 'Knowledge Status',
        description: 'Return structured knowledge runtime status and record counts.',
        category: 'knowledge',
        scopes: ['read:knowledge'],
        http: { method: 'GET', path: '/api/knowledge/status' },
        inputSchema: objectSchema(KNOWLEDGE_SPACE_INPUT_FIELDS),
        outputSchema: KNOWLEDGE_STATUS_SCHEMA,
    }),
    methodDescriptor({
        id: 'knowledge.sources.list',
        title: 'List Knowledge Sources',
        description: 'Return ingested structured knowledge sources.',
        category: 'knowledge',
        scopes: ['read:knowledge'],
        http: { method: 'GET', path: '/api/knowledge/sources' },
        inputSchema: objectSchema({ limit: NUMBER_SCHEMA, ...KNOWLEDGE_SPACE_INPUT_FIELDS }),
        outputSchema: KNOWLEDGE_SOURCES_OUTPUT_SCHEMA,
    }),
    methodDescriptor({
        id: 'knowledge.nodes.list',
        title: 'List Knowledge Nodes',
        description: 'Return compiled knowledge nodes.',
        category: 'knowledge',
        scopes: ['read:knowledge'],
        http: { method: 'GET', path: '/api/knowledge/nodes' },
        inputSchema: objectSchema({ limit: NUMBER_SCHEMA, ...KNOWLEDGE_SPACE_INPUT_FIELDS }),
        outputSchema: KNOWLEDGE_NODES_OUTPUT_SCHEMA,
    }),
    methodDescriptor({
        id: 'knowledge.issues.list',
        title: 'List Knowledge Issues',
        description: 'Return current knowledge lint and health issues.',
        category: 'knowledge',
        scopes: ['read:knowledge'],
        http: { method: 'GET', path: '/api/knowledge/issues' },
        inputSchema: objectSchema({ limit: NUMBER_SCHEMA, ...KNOWLEDGE_SPACE_INPUT_FIELDS }),
        outputSchema: KNOWLEDGE_ISSUES_OUTPUT_SCHEMA,
    }),
    methodDescriptor({
        id: 'knowledge.issue.review',
        title: 'Review Knowledge Issue',
        description: 'Record an LLM or user review decision for a knowledge issue and optionally apply semantic facts to the linked source or node.',
        category: 'knowledge',
        access: 'admin',
        scopes: ['write:knowledge'],
        http: { method: 'POST', path: '/api/knowledge/issues/{id}/review' },
        inputSchema: objectSchema({
            id: STRING_SCHEMA,
            action: STRING_SCHEMA,
            reviewer: STRING_SCHEMA,
            value: JSON_RECORD_SCHEMA,
        }, ['id', 'action']),
        outputSchema: KNOWLEDGE_ISSUE_REVIEW_OUTPUT_SCHEMA,
    }),
    methodDescriptor({
        id: 'knowledge.item.get',
        title: 'Get Knowledge Item',
        description: 'Return a single structured knowledge source, node, or issue with linked relations.',
        category: 'knowledge',
        scopes: ['read:knowledge'],
        http: { method: 'GET', path: '/api/knowledge/items/{id}' },
        inputSchema: objectSchema({ id: STRING_SCHEMA, ...KNOWLEDGE_SPACE_INPUT_FIELDS }, ['id']),
        outputSchema: KNOWLEDGE_ITEM_ENTITY_OUTPUT_SCHEMA,
    }),
    methodDescriptor({
        id: 'knowledge.connectors.list',
        title: 'List Knowledge Connectors',
        description: 'Return discoverable knowledge ingest connectors with input metadata and examples.',
        category: 'knowledge',
        scopes: ['read:knowledge'],
        http: { method: 'GET', path: '/api/knowledge/connectors' },
        inputSchema: EMPTY_OBJECT_SCHEMA,
        outputSchema: KNOWLEDGE_CONNECTORS_OUTPUT_SCHEMA,
    }),
    methodDescriptor({
        id: 'knowledge.connector.doctor',
        title: 'Doctor Knowledge Connector',
        description: 'Return readiness and setup diagnostics for a knowledge connector.',
        category: 'knowledge',
        scopes: ['read:knowledge'],
        http: { method: 'GET', path: '/api/knowledge/connectors/{id}/doctor' },
        inputSchema: objectSchema({ id: STRING_SCHEMA }, ['id']),
        outputSchema: KNOWLEDGE_CONNECTOR_DOCTOR_OUTPUT_SCHEMA,
    }),
    methodDescriptor({
        id: 'knowledge.connector.get',
        title: 'Get Knowledge Connector',
        description: 'Return a single knowledge connector manifest.',
        category: 'knowledge',
        scopes: ['read:knowledge'],
        http: { method: 'GET', path: '/api/knowledge/connectors/{id}' },
        inputSchema: objectSchema({ id: STRING_SCHEMA }, ['id']),
        outputSchema: KNOWLEDGE_CONNECTOR_ENTITY_OUTPUT_SCHEMA,
    }),
    methodDescriptor({
        id: 'knowledge.ingest.url',
        title: 'Ingest URL Into Knowledge',
        description: 'Fetch, snapshot, and compile a URL into the structured knowledge store.',
        category: 'knowledge',
        scopes: ['write:knowledge'],
        access: 'admin',
        http: { method: 'POST', path: '/api/knowledge/ingest/url' },
        inputSchema: bodyEnvelopeSchema({
            url: STRING_SCHEMA,
            title: STRING_SCHEMA,
            sourceType: KNOWLEDGE_SOURCE_TYPE_SCHEMA,
            sessionId: STRING_SCHEMA,
            tags: arraySchema(STRING_SCHEMA),
            folderPath: STRING_SCHEMA,
            allowPrivateHosts: BOOLEAN_SCHEMA,
            metadata: METADATA_SCHEMA,
        }, ['url']),
        outputSchema: KNOWLEDGE_INGEST_RESULT_SCHEMA,
    }),
    methodDescriptor({
        id: 'knowledge.ingest.bookmarks',
        title: 'Import Bookmark File',
        description: 'Parse a bookmark export file and ingest its URLs into the structured knowledge store.',
        category: 'knowledge',
        scopes: ['write:knowledge'],
        access: 'admin',
        http: { method: 'POST', path: '/api/knowledge/ingest/bookmarks' },
        inputSchema: bodyEnvelopeSchema({
            path: STRING_SCHEMA,
            sessionId: STRING_SCHEMA,
            allowPrivateHosts: BOOLEAN_SCHEMA,
            metadata: METADATA_SCHEMA,
        }, ['path']),
        outputSchema: KNOWLEDGE_BATCH_INGEST_RESULT_SCHEMA,
    }),
    methodDescriptor({
        id: 'knowledge.ingest.urls',
        title: 'Import URL List',
        description: 'Parse a URL list file and ingest its entries into the structured knowledge store.',
        category: 'knowledge',
        scopes: ['write:knowledge'],
        access: 'admin',
        http: { method: 'POST', path: '/api/knowledge/ingest/urls' },
        inputSchema: bodyEnvelopeSchema({
            path: STRING_SCHEMA,
            sessionId: STRING_SCHEMA,
            allowPrivateHosts: BOOLEAN_SCHEMA,
            metadata: METADATA_SCHEMA,
        }, ['path']),
        outputSchema: KNOWLEDGE_BATCH_INGEST_RESULT_SCHEMA,
    }),
    methodDescriptor({
        id: 'knowledge.ingest.connector',
        title: 'Ingest Connector Input',
        description: 'Resolve a knowledge connector against inline input, inline content, or file-backed content.',
        category: 'knowledge',
        scopes: ['write:knowledge'],
        access: 'admin',
        http: { method: 'POST', path: '/api/knowledge/ingest/connector' },
        inputSchema: KNOWLEDGE_CONNECTOR_INGEST_INPUT_SCHEMA,
        outputSchema: KNOWLEDGE_BATCH_INGEST_RESULT_SCHEMA,
    }),
    methodDescriptor({
        id: 'knowledge.ingest.artifact',
        title: 'Ingest Artifact Into Knowledge',
        description: 'Snapshot an existing artifact, daemon-local path, remote URI, multipart file upload, or raw binary upload into the structured knowledge store and run structured extraction.',
        category: 'knowledge',
        scopes: ['write:knowledge'],
        access: 'admin',
        http: { method: 'POST', path: '/api/knowledge/ingest/artifact' },
        events: [runtimeEventId('knowledge')],
        inputSchema: bodyEnvelopeSchema({
            artifactId: STRING_SCHEMA,
            path: STRING_SCHEMA,
            uri: STRING_SCHEMA,
            sourceType: KNOWLEDGE_SOURCE_TYPE_SCHEMA,
            title: STRING_SCHEMA,
            sessionId: STRING_SCHEMA,
            tags: arraySchema(STRING_SCHEMA),
            folderPath: STRING_SCHEMA,
            allowPrivateHosts: BOOLEAN_SCHEMA,
            metadata: METADATA_SCHEMA,
        }),
        outputSchema: KNOWLEDGE_INGEST_RESULT_SCHEMA,
        metadata: {
            uploadModes: ['json-artifact-reference', 'json-path-or-uri', 'multipart-file', 'raw-body'],
            largeUploadConfigKey: 'storage.artifacts.maxBytes',
        },
    }),
    methodDescriptor({
        id: 'knowledge.ingest.browserHistory',
        title: 'Sync Browser History Into Knowledge',
        description: 'Read local browser history and bookmarks and index them as metadata-first structured knowledge.',
        category: 'knowledge',
        scopes: ['write:knowledge'],
        access: 'admin',
        http: { method: 'POST', path: '/api/knowledge/ingest/browser-history' },
        inputSchema: bodyEnvelopeSchema({
            limit: NUMBER_SCHEMA,
            sinceMs: NUMBER_SCHEMA,
            browsers: arraySchema(STRING_SCHEMA),
            sourceKinds: arraySchema(STRING_SCHEMA),
            homeOverride: STRING_SCHEMA,
            sessionId: STRING_SCHEMA,
            connectorId: STRING_SCHEMA,
            metadata: METADATA_SCHEMA,
        }),
        outputSchema: KNOWLEDGE_BROWSER_SYNC_RESULT_SCHEMA,
    }),
    methodDescriptor({
        id: 'knowledge.search',
        title: 'Search Structured Knowledge',
        description: 'Search structured knowledge sources and nodes with compact ranked results.',
        category: 'knowledge',
        scopes: ['read:knowledge'],
        http: { method: 'POST', path: '/api/knowledge/search' },
        inputSchema: bodyEnvelopeSchema({
            query: STRING_SCHEMA,
            limit: NUMBER_SCHEMA,
            ...KNOWLEDGE_SPACE_INPUT_FIELDS,
            includeSources: BOOLEAN_SCHEMA,
            includeNodes: BOOLEAN_SCHEMA,
            metadata: METADATA_SCHEMA,
        }, ['query']),
        outputSchema: KNOWLEDGE_SEARCH_OUTPUT_SCHEMA,
    }),
    methodDescriptor({
        id: 'knowledge.ask',
        title: 'Ask Knowledge',
        description: 'Search, semantically synthesize, and return a source-backed answer from the structured knowledge/wiki store.',
        category: 'knowledge',
        scopes: ['read:knowledge'],
        http: { method: 'POST', path: '/api/knowledge/ask' },
        inputSchema: bodyEnvelopeSchema({
            query: STRING_SCHEMA,
            knowledgeSpaceId: STRING_SCHEMA,
            limit: NUMBER_SCHEMA,
            mode: STRING_SCHEMA,
            includeSources: BOOLEAN_SCHEMA,
            includeConfidence: BOOLEAN_SCHEMA,
            includeLinkedObjects: BOOLEAN_SCHEMA,
            candidateSourceIds: STRING_LIST_SCHEMA,
            candidateNodeIds: STRING_LIST_SCHEMA,
            strictCandidates: BOOLEAN_SCHEMA,
            timeoutMs: NUMBER_SCHEMA,
            metadata: METADATA_SCHEMA,
        }, ['query']),
        outputSchema: KNOWLEDGE_ASK_OUTPUT_SCHEMA,
    }),
    methodDescriptor({
        id: 'knowledge.extractions.list',
        title: 'List Knowledge Extractions',
        description: 'Return structured extraction records for ingested sources.',
        category: 'knowledge',
        scopes: ['read:knowledge'],
        http: { method: 'GET', path: '/api/knowledge/extractions' },
        inputSchema: objectSchema({ limit: NUMBER_SCHEMA, sourceId: STRING_SCHEMA, ...KNOWLEDGE_SPACE_INPUT_FIELDS }),
        outputSchema: KNOWLEDGE_EXTRACTIONS_OUTPUT_SCHEMA,
    }),
    methodDescriptor({
        id: 'knowledge.extraction.get',
        title: 'Get Knowledge Extraction',
        description: 'Return a single knowledge extraction record.',
        category: 'knowledge',
        scopes: ['read:knowledge'],
        http: { method: 'GET', path: '/api/knowledge/extractions/{id}' },
        inputSchema: objectSchema({ id: STRING_SCHEMA }, ['id']),
        outputSchema: KNOWLEDGE_EXTRACTION_OUTPUT_SCHEMA,
    }),
    methodDescriptor({
        id: 'knowledge.source.extraction.get',
        title: 'Get Source Extraction',
        description: 'Return the structured extraction record for a single knowledge source.',
        category: 'knowledge',
        scopes: ['read:knowledge'],
        http: { method: 'GET', path: '/api/knowledge/sources/{id}/extraction' },
        inputSchema: objectSchema({ id: STRING_SCHEMA }, ['id']),
        outputSchema: KNOWLEDGE_EXTRACTION_OUTPUT_SCHEMA,
    }),
    methodDescriptor({
        id: 'knowledge.packet',
        title: 'Build Knowledge Packet',
        description: 'Build a compact structured knowledge packet for a task and write scope.',
        category: 'knowledge',
        scopes: ['read:knowledge'],
        http: { method: 'POST', path: '/api/knowledge/packet' },
        inputSchema: bodyEnvelopeSchema({
            task: STRING_SCHEMA,
            writeScope: arraySchema(STRING_SCHEMA),
            budgetLimit: NUMBER_SCHEMA,
            detail: KNOWLEDGE_PACKET_DETAIL_SCHEMA,
            ...KNOWLEDGE_SPACE_INPUT_FIELDS,
        }, ['task']),
        outputSchema: KNOWLEDGE_PACKET_SCHEMA,
    }),
    methodDescriptor({
        id: 'knowledge.usage.list',
        title: 'List Knowledge Usage',
        description: 'Return the recent knowledge usage ledger for packet hits, search hits, and item inspection.',
        category: 'knowledge',
        scopes: ['read:knowledge'],
        http: { method: 'GET', path: '/api/knowledge/usage' },
        inputSchema: objectSchema({ limit: NUMBER_SCHEMA, targetKind: STRING_SCHEMA, targetId: STRING_SCHEMA, usageKind: STRING_SCHEMA }),
        outputSchema: KNOWLEDGE_USAGE_OUTPUT_SCHEMA,
    }),
    methodDescriptor({
        id: 'knowledge.candidates.list',
        title: 'List Consolidation Candidates',
        description: 'Return scored consolidation candidates for durable memory promotion, review, or source refresh.',
        category: 'knowledge',
        scopes: ['read:knowledge'],
        http: { method: 'GET', path: '/api/knowledge/candidates' },
        inputSchema: objectSchema({ limit: NUMBER_SCHEMA, status: STRING_SCHEMA, subjectKind: STRING_SCHEMA, subjectId: STRING_SCHEMA }),
        outputSchema: KNOWLEDGE_CANDIDATES_OUTPUT_SCHEMA,
    }),
    methodDescriptor({
        id: 'knowledge.candidate.get',
        title: 'Get Consolidation Candidate',
        description: 'Return a single consolidation candidate.',
        category: 'knowledge',
        scopes: ['read:knowledge'],
        http: { method: 'GET', path: '/api/knowledge/candidates/{id}' },
        inputSchema: objectSchema({ id: STRING_SCHEMA }, ['id']),
        outputSchema: KNOWLEDGE_CANDIDATE_OUTPUT_SCHEMA,
    }),
    methodDescriptor({
        id: 'knowledge.candidate.decide',
        title: 'Decide Consolidation Candidate',
        description: 'Accept, reject, or supersede a knowledge consolidation candidate.',
        category: 'knowledge',
        scopes: ['write:knowledge'],
        access: 'admin',
        http: { method: 'POST', path: '/api/knowledge/candidates/{id}/decide' },
        inputSchema: bodyEnvelopeSchema({
            decision: KNOWLEDGE_CONSOLIDATION_DECISION_SCHEMA,
            decidedBy: STRING_SCHEMA,
            reason: STRING_SCHEMA,
            metadata: METADATA_SCHEMA,
        }, ['decision']),
        outputSchema: KNOWLEDGE_CANDIDATE_OUTPUT_SCHEMA,
    }),
    methodDescriptor({
        id: 'knowledge.reports.list',
        title: 'List Consolidation Reports',
        description: 'Return deterministic knowledge consolidation reports.',
        category: 'knowledge',
        scopes: ['read:knowledge'],
        http: { method: 'GET', path: '/api/knowledge/reports' },
        inputSchema: objectSchema({ limit: NUMBER_SCHEMA, ...KNOWLEDGE_SPACE_INPUT_FIELDS }),
        outputSchema: KNOWLEDGE_REPORTS_OUTPUT_SCHEMA,
    }),
    methodDescriptor({
        id: 'knowledge.report.get',
        title: 'Get Consolidation Report',
        description: 'Return a single knowledge consolidation report.',
        category: 'knowledge',
        scopes: ['read:knowledge'],
        http: { method: 'GET', path: '/api/knowledge/reports/{id}' },
        inputSchema: objectSchema({ id: STRING_SCHEMA }, ['id']),
        outputSchema: KNOWLEDGE_REPORT_OUTPUT_SCHEMA,
    }),
    methodDescriptor({
        id: 'knowledge.jobs.list',
        title: 'List Knowledge Jobs',
        description: 'Return built-in structured knowledge maintenance jobs.',
        category: 'knowledge',
        scopes: ['read:knowledge'],
        http: { method: 'GET', path: '/api/knowledge/jobs' },
        inputSchema: EMPTY_OBJECT_SCHEMA,
        outputSchema: KNOWLEDGE_JOBS_OUTPUT_SCHEMA,
    }),
    methodDescriptor({
        id: 'knowledge.job.get',
        title: 'Get Knowledge Job',
        description: 'Return a single knowledge job definition.',
        category: 'knowledge',
        scopes: ['read:knowledge'],
        http: { method: 'GET', path: '/api/knowledge/jobs/{jobId}' },
        inputSchema: objectSchema({ jobId: STRING_SCHEMA }, ['jobId']),
        outputSchema: KNOWLEDGE_JOB_OUTPUT_SCHEMA,
    }),
    methodDescriptor({
        id: 'knowledge.job-runs.list',
        title: 'List Knowledge Job Runs',
        description: 'Return recent knowledge job runs.',
        category: 'knowledge',
        scopes: ['read:knowledge'],
        http: { method: 'GET', path: '/api/knowledge/job-runs' },
        inputSchema: objectSchema({ limit: NUMBER_SCHEMA, jobId: STRING_SCHEMA }),
        outputSchema: KNOWLEDGE_JOB_RUNS_OUTPUT_SCHEMA,
    }),
    methodDescriptor({
        id: 'knowledge.refinement.tasks.list',
        title: 'List Knowledge Refinement Tasks',
        description: 'Return durable semantic refinement tasks with state, traces, accepted/rejected source assessments, and blocked reasons.',
        category: 'knowledge',
        scopes: ['read:knowledge'],
        http: { method: 'GET', path: '/api/knowledge/refinement/tasks' },
        inputSchema: objectSchema({
            limit: NUMBER_SCHEMA,
            spaceId: STRING_SCHEMA,
            knowledgeSpaceId: STRING_SCHEMA,
            state: STRING_SCHEMA,
            subjectKind: STRING_SCHEMA,
            subjectId: STRING_SCHEMA,
            gapId: STRING_SCHEMA,
        }),
        outputSchema: KNOWLEDGE_REFINEMENT_TASKS_OUTPUT_SCHEMA,
    }),
    methodDescriptor({
        id: 'knowledge.refinement.task.get',
        title: 'Get Knowledge Refinement Task',
        description: 'Return one semantic refinement task and its trace.',
        category: 'knowledge',
        scopes: ['read:knowledge'],
        http: { method: 'GET', path: '/api/knowledge/refinement/tasks/{id}' },
        inputSchema: objectSchema({ id: STRING_SCHEMA }, ['id']),
        outputSchema: KNOWLEDGE_REFINEMENT_TASK_OUTPUT_SCHEMA,
    }),
    methodDescriptor({
        id: 'knowledge.refinement.run',
        title: 'Run Knowledge Refinement',
        description: 'Run source-backed semantic self-improvement for a space, source list, or specific gaps.',
        category: 'knowledge',
        access: 'admin',
        scopes: ['write:knowledge'],
        http: { method: 'POST', path: '/api/knowledge/refinement/run' },
        inputSchema: bodyEnvelopeSchema({
            knowledgeSpaceId: STRING_SCHEMA,
            spaceId: STRING_SCHEMA,
            gapIds: STRING_LIST_SCHEMA,
            sourceIds: STRING_LIST_SCHEMA,
            limit: NUMBER_SCHEMA,
            maxRunMs: NUMBER_SCHEMA,
            force: BOOLEAN_SCHEMA,
        }),
        outputSchema: KNOWLEDGE_REFINEMENT_RUN_OUTPUT_SCHEMA,
    }),
    methodDescriptor({
        id: 'knowledge.refinement.task.cancel',
        title: 'Cancel Knowledge Refinement Task',
        description: 'Mark a queued or active semantic refinement task as cancelled.',
        category: 'knowledge',
        access: 'admin',
        scopes: ['write:knowledge'],
        http: { method: 'POST', path: '/api/knowledge/refinement/tasks/{id}/cancel' },
        inputSchema: bodyEnvelopeSchema({ id: STRING_SCHEMA }, ['id']),
        outputSchema: KNOWLEDGE_REFINEMENT_TASK_OUTPUT_SCHEMA,
    }),
    methodDescriptor({
        id: 'knowledge.schedules.list',
        title: 'List Knowledge Schedules',
        description: 'Return managed schedules for background knowledge maintenance jobs.',
        category: 'knowledge',
        scopes: ['read:knowledge'],
        http: { method: 'GET', path: '/api/knowledge/schedules' },
        inputSchema: objectSchema({ limit: NUMBER_SCHEMA }),
        outputSchema: KNOWLEDGE_SCHEDULES_OUTPUT_SCHEMA,
    }),
    methodDescriptor({
        id: 'knowledge.schedule.get',
        title: 'Get Knowledge Schedule',
        description: 'Return a single managed knowledge schedule.',
        category: 'knowledge',
        scopes: ['read:knowledge'],
        http: { method: 'GET', path: '/api/knowledge/schedules/{id}' },
        inputSchema: objectSchema({ id: STRING_SCHEMA }, ['id']),
        outputSchema: KNOWLEDGE_SCHEDULE_OUTPUT_SCHEMA,
    }),
    methodDescriptor({
        id: 'knowledge.schedule.save',
        title: 'Save Knowledge Schedule',
        description: 'Create or update a managed schedule for a knowledge maintenance job.',
        category: 'knowledge',
        scopes: ['write:knowledge'],
        access: 'admin',
        http: { method: 'POST', path: '/api/knowledge/schedules' },
        inputSchema: bodyEnvelopeSchema({
            id: STRING_SCHEMA,
            jobId: STRING_SCHEMA,
            label: STRING_SCHEMA,
            enabled: BOOLEAN_SCHEMA,
            schedule: KNOWLEDGE_SCHEDULE_INPUT_SCHEMA,
            metadata: METADATA_SCHEMA,
        }, ['jobId', 'schedule']),
        outputSchema: KNOWLEDGE_SCHEDULE_OUTPUT_SCHEMA,
    }),
    methodDescriptor({
        id: 'knowledge.schedule.delete',
        title: 'Delete Knowledge Schedule',
        description: 'Delete a managed knowledge schedule.',
        category: 'knowledge',
        scopes: ['write:knowledge'],
        access: 'admin',
        http: { method: 'DELETE', path: '/api/knowledge/schedules/{id}' },
        inputSchema: objectSchema({ id: STRING_SCHEMA }, ['id']),
        outputSchema: objectSchema({ deleted: BOOLEAN_SCHEMA }, ['deleted'], { additionalProperties: false }),
    }),
    methodDescriptor({
        id: 'knowledge.schedule.enable',
        title: 'Set Knowledge Schedule Enabled',
        description: 'Enable or disable a managed knowledge schedule.',
        category: 'knowledge',
        scopes: ['write:knowledge'],
        access: 'admin',
        http: { method: 'POST', path: '/api/knowledge/schedules/{id}/enabled' },
        inputSchema: bodyEnvelopeSchema({
            enabled: BOOLEAN_SCHEMA,
        }, ['enabled']),
        outputSchema: KNOWLEDGE_SCHEDULE_OUTPUT_SCHEMA,
    }),
    methodDescriptor({
        id: 'knowledge.job.run',
        title: 'Run Knowledge Job',
        description: 'Queue or run a structured knowledge maintenance job.',
        category: 'knowledge',
        scopes: ['write:knowledge'],
        access: 'admin',
        http: { method: 'POST', path: '/api/knowledge/jobs/{jobId}/run' },
        events: [runtimeEventId('knowledge')],
        inputSchema: KNOWLEDGE_JOB_RUN_REQUEST_SCHEMA,
        outputSchema: KNOWLEDGE_JOB_RUN_OUTPUT_SCHEMA,
    }),
    methodDescriptor({
        id: 'knowledge.lint',
        title: 'Lint Structured Knowledge',
        description: 'Run deterministic knowledge lint checks and return the current issues.',
        category: 'knowledge',
        scopes: ['write:knowledge'],
        access: 'admin',
        http: { method: 'POST', path: '/api/knowledge/lint' },
        inputSchema: EMPTY_OBJECT_SCHEMA,
        outputSchema: KNOWLEDGE_LINT_OUTPUT_SCHEMA,
    }),
    methodDescriptor({
        id: 'knowledge.reindex',
        title: 'Reindex Structured Knowledge',
        description: 'Rebuild derived knowledge relations and sync reviewed memory into the structured knowledge store.',
        category: 'knowledge',
        scopes: ['write:knowledge'],
        access: 'admin',
        http: { method: 'POST', path: '/api/knowledge/reindex' },
        inputSchema: EMPTY_OBJECT_SCHEMA,
        outputSchema: KNOWLEDGE_REINDEX_OUTPUT_SCHEMA,
    }),
    methodDescriptor({
        id: 'knowledge.projections.list',
        title: 'List Knowledge Projections',
        description: 'Return renderable markdown/wiki projection targets for the knowledge domain.',
        category: 'knowledge',
        scopes: ['read:knowledge'],
        http: { method: 'GET', path: '/api/knowledge/projections' },
        inputSchema: objectSchema({ limit: NUMBER_SCHEMA }),
        outputSchema: KNOWLEDGE_PROJECTION_TARGETS_OUTPUT_SCHEMA,
    }),
    methodDescriptor({
        id: 'knowledge.map',
        title: 'Map Knowledge Graph',
        description: 'Return a deterministic visual map of structured knowledge nodes, sources, edges, and optional issues.',
        category: 'knowledge',
        scopes: ['read:knowledge'],
        http: { method: 'GET', path: '/api/knowledge/map' },
        inputSchema: objectSchema({
            limit: NUMBER_SCHEMA,
            ...KNOWLEDGE_SPACE_INPUT_FIELDS,
            includeSources: BOOLEAN_SCHEMA,
            includeIssues: BOOLEAN_SCHEMA,
            includeGenerated: BOOLEAN_SCHEMA,
            query: STRING_SCHEMA,
            recordKinds: STRING_LIST_SCHEMA,
            ids: STRING_LIST_SCHEMA,
            linkedToIds: STRING_LIST_SCHEMA,
            nodeKinds: STRING_LIST_SCHEMA,
            sourceTypes: STRING_LIST_SCHEMA,
            sourceStatuses: STRING_LIST_SCHEMA,
            nodeStatuses: STRING_LIST_SCHEMA,
            issueCodes: STRING_LIST_SCHEMA,
            issueStatuses: STRING_LIST_SCHEMA,
            issueSeverities: STRING_LIST_SCHEMA,
            edgeRelations: STRING_LIST_SCHEMA,
            tags: STRING_LIST_SCHEMA,
            minConfidence: NUMBER_SCHEMA,
        }),
        outputSchema: KNOWLEDGE_MAP_OUTPUT_SCHEMA,
    }),
    methodDescriptor({
        id: 'knowledge.projection.render',
        title: 'Render Knowledge Projection',
        description: 'Render a markdown/wiki projection from the canonical structured knowledge store.',
        category: 'knowledge',
        scopes: ['read:knowledge'],
        http: { method: 'POST', path: '/api/knowledge/projections/render' },
        inputSchema: bodyEnvelopeSchema({
            kind: STRING_SCHEMA,
            id: STRING_SCHEMA,
            limit: NUMBER_SCHEMA,
            ...KNOWLEDGE_SPACE_INPUT_FIELDS,
        }, ['kind']),
        outputSchema: KNOWLEDGE_PROJECTION_BUNDLE_SCHEMA,
    }),
    methodDescriptor({
        id: 'knowledge.projection.materialize',
        title: 'Materialize Knowledge Projection',
        description: 'Render and persist a markdown/wiki projection as a derived artifact.',
        category: 'knowledge',
        scopes: ['write:knowledge'],
        access: 'admin',
        http: { method: 'POST', path: '/api/knowledge/projections/materialize' },
        inputSchema: bodyEnvelopeSchema({
            kind: STRING_SCHEMA,
            id: STRING_SCHEMA,
            limit: NUMBER_SCHEMA,
            ...KNOWLEDGE_SPACE_INPUT_FIELDS,
        }, ['kind']),
        outputSchema: KNOWLEDGE_MATERIALIZED_PROJECTION_SCHEMA,
    }),
    methodDescriptor({
        id: 'knowledge.graphql.schema',
        title: 'Knowledge GraphQL Schema',
        description: 'Return the SDL for the dedicated knowledge GraphQL endpoint.',
        category: 'knowledge',
        scopes: ['read:knowledge'],
        http: { method: 'GET', path: '/api/knowledge/graphql/schema' },
        inputSchema: EMPTY_OBJECT_SCHEMA,
        outputSchema: KNOWLEDGE_GRAPHQL_SCHEMA_OUTPUT_SCHEMA,
    }),
    methodDescriptor({
        id: 'knowledge.graphql.execute',
        title: 'Execute Knowledge GraphQL',
        description: 'Execute a GraphQL query or mutation against the dedicated knowledge domain endpoint.',
        category: 'knowledge',
        scopes: ['read:knowledge'],
        http: { method: 'POST', path: '/api/knowledge/graphql' },
        inputSchema: bodyEnvelopeSchema({
            query: STRING_SCHEMA,
            operationName: STRING_SCHEMA,
            variables: GRAPHQL_VARIABLES_SCHEMA,
        }, ['query']),
        outputSchema: KNOWLEDGE_GRAPHQL_EXECUTE_OUTPUT_SCHEMA,
    }),
    methodDescriptor({
        id: 'projectPlanning.status',
        title: 'Project Planning Status',
        description: 'Return passive, project-scoped planning artifact counts and SDK capabilities without starting a planning loop.',
        category: 'knowledge',
        scopes: ['read:knowledge'],
        http: { method: 'GET', path: '/api/projects/planning/status' },
        inputSchema: PROJECT_PLANNING_SPACE_INPUT_SCHEMA,
        outputSchema: PROJECT_PLANNING_STATUS_SCHEMA,
    }),
    methodDescriptor({
        id: 'projectPlanning.state.get',
        title: 'Get Project Planning State',
        description: 'Return the current project-scoped planning state artifact. The TUI owns the active conversation loop.',
        category: 'knowledge',
        scopes: ['read:knowledge'],
        http: { method: 'GET', path: '/api/projects/planning/state' },
        inputSchema: objectSchema({ projectId: STRING_SCHEMA, knowledgeSpaceId: STRING_SCHEMA, planningId: STRING_SCHEMA }),
        outputSchema: PROJECT_PLANNING_STATE_OUTPUT_SCHEMA,
    }),
    methodDescriptor({
        id: 'projectPlanning.state.upsert',
        title: 'Upsert Project Planning State',
        description: 'Persist project-scoped planning state from the TUI interview loop and evaluate readiness.',
        category: 'knowledge',
        access: 'admin',
        scopes: ['write:knowledge'],
        http: { method: 'POST', path: '/api/projects/planning/state' },
        inputSchema: bodyEnvelopeSchema({
            projectId: STRING_SCHEMA,
            knowledgeSpaceId: STRING_SCHEMA,
            state: JSON_RECORD_SCHEMA,
        }, ['state']),
        outputSchema: PROJECT_PLANNING_STATE_OUTPUT_SCHEMA,
    }),
    methodDescriptor({
        id: 'projectPlanning.evaluate',
        title: 'Evaluate Project Planning Readiness',
        description: 'Validate planning state and return gaps/next-question hints without mutating state or driving conversation.',
        category: 'knowledge',
        scopes: ['read:knowledge'],
        http: { method: 'POST', path: '/api/projects/planning/evaluate' },
        inputSchema: bodyEnvelopeSchema({
            projectId: STRING_SCHEMA,
            knowledgeSpaceId: STRING_SCHEMA,
            planningId: STRING_SCHEMA,
            state: JSON_RECORD_SCHEMA,
        }),
        outputSchema: PROJECT_PLANNING_EVALUATION_SCHEMA,
    }),
    methodDescriptor({
        id: 'projectPlanning.decisions.list',
        title: 'List Project Decisions',
        description: 'Return durable decision records from the current project planning knowledge space.',
        category: 'knowledge',
        scopes: ['read:knowledge'],
        http: { method: 'GET', path: '/api/projects/planning/decisions' },
        inputSchema: PROJECT_PLANNING_SPACE_INPUT_SCHEMA,
        outputSchema: PROJECT_PLANNING_DECISIONS_OUTPUT_SCHEMA,
    }),
    methodDescriptor({
        id: 'projectPlanning.decisions.record',
        title: 'Record Project Decision',
        description: 'Persist a meaningful project decision record for future TUI and agent context.',
        category: 'knowledge',
        access: 'admin',
        scopes: ['write:knowledge'],
        http: { method: 'POST', path: '/api/projects/planning/decisions' },
        inputSchema: bodyEnvelopeSchema({
            projectId: STRING_SCHEMA,
            knowledgeSpaceId: STRING_SCHEMA,
            decision: JSON_RECORD_SCHEMA,
        }, ['decision']),
        outputSchema: PROJECT_PLANNING_DECISION_OUTPUT_SCHEMA,
    }),
    methodDescriptor({
        id: 'projectPlanning.language.get',
        title: 'Get Project Language',
        description: 'Return canonical project vocabulary and resolved ambiguity records from the project knowledge space.',
        category: 'knowledge',
        scopes: ['read:knowledge'],
        http: { method: 'GET', path: '/api/projects/planning/language' },
        inputSchema: PROJECT_PLANNING_SPACE_INPUT_SCHEMA,
        outputSchema: PROJECT_PLANNING_LANGUAGE_OUTPUT_SCHEMA,
    }),
    methodDescriptor({
        id: 'projectPlanning.language.upsert',
        title: 'Upsert Project Language',
        description: 'Persist project vocabulary and ambiguity-resolution records without changing any live daemon session behavior.',
        category: 'knowledge',
        access: 'admin',
        scopes: ['write:knowledge'],
        http: { method: 'POST', path: '/api/projects/planning/language' },
        inputSchema: bodyEnvelopeSchema({
            projectId: STRING_SCHEMA,
            knowledgeSpaceId: STRING_SCHEMA,
            language: JSON_RECORD_SCHEMA,
        }, ['language']),
        outputSchema: PROJECT_PLANNING_LANGUAGE_OUTPUT_SCHEMA,
    }),
    ...builtinGatewayHomeGraphMethodDescriptors,
];
