web/website/integrations/osticket/dev-jarvis-policy.php
2026-11-27 23:43:05 +00:00

110 lines
12 KiB
PHP
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

<?php
// Request planning only. No issuance secret, executor, SQL or domain writes here.
function dune_jarvis_routes() {
return ['existing'=>'Execute an existing J.A.R.V.I.S. action','idea'=>'New feature / future idea','capability'=>'New key / J.A.R.V.I.S. action proposal','code'=>'Code / interface change','devkey'=>'Dev key request'];
}
function dune_jarvis_catalogue() {
$path=__DIR__.'/dev-jarvis-catalogue.json';
if(!is_file($path))return ['actions'=>[],'sourceHash'=>'unavailable'];
$data=json_decode(file_get_contents($path),true);
return is_array($data)&&isset($data['actions'],$data['sourceHash'])?$data:['actions'=>[],'sourceHash'=>'unavailable'];
}
function dune_jarvis_fields() {
return [
'title'=>['Request title',true,160,'input','A short, specific outcome'],
'workflow'=>['Execution route',true,40,'route',dune_jarvis_routes()],
'type'=>['Request category',true,40,'select',['Feature','Bug','Design / artwork','Operations','Documentation','Release / verification']],
'system'=>['System / component',true,120,'input','Website, Support, Shop, Minecraft, clan, company or server'],
'environment'=>['Target environment',true,40,'choice',['proposal'=>'Not decided — proposal only','test'=>'Test','staging'=>'Staging','production'=>'Production']],
'action_id'=>['Existing mastertemplate / action',false,80,'action',[]],
'catalogue_review'=>['Catalogue review / why the normal action is insufficient',false,2000,'textarea','Which existing actions were checked? Explain the specific gap; do not bypass them.'],
'targets'=>['Target users / organisations / records',true,2000,'textarea','For an operation: exact account names and record references. For an idea: intended users or audience; technical IDs are not required.'],
'objective'=>['Objective / full request',true,12000,'textarea','What must change, and why? Describe the requested outcome, not arbitrary executable code.'],
'current'=>['Current behaviour / context',true,6000,'textarea','What happens now? Include the relevant page, command or version.'],
'expected'=>['Expected result',true,6000,'textarea','Describe the finished result from the user’s point of view.'],
'acceptance'=>['Acceptance criteria / execution evidence',true,6000,'textarea','Observable before/after checks, expected result and the receipt or audit evidence needed to close this request.'],
'scope'=>['Scope and exclusions',true,4000,'textarea','Exact approved scope. What must remain untouched?'],
'preserve'=>['Records / behaviour that must be preserved',true,3000,'textarea','Protected organisations, members, balances, votes, uploads and unrelated records. Use None only when appropriate.'],
'missing_capability'=>['Proposed key / action and what it should allow',false,3000,'textarea','Describe the desired ability in plain language. You do not need to know how an adapter is implemented.'],
'dev_actor'=>['Requested developer executor',false,120,'input','Developer account or operator to review; this field does not grant authority.'],
'dev_actions'=>['Exact requested developer manifest / operations',false,6000,'textarea','List the exact actions and target IDs. The developer must create and independently validate the final manifest before issuance.'],
'dev_expiry'=>['Requested devkey lifetime in minutes (1–15)',false,2,'number','10'],
'destructive_actions'=>['Irreversible / destructive effects',false,3000,'textarea','Explicitly list deletions, resets or wipes and their exact boundaries. Write None if there are no destructive effects.'],
'risk'=>['Data, rollout and rollback considerations',false,4000,'textarea','Backup or restore plan, recovery limitations and service impact. A devkey request must include this.'],
'reproduction'=>['Reproduction steps / error messages',false,6000,'textarea','For bugs: steps, exact error, client and server versions.'],
'testplan'=>['Suggested tests',false,4000,'textarea','Positive and failure cases, preserved records, repeated requests and relevant devices.'],
'references'=>['Links / related tickets / receipts',false,4000,'textarea','Relevant HTTPS pages, source paths, ticket IDs or existing audit references. Never paste a key or credentials.'],
'dependencies'=>['Dependencies / related tasks',false,3000,'textarea','What must be ready first? Who can clarify the request?'],
'priority'=>['Requested priority',true,40,'select',['Medium','Low','High']],
'timing'=>['Desired timing / reason',false,500,'input','A request, not a guaranteed deadline'],
];
}
function dune_jarvis_request_validate($input) {
$values=[];$errors=[];$definitions=dune_jarvis_fields();
foreach($definitions as$key=>[$label,$required,$max,$type,$hint]) {
$value=is_string($input[$key]??null)?trim($input[$key]):'';
if(($required&&$value==='')||!dune_dev_text_valid($value,0,$max)||(isset($input[$key])&&!is_string($input[$key])))$errors[]=$label.': enter a valid value (maximum '.$max.' characters).';
if(in_array($type,['route','choice'],true)&&!array_key_exists($value,$hint))$errors[]=$label.': choose a listed option.';
if($type==='select'&&!in_array($value,$hint,true))$errors[]=$label.': choose a listed option.';
$values[$key]=$value;
}
$route=$values['workflow'];$catalogue=dune_jarvis_catalogue();$action=null;$parameters=[];
foreach($catalogue['actions']as$item)if($item['id']===$values['action_id'])$action=$item;
if($route==='existing'){
if(!$action)$errors[]='Choose an existing action from the current Jarvis catalogue.';
$submitted=$input['jarvis_values']??[];
if(!is_array($submitted)){$errors[]='Action fields must be a structured form.';$submitted=[];}
$allowed=array_column($action['fields']??[],'name');
foreach(array_keys($submitted)as$name)if(!in_array($name,$allowed,true))$errors[]='Unknown action parameter.';
foreach($action['fields']??[]as$field){
$name=$field['name'];$value=$submitted[$name]??'';$label=$field['label'];
if(!is_string($value)||!dune_dev_text_valid($value,0,$field['maxLength']??240)){$errors[]='Invalid action field: '.$label;continue;}
$value=trim($value);if(($field['required']??false)&&$value===''){$errors[]=$label.' is required.';continue;}
if($value===''&&!($field['required']??false))continue;
if(($field['type']??'text')==='number'){
if(!preg_match('/^-?[0-9]+$/D',$value)||filter_var($value,FILTER_VALIDATE_INT)===false||(int)$value<($field['min']??0)||abs((float)$value)>9007199254740991){$errors[]='Invalid action field: '.$label;continue;}
$value=(int)$value;
}
$parameters[$name]=$value;
}
}else{
// Never accept a hidden ordinary-action payload as developer authority.
$values['action_id']='';
if(!empty($input['jarvis_values']))$errors[]='Action parameters do not belong to the selected route.';
if(in_array($route,['idea','capability'],true)&&$values['catalogue_review']==='')$values['catalogue_review']='Not yet reviewed — reviewer must check the existing catalogue before implementation.';
if(!dune_dev_text_valid($values['catalogue_review'],10,2000))$errors[]='Explain which normal Jarvis actions were checked, or state that catalogue review is needed.';
}
if($values['environment']==='proposal'&&!in_array($route,['idea','capability'],true))$errors[]='Choose a concrete environment for an operation or developer request.';
if($route==='capability'&&!dune_dev_text_valid($values['missing_capability'],10,3000))$errors[]='Describe the missing Jarvis adapter or capability.';
if($route==='devkey'){
foreach(['dev_actor','dev_actions','destructive_actions','risk']as$key)if(!dune_dev_text_valid($values[$key],$key==='dev_actor'?1:4,$definitions[$key][2]))$errors[]=$definitions[$key][0].' is required for a dev key request.';
if(!preg_match('/^(?:[1-9]|1[0-5])$/D',$values['dev_expiry']))$errors[]='A developer key lifetime must be 1–15 minutes.';
if(($input['dev_acknowledgement']??'')!=='1')$errors[]='Acknowledge that this requests review only; developer issuance and execution remain separately controlled.';
}else{
foreach(['dev_actor','dev_actions','dev_expiry','destructive_actions']as$key){if($values[$key]!=='')$errors[]='Choose Dev key request for developer-only request fields.';$values[$key]='';}
}
if(($input['privacy']??'')!=='1')$errors[]='Confirm that the request contains no passwords, tokens or unnecessary personal data.';
$values['jarvis_request_version']=1;
$values['action_parameters']=json_encode((object)$parameters,JSON_UNESCAPED_SLASHES|JSON_UNESCAPED_UNICODE|JSON_THROW_ON_ERROR);
$values['action_template_version']=$action&&$route==='existing'?(int)$action['version']:null;
$values['catalogue_source_hash']=$catalogue['sourceHash'];
$values['execution_state']='requested';
return [$values,array_values(array_unique($errors))];
}
function dune_jarvis_execution_brief($values) {
$route=$values['workflow']??'';
if(!isset(dune_jarvis_routes()[$route]))return "Legacy request — manual Jarvis review required. The original request is retained. Do not infer permission to code, issue keys or execute data operations from this legacy brief.";
$steps=[
'existing'=>"1. Recheck the current catalogue, identity, action scope and domain conditions.\n2. Use the existing validated domain adapter with the recorded typed parameters. Do not write code or direct SQL for a supported data operation. Select an available supported interface before starting; lack of browser control is not missing domain authority.\n3. Obtain any required normal scoped key through its existing flow; execute once and record the real receipt. If the adapter is unavailable, stop and report the exact missing capability.",
'idea'=>"1. Treat this as a feature proposal, not an instruction to execute a data operation.\n2. Review the desired outcome and existing Jarvis capabilities; staff need not know technical adapter names.\n3. Clarify feasibility and acceptance criteria during review. Agree the implementation scope before building or issuing any key.",
'capability'=>"1. Confirm the gap against the current masterkey catalogue and domain adapters.\n2. Implement only the smallest missing typed action; register it, test it and publish through Git/CI.\n3. Then execute the original request through the normal Jarvis action, with current authority and scope checks.",
'code'=>"1. Confirm this is an implementation change rather than an already supported data action.\n2. Make the smallest approved source change; reuse existing adapters and permissions.\n3. Run focused checks and required CI, then verify publication. Do not treat deployed code as proof a requested data operation ran.",
'devkey'=>"1. Treat this ticket as a DEV KEY REQUEST, never as an ordinary web key or an instruction to modify the database directly.\n2. Recheck why normal scoped Jarvis actions are insufficient. An authorised developer must independently validate the exact manifest, actor, environment, preservation rules, destructive effects and short lifetime.\n3. Developer issuance remains server/CLI-only. Ticket approval is not a key, not a grant of developer authority and not evidence of execution.\n4. Execute only through the separately permitted developer executor, bound to the exact manifest and current authorised actor. Record issuance/hash and execution results without any secret. Stop if the manifest, scope, environment or authority changes."
];
$parts=['J.A.R.V.I.S. REQUEST v1 — '.dune_jarvis_routes()[$route],"State: REQUESTED / NOT EXECUTED. Ticket approval does not execute an operation.","Execution route\n".$steps[$route]];
foreach(dune_jarvis_fields()as$key=>[$label])if(($values[$key]??'')!=='')$parts[]=$label."\n".$values[$key];
if($route==='existing')$parts[]="Recorded action template version: ".($values['action_template_version']??'unknown')."\nTyped action parameters:\n".($values['action_parameters']??'{}');
$parts[]='Language: use English for new user-facing text, documentation, ticket updates and completion reports. Preserve proper names and original quotations when needed.';
$parts[]='Completion requires actual results, preserved-record checks and an audit/receipt reference. Clearly distinguish planned, simulated, staged, deployed and executed. Never include a secret key in ticket text or attachments.';
return implode("\n\n",$parts);
}